Skip to content

Share one Cosmos session across several cameras - #8492

Closed
temiroff wants to merge 174 commits into
isaac-sim:exp/cosmosfrom
temiroff:atemirov/cosmos-multi-camera
Closed

temiroff wants to merge 174 commits into
isaac-sim:exp/cosmosfrom
temiroff:atemirov/cosmos-multi-camera

Conversation

@temiroff

@temiroff temiroff commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Let several cameras, such as a base and a wrist camera, share one Cosmos session, so a task with several cameras gets Cosmos images on all of them from one service.

Depends on #8462.

from isaaclab_experimental.cosmos import apply_cosmos

apply_cosmos(
    env_cfg,
    camera=["base_camera", "wrist_camera"],
    prompt=[
        "A KUKA arm with an Allegro hand turning a cube in a bright lab, seen from the side.",
        "A close-up of an Allegro hand turning a cube in a bright lab, seen from its wrist.",
    ],
)

Why one session: the Cosmos Framework allows one live generation session per loaded model (its history buffers come from a pool the model owns), so cameras on one service must be views of one batch. A batch needs one canvas; prompts, seeds, and output sizes can differ per view.

  • CosmosModelCfg.cameras names the cameras that share the session. Camera k's environment v is view k * num_envs + v, which selects its prompt (prompt[view % len(prompt)]). A camera's view takes its environment's seed, so an environment's cameras share it and reset together.
  • Each camera's modifier still queues its own controls. The first camera to complete its chunk reads the other cameras' data, which updates them (lazy sensor updates), so their modifiers add their chunks; the last one runs the batched step, and each camera publishes its own views. A camera that does not capture with the others stops the session with an error, and any failure closes the session for every camera.
  • apply_cosmos(camera=[...]) takes the names of the cameras to share the session, in order. The cameras render at the canvas closest to the first camera's aspect ratio, and each keeps its own output size through the existing center crop and resize. cosmos_camera takes the canvas to use. Cameras must have the same update period, no modifiers yet, and synchronous rendering; each camera is checked and named in the error, and none is changed if any fails.
  • With one environment, an environment's views reset together, which the eager runtime supports; with several environments, the service needs independent resets as before. Several services (Split Cosmos environments across several services, one per GPU #8462) split the views as they split environments.
  • Views of different cameras are generated independently, so they need not agree with each other (for example on colors or materials).
  • Docs: "Several cameras". It is set up in configuration code; no registered preset provides it yet. Each camera receives its own copy of the shared prompt, endpoint, and transport, and the cameras share a session only while the copies match.

Review cosmos_model.py first: _CameraGroup and _CameraStream, and open_stream routing to them. Then apply_cosmos.

Compatibility

One camera behaves as before: cameras defaults to empty, which gives each camera its own session. The protocol and the service are unchanged; the service sees an ordinary batched session of num_cameras * num_envs views, which needs GPU memory like as many environments.

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.

  • Unit tests: test_cosmos.py (two cameras of two environments sharing one 4-view session through a local service with a stand-in model: one session, view order, prompts, seeds, either camera completing its chunk first, a reset of one environment on both cameras; a camera missing a shared capture closing the session for both) and test_cosmos_any_task.py (both Kuka Allegro duo_camera cameras by name with a wider wrist camera, camera order, the independent-reset check, duplicate names, and synchronous rendering on every camera) passed on Windows; Unix socket and peer-GPU tests skipped there.
    On Linux at 2ff5c34 (RTX PRO 6000 Blackwell, one MIG 2g.48gb slice; Newton physics and renderer; the real Cosmos3-Nano-Sim-Transfer service, compiled, --kv-window 4):

  • Unit tests: 137 passed, none skipped, each file in its own process (test_cosmos.py, test_cosmos_batch_stream.py, test_cosmos_camera.py, test_image_transfer.py, test_shadow_hand_camera_presets.py, test_cosmos_any_task.py), including the Unix-socket tests and the CUDA IPC round trip on cuda:0. This slice has no second GPU, so the peer-GPU case was not parametrized.

  • Both cameras (the --cosmos_camera all flag at the time, now camera=["base_camera", "wrist_camera"]) on Isaac-Reorient-KukaAllegro-Camera with presets=cube,duo_camera,rgb64, one environment: the log reports Cosmos cameras base_camera, wrist_camera share one session of 2 views and CUDA IPC; 3 training iterations of 12.8, 11.6, and 11.6 s; peak memory 41.7 GiB for the simulator and service together; the service reported no active session afterwards.

  • Recordings of each camera (--video sensor:<camera>:rgb, 64 frames each) show generated color images, with no black or white frames: the base camera a table and wall, the wrist camera the hand in changing poses.

  • camera=["wrist_camera", "base_camera"] (repeated flags at the time) makes the wrist camera view 0 with the first prompt; one iteration completed.

  • Two environments of two cameras (4 views) did not fit this 48 GB slice: the second iteration failed in the VAE decoder with a PyTorch allocator assertion at 47.2 of 47.4 GiB, and the service recovered to idle. Four views need a larger GPU, or a split across services (Split Cosmos environments across several services, one per GPU #8462).

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
pbarejko pushed a commit that referenced this pull request Oct 20, 2026
## Description

Add a short README, `demos/cosmos3-transfer/README.md`, that shows how
to train the Shadow Hand camera task with Cosmos on its camera. It uses
only the built-in commands from `cosmos_service.md` and `cosmos.md`:
start `isaaclab-cosmos-server` in one terminal, then run `isaaclab train
... presets=cosmos` in another, with the prompts set by an ordinary
Isaac Lab override, `env.cosmos.prompt`, and each option explained. A
separate section records a clip of both environments without mid-episode
resets.

Depends on #8492 and #8488.

A Linux run with the real model (two 48 GB MIG slices) trained with
these commands before the latest review changes: both prompts appeared,
and the socket transport and depth-range overrides took effect. It is
being repeated on the final commits.

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [ ] 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
- [ ] 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
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Alexander Temirov <atemirov@nvidia.com>
@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