Skip to content
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

[misc] Add conversions for unsigned types, torch > 2.3.0 #8528

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions python/taichi/lang/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,18 @@ def to_pytorch_type(dt):
return torch.uint8
if dt == f16:
return torch.float16

if dt in (u16, u32, u64):
raise RuntimeError(f"PyTorch doesn't support {dt.to_string()} data type.")
if hasattr(torch, "uint16"):
if dt == u16:
return torch.uint16
if dt == u32:
return torch.uint32
if dt == u64:
return torch.uint64
raise RuntimeError(f"PyTorch doesn't support {dt.to_string()} data type before version 2.3.0.")

raise RuntimeError(f"PyTorch doesn't support {dt.to_string()} data type.")
assert False
bobcao3 marked this conversation as resolved.
Show resolved Hide resolved


Expand Down Expand Up @@ -266,8 +276,16 @@ def to_taichi_type(dt):
return u8
if dt == torch.float16:
return f16
if dt in (u16, u32, u64):
raise RuntimeError(f"PyTorch doesn't support {dt.to_string()} data type.")

if hasattr(torch, "uint16"):
if dt == torch.uint16:
return u16
if dt == torch.uint32:
return u32
if dt == torch.uint64:
return u64

raise RuntimeError(f"PyTorch doesn't support {dt.to_string()} data type before version 2.3.0.")

if has_paddle():
import paddle # pylint: disable=C0415
Expand Down
Loading