-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
move TypedStorage handling to assertEqual #89557
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/89557
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 254491c: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
There are two distinct errors left:
-
https://github.com/pytorch/pytorch/actions/runs/3539134271/jobs/5941041682#step:10:99929
pytorch/test/test_serialization.py
Line 678 in 1588ea0
def test_save_different_dtype_unallocated(self): Unless I'm mistaken we should simply add
exact_dtype=False
to theassertEqual
calls. -
https://github.com/pytorch/pytorch/actions/runs/3539134271/jobs/5940935728#step:10:29047
Line 194 in 1588ea0
def test_storage_setitem(self, device, dtype): The problem is only occurs for the quantized dtypes. It happens, because you can't instantiate a new tensor with such a dtype directly, but our logic currently tries to.
As for your errors:
I think we want the dtypes to match when we perform the comparison--otherwise it wouldn't be possible to ensure an exact match, right? I'm not sure why the dtypes disagree. The loaded storage's dtype at least matches the saved storage's dtype in
You may be able to use something like this trick to interpret the quantized type as the appropriate nonquantized type: Lines 530 to 543 in 7322f73
|
I've looked more closely into the test and as is it makes little sense. Since we operate without any data pytorch/test/test_serialization.py Line 693 in b0bd5c4
the only thing we could be checking with pytorch/test/test_serialization.py Lines 688 to 689 in b0bd5c4
is the dtype. However, due to some quirks in >>> a = torch.tensor([], dtype=torch.int)
>>> b = a.float()
>>> torch.testing.assert_close(a, b)
AssertionError: The values for attribute 'dtype' do not match: torch.int32 != torch.float32.
>>> torch.testing.assert_close(a.tolist(), b.tolist()) Even if we had some data before, the check wouldn't have been doing a dtype check due to some legacy quirks in pytorch/torch/testing/_internal/common_utils.py Lines 1491 to 1496 in 8b08478
In conclusion, before this PR Now for the part why this is failing after this PR. A minimal reproduction is import io
import torch
dtype = torch.float64
other_dtype = torch.float32
t = torch.tensor([], dtype=dtype)
s = torch.TypedStorage(wrap_storage=t.storage().untyped(), dtype=other_dtype)
with io.BytesIO() as buffer:
torch.save([t, s], buffer)
buffer.seek(0)
*_, s_loaded = torch.load(buffer)
assert s_loaded.dtype == s.dtype Is the mismatch between Interestingly, the behavior is correct when only serializing
|
Ah sorry, I forgot about this until now. Yes the mismatch between Historically, it has not been possible to save/load multiple tensors/storages that point to the same location (though I think it may be fairly straightforward to add that feature now that all the storage refactoring is complete). In a = torch.tensor([])
s = a.storage() and this a = torch.tensor([])
s = torch.Storage() produce exactly the same We do allow saving and loading unallocated tensors/storages of different dtypes. The only reason why the test for this exists is because I broke this behavior at one point and had to fix it. The history of this is here: #58970 It probably would have been better if I had not used |
And it appears that the dtype mismatch between the saved and loaded storage is an upstream bug. If I change the test to do this: self.assertEqual(a.dtype, a_loaded.dtype)
self.assertEqual(b.dtype, b_loaded.dtype) it fails. I had assumed |
It will after this PR. Should we maybe xfail this test in this PR and merge it so you can have a testing ground? |
I took the liberty to do that in 822f6b2. In case you want to go another round, I'll revert later. |
Expected failure seems like a good idea to me |
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.
Stamped, but be sure to revert the fbgemm changes
@pytorchbot merge -g |
Merge startedYour change will be merged once all checks on your PR pass since you used the green (-g) flag (ETA: 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
#85303 added a patch to
torch.testing.assert_close
to handletorch.storage.TypedStorage
's. This change is not reflected in the docs and is not intended for the public API. This PR removes the patch ones again and moves the behavior toTestCase.assertEqual
instead. Meaning,TypedStorage
's are again not supported by the public API, but the behavior is the same for all internal use cases.cc @gujinghui @PenghuiCheng @XiaobingSuper @jianyuh @jgong5 @mingfeima @sanchitintel @ashokei @jingxu10 @min-jean-cho @yanbing-j @Guobing-Chen @Xia-Weiwen