Repository navigation
Improve manager and direct task hot paths - #6492
Closed
kellyguo11 wants to merge 1 commit into
Closed
kellyguo11 wants to merge 1 commit into
kellyguo11 wants to merge 1 commit into
Conversation
StafaH
added a commit
to StafaH/IsaacLab
that referenced
this pull request
Sep 28, 2026
Cache ActionManager term dimensions, which are fixed after term construction but were recomputed on every action step. Keep Cartpole direct joint indices on the device so observations, rewards, terminations, resets, and effort writes no longer upload host lists each step, and drop redundant action copies in the Cartpole and Reorient direct tasks. The locomotion task keeps its copy because its reset zeroes the stored actions in place.
1 task done
Collaborator
|
Closing in favor of #8039 which includes still relevant fixes from this PR |
ooctipus
added a commit
that referenced
this pull request
Sep 28, 2026
# Description Part 4 of the camera performance series. Based on the latest `develop`, including #8084 and #8087. Supersedes #7495. Profiling the camera and direct tasks found host-device synchronizations in every step: the CPU blocked on the GPU, then ran Python code while the GPU sat idle. This PR removes them from termination tracking, the Lift rewards and success monitoring, marker validation, camera updates, and the Cartpole and Pendulum direct tasks. It also incorporates the hot-path fixes from #6492 (by @kellyguo11) that still apply to current `develop`. - `torch.where` replaces `nonzero` in the termination manager and replaces boolean-mask writes in the Lift progress rewards. - `SuccessMonitor` updates no longer synchronize. They rank outcomes with fixed-size scatters instead of `unique_consecutive`, `repeat_interleave`, and boolean masks. Masked or overflowing outcomes go to an internal scratch row. A new `valid` argument lets the Lift reset hook pass a mask instead of filtering. - `SuccessMonitor.get_mean_success_rate()` returns a 0-d tensor, so logging it does not synchronize. The Cartpole direct and Pendulum MARL success rates are logged as tensors for the same reason. Call `.item()` where a Python float is needed. - Cartpole direct and Pendulum MARL store their joint indices as device tensors. Observations, rewards, terminations, resets, and effort writes no longer upload host lists each step. - Marker index validation runs only when a backend consumes the IDs, and once per ID tensor. - Cameras with `update_period == 0` skip the outdated-mask readback. - Zero-width uniform `add` noise returns its input. - `object_point_cloud_b` defaults to `visualize=False`. Drawing 262k markers every step cost a sync, and with RTX the markers appeared in camera images. The Kuka rendering test already disabled them for that reason. - `ActionManager` caches its term dimensions, which are fixed after construction but were recomputed on every action step (from #6492). - The Cartpole and Reorient direct tasks drop redundant action copies (from #6492). With #8087, managers finalize scene-entity selections to device tensors. `object_ee_distance` therefore indexes with `asset_cfg.body_ids` directly, and this PR's earlier cached device-ID helper was removed. After #8087 it would have iterated the finalized tensor to build its cache key, reading indices back from the device. ### Changes from #6492 Each #6492 change was checked against current `develop`: | #6492 change | Decision | | --- | --- | | Skip observation-term clones | Not taken: `develop` already provides this through #8038. | | Cabinet direct `actions.clone()` | Not taken: the line no longer exists. | | `ActionManager` caches term dimensions | **Taken.** | | Cartpole direct index cleanup | **Taken and extended.** #6492 fixed 1 of the 9 synchronizations caused by host-list joint indexing. Storing the joint indices as device tensors removes all 9. | | Drop `actions.clone()` in the Cartpole and Reorient direct tasks | **Taken.** Neither task modifies the stored actions in place. | | Drop `actions.clone()` in the Locomotion direct task | **Not taken.** Its reset zeroes `self.actions` in place, which would zero the policy's own action tensor, e.g. the one held in RL rollout storage. | ### Investigated and dropped: Newton sensor-graph flag cache An earlier revision cached the Newton sensor graph's task flags and skipped the upload when they were unchanged, on the premise that each upload synchronized the stream. That premise does not hold for the current Warp (1.17), so the change was reverted and `develop`'s per-call upload is kept: - Warp uploads the flags with a single `cudaMemcpyAsync` from pageable memory, which CUDA stages on the host without waiting for the stream. - Behind about 455 ms of Warp kernels queued on the same stream, ten uploads return in 0.07–0.13 ms. - An Nsight Systems trace of the Kuka camera task shows each flag upload's `cudaMemcpyAsync` returning in 5.9 µs on average, 35.6 µs at most. - End to end (Kuka camera task, 256 environments), `develop`'s upload, the cache, and device-side flag writes measured 12.53, 12.50, and 12.47 ms per step. That spread is within run-to-run noise (12.45–12.58 ms). ## Series 1. #8036: Read camera outputs through `ProxyArray.torch` (bug fix) (base: develop) 2. #8037: Fused normalization for strided camera images (base: #8036) 3. #8038: Skip redundant observation copies (base: #8037) 4. #8039: Remove per-step host synchronizations (base: develop) 5. #8040: Newton `render_batch` in one sensor-graph launch (base: develop) 6. #8041: RSL-RL cuDNN benchmark, mixed precision and compile settings (base: develop) 7. #8042: Kuka Allegro camera tasks on the shared image observation (base: #8038) The series is split from #7440, which remains the combined reference branch. ## Type of change - Bug fix (non-breaking change which fixes an issue) - Changes to `SuccessMonitor`: `get_mean_success_rate()` returns a 0-d tensor instead of a float, and `success_update()` gains a `valid` argument. The changelog includes migration guidance. ## Performance RTX PRO 6000 Blackwell Workstation Edition (driver 595.91.07); PyTorch 2.12.0+cu130; Warp 1.17.0; Newton 1.6.0; GPU otherwise idle. `develop` at `10fdf81d9` compared with this PR (`b2727a0f2`; later commits only trim comments and revert the Newton change above), with the same `uv.lock`. Runtime benchmark (`isaaclab benchmark runtime`), Newton/MJWarp, seed 42, no visualizer. Three fresh processes per revision, run in alternating order. Figures are the mean step time across processes. | Workload | `develop` | This PR | Change | | --- | ---: | ---: | ---: | | `Isaac-Lift-KukaAllegro-Camera`, 256 envs, `presets=duo_camera,rgb128`, Newton renderer (500 steps) | 14.44 ms | 12.62 ms | **−12.6%** (+14.4% throughput) | | `Isaac-Cartpole-Direct`, 4096 envs (2,000 steps) | 1.674 ms | 1.441 ms | **−13.9%** (+16.2% throughput) | | `Isaac-Pendulum-MARL-Direct`, 4096 envs (2,000 steps) | 2.144 ms | 1.862 ms | **−13.2%** (+15.2% throughput) | Per-process step times (`develop` → PR): - Camera: `14.44, 14.48, 14.40` → `12.67, 12.63, 12.57` ms. - Cartpole: `1.680, 1.685, 1.657` → `1.446, 1.438, 1.439` ms. - Pendulum: `2.137, 2.158, 2.137` → `1.827, 1.863, 1.895` ms. Host synchronizations per `env.step()`, attributed to call sites with PyTorch sync-debug mode over 170 steps (4096 envs): | Task | `develop` | This PR | Remaining | | --- | ---: | ---: | --- | | `Isaac-Lift-KukaAllegro-Camera` (`presets=cube`, Newton renderer) | 21.3 | 4.2 | step reset and command-resample `nonzero`; curriculum, command-metric, and termination logging reads | | `Isaac-Cartpole-Direct` | 10.3 | 1.0 | step reset `nonzero` | | `Isaac-Pendulum-MARL-Direct` | 10.0 | 1.0 | step reset `nonzero` | PyTorch labels sync-debug mode a prototype that does not detect every synchronization, and it does not see synchronizations issued by Warp, so these counts are lower bounds. Reproduce with: ```bash uv run --frozen isaaclab benchmark runtime \ --task Isaac-Lift-KukaAllegro-Camera --num_envs 256 --num_steps 500 \ --warmup_steps 100 --seed 42 --device cuda:0 --visualizer none \ --output_path /tmp/pr8039 physics=newton_mjwarp renderer=newton_renderer presets=duo_camera,rgb128 ``` ### Not addressed - **Step reset and command resampling:** both still call `nonzero` once per step. Both convert a mask into variable-length environment IDs, and the reset and command pipelines consume those IDs throughout. Removing these synchronizations means moving those pipelines to masks or padded IDs, which is out of scope here. - **Warp-side synchronizations:** the Nsight trace above also records many `cudaStreamSynchronize` calls outside the flag uploads, which PyTorch's sync-debug mode cannot attribute. Their sources are not yet identified. ## Validation - Cartpole direct produces bit-identical observation and reward checksums to `develop` after 150 seeded steps, including resets. - Pendulum MARL is not run-to-run deterministic on MJWarp. Its observations and rewards were instead compared on identical state against `develop`'s host-index formulas for 150 steps, with a maximum difference of 0.0. Reorient direct is also non-deterministic; its change only removes a copy of an action tensor that is never modified in place. - `test_circular_buffer.py`, `test_noise.py`, `test_curriculum.py`, the manager tests (including `test_event_manager.py`, `test_reward_manager.py`, `test_termination_manager.py`, and `test_scene_entity_cfg.py`), `test_lift_env_cfg.py`, `test_sensor_base.py`, `test_visualization_markers.py`, and `test_kit_visualizer_scene_partitioning.py` pass. - `test_rendering_lift_kuka_homo_kitless.py` passes for the Newton renderer and legacy OVRTX cases. The two `ovstage` OVRTX cases fail identically on `develop`. - `uv run --frozen isaaclab -f` passes, including changelog checks. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` --------- Co-authored-by: Octi Zhang <[email protected]>
isaaclab-bot Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
# Description Part 4 of the camera performance series. Based on the latest `develop`, including #8084 and #8087. Supersedes #7495. Profiling the camera and direct tasks found host-device synchronizations in every step: the CPU blocked on the GPU, then ran Python code while the GPU sat idle. This PR removes them from termination tracking, the Lift rewards and success monitoring, marker validation, camera updates, and the Cartpole and Pendulum direct tasks. It also incorporates the hot-path fixes from #6492 (by @kellyguo11) that still apply to current `develop`. - `torch.where` replaces `nonzero` in the termination manager and replaces boolean-mask writes in the Lift progress rewards. - `SuccessMonitor` updates no longer synchronize. They rank outcomes with fixed-size scatters instead of `unique_consecutive`, `repeat_interleave`, and boolean masks. Masked or overflowing outcomes go to an internal scratch row. A new `valid` argument lets the Lift reset hook pass a mask instead of filtering. - `SuccessMonitor.get_mean_success_rate()` returns a 0-d tensor, so logging it does not synchronize. The Cartpole direct and Pendulum MARL success rates are logged as tensors for the same reason. Call `.item()` where a Python float is needed. - Cartpole direct and Pendulum MARL store their joint indices as device tensors. Observations, rewards, terminations, resets, and effort writes no longer upload host lists each step. - Marker index validation runs only when a backend consumes the IDs, and once per ID tensor. - Cameras with `update_period == 0` skip the outdated-mask readback. - Zero-width uniform `add` noise returns its input. - `object_point_cloud_b` defaults to `visualize=False`. Drawing 262k markers every step cost a sync, and with RTX the markers appeared in camera images. The Kuka rendering test already disabled them for that reason. - `ActionManager` caches its term dimensions, which are fixed after construction but were recomputed on every action step (from #6492). - The Cartpole and Reorient direct tasks drop redundant action copies (from #6492). With #8087, managers finalize scene-entity selections to device tensors. `object_ee_distance` therefore indexes with `asset_cfg.body_ids` directly, and this PR's earlier cached device-ID helper was removed. After #8087 it would have iterated the finalized tensor to build its cache key, reading indices back from the device. ### Changes from #6492 Each #6492 change was checked against current `develop`: | #6492 change | Decision | | --- | --- | | Skip observation-term clones | Not taken: `develop` already provides this through #8038. | | Cabinet direct `actions.clone()` | Not taken: the line no longer exists. | | `ActionManager` caches term dimensions | **Taken.** | | Cartpole direct index cleanup | **Taken and extended.** #6492 fixed 1 of the 9 synchronizations caused by host-list joint indexing. Storing the joint indices as device tensors removes all 9. | | Drop `actions.clone()` in the Cartpole and Reorient direct tasks | **Taken.** Neither task modifies the stored actions in place. | | Drop `actions.clone()` in the Locomotion direct task | **Not taken.** Its reset zeroes `self.actions` in place, which would zero the policy's own action tensor, e.g. the one held in RL rollout storage. | ### Investigated and dropped: Newton sensor-graph flag cache An earlier revision cached the Newton sensor graph's task flags and skipped the upload when they were unchanged, on the premise that each upload synchronized the stream. That premise does not hold for the current Warp (1.17), so the change was reverted and `develop`'s per-call upload is kept: - Warp uploads the flags with a single `cudaMemcpyAsync` from pageable memory, which CUDA stages on the host without waiting for the stream. - Behind about 455 ms of Warp kernels queued on the same stream, ten uploads return in 0.07–0.13 ms. - An Nsight Systems trace of the Kuka camera task shows each flag upload's `cudaMemcpyAsync` returning in 5.9 µs on average, 35.6 µs at most. - End to end (Kuka camera task, 256 environments), `develop`'s upload, the cache, and device-side flag writes measured 12.53, 12.50, and 12.47 ms per step. That spread is within run-to-run noise (12.45–12.58 ms). ## Series 1. #8036: Read camera outputs through `ProxyArray.torch` (bug fix) (base: develop) 2. #8037: Fused normalization for strided camera images (base: #8036) 3. #8038: Skip redundant observation copies (base: #8037) 4. #8039: Remove per-step host synchronizations (base: develop) 5. #8040: Newton `render_batch` in one sensor-graph launch (base: develop) 6. #8041: RSL-RL cuDNN benchmark, mixed precision and compile settings (base: develop) 7. #8042: Kuka Allegro camera tasks on the shared image observation (base: #8038) The series is split from #7440, which remains the combined reference branch. ## Type of change - Bug fix (non-breaking change which fixes an issue) - Changes to `SuccessMonitor`: `get_mean_success_rate()` returns a 0-d tensor instead of a float, and `success_update()` gains a `valid` argument. The changelog includes migration guidance. ## Performance RTX PRO 6000 Blackwell Workstation Edition (driver 595.91.07); PyTorch 2.12.0+cu130; Warp 1.17.0; Newton 1.6.0; GPU otherwise idle. `develop` at `10fdf81d9` compared with this PR (`b2727a0f2`; later commits only trim comments and revert the Newton change above), with the same `uv.lock`. Runtime benchmark (`isaaclab benchmark runtime`), Newton/MJWarp, seed 42, no visualizer. Three fresh processes per revision, run in alternating order. Figures are the mean step time across processes. | Workload | `develop` | This PR | Change | | --- | ---: | ---: | ---: | | `Isaac-Lift-KukaAllegro-Camera`, 256 envs, `presets=duo_camera,rgb128`, Newton renderer (500 steps) | 14.44 ms | 12.62 ms | **−12.6%** (+14.4% throughput) | | `Isaac-Cartpole-Direct`, 4096 envs (2,000 steps) | 1.674 ms | 1.441 ms | **−13.9%** (+16.2% throughput) | | `Isaac-Pendulum-MARL-Direct`, 4096 envs (2,000 steps) | 2.144 ms | 1.862 ms | **−13.2%** (+15.2% throughput) | Per-process step times (`develop` → PR): - Camera: `14.44, 14.48, 14.40` → `12.67, 12.63, 12.57` ms. - Cartpole: `1.680, 1.685, 1.657` → `1.446, 1.438, 1.439` ms. - Pendulum: `2.137, 2.158, 2.137` → `1.827, 1.863, 1.895` ms. Host synchronizations per `env.step()`, attributed to call sites with PyTorch sync-debug mode over 170 steps (4096 envs): | Task | `develop` | This PR | Remaining | | --- | ---: | ---: | --- | | `Isaac-Lift-KukaAllegro-Camera` (`presets=cube`, Newton renderer) | 21.3 | 4.2 | step reset and command-resample `nonzero`; curriculum, command-metric, and termination logging reads | | `Isaac-Cartpole-Direct` | 10.3 | 1.0 | step reset `nonzero` | | `Isaac-Pendulum-MARL-Direct` | 10.0 | 1.0 | step reset `nonzero` | PyTorch labels sync-debug mode a prototype that does not detect every synchronization, and it does not see synchronizations issued by Warp, so these counts are lower bounds. Reproduce with: ```bash uv run --frozen isaaclab benchmark runtime \ --task Isaac-Lift-KukaAllegro-Camera --num_envs 256 --num_steps 500 \ --warmup_steps 100 --seed 42 --device cuda:0 --visualizer none \ --output_path /tmp/pr8039 physics=newton_mjwarp renderer=newton_renderer presets=duo_camera,rgb128 ``` ### Not addressed - **Step reset and command resampling:** both still call `nonzero` once per step. Both convert a mask into variable-length environment IDs, and the reset and command pipelines consume those IDs throughout. Removing these synchronizations means moving those pipelines to masks or padded IDs, which is out of scope here. - **Warp-side synchronizations:** the Nsight trace above also records many `cudaStreamSynchronize` calls outside the flag uploads, which PyTorch's sync-debug mode cannot attribute. Their sources are not yet identified. ## Validation - Cartpole direct produces bit-identical observation and reward checksums to `develop` after 150 seeded steps, including resets. - Pendulum MARL is not run-to-run deterministic on MJWarp. Its observations and rewards were instead compared on identical state against `develop`'s host-index formulas for 150 steps, with a maximum difference of 0.0. Reorient direct is also non-deterministic; its change only removes a copy of an action tensor that is never modified in place. - `test_circular_buffer.py`, `test_noise.py`, `test_curriculum.py`, the manager tests (including `test_event_manager.py`, `test_reward_manager.py`, `test_termination_manager.py`, and `test_scene_entity_cfg.py`), `test_lift_env_cfg.py`, `test_sensor_base.py`, `test_visualization_markers.py`, and `test_kit_visualizer_scene_partitioning.py` pass. - `test_rendering_lift_kuka_homo_kitless.py` passes for the Newton renderer and legacy OVRTX cases. The two `ovstage` OVRTX cases fail identically on `develop`. - `uv run --frozen isaaclab -f` passes, including changelog checks. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` --------- Co-authored-by: Octi Zhang <[email protected]> (cherry picked from commit 60bc09f)
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
Improves the training hot paths that are shared by manager-based tasks and the selected direct core tasks.
This PR:
ActionManageraction dimensions instead of rebuilding them every stepFixes #
Benchmark impact
Runtime throughput from the exploration benchmark set:
Isaac-Cartpole-DirectIsaac-AntIsaac-Velocity-Flat-UnitreeGo2Isaac-Open-Drawer-FrankaIsaac-Ant-DirectShort RSL-RL throughput checks:
Isaac-Cartpole-Direct, 10 itersIsaac-Ant, 50 itersIsaac-Velocity-Flat-UnitreeGo2, 150 itersConvergence sanity: the Cartpole direct 10-iteration run preserved the same max reward, last reward, max episode length, and last episode length. The Go2 150-iteration reward curve stayed in the same learning regime, but the final seed-42 reward was slightly below baseline, so longer multi-seed validation is still recommended before treating convergence neutrality as final.
Type of change
Screenshots
Not applicable.
Validation
./isaaclab.sh -p -m pytest source/isaaclab/test/managers/test_observation_manager.py./isaaclab.sh -fChecklist
./isaaclab.sh --formatsource/<pkg>/changelog.d/for every touched packageCONTRIBUTORS.mdor my name already exists there