[GH-ISSUE #169] pytorch version comparison code fails for pytorch 1.10 #148

Closed
opened 2026-10-31 21:11:43 +00:00 by bsakaguchi · 5 comments
Owner

Originally created by @matthewfranglen on GitHub (Nov 1, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/169

A warning is produced when running clip using pytorch version 1.10 or greater.

The version check code performs a comparison using strings. This fails for version 1.10 because string comparison is left to right and 1 is less than 7.

>>> ["1", "10", "0"] < ["1", "7", "1"]
True
>>> ["1", "9", "0"] < ["1", "7", "1"]
False

There is the TorchVersion class that would make this comparison easier to perform however that does not exist in pytorch 1.7. I suggest converting the strings into integers before performing the comparison.

Originally created by @matthewfranglen on GitHub (Nov 1, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/169 A warning is produced when running clip using pytorch version 1.10 or greater. The [version check code](https://github.com/openai/CLIP/blob/c13005fd422b20dcd11774e9fff46370887218e4/clip/clip.py#L22-L23) performs a comparison using strings. This fails for version 1.10 because string comparison is left to right and 1 is less than 7. ``` >>> ["1", "10", "0"] < ["1", "7", "1"] True >>> ["1", "9", "0"] < ["1", "7", "1"] False ``` There is the [TorchVersion](https://github.com/pytorch/pytorch/blob/8deaa476ac33daea6af4cf079eb13757ca86c2ad/torch/torch_version.py) class that would make this comparison easier to perform however that does not exist in pytorch 1.7. I suggest converting the strings into integers before performing the comparison.
Author
Owner

@jongwook commented on GitHub (Nov 1, 2021):

This was suggested in #160 but using TorchVersion does look cleaner. I'll look into fixing this

<!-- gh-comment-id:956699529 --> @jongwook commented on GitHub (Nov 1, 2021): This was suggested in #160 but using `TorchVersion` does look cleaner. I'll look into fixing this
Author
Owner

@matthewfranglen commented on GitHub (Nov 1, 2021):

Ah dammit I've just written an identical comparison. Looking at the 1.7 branch of torch I do not see TorchVersion as the torch_version.py file is missing. If you were able to import it to use it then the comparison would pass.

<!-- gh-comment-id:956712222 --> @matthewfranglen commented on GitHub (Nov 1, 2021): Ah dammit I've just written an identical comparison. Looking at the [1.7 branch](https://github.com/pytorch/pytorch/tree/1.7/torch) of torch I do not see TorchVersion as the torch_version.py file is missing. If you were able to import it to use it then the comparison would pass.
Author
Owner

@alex8937 commented on GitHub (Nov 9, 2021):

Got a problem when torch version is 1.9.0a0+2ecb2c7

<!-- gh-comment-id:963685190 --> @alex8937 commented on GitHub (Nov 9, 2021): Got a problem when torch version is `1.9.0a0+2ecb2c7`
Author
Owner

@vinhkhuc commented on GitHub (Nov 10, 2021):

Did anyone try packaging.version from setuptools? It seems to work well for the following test cases:

>>> from packaging import version
>>> version.parse("1.5.0") < version.parse("1.7.1")
True
>>> version.parse("1.10.0") < version.parse("1.7.1")
False
>>> version.parse("1.9.0") < version.parse("1.7.1")
False
>>> version.parse("1.9.0a0+2ecb2c7") < version.parse("1.7.1")
False
>>> import torch
>>> type(torch.__version__), torch.__version__
(<class 'torch.torch_version.TorchVersion'>, '1.10.0')
>>> version.parse(torch.__version__) < version.parse("1.7.1")
False
<!-- gh-comment-id:964716538 --> @vinhkhuc commented on GitHub (Nov 10, 2021): Did anyone try `packaging.version` from `setuptools`? It seems to work well for the following test cases: ``` >>> from packaging import version >>> version.parse("1.5.0") < version.parse("1.7.1") True >>> version.parse("1.10.0") < version.parse("1.7.1") False >>> version.parse("1.9.0") < version.parse("1.7.1") False >>> version.parse("1.9.0a0+2ecb2c7") < version.parse("1.7.1") False ``` ``` >>> import torch >>> type(torch.__version__), torch.__version__ (<class 'torch.torch_version.TorchVersion'>, '1.10.0') >>> version.parse(torch.__version__) < version.parse("1.7.1") False ```
Author
Owner

@jiahuei commented on GitHub (Nov 10, 2021):

This can be closed now since 573315e solves the issue.

<!-- gh-comment-id:964949597 --> @jiahuei commented on GitHub (Nov 10, 2021): This can be closed now since 573315e solves the issue.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#148
No description provided.