Skip to content

fix: do not require packaging for Torch 2.3.0+ datatype support#705

Open
akx wants to merge 1 commit intohuggingface:mainfrom
akx:no-packaging
Open

fix: do not require packaging for Torch 2.3.0+ datatype support#705
akx wants to merge 1 commit intohuggingface:mainfrom
akx:no-packaging

Conversation

@akx
Copy link
Contributor

@akx akx commented Feb 9, 2026

What does this PR do?

This PR drops the dependency on packaging; looking at whether torch.uint64 exists is enough of a canary to see whether Torch 2.3.0 is in use and the new uint types are there.

$ uvx --python=3.10 --with=torch==2.0.0 python -c 'import torch; print(torch.__version__, hasattr(torch, "uint16"), hasattr(torch, "uint32"), hasattr(torch, "uint64"))'
2.0.0 False False False
$ uvx --python=3.10 --with=torch==2.1.0 python -c 'import torch; print(torch.__version__, hasattr(torch, "uint16"), hasattr(torch, "uint32"), hasattr(torch, "uint64"))'
2.1.0 False False False
$ uvx --python=3.10 --with=torch==2.2.0 python -c 'import torch; print(torch.__version__, hasattr(torch, "uint16"), hasattr(torch, "uint32"), hasattr(torch, "uint64"))'
2.2.0 False False False
$ uvx --python=3.10 --with=torch==2.3.0 python -c 'import torch; print(torch.__version__, hasattr(torch, "uint16"), hasattr(torch, "uint32"), hasattr(torch, "uint64"))'
2.3.0 True True True

Beyond the unnecessary dependency, this is also faster and that's not counting the import time for packaging...

$ uvx --python=3.10 --with=torch==2.3.0 --with=packaging python -m timeit -s 'from packaging.version import Version; import torch' 'Version(torch.__version__) >= Version("2.3.0")'
100000 loops, best of 5: 3.72 usec per loop
$ uvx --python=3.10 --with=torch==2.3.0 --with=packaging python -m timeit -s 'import torch' 'hasattr(torch, "uint64")'
10000000 loops, best of 5: 30.6 nsec per loop

Follows up on #664, #643.

@SunMarc SunMarc requested a review from danieldk February 27, 2026 13:11
@akx akx requested a review from McPatate as a code owner March 11, 2026 08:39
@akx
Copy link
Contributor Author

akx commented Mar 11, 2026

Rebased post #710. Strictly speaking the hasattr checks aren't required anymore since the minimum bound is torch 2.4.0, but there's a whole bunch of other torch version check stuff that became obsolete with #710 still hanging around, so another PR would be good to clean that up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant