-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fixing user inputs for low, high in make_tensor
#61108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing user inputs for low, high in make_tensor
#61108
Conversation
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit cd166fa (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @krshrimali for the PR. Apart from my inline comments, I remember that discussed using torch.distributions.Uniform
as the base sampler rather than torch.rand
. What became of that plan?
Thanks for the review, @pmeier - I have addressed a couple of your comments, will take a better look and update this PR with changes suggested. Regarding using: |
make_tensor
make_tensor
…rshrimali/pytorch into origin_dev/make_tensor_min_max
Co-authored-by: Philip Meier <github.pmeier@posteo.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ready for another round of review, unless and until there are unexpected test failures. A couple of comments still require attention, I'm looking at them. Thanks!
Leaving some sample outputs from modified make_tensor
:
Click to expand!
>>> make_tensor((1, 2), device='cpu', dtype=torch.float32, low=-9, high=9)
tensor([[-8.4784, -1.7658]])
>>> make_tensor((1, 2), device='cpu', dtype=torch.uint8, low=-9, high=9)
tensor([[3, 2]], dtype=torch.uint8)
>>> make_tensor((1, 2), device='cpu', dtype=torch.uint8, low=-9, high=None)
tensor([[6, 4]], dtype=torch.uint8)
>>> make_tensor((1, 2), device='cpu', dtype=torch.uint8, low=None, high=None)
tensor([[2, 5]], dtype=torch.uint8)
>>> make_tensor((1, 2), device='cpu', dtype=torch.float32, low=None, high=None)
tensor([[ 3.1285, -3.0337]])
>>> make_tensor((1, 10), device='cpu', dtype=torch.float32, low=None, high=None)
tensor([[ 5.1067, 1.1351, 4.9473, 5.7744, -3.9730, 3.2708, -3.8939, 2.8211,
-4.7024, 4.1631]])
>>> make_tensor((1, 10), device='cpu', dtype=torch.float32, low=None, high=float('inf'))
tensor([[2.0459e+38, 1.0356e+38, 8.6688e+37, 2.1416e+38, 3.2889e+38, 2.5179e+38,
1.5371e+38, 1.6188e+38, 2.6685e+38, 5.1892e+37]])
>>> make_tensor((1, 2), device='cpu', dtype=torch.float32, low=float('inf'), high=float('inf'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/krshrimali/pytorch/torch/testing/_internal/common_utils.py", line 2047, in make_tensor
low, high = _modify_low_high(ranges_floats, low, high, default_values=(-9, 9))
File "/home/krshrimali/pytorch/torch/testing/_internal/common_utils.py", line 2028, in _modify_low_high
low = _for_val('low')
File "/home/krshrimali/pytorch/torch/testing/_internal/common_utils.py", line 2008, in _for_val
raise ValueError(f"Found invalid value {val} for {inp}")
ValueError: Found invalid value inf for low
>>> make_tensor((1,2), 'cpu', torch.float32, low=float('nan'), high=float('nan'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/krshrimali/pytorch/torch/testing/_internal/common_utils.py", line 2048, in make_tensor
low, high = _modify_low_high(ranges_floats, low, high, default_values=(-9, 9))
File "/home/krshrimali/pytorch/torch/testing/_internal/common_utils.py", line 2029, in _modify_low_high
low = _for_val('low')
File "/home/krshrimali/pytorch/torch/testing/_internal/common_utils.py", line 2009, in _for_val
raise ValueError(f"Found invalid value {val} for {inp}")
ValueError: Found invalid value nan for low
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good, @krshrimali. I just made a couple suggestions and then we should wait for the tests
…rshrimali/pytorch into origin_dev/make_tensor_min_max
This is ready for a final review @mruberry - thanks for your patience and help. PTAL, whenever you find the time. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool; finally a make_tensor() that respects the user's low and high!
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: **TODOs:** * [x] Do not clamp inputs for low and high when given and valid. * [x] Devise rules for modifying `low` and `high` when extremals/invalid values passed. * [x] Testing with `test_references_numerics_hard` with the revised changes. _(I've tested locally, the changes will take place in a separate PR though after offline discussion with mruberry)_ * [x] Revise comments/documentation for `make_tensor` See #61758 for tracker issue. cc: mruberry pmeier Pull Request resolved: #61108 Reviewed By: VitalyFedyunin Differential Revision: D30296167 Pulled By: mruberry fbshipit-source-id: 67e8d15b173209a9c97ca013231494a5fa99f8c7
TODOs:
low
andhigh
when extremals/invalid values passed.test_references_numerics_hard
with the revised changes. (I've tested locally, the changes will take place in a separate PR though after offline discussion with @mruberry)make_tensor
See #61758 for tracker issue.
cc: @mruberry @pmeier