-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
[AIR] Address UserWarning
from Torch training
#28004
[AIR] Address UserWarning
from Torch training
#28004
Conversation
# NOTE: PyTorch raises a `UserWarning` if `ndarray` isn't writeable. See #28003. | ||
if not ndarray.flags["WRITEABLE"]: | ||
ndarray = np.copy(ndarray) | ||
return torch.as_tensor(ndarray, dtype=dtype, device=device) |
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.
I don't think that copying the ndarray here is the right solution, since we want to be able to reuse the shared memory tensor data buffers without incurring unnecessary copies. We're also under the expectation the user/model will not mutate these input tensors during training and inference, so I don't think that the copy is necessary for correctness.
What if we suppressed the warning instead via something like:
# NOTE: PyTorch raises a `UserWarning` if `ndarray` isn't writeable. See #28003. | |
if not ndarray.flags["WRITEABLE"]: | |
ndarray = np.copy(ndarray) | |
return torch.as_tensor(ndarray, dtype=dtype, device=device) | |
with warnings.catch_warnings(): | |
warnings.simplefilter("ignore") | |
tensor = torch.as_tensor(ndarray, dtype=dtype, device=device) | |
return tensor |
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.
Are we confident that the warning is harmless? If so, I think this is fine/
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.
If the user tries to mutate the tensor (e.g. with in-place tensor operations) then this will be undefined behavior, but the common case is that this tensor data buffer will be left untouched in Plasma until we either (a) transfer the tensor to the GPU, or (b) we create a new tensor via an operation that creates a copy; in either case, we're not likely to mutate it.
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.
I'm not sure if we should suppress the warning, though, since it's a useful signal to the user that they will need to .clone()
it if they wish to mutate it.
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.
It'd be great to suppress the repeated warnings (if that is somehow possible).
Closing this PR because I don't know how to suppress repeated warning with multiple workers |
Why are these changes needed?
Related issue number
Fixes #28003
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.