Skip to content

Fix TorchRL stepping across simulation and output devices - #8240

Merged
kellyguo11 merged 2 commits into
isaac-sim:developfrom
cyanseek:codex/fix-torchrl-output-device
Oct 13, 2026
Merged

kellyguo11 merged 2 commits into
isaac-sim:developfrom
cyanseek:codex/fix-torchrl-output-device

Conversation

@cyanseek

@cyanseek cyanseek commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

IsaacLabTorchRLWrapper(env, device="cpu") could reset a CUDA environment but crashed on the first step: observations had moved to the wrapper device while the terminal-selection mask remained on CUDA.

Move the combined done mask to the wrapper device before selecting terminal observations. Extend the existing wrapper test matrix to exercise CPU output with captured terminal observations and the NaN fallback, while retaining the default same-device path. The current training CLI defaults are unchanged.

Fixes #8239

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Release backport

  • Backport this pull request to the active release branch after it merges into develop

Validation

Revalidated after merging develop at 5afb1f7949e8ab02d9b97253caf2e71b5aabfd45 on 2026-10-09. The fixture now uses the current launch_simulation(cfg) interface.

Real Newton/MJWarp Cartpole simulation on an RTX 4090, Ubuntu 24.04.3, driver 580.126.09, Python 3.12.13, PyTorch 2.11.0+cu130, Warp 1.17.0, TorchRL 0.14.0 and TensorDict 0.14.2; seed 42. Dependencies used the versions in uv.lock, including Newton commit 5ea82eef6f7911388025a8df6ccdb172e2fed286.

  • CPU-output regression cases against the original wrapper: 2 failed. Both failures were the expected CUDA/CPU mismatch.
  • Complete source/isaaclab_rl/test/test_wrappers.py, with the test, torchrl, rl-games, sb3 and skrl extras: 10 passed, no skips.

Command: uv run --frozen --no-sync python -m pytest source/isaaclab_rl/test/test_wrappers.py -q (--no-sync uses the already prepared locked environment). Official Cartpole assets were cached without modification via ISAACSIM_ASSET_ROOT.

This verifies wrapper correctness, not training throughput. PhysX, multi-GPU transfers, and rendering were not tested. The test run reports existing dependency/backend warnings; it is not warning-free.

Checklist

  • Read the contribution guidelines and applied the test-audit criteria.
  • Ran pre-commit through isaaclab --format (all applicable hooks passed).
  • Existing device documentation describes the restored behavior; no API change.
  • Validated the changed behavior and adjacent wrappers with real GPU simulation.
  • Added an isaaclab_rl changelog fragment.
  • Added the contributor name to CONTRIBUTORS.md.

@cyanseek
cyanseek requested a review from a team October 1, 2026 13:51
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Oct 1, 2026
@cyanseek

cyanseek commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 1, 2026
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes device mismatch in TorchRL wrapper stepping.

The PR appears safe to merge; no actionable regression was established.

Summary

The PR moves the TorchRL terminal-selection mask to the wrapper device so stepping can use a different output device from the simulation. It also adds CPU-output regression cases, a changelog fragment, and a contributor entry.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Simulation: observations and done flags] --> B[Convert observations to wrapper device]
  A --> C[Convert combined done mask to wrapper device]
  B --> D[Select terminal observations]
  C --> D
Loading

Reviews (1) · Last reviewed commit: "Fix TorchRL stepping across simulation a..."

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac Lab Review Bot

The patch correctly moves the combined TorchRL done mask to the wrapper output device before terminal-observation selection. The change is minimal, non-breaking, documented in the package changelog, and covered by focused mixed-device regression cases.

  • Design and architecture: The transfer remains at the wrapper boundary that owns self.device. _terminal_observations consumes observations and its selection mask on the same device, without introducing new state, helpers, or competing device ownership.
  • API: No public signatures, keywords, import paths, task IDs, CLI flags, or serialized forms changed. IsaacLabTorchRLWrapper(env, device=...) retains the same returned keys, shapes, and dtypes; the previously failing mixed simulation/output-device path now works.
  • Compatibility and deprecation: Breaking changes: none identified. The compatibility ledger is unchanged, and moving done with .to(self.device) is a no-op for the existing same-device path. No deprecation bridge is needed.
  • Implementation: Tracing _step through _terminal_observations confirms that done is used to index the output-device observation TensorDict, so moving the mask before that call fixes the concrete mismatch at the correct boundary. Reset, close, spec construction, and unrelated wrapper paths are unchanged. The required isaaclab_rl changelog fragment is present.
  • Style consistency: The one-line implementation follows surrounding naming and formatting conventions. The changelog entry is concise, and the CONTRIBUTORS entry is placed consistently. No redundant or misleading added prose requires cleanup.
  • Test quality: The changed integration test extends the existing owner-boundary wrapper matrix. It preserves the default TorchRL path and adds distinct CPU-output cases for captured terminal observations and the NaN fallback. These cases exercise separate terminal-observation branches and directly validate the mixed-device regression; no unsupported duplication or junk-pattern test was identified.

No blocking issues. No inline issue met the actionable-evidence threshold; the assessment above records the review feedback.

Automated review; human maintainers own approval decisions.

@cyanseek

cyanseek commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 9, 2026
@kellyguo11
kellyguo11 merged commit bbcbab6 into isaac-sim:develop Oct 13, 2026
59 checks passed
kellyguo11 pushed a commit that referenced this pull request Oct 13, 2026
Backports #8240 to `release/3.0.0`.

The original cherry-pick conflicted. An NVIDIA inference model proposed
this resolution, and deterministic validation confirmed that it changes
no paths outside the original PR. Because conflict resolution cannot be
certified as an exact patch replay, this PR is intentionally a draft and
requires release-maintainer review.

| Field | Commit |
|---|---|
| Original merged change | `bbcbab6b64d5538c1e6800646d57b462389c1410` |
| Release base used | `84e10dbfef3c449be2b1d21eb30f8b0fd1795962` |
| Proposed backport | `58eebd7fdb191cf0ea7e2a9ffe93544e362e9d3a` |

Co-authored-by: cyanseek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report] TorchRL wrapper crashes when output and simulation devices differ

2 participants