Skip to content

Put Cosmos on camera tasks through configuration overrides and apply_cosmos - #8411

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

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

Conversation

@temiroff

@temiroff temiroff commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Put Cosmos on compatible RGB camera tasks through the task's configuration, with Isaac Lab's own overrides for its options, while preserving the image size seen by the policy. It adds no command-line flags.

Depends on #8410.

uv run isaaclab train --task Isaac-Reorient-Cube-Shadow-Camera-Direct --rl_library rsl_rl presets=cosmos \
  env.cosmos.prompt="A close-up overhead view of a robotic Shadow Hand turning a red cube."
  • Both Shadow Hand cosmos presets expose the camera's own Cosmos settings as env.cosmos, a property that reads and sets the camera's own settings (not a copy), so env.cosmos.prompt, env.cosmos.endpoint, and env.cosmos.transport are ordinary overrides, and subclasses of the presets keep them.
  • A misspelled override field (a small change to the override applier in isaaclab_tasks/utils/hydra.py) now fails with an error naming it, instead of being added silently while the intended field keeps its value. Dictionary keys, such as a modifier's params, are not checked.
  • apply_cosmos(env_cfg, prompt=..., ...) puts Cosmos with depth control on any compatible RGB camera task in code, and cosmos_camera builds a Cosmos camera for a preset. It uses the task's env.scene.num_envs (--num_envs); several environments are batched after checking that the service runs compiled, which independent resets need.
  • apply_cosmos / cosmos_camera render at a supported Cosmos canvas and center-crop/resize generated images to the original output size. Each task requests an episode budget from its duration and capture rate, without changing capture timing; apply_cosmos checks that the service is running and idle before training.
  • Add the Manager-based Shadow Hand cosmos preset alongside the Direct preset. Both presets take --num_envs, and env.cosmos.prompt takes one entry per environment. Their camera now captures every environment step, like the task's other cameras, instead of every 0.1 s: generated images update at 15 Hz of simulation time, and a 10-second episode requests 601 frames. env.scene.tiled_camera.update_period=0.1 restores the slower rate. Their feature extractor holds each environment's pose target until that environment's image changes and leaves environments showing black after a reset out of the loss.

Review cosmos/client/camera.py and the output resize, then the override check in hydra.py, the Shadow Hand presets, and the feature extractor. Service and transport implementation belong to the preceding PRs.

Supported tasks and limits

The selected camera must publish only rgb, use a pinhole lens, have no existing modifiers, render synchronously, and use lazy sensor updates. The published RGB retains its original size; camera configuration and intrinsics describe the larger render canvas. Direct tasks that derive observation dimensions from that configuration, such as Isaac-Cartpole-Camera-Direct, are unsupported. This is not a promise that every camera task works unchanged.

One environment is the default; several need a compiled service, and GPU memory limits the batch. Prompt lists cycle per episode for one environment; with several, each environment keeps its assigned prompt across resets. An environment that resets mid-chunk shows black until the next chunk. Recording every environment uses the Newton GL streaming view (--viz newton_gl --video viz:newton_gl:streaming_view); see the docs' "Record several environments".

Validation

The GPU runs below were measured before the Cosmos options moved from command-line flags to configuration overrides, and have not been repeated. The rewritten unit tests (test_cosmos_any_task.py, the override tests in test_parse_cfg.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 with the documented overrides before the latest review changes; 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), each file in its own process:

  • test_cosmos_camera.py: 6 passed — canvas/view selection and actual output pixels, shape, dtype, and view separation.
  • test_cosmos_any_task.py: 14 passed — apply_cosmos, preset overrides, camera selection, episode budgets, scheduling, and service capability checks.
  • test_shadow_hand_camera_presets.py: 37 passed — Direct and Manager-based presets.

No failures or skips. Shadow Hand training with presets=cosmos and the real model completed three iterations with one environment and with two environments and two prompts. Earlier, on an RTX PRO 6000 Blackwell MIG 48 GB slice shared with Isaac Sim (--kv-window 4), two Shadow Hand environments with two prompts ran four training iterations with a 10 Hz camera, and recorded a 10-second clip of both views through the streaming view with the camera capturing every step (601-frame budget).

The image test now fails if resizing returns the original canvas or crops from a corner. It uses known input colors and crop bounds; it does not test Cosmos image quality. Task tests emit existing TorchScript deprecation warnings. Formatting/lint and the changelog gate passed.

The standalone Cosmos documentation was checked against the implementation. The shared service/transport files have separate validation in #8409 and #8410. No tests from the external Cosmos Framework repository were added or run.

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:

  • Kuka Allegro, one environment: training produced identical losses over socket and CUDA IPC.
  • Two environments with two prompts: about 7.2 s per 64-step iteration (113 ms per environment step).
  • Shadow Hand presets=cosmos with its former 10 Hz camera: 4.5 s per 64 steps, versus 1.9 s without Cosmos. Capturing every step sends Cosmos six times as many chunks per simulated second.

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>
@temiroff
temiroff force-pushed the atemirov/cosmos-camera branch from 523848b to e522cf6 Compare October 9, 2026 03:19
@temiroff
temiroff force-pushed the atemirov/cosmos-camera branch from e522cf6 to 8aad50a Compare October 9, 2026 15:59
@temiroff temiroff changed the title Run any camera task with Cosmos through --cosmos Apply Cosmos to compatible camera tasks with --cosmos Oct 9, 2026
…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>
@temiroff
temiroff force-pushed the atemirov/cosmos-camera branch from 8aad50a to 0ec63a9 Compare October 9, 2026 16:15
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.
@temiroff temiroff changed the title Apply Cosmos to compatible camera tasks with --cosmos Put Cosmos on camera tasks through configuration overrides and apply_cosmos Oct 19, 2026
@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