Repository navigation
Conversation
This was referenced Sep 27, 2026
StafaH
added a commit
that referenced
this pull request
Sep 28, 2026
# Description Finalize resolved scene-entity selections to device tensors, following Newton's build-then-finalize model. Manager terms index with the existing `*_ids` fields and no longer upload indices or synchronize CUDA on every call. No second field or helper is needed. Alternative A to #8088, which adds separate `*_ids_torch` fields. Related: #8039, #8089. ## Design - **Build:** `SceneEntityCfg.resolve(scene)` is unchanged. It fills `joint_ids`, `body_ids`, `fixed_tendon_ids`, and `object_collection_ids` with host lists. Class-based terms can read these lists in `__init__`. - **Finalize:** once every term is constructed, `ManagerBase` calls the new `SceneEntityCfg.finalize(device)` on the configurations it resolved. Each list becomes a `torch.long` tensor on the simulation device, shared by the terms that use it, and slices stay slices. Finalization is one-way, and calling it again does nothing. Configurations resolved outside managers, such as by action or command terms, are left unchanged. - **Consumers:** term calls use `data[:, cfg.joint_ids]` and pass `cfg.joint_ids` to asset write methods as before. Tensors compare unequal to `slice(None)`, so the existing `ids == slice(None)` checks continue to work. - **No per-step host reads:** a scalar selection such as `data[:, cfg.body_ids[0]]` would read a CUDA tensor back to the host, so these reads become device gathers: `data[:, cfg.body_ids][:, 0]`. Event terms that previously rebuilt index tensors on each call now use the finalized tensors directly; every backend accepts int64 index tensors. - **Scope:** 13 files, all in `isaaclab` and `isaaclab_tasks`. Backend asset APIs, `isaaclab_experimental` (whose managers are a separate implementation), and serialization helpers are unchanged. ### Why tensors rather than `ProxyArray` or a wrapper | Design | Call site | `joint_pos` (µs/call) | `joint_pos_limits` (µs/call) | Syncs/call | | --- | --- | ---: | ---: | ---: | | develop (host lists) | `data[:, cfg.joint_ids]` | 383 † | 1470–1566 † | 1 / 4 | | Previous revision: `IndexSequence` wrapper | `data[:, cfg.joint_ids]` | 8.45–8.50 | 64.4–65.7 | 0 | | #8088: separate `*_ids_torch` | `data[:, cfg.joint_ids_torch]` | 5.34–5.99 | 47.95–48.83 | 0 | | **This PR: finalized tensors** | `data[:, cfg.joint_ids]` | **5.32–6.38** | **48.00–49.19** | 0 | Finalized tensors match #8088 with a single field. A finalized `ProxyArray` was also prototyped. Indexing with it directly cost about 2 µs more per index (7.7 µs vs. 5.3–6.1 µs), because it dispatches through `ProxyArray`'s deprecated Torch bridge, and asset write methods reject it. It would therefore need an explicit accessor at every call site. No consumer used its Warp view. Benchmark: RTX PRO 6000 Blackwell, PyTorch 2.12.0+cu130. Real `joint_pos` observation and `joint_pos_limits` reward, `(4096, 32)` CUDA data, joints `[15, 2, 29, 5, 22, 11, 30, 0]`. Each fresh process ran 200 warmup calls, then five blocks of 2,000 calls. Figures are median block times from two or more processes per design, run in alternating order. Synchronizations were counted with PyTorch's sync-debug mode. † The GPU was fully utilized by unrelated processes during these runs, which inflates develop's synchronizing path. On an idle GPU, the same benchmark previously measured develop at 13.05–13.11 µs. The synchronization-free designs are CPU-bound and are comparable with one another. ## Type of change - New feature - Breaking change: term calls receive finalized `torch.long` tensors instead of host lists. Migration: - Replace per-step scalar reads such as `data[:, cfg.body_ids[0]]` with `data[:, cfg.body_ids][:, 0]`, or read host values in the term's `__init__`. - Replace `torch.tensor(cfg.body_ids)` with `cfg.body_ids`; the finalized selection is already a device tensor. - Replace `isinstance(ids, list)` checks with `isinstance(ids, slice)`. - Class terms can still read host lists in `__init__`. - Documentation update ## Validation - 206 focused tests passed: managers (event, observation, reward, termination, base, scene selection), dict, configclass, wrench composer, gravity observations, and Lift configuration. - New tests cover: - finalization of ordering, slices, empty selections, and copies; - that class terms see host lists while term calls see device tensors, whether the manager is created while the simulation is playing or deferred until physics is ready; - a real `joint_pos` consumer and a device gather under CUDA sync-debug `error` mode; - external-force sizing for a finalized body subset. - All six new tests fail when `finalize` is disabled. - Newton/MJWarp runtime smoke tests passed with 64 environments, seed 42, 20 warmup and 100 measured steps, and no renderer, for `Isaac-Lift-KukaAllegro`, `Isaac-Velocity-Flat-AnymalD`, and `Isaac-Open-Drawer-Franka`. The last exercises the changed drawer-joint gather. No implicit `ProxyArray` deprecation warnings were emitted. - `uv run --frozen isaaclab -f` passed, including changelog checks. - Not run: the full documentation build, PhysX/OVPhysX runtime, and `test_recorder_manager_integration` (requires full Isaac Sim). Reproduce the smoke test: ```bash uv run --frozen isaaclab benchmark runtime \ --task Isaac-Lift-KukaAllegro --num_envs 64 --num_steps 100 \ --warmup_steps 20 --seed 42 --device cuda:0 --visualizer none \ --output_path /tmp/scene-selector-smoke physics=newton_mjwarp ``` ## Known limitations - Serializing a finalized configuration emits tensors for its selections, following the existing `class_to_dict` tensor handling. No code in this repository serializes term configurations after finalization. - Finalized tensors are read-only by convention. Calling `resolve()` after `finalize()` is unsupported. - A few class terms copy selection fields in `__init__` and therefore keep the host list or their own tensor. Two of these, NIST `reset_end_effector_around_asset` and PhysX `randomize_rigid_body_material`, keep host lists: the first can adopt the finalized tensor in a follow-up, while the second iterates backend body IDs on the CPU and should stay on the host. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` ## Checklist - [x] I have read and understood the contribution guidelines. - [x] I have run the pre-commit checks with `uv run --frozen isaaclab -f`. - [x] I have made corresponding changes to the documentation. - [x] I have added tests that prove the behavior and checked them against the change disabled. - [x] I have added a changelog fragment for every touched source package. - [x] My name already exists in `CONTRIBUTORS.md`.
isaaclab-bot Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
# Description Finalize resolved scene-entity selections to device tensors, following Newton's build-then-finalize model. Manager terms index with the existing `*_ids` fields and no longer upload indices or synchronize CUDA on every call. No second field or helper is needed. Alternative A to #8088, which adds separate `*_ids_torch` fields. Related: #8039, #8089. ## Design - **Build:** `SceneEntityCfg.resolve(scene)` is unchanged. It fills `joint_ids`, `body_ids`, `fixed_tendon_ids`, and `object_collection_ids` with host lists. Class-based terms can read these lists in `__init__`. - **Finalize:** once every term is constructed, `ManagerBase` calls the new `SceneEntityCfg.finalize(device)` on the configurations it resolved. Each list becomes a `torch.long` tensor on the simulation device, shared by the terms that use it, and slices stay slices. Finalization is one-way, and calling it again does nothing. Configurations resolved outside managers, such as by action or command terms, are left unchanged. - **Consumers:** term calls use `data[:, cfg.joint_ids]` and pass `cfg.joint_ids` to asset write methods as before. Tensors compare unequal to `slice(None)`, so the existing `ids == slice(None)` checks continue to work. - **No per-step host reads:** a scalar selection such as `data[:, cfg.body_ids[0]]` would read a CUDA tensor back to the host, so these reads become device gathers: `data[:, cfg.body_ids][:, 0]`. Event terms that previously rebuilt index tensors on each call now use the finalized tensors directly; every backend accepts int64 index tensors. - **Scope:** 13 files, all in `isaaclab` and `isaaclab_tasks`. Backend asset APIs, `isaaclab_experimental` (whose managers are a separate implementation), and serialization helpers are unchanged. ### Why tensors rather than `ProxyArray` or a wrapper | Design | Call site | `joint_pos` (µs/call) | `joint_pos_limits` (µs/call) | Syncs/call | | --- | --- | ---: | ---: | ---: | | develop (host lists) | `data[:, cfg.joint_ids]` | 383 † | 1470–1566 † | 1 / 4 | | Previous revision: `IndexSequence` wrapper | `data[:, cfg.joint_ids]` | 8.45–8.50 | 64.4–65.7 | 0 | | #8088: separate `*_ids_torch` | `data[:, cfg.joint_ids_torch]` | 5.34–5.99 | 47.95–48.83 | 0 | | **This PR: finalized tensors** | `data[:, cfg.joint_ids]` | **5.32–6.38** | **48.00–49.19** | 0 | Finalized tensors match #8088 with a single field. A finalized `ProxyArray` was also prototyped. Indexing with it directly cost about 2 µs more per index (7.7 µs vs. 5.3–6.1 µs), because it dispatches through `ProxyArray`'s deprecated Torch bridge, and asset write methods reject it. It would therefore need an explicit accessor at every call site. No consumer used its Warp view. Benchmark: RTX PRO 6000 Blackwell, PyTorch 2.12.0+cu130. Real `joint_pos` observation and `joint_pos_limits` reward, `(4096, 32)` CUDA data, joints `[15, 2, 29, 5, 22, 11, 30, 0]`. Each fresh process ran 200 warmup calls, then five blocks of 2,000 calls. Figures are median block times from two or more processes per design, run in alternating order. Synchronizations were counted with PyTorch's sync-debug mode. † The GPU was fully utilized by unrelated processes during these runs, which inflates develop's synchronizing path. On an idle GPU, the same benchmark previously measured develop at 13.05–13.11 µs. The synchronization-free designs are CPU-bound and are comparable with one another. ## Type of change - New feature - Breaking change: term calls receive finalized `torch.long` tensors instead of host lists. Migration: - Replace per-step scalar reads such as `data[:, cfg.body_ids[0]]` with `data[:, cfg.body_ids][:, 0]`, or read host values in the term's `__init__`. - Replace `torch.tensor(cfg.body_ids)` with `cfg.body_ids`; the finalized selection is already a device tensor. - Replace `isinstance(ids, list)` checks with `isinstance(ids, slice)`. - Class terms can still read host lists in `__init__`. - Documentation update ## Validation - 206 focused tests passed: managers (event, observation, reward, termination, base, scene selection), dict, configclass, wrench composer, gravity observations, and Lift configuration. - New tests cover: - finalization of ordering, slices, empty selections, and copies; - that class terms see host lists while term calls see device tensors, whether the manager is created while the simulation is playing or deferred until physics is ready; - a real `joint_pos` consumer and a device gather under CUDA sync-debug `error` mode; - external-force sizing for a finalized body subset. - All six new tests fail when `finalize` is disabled. - Newton/MJWarp runtime smoke tests passed with 64 environments, seed 42, 20 warmup and 100 measured steps, and no renderer, for `Isaac-Lift-KukaAllegro`, `Isaac-Velocity-Flat-AnymalD`, and `Isaac-Open-Drawer-Franka`. The last exercises the changed drawer-joint gather. No implicit `ProxyArray` deprecation warnings were emitted. - `uv run --frozen isaaclab -f` passed, including changelog checks. - Not run: the full documentation build, PhysX/OVPhysX runtime, and `test_recorder_manager_integration` (requires full Isaac Sim). Reproduce the smoke test: ```bash uv run --frozen isaaclab benchmark runtime \ --task Isaac-Lift-KukaAllegro --num_envs 64 --num_steps 100 \ --warmup_steps 20 --seed 42 --device cuda:0 --visualizer none \ --output_path /tmp/scene-selector-smoke physics=newton_mjwarp ``` ## Known limitations - Serializing a finalized configuration emits tensors for its selections, following the existing `class_to_dict` tensor handling. No code in this repository serializes term configurations after finalization. - Finalized tensors are read-only by convention. Calling `resolve()` after `finalize()` is unsupported. - A few class terms copy selection fields in `__init__` and therefore keep the host list or their own tensor. Two of these, NIST `reset_end_effector_around_asset` and PhysX `randomize_rigid_body_material`, keep host lists: the first can adopt the finalized tensor in a follow-up, while the second iterates backend body IDs on the CPU and should stay on the host. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` ## Checklist - [x] I have read and understood the contribution guidelines. - [x] I have run the pre-commit checks with `uv run --frozen isaaclab -f`. - [x] I have made corresponding changes to the documentation. - [x] I have added tests that prove the behavior and checked them against the change disabled. - [x] I have added a changelog fragment for every touched source package. - [x] My name already exists in `CONTRIBUTORS.md`. (cherry picked from commit 10fdf81)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Alternative C: prototype native Torch selectors in
SceneEntityCfg, with no retained Python-index copy and no second Torch-selector field.Compare with #8087 (automatic wrapper) and #8088 (separate tensor accessor). All three independently start from develop
e140fa930cecc84f4fe1599569c8c998c24148bb, so their changes can be compared directly. Related: #8039. These are alternatives; choose one design rather than merging them together.Implementation
joint_ids,body_ids,fixed_tendon_ids, andobject_collection_idswith a one-dimensionaltorch.longtensor on the scene device. Slices remain slices.tolist()rather than reading individual device scalars.Migration and ownership
This is a breaking prototype: after resolution,
*_idsare tensors or slices, not Python lists. Existing list configurations still work. There is one authoritative device selector and no retained host index cache.ids[0]is a zero-dimensional tensor; using it as a scalar array index or Python integer can synchronize CUDA.len(ids)andids.shapeonly inspect metadata. Treat selectors as read-only and replace/re-resolve after configuration edits. Copies own copies of their tensor storage. Re-resolution and serialization both read back device indices and belong outside stepping code. This design has neither the stale-host/device-cache risk of two mutable representations nor the cheap host-value access supplied by the other two alternatives.Performance comparison
Same machine: RTX PRO 6000 Blackwell, PyTorch 2.12.0+cu130. Fresh processes in forward/reverse order (
base, wrapper, separate, native, then reversed), 200 warmup calls, five blocks of 2,000 calls, CUDA synchronization at each block boundary. Each cell shows the median block time from both process runs, in µs/call.joint_pos,(4096, 32)input, eight shuffled selected joints.position_command_error, 4,096 environments. The first two alternatives preserve host scalar indexing; this prototype uses the migrated device selection.Native tensors are effectively tied with the separate accessor for ordinary indexing; the small difference does not establish a meaningful winner. The automatic wrapper has additional dispatch overhead.
The tradeoff is visible in the other consumers: native single-body selection performs a gather/allocation where a host integer allowed a tensor view, and
tolist()introduces a device-to-host copy plus synchronization. The pose-reward timings also show run-to-run variation (particularly the baseline), so use these as measured cases rather than a universal throughput prediction.Profiler, 50 calls per case:
Full task comparison
Isaac-Lift-KukaAllegro, Newton MJWarp, 64 environments, seed 42, no renderer, 200 warmup steps and 1,000 measured steps. Fresh processes in separate/native/native/separate order. Values are mean ms/iteration:All runs completed. These are host-return measurements including resets; a documentation build was active on the CPU. They do not establish an end-to-end advantage for native selectors. This prototype primarily simplifies representation and automatically accelerates existing tensor-indexing consumers, with an API migration and potentially more expensive scalar/host consumers.
Focused benchmark reproduction (run in each branch)
Save this script outside the repository and execute it with
uv run --frozen python /tmp/benchmark.py:Validation
newton_mjwarppreset; the reason was inspected.joint_posconsumer, then passes here.position_command_errorwith a synchronizing operation. Restoring the migrated expression makes it pass.uv run --frozen isaaclab -fpassed, including changelog validation.uv run --frozen --isolated --extra dev -- make -C docs current-docs 'SPHINXOPTS=-j 4').Type of change
Release backport
developChecklist
uv run --frozen isaaclab -f.CONTRIBUTORS.md.