Repository navigation
Conversation
…ervice The Cosmos service served one camera view with fixed settings. It now: - batches up to --max-views camera views in one session, each with its own prompt, seed, VAE caches, and generation history; views reset on their own on the compiled runtime, and all together on the eager one; - accepts a list of prompts, cycled per episode for one view and assigned per view for several; a reset may bring the next episode's prompt; - takes its episode cap from --max-episode-frames (default 201, 0 for none); - uses the Sim-Transfer recipe's history window (--kv-window 30, --attention-sink 3) and its prompts as given, without an appended instruction to follow the control; - adds the blur control, filtered in the service by the Framework's own augmentor with the recipe's medium preset. The image transfer modifier lets a view that resets mid-chunk join the next chunk with its newest control, so all views keep one cadence. Signed-off-by: Alexander Temirov <atemirov@nvidia.com>
Address review follow-ups on the batched service: - Warmup ran 33 frames, which filled the old 8-latent window but not the default 30, leaving the full-history path to the first real episode. It now runs 1 + 4 * kv_window frames (121 by default), within the episode cap. - A closed batch stream keeps no references to its views' VAE caches. - Only the batch tests that need the CUDA device skip without one; the prompt merging and warmup tests run on CPU machines. Signed-off-by: Alexander Temirov <atemirov@nvidia.com>
4910fd1 to
e3eff97
Compare
e3eff97 to
1349d46
Compare
…ix socket Every Cosmos step copied the camera's controls to the host, sent them over TCP, and copied the generated images back, with the service listening on a TCP port. - CUDA IPC transport: on the same Linux machine and GPU, the camera shares GPU buffers with the service once per session, one row per view, and interprocess CUDA events order each step; only a small message goes over the endpoint. The model accepts CUDA tensors for this path. CosmosModelCfg.transport selects auto (default), cuda_ipc, or socket. - Unix socket endpoints: the service and cameras default to /tmp/isaaclab-cosmos-<uid>.sock on Linux, owner-only, with no network port; tcp://host:port remains for other machines. The server takes --endpoint instead of --host and --port. - Small messages leave in one write with TCP_NODELAY, so they no longer wait 40 ms for a delayed acknowledgment, and a connection failure names the endpoint. Signed-off-by: Alexander Temirov <atemirov@nvidia.com>
1349d46 to
dbd6c8c
Compare
After independent resets, environments with a camera slower than the environment step capture at different steps, but each capture ran the modifier for every view, queueing the skipped views' stale renders as new frames and exhausting their episode budget. Read the owning sensor's capture mask and queue a control only for the views it covers.
Each session already requests its own frame budget, which also tells the model the episode's duration. The optional --max-episode-frames cap only added a second number to configure; drop it and its status field.
… after the other releases it The camera allocates the control buffer and event, the service the output buffer and event, so neither process writes memory the other can free. CUDA leaves freeing memory another process still has open undefined: the camera frees its controls only after the service confirms the close and otherwise keeps them until it exits, and after a failure the service frees its output once the camera disconnects. An idle session's next request now receives an error instead of waiting on a closed session.
A probe that times out or is refused permission can meet a running service; unlinking its file would strand it and let a second service take the endpoint.
…ervice (#8409) ## Description Let one resident Cosmos service generate several environments together while keeping each view's episode state separate. **Stack 1/3: service. Review and merge this PR first, then #8410 (transport), then #8411 (camera integration).** This PR builds on #8393 and can be reviewed and merged independently of the two drafts. Its Files changed tab shows only this PR's changes against `exp/cosmos`. - Each session requests its view count when it opens; the server needs no view setting. Each view has its own seed, history, and VAE caches. Independent resets require the compiled runtime; eager inference resets all views together. - Prompt lists cycle per episode with one environment. With several environments, each gets a prompt that stays fixed across its resets. - Each session requests its own episode frame budget, which also tells the model the clip's duration. The server sets no episode length limit; #8393's fixed limit is removed. `episode_frame_budget` computes the budget from the episode length and the camera's update period, counting steps as the environment does; the Shadow Hand preset and, in #8411, `--cosmos` use it. - The Sim-Transfer defaults are a 30-latent history window and 3 attention sinks. Prompts are sent as written. Blur control uses the Framework's medium blur filter. `CosmosModelCfg.modality` defaults to `"depth"`. - Fixes in the shared image-transfer modifier: a view resetting mid-chunk stays in step with the others, and a capture queues controls only for the views it covers, since environments that reset independently capture at different steps. Warmup fills the configured history window. Per-view caches are initialized once; iterator creation no longer resets them or allocates them again. Review the service/model adapter first, then the camera client's prompt handling and the shared image-transfer fixes. CUDA IPC and the training CLI belong to the next PRs. ## Compatibility One view remains the default. Protocol version 2 is required. The default history window changes from 8 to 30, and the service stops appending a control instruction to prompts. These settings can change memory use and generated appearance. `CosmosModelCfg.modality` now defaults to `"depth"` (was `"edge"`). `CosmosModelCfg.max_episode_frames` no longer has a default: the Shadow Hand preset derives it with the new public `episode_frame_budget`, and hand-written camera chains must set it. `status` no longer reports `max_episode_frames`. ## Validation On Linux with two NVIDIA L40 GPUs, at the top of the stack (#8462, which contains this PR), each file in its own process: - `test_cosmos_batch_stream.py`: 11 passed — per-view adapter behavior, restart seeds reaching generation, cache release, blur controls, and warmup. - `test_image_transfer.py`: 9 passed — publication and reset cadence, including per-capture queueing. - `test_shadow_hand_camera_presets.py`: 37 passed — including the derived frame budgets. - `test_cosmos.py`: 55 passed; it also holds the later PRs' tests. No failures or skips. Shadow Hand training with the real model, one and two environments, completed three iterations each on the same stack. The cache test checks that tensors are released while the closed stream and resident model stay alive. Disabling the adapter's cleanup makes it fail. The configurable warmup case remains because it catches a hard-coded default window. These tests cover this repository's integration with a stand-in Framework; they do not validate the upstream model or image quality. Formatting/lint and the changelog gate passed. <details> <summary>Earlier model measurements (not rerun)</summary> Measured before the split on Linux, RTX PRO 6000 Blackwell MIG 2g.48gb, compiled, 640 x 640; these benchmarks were not rerun for this update: - At `--kv-window 8`, one view took 917 ms per step and two took 1596 ms (1.15x throughput), with 39.7 GiB peak memory. - Batched views versus separate runs: 40–45 dB early in an episode; a restarted view versus a fresh episode: 42–36 dB. - One view at window/sink 8/3: 923 ms and 36.0 GiB; at 30/3: 1006 ms and 40.9 GiB. Two views at 30/3 did not fit in 48 GB. </details> ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `uv run isaaclab --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have validated the changed behavior with focused coverage and applied the [test-audit criteria](https://github.com/isaac-sim/IsaacLab/blob/develop/skills/developer/test-audit/SKILL.md) to any test changes - [x] I have added a changelog fragment under `source/<pkg>/changelog.d/` for every touched package - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Signed-off-by: Alexander Temirov <atemirov@nvidia.com>
|
| DEFAULT_ENDPOINT = ( | ||
| f"unix:///tmp/isaaclab-cosmos-{os.getuid()}.sock" if hasattr(socket, "AF_UNIX") else "tcp://127.0.0.1:5555" | ||
| ) |
There was a problem hiding this comment.
Cosmos imports fail on Windows
On supported Windows installations, Python exposes socket.AF_UNIX but not os.getuid. Computing DEFAULT_ENDPOINT therefore raises AttributeError when _protocol.py is imported, before users can select TCP. This breaks the Cosmos client and status command even with an explicit TCP endpoint. Choose the Linux default with an explicit platform check and keep TCP as the Windows default.
| if not camera_released: | ||
| # The camera may still have the output buffer open; it releases it before disconnecting. | ||
| _await_disconnect(connection) | ||
| state.executor.submit(channel.close).result() |
There was a problem hiding this comment.
_await_disconnect can return while the camera still has the output buffer open. Accepted sockets have a 600-second timeout, which the helper suppresses before cleanup calls channel.close() with peer_released=True. A paused camera can therefore keep its mapping after the service frees the memory, risking GPU errors or corrupted images.
Service shutdown also calls shutdown(SHUT_RDWR) locally, so the resulting end of reads does not confirm that the camera released the buffer. Return whether release was confirmed, and retain the service's allocation when it was not.
There was a problem hiding this comment.
Fixed in 6c5656a. _await_disconnect now returns whether the camera closed the connection. After an idle timeout or the service's own shutdown, the service keeps its output buffer until it exits (peer_released=False), as the camera already does with its control buffer. A connection that ends because the service is shutting down no longer counts as the camera's release either. The failure test now covers a camera disconnect, an idle timeout, and a service shutdown.
| except ConnectionRefusedError: | ||
| # Nothing listens on the file: a stopped service left it behind. | ||
| os.unlink(path) |
There was a problem hiding this comment.
Services replace each other's socket
Two services starting at the same Unix endpoint can replace each other's socket. After the first service binds but before it calls listen, the second service's probe gets ConnectionRefusedError and unlinks the first service's socket. Both can then load models, but the first listener is unreachable. Its unconditional exit cleanup can also unlink the replacement service's socket.
Protect the probe, replacement, bind, and listen sequence with a shared lock. During exit, only unlink the socket this service created.
There was a problem hiding this comment.
Isaac Lab Review Bot
Needs attention: Scope and over-engineering (2), Compatibility and deprecation (1), Implementation (1), Style consistency (1). Other reviewed categories look good.
- PR description: The scope matches, but validation and timings use downstream or pre-split revisions; report head-only tests and rerun baseline/head benchmarks with command, revisions, hardware/backend, views, warmup, and metric, or remove timings.
- Design and architecture: Architecture looks good.
- Scope and over-engineering: Minimal implementation: extend
_protocol.py, client, service, and_framework.py; keep_cuda_ipc.pyfor irreducible CUDA resource lifecycle, but delete the unused top-level export, scalar frame form, and echoed frame field. Suggested PR breakdown: (1) endpoints, compatibility, and docs; (2) TCP write/Nagle fix; (3) CUDA IPC negotiation, ownership, and focused tests. - API: API changes look good.
- Compatibility and deprecation: Breaking changes: documented
--host/--portandserve(host=..., port=...)are removed without deprecation; retain them for one cycle, map toendpoint, warn, document migration, and cover transition. - Implementation: The server only echoes client-supplied frame counts, so the client check proves nothing; remove the echoed field and retain empty-array validation.
- Style consistency:
_cuda_ipc.pyviolates the required public-before-private module ordering; regroup public functions and classes before private helpers and classes. - Test quality: Test quality looks good.
Significant concerns. Posted 5 inline findings.
Automated review; human maintainers own approval decisions.
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| __all__ = [ | ||
| "DEFAULT_ENDPOINT", |
There was a problem hiding this comment.
🟡 Warning · Scope Complexity — Unused public DEFAULT_ENDPOINT export
No client, server, configuration, or documentation consumer imports this through the package; every caller uses _protocol.DEFAULT_ENDPOINT. Delete both stub lines instead of committing to a new public symbol.
| _LAZY_PEER_ACCESS = 0x1 # CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS | ||
|
|
||
|
|
||
| class _Handle(ctypes.Structure): |
There was a problem hiding this comment.
🟡 Warning · Style Consistency — Module ignores public/private ordering
The guide prescribes constants, public functions, public classes, then private ones; here _Handle, _lib, _Context, _CudaArray, and _encode are interleaved with available, host_id, and the Shared* classes. Regroup them.
| self._channel.control_ready.record() | ||
| request["frames"] = frames | ||
| reply, generated = self._exchange(request) | ||
| if generated or reply.get("frames") != frames: |
There was a problem hiding this comment.
🟡 Warning · Implementation — Frame echo check can never fail
The service echoes metadata["frames"], which is the client's own list, so this comparison always passes and validates nothing. Drop the echoed field and keep only the empty-generated assertion.
There was a problem hiding this comment.
Removed the echoed field and its check in 6c5656a. The client still rejects images sent through the socket in a CUDA IPC session.
|
|
||
| def _channel_frames(frames: object, num_views: int) -> list[int]: | ||
| """Return one frame count per view of a CUDA IPC step; a single integer is the one-view form.""" | ||
| frames = [frames] if type(frames) is int else frames |
There was a problem hiding this comment.
🟡 Warning · Scope Complexity — Scalar frames form has no producer
The camera always sends one count per view as a list, so this coercion is unreachable and adds a second accepted wire shape to maintain. Require the list form.
There was a problem hiding this comment.
Removed in 6c5656a; the service now requires one count per view.
| parser.add_argument("--device", default="cuda:0") | ||
| parser.add_argument("--host", default="127.0.0.1") | ||
| parser.add_argument("--port", type=int, default=5555) | ||
| parser.add_argument( |
There was a problem hiding this comment.
🟡 Warning · Compatibility — Endpoint flag replaces host and port
--host/--port and serve(model, host=..., port=...) stop working immediately, and the docs previously documented both. Keep them accepted for one cycle, map them onto endpoint, and emit the established FutureWarning.
The service frees its output buffer only when the camera closes the connection; after an idle timeout or its own shutdown it keeps the buffer until it exits, as the camera keeps its control buffer. Also remove the frame-count echo, whose check could not fail, and the unused single-count form; drop the unused package-level DEFAULT_ENDPOINT export; default to TCP where os.getuid is unavailable; and on exit remove the Unix socket file only if it is still this service's.
|
|
||
|
|
||
| def _blur_controls(frames: np.ndarray) -> np.ndarray: | ||
| def _blur_controls(frames: np.ndarray | torch.Tensor) -> np.ndarray | torch.Tensor: |
There was a problem hiding this comment.
why do we need np.ndarray?
There was a problem hiding this comment.
Blur is already in the merged service (#8409). This PR only lets _blur_controls accept device tensors, so blur mode keeps working with CUDA IPC. The current checkpoint is depth-trained, so nothing in our demos uses blur today; it stays for the other Transfer modalities.
There was a problem hiding this comment.
Removed. The blur control was the only reason for this function, so it is gone along with the NumPy/tensor handling (ec5fc69).
There was a problem hiding this comment.
Socket transport uses NumPy. CUDA IPC uses tensors.
Blur is only used for the blur modality, which the depth-trained Sim-Transfer checkpoint does not use, and it is kept for the other Transfer modalities. Say that controls are arrays over the socket transport and device tensors over CUDA IPC, and that a device tensor makes a GPU to CPU to GPU round trip for the Framework filter.
|
Closing: the |
Description
Transfer Cosmos images between the camera and service through shared GPU buffers on the same Linux machine and GPU, and use a private local socket by default.
transport=autoselects IPC when the service'sstatusreports this machine's boot ID and the camera's GPU, otherwise socket transport, so a local endpoint tunneled to another machine uses the socket; explicitcuda_ipcfails clearly when unavailable.unix:///tmp/isaaclab-cosmos-<uid>.sock, owner-only (0600), without opening a network port. A socket file is replaced only when nothing listens on it; a live, busy, or inaccessible service is preserved. TCP remains available for remote use, such as through an SSH tunnel.TCP_NODELAYon both ends, removing the delayed-acknowledgment stall.localhost) can also use CUDA IPC.main, asmainalready does; the olddeveloplink returns 404 and failed the link check on every PR intoexp/cosmos.blurcontrol andblur_processor, which Batch Cosmos camera views and follow the Sim-Transfer recipe in the service #8409 added. Nothing uses it: the current Sim-Transfer checkpoint is depth-trained, and blur was the only control that made the service copy images between GPU and CPU.edgeandsegcontrols with their helpers, andCosmosModelCfg.modality, which the service never used. The service protocol becomes version 3.Review
_cuda_ipc.py(SharedChannel: ownership and release), then endpoint/protocol handling and the client/server handoff, including the release order in_releaseand the service's session cleanup. The service's batching and prompts are inherited from #8409.Compatibility
isaaclab-cosmos-server --host/--portbecomes--endpoint. Linux's default endpoint changes to the Unix socket; Windows retainstcp://127.0.0.1:5555. CUDA IPC requires the same Linux host and GPU. Socket image messages carry at most 16 views. IPC avoids that protocol limit; GPU memory still limits the batch size.Validation
Lint, format and the unit tests (on Windows) were rerun after the blur removal and the boot-ID change. The GPU runs below predate them; a Linux run of the whole stack with the real model (two 48 GB MIG slices) trained the Shadow Hand task over CUDA IPC before these last changes, and it is being repeated on the final commits.
On Linux with two NVIDIA L40 GPUs, at the top of the stack (#8462, which contains this PR):
test_cosmos.py55 passed, none skipped (ISAACLAB_TEST_DEVICES=111), including the Unix-socket lifecycle and the real CUDA IPC round trips. Shadow Hand training overcuda_ipcwith the real model completed three iterations; after a service was stopped mid-training, the other service ended its session, reported no active session, and accepted a new one.autouses the socket for a service that reports another machine's boot ID.Formatting/lint and the changelog gate passed. All tests belong to Isaac Lab's transport implementation, not the upstream model repository.
Earlier model measurements (not rerun)
Measured before the split on Linux, RTX PRO 6000 Blackwell MIG 2g.48gb; these benchmarks were not rerun for this update:
Checklist
pre-commitchecks withuv run isaaclab --formatsource/<pkg>/changelog.d/for every touched packageCONTRIBUTORS.mdor my name already exists there