Skip to content
Discussion options

You must be logged in to vote

You’re right — comparing version strings directly is unsafe because of lexicographic ordering (e.g. "1.8.1" > "1.13.0"). The standard way to handle this is to parse versions properly. Your solution using packaging.version.parse is correct and aligns with PEP 440.

from packaging import version
kwargs = {"weights_only": True} if version.parse(torch.__version__) >= version.parse("1.13") else {}

That’s a clean fix and definitely PR-worthy. Just make sure to import packaging.version (not pkg_resources.packaging) since packaging is the modern maintained package.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RIP-Skillan
Comment options

Answer selected by RIP-Skillan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants