Add unsigned support to IValue (#160102)

- Moved repeated logic of saving int64/uint64 into a polymorphic container into `THPUtils_unpackInteger`
- Added `TestPythonDispatch.test_dispatch_uint64` regression test

Fixes https://github.com/pytorch/pytorch/issues/159168

Pull Request resolved: https://github.com/pytorch/pytorch/pull/160102
Approved by: https://github.com/ezyang
This commit is contained in:
Nikita Shulga
2025-08-10 20:07:40 -04:00
committed by PyTorch MergeBot
parent e7152ff8a6
commit d8cb3db533
6 changed files with 86 additions and 19 deletions

View File

@ -2513,6 +2513,19 @@ def forward(self, x_1):
with Mode():
torch.cond(pred, lambda x: x.sin(), lambda x: x.cos(), (x,))
def test_dispatch_uint64(self):
class DummyMode(TorchDispatchMode):
def __torch_dispatch__(self, func, types, args, kwargs):
self.last_args = args
return func(*args, **kwargs)
# Value that could not be intepreted as signed int64
uarg = 2**63 + 1
with DummyMode() as m:
a = torch.full((3, 3), uarg, dtype=torch.uint64)
self.assertEqual(m.last_args[1], uarg)
self.assertTrue((a == uarg).all().item())
class TestPythonDispatcher(TestCase):
def test_basic(self):