Repository navigation
[BugFix] Sample the inclusive high bound in integer Bounded.rand - #4497
Conversation
Bounded treats both bounds as inclusive (is_in and project accept high), but the integer branch of rand scaled a [0, 1) draw by high - low and cast it to the target dtype. The cast truncates toward zero, so high was never drawn, Bounded(0, 1, dtype=torch.int64).rand() always returned 0, and ranges that straddle zero never produced low and drew 0 twice as often as other values. Draw floor(u * (high - low + 1)) + low instead, clamped to high. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4497
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Cancelled Job, 2 Unrelated FailuresAs of commit dfbeae8 with merge base 71a4143 ( CANCELLED JOB - The following job was cancelled. Please retry:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @jayzuccarelli! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
theap06
left a comment
There was a problem hiding this comment.
Thanks for contributing and catching this! LGTM.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Bounded treats both bounds as inclusive (is_in and project accept high), but the integer branch of rand scaled a [0, 1) draw by high - low and cast it to the target dtype. The cast truncates toward zero, so high was never drawn, Bounded(0, 1, dtype=torch.int64).rand() always returned 0, and ranges that straddle zero never produced low and drew 0 twice as often as other values.
Draw floor(u * (high - low + 1)) + low instead, clamped to high.
Description
Describe your changes in detail.
Motivation and Context
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax
close #15213if this solves the issue #15213Types of changes
What types of changes does your code introduce? Remove all that do not apply:
Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!
AI assistance (Claude) was used to find and fix this; I reviewed the change and ran the tests.