Skip to content

Conversation

@rwmutel
Copy link

@rwmutel rwmutel commented Jul 2, 2025

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:

File "/root/.cache/torch/hub/facebookresearch_dinov2_main/dinov2/layers/attention.py", line 58, in Attention
    self, init_attn_std: float | None = None, init_proj_std: float | None = None, factor: float = 1.0
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

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')

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants