Conversation
Signed-off-by: Xu Zihan <2024010904024@std.uestc.edu.cn>
Add test for invalid time lag handling in delay buffer. Signed-off-by: Xu Zihan <2024010904024@std.uestc.edu.cn>
Fixes an issue with DelayBuffer that caused invalid delays to remain in the buffer after validation failure. Signed-off-by: Xu Zihan <2024010904024@std.uestc.edu.cn>
There was a problem hiding this comment.
Isaac Lab Review Bot
The change makes DelayBuffer.set_time_lag transactional: updates are staged, validated as a complete candidate state, and committed only after validation succeeds. Rejected scalar and tensor lags therefore leave the live lag tensor and cached extrema unchanged.
- Design and architecture: State remains owned by
DelayBuffer, with the committed lag tensor and cached minimum/maximum updated together. Usingcopy_()preserves the existing tensor identity, whilecompute()continues to consume the same_time_lagsobject. - API: Accepted inputs, validation errors, device conversion, and successful update semantics remain unchanged. The observable behavior on failed validation is corrected without renaming or removing public APIs, and the package includes an appropriate past-tense changelog fragment.
- Implementation: Both scalar and tensor updates now target a clone before range validation, and the live state is committed only on success. Regression coverage checks rejected negative and over-limit updates. The added clone introduces a small per-update allocation, and the new test still warrants execution in the project environment because it was not run by the author, but neither issue requires a pre-merge correction based on the supplied patch.
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.
|
| expected_lags = delay_buffer.time_lags.clone() | ||
|
|
||
| with pytest.raises(ValueError): | ||
| delay_buffer.set_time_lag(time_lag, batch_ids) | ||
|
|
||
| assert torch.equal(delay_buffer.time_lags, expected_lags) |
There was a problem hiding this comment.
Tensor identity remains untested
This regression test verifies only the tensor values and cached extrema, while the implementation explicitly preserves time_lags identity for callers that retain a reference. Retain the pre-call tensor and assert that it remains the same object after the rejected update. Otherwise, a future change from copy_() to tensor reassignment could break that compatibility guarantee while this test continues to pass.
| expected_lags = delay_buffer.time_lags.clone() | |
| with pytest.raises(ValueError): | |
| delay_buffer.set_time_lag(time_lag, batch_ids) | |
| assert torch.equal(delay_buffer.time_lags, expected_lags) | |
| expected_lags = delay_buffer.time_lags | |
| expected_values = expected_lags.clone() | |
| with pytest.raises(ValueError): | |
| delay_buffer.set_time_lag(time_lag, batch_ids) | |
| assert delay_buffer.time_lags is expected_lags | |
| assert torch.equal(delay_buffer.time_lags, expected_values) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Description
Fixes #7793
DelayBuffer.set_time_lag currently writes the requested lag into the live tensor before validating the resulting range. If validation raises, the invalid value remains in the buffer and later compute() calls use it.
This stages the update in a cloned tensor, validates the complete candidate state, and commits it with copy_() only after validation succeeds. The existing tensor identity is preserved for callers that retain a reference to time_lags.
Type of change
Checklist
Local checks: python -m compileall and git diff --check passed. I could not run the unit test here because PyTorch is not installed and the uv-managed environment could not bootstrap in this container.