Repository navigation
Conversation
# Description `torch.rand` can return exact 0 per its [0, 1) contract (~1 in 2^25 on CUDA). The scale-branch of test_noise recovers the scale factor and noise contribution by dividing `noisy_data / data`. Since `data` was generated via `torch.rand`, this produces NaN about ~1 in 1000 test runs (0.1% of the time.) This can be deterministically reproduced by feeding it a seed of 1981. This change fixes the test by switching `data` to `torch.ones` for the scale branch in all three noise tests so `noisy_data` is the noise term directly. There is no need to recover the scale factor and noise contribution separately. The internal `rand_like` call inside `noise_cfg.func` is still exercised and measured, which is the goal of the test. ## Type of change - Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [ ] I have made corresponding changes to the documentation *(N/A - test change only)* - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there Co-authored-by: Kelly Guo <[email protected]>
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
This is a well-crafted cherry-pick that fixes a non-deterministic test failure in test_noise.py. The root cause is correctly identified: torch.rand can return exact 0 per its [0, 1) contract, causing division by zero when the op="scale" tests recover noise by dividing noisy_data / data.
Analysis
Root Cause Understanding ✅
torch.randon CUDA has ~1 in 2^25 chance of returning exactly 0- With 10000 samples × 3 columns × multiple parametrized runs, this manifests ~0.1% of the time
- The seed 1981 deterministically reproduces this failure
Fix Correctness ✅
The fix is elegant and minimal:
- Uses
torch.onesinstead oftorch.randonly forop="scale"tests - This eliminates division-by-zero while preserving test coverage
- The
rand_likecall insidenoise_cfg.funcis still exercised op="add"andop="abs"continue using random data as intended
Code Changes
- All three test functions (
test_gaussian_noise,test_uniform_noise,test_constant_noise) apply the same pattern - The conditional logic is clean and well-commented
- Simplifies result calculation by combining
scaleandabsbranches (both now usenoisy_datadirectly)
Testing Considerations
- The test still validates the noise functions' statistical properties (mean, std, min, max)
- Device placement assertions are preserved
- The parametrized test matrix remains intact
CI Status
Most checks are still pending, but pre-commit and changelog checks have passed. The core logic change is test-only and low-risk.
Verdict
Looks good! This is a clean, well-documented fix for a legitimate flaky test issue. The change is minimal, targeted, and maintains full test coverage of the noise functions.
🔬 Reviewed by Isaac Lab Review Bot | Automated code review
Greptile SummaryThis cherry-pick fixes a non-deterministic test failure in
Confidence Score: 5/5Safe to merge — the change is confined to test helpers and a changelog fragment, with no modifications to production noise functions. The root cause (torch.rand returning 0 causing a NaN on division) is correctly addressed by using torch.ones for the scale branch. The merged scale/abs verification path is mathematically equivalent because dividing by 1 is a no-op. All three test functions are updated consistently, and the internal rand_like/randn_like calls inside the noise implementations remain exercised. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["test_*_noise(device, noise_device, op)"] --> B{op == 'scale'?}
B -- Yes --> C["data = torch.ones(10000, 3)"]
B -- No --> D["data = torch.rand(10000, 3)"]
C --> E["noisy_data = noise_cfg.func(data, cfg)"]
D --> E
E --> F{op branch}
F -- add --> G["result = noisy_data - data"]
F -- "scale or abs" --> H["result = noisy_data directly"]
G --> I["assert result ≈ expected noise params"]
H --> I
style C fill:#d4edda,stroke:#28a745
style H fill:#d4edda,stroke:#28a745
Reviews (1): Last reviewed commit: "OMPE-94619: Fix non-deterministic test_n..." | Re-trigger Greptile |
Description
Cherry pick PR #5732:
torch.randcan return exact 0 per its [0, 1) contract (~1 in 2^25 on CUDA). The scale-branch of test_noise recovers the scale factor and noise contribution by dividingnoisy_data / data. Sincedatawas generated viatorch.rand, this produces NaN about ~1 in 1000 test runs (0.1% of the time.) This can be deterministically reproduced by feeding it a seed of 1981.This change fixes the test by switching
datatotorch.onesfor the scale branch in all three noise tests sonoisy_datais the noise term directly. There is no need to recover the scale factor and noise contribution separately. The internalrand_likecall insidenoise_cfg.funcis still exercised and measured, which is the goal of the test.Type of change
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there