Skip to content

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

Closed

Description

@cyanseek

Describe the bug

IsaacLabTorchRLWrapper(env, device="cpu") resets successfully but fails on its first step when the wrapped environment runs on CUDA. The constructor documents device as the device of the returned tensordicts.

The wrapper moves observations to its output device, while the done mask used to select terminal observations remains on the simulation device. Both terminal-observation paths fail: TensorDict.where when compute_final_obs=True, and the NaN-filling torch.where when it is false. This happens even before an environment terminates.

Steps to reproduce

With the torchrl extra installed, run this on a CUDA-capable machine against develop:

import gymnasium as gym
import torch
from isaaclab_newton.physics import MJWarpSolverCfg, NewtonCfg

from isaaclab.app import launch_simulation
from isaaclab_rl.torchrl import IsaacLabTorchRLWrapper
import isaaclab_tasks
from isaaclab_tasks.utils.parse_cfg import parse_env_cfg

cfg = parse_env_cfg("Isaac-Cartpole", device="cuda:0", num_envs=2)
cfg.sim.physics = NewtonCfg(solver_cfg=MJWarpSolverCfg())
cfg.seed = 42
cfg.compute_final_obs = True  # False reproduces the other terminal-observation path.

with launch_simulation(cfg, {"headless": True, "visualizer": ["none"]}):
    raw_env = gym.make("Isaac-Cartpole", cfg=cfg)
    try:
        env = IsaacLabTorchRLWrapper(raw_env, device="cpu")
        td = env.reset()
        td["action"] = torch.zeros((2, 1), device="cpu")
        env.step(td)
    finally:
        raw_env.close()

Observed in both configurations:

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

The stack reaches IsaacLabTorchRLWrapper._terminal_observations, at obs.where(~done, final_obs) or torch.where(expand_as_right(done, value), fill, value).

Control: the same Newton Cartpole setup with device="cuda:0" completed four steps, including a three-step time limit and automatic reset. Both CPU-output configurations failed on step one. These are real RTX 4090 simulation runs, not mocked environments. Official Cartpole assets were cached locally through the supported asset-root setting; no physics assets were modified.

System Info

  • Isaac Lab commit: ae5d4e39701724e4d686ff7992f5544847cd86a1 (develop)
  • Isaac Sim: not used; kitless Newton / MJWarp
  • GPU: NVIDIA GeForce RTX 4090
  • Driver: 580.126.09
  • Python: 3.12.13
  • PyTorch: 2.12.0+cu130 (CUDA 13.0)
  • Warp: 1.17.0
  • Newton: 1.6.1rc1, locked commit dff296359317779bd08e3ba4bc23bc5d4e20bbcd
  • TorchRL / TensorDict: 0.14.0 / 0.14.2

Additional context

This concerns the wrapper's explicit output-device argument. The current TorchRL train/play CLI uses the simulation device by default; this report does not propose changing agent-device defaults as in #8193. Action transfer is already handled by the underlying environment.

A small fix would place the terminal-selection mask on the wrapper device before selecting observations, with coverage in the existing wrapper integration test for both terminal-observation modes and the default same-device path.

Checklist

  • I have checked that there is no similar issue in the repo.
  • The reproducer uses kitless Newton and the failure is in the Isaac Lab wrapper.

Acceptance Criteria

  • A CUDA environment can return CPU tensordicts through the wrapper through stepping, termination, and automatic reset.
  • Both captured terminal observations and the NaN fallback retain their existing semantics.
  • The default same-device path continues to pass the wrapper contract tests.

Activity

  1. RandomOakForest commented on Oct 7, 2026

    @RandomOakForest
    Collaborator

    Thank you for posting this and adding the PR. The team will review it.

  2. added
    bug
    on Oct 7, 2026
  3. added a commit that references this issue on Oct 13, 2026
    bbcbab6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions