Skip to content

Move Cosmos images between peer GPUs with CUDA IPC - #8461

Closed
temiroff wants to merge 119 commits into
isaac-sim:exp/cosmosfrom
temiroff:atemirov/cosmos-gpu-peer
Closed

temiroff wants to merge 119 commits into
isaac-sim:exp/cosmosfrom
temiroff:atemirov/cosmos-gpu-peer

Conversation

@temiroff

@temiroff temiroff commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Let the Cosmos service run on a different GPU from Isaac Lab on the same machine while images still move GPU to GPU, over NVLink or PCIe peer access, without host copies.

Depends on #8411.

Today CUDA IPC needs the service on the camera's GPU. A service on another GPU falls back to the socket, which copies images through host memory.

  • Keep Cosmos images on the GPU with CUDA IPC and serve on a private Unix socket #8410 already has each process create the buffer it writes and the event it records: the camera control and control_ready, the service output and output_ready. CUDA records an event only on the device that created it, so that split is what lets the GPUs differ. Each process now maps the other's buffer on the GPU that holds it and imports the other's event on its own GPU, whose stream waits for it; waiting on an event imported on the other GPU crashed the driver. Reading the other process's buffer is one peer copy; on a single GPU the service still reads controls in place.
  • Transport selection finds the service's GPU by PCI bus ID and requires peer access in both directions (cuDeviceCanAccessPeer), instead of the same GPU. The service checks the camera's GPU the same way and rejects one it cannot see or access directly, so a CUDA IPC session never stages copies through host memory. cuda_ipc fails instead of falling back; auto falls back to the socket.
  • Docs: "Cosmos on another GPU", with --device cuda:1 for the service and both GPUs visible to both processes. auto falls back to the socket when this process cannot use the service's GPU; if the service cannot see the camera's GPU, the session is rejected even with auto.
uv run --no-sync isaaclab-cosmos-server --checkpoint "$COSMOS_CHECKPOINT" --device cuda:1

Then train as usual on cuda:0, with env.cosmos.transport=cuda_ipc to require GPU-to-GPU transfer.

Review _cuda_ipc.py (SharedChannel, device_by_bus_id, can_access_peer), then the open handshake and close order in cosmos_model.py and service.py.

Compatibility

The protocol and same-GPU sessions are unchanged. Both processes must see both GPUs: CUDA_VISIBLE_DEVICES must not hide the other GPU. Each process creates a CUDA context on the other GPU, about 0.4 GB in our test. MIG instances have no peer access to each other. The peer round-trip test parametrizes the service's GPU over the run's test devices, so ISAACLAB_TEST_DEVICES=111 (CPU, cuda:0, cuda:1) runs the peer case; the default run covers the same GPU.

Validation

The GPU runs below were measured before the Cosmos options moved from command-line flags to configuration overrides and apply_cosmos arguments, and have not been repeated. The rewritten unit tests (test_cosmos_any_task.py and the Cosmos sensor and Shadow Hand tests) pass on Windows. A Linux run of the whole stack with the real model (two 48 GB MIG slices) trained the Shadow Hand task before the latest review changes; it is being repeated on the final commits.

Two NVIDIA L40 GPUs with PCIe peer access in both directions (no NVLink), driver R570 with the CUDA 13 forward-compatibility library. Isaac Lab on Python 3.12 and Torch 2.12, the service on Python 3.13 and Torch 2.10.

  • Unit tests, each Cosmos test file in its own process: 126 passed, none skipped. Events are imported on the waiting GPU, which cuStreamWaitEvent requires.
  • Nsight Systems, 41 frames at 640×640 with a stand-in model: cuda_ipc moved 100.8 MB peer-to-peer with no host image copies; socket moved 100.8 MB each of device-to-host and host-to-device.
  • Shadow Hand training, one environment, three iterations, Isaac Lab on GPU 0. Service on GPU 1: 65.9 s with cuda_ipc, 76.4 s with socket. Service on GPU 0 with cuda_ipc: 61.2 s. These are short runs, not a benchmark. Nsight of the training process shows the images moving peer-to-peer with cuda_ipc, and through host memory in both directions with socket.

At the top of the stack: test_cosmos.py 55 passed, none skipped, with ISAACLAB_TEST_DEVICES=111, including the round trip with the service on cuda:0 and on cuda:1. Shadow Hand training, one environment, service on GPU 1 over cuda_ipc: three iterations of 18.5, 25.6, and 18.6 s. No GPU processes remained.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

…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>
…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>
Putting Cosmos on a task needed a task-specific preset. Now:

- --cosmos on isaaclab train and play puts Cosmos on the task's rgb camera
  with --cosmos_prompt (repeat for a list), --cosmos_camera,
  --cosmos_control depth/edge/blur, --cosmos_near/--cosmos_far,
  --cosmos_endpoint, and --cosmos_transport. --num_envs N batches the
  environments' cameras on a service started with --max-views N.
- apply_cosmos and cosmos_camera render the camera at the Cosmos canvas
  with the same aspect ratio and view, and center_crop_resize returns the
  generated image to the camera's size, so observations keep their shape.
  The camera captures every few steps when an episode would exceed the
  service's episode cap.
- The Manager-based Shadow Hand camera task gets the cosmos preset of the
  Direct task.

Signed-off-by: Alexander Temirov <atemirov@nvidia.com>
The feature extractor held each generated image's pose target by counting
captures 1, 5, 9, which only matches when every view starts its episode
together. Batched Cosmos views share one chunk cadence, so a view that resets
mid-chunk shows black and then updates off that count. Hold each view's target
until its image changes instead, leave black views out of the loss, and drop
the one-environment check so both presets accept --num_envs and one
--cosmos_prompt per environment.
Independent resets shift each environment's capture times, and every capture
runs the Cosmos step for all views, so a camera slower than the environment
step queued extra frames and ran views past their episode budget. Reject that
combination in apply_cosmos and the Shadow Hand presets, and document the
multi-environment setup: server without warmup and a smaller history window
on 48 GB, per-step Shadow Hand captures, and recording every environment
through the Newton GL streaming view.
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.
The image transfer modifier now queues controls only for the views each
capture covers, so cameras slower than the environment step batch several
environments correctly. Remove the guard, keep the Shadow Hand presets at
their 10 Hz camera, and document recording every environment.
# Conflicts:
#	source/isaaclab_tasks/changelog.d/cosmos-session-settings.fixed.rst
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 19, 2026
@temiroff

Copy link
Copy Markdown
Contributor Author

Closing: the exp/cosmos branch is no longer used. Cosmos Transfer is now proposed on main in #8898.

@temiroff temiroff closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant