Unified type hints to support torchhub-based deployment on Python 3.8-3.9 #539
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all, I would like to thank the authors and contributors: your work inspires me and helped me a lot in learning computer vision!
I use slightly old environment with Python 3.8, and I like to use DINOv2 via PyTorch Hub. Recently, I found out that launching old code with same package versions now raises TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'. The problem was caused by commit 12592a9, especially by line 58 in layers/attention.py:
This pull request does not affect the code, but rather unifies type hints to be compatible with Python 3.8, which is still popular, especially in research papers. Moreover, some of "old school" annotations like Optional[float] were already used in the codebase, so I found it useful to unify them all to a single broadly supported format.
P.S., the workaround as of now is to specify earlier branches when loading model through PyTorch Hub:
torch.hub.load('facebookresearch/dinov2:qasfb-patch-3', 'dinov2_vits14')