Skip to content

Fix conceptually incorrect, non-breaking image shape tuple unpacking. - #582

Open
SSKlearns wants to merge 1 commit into
facebookresearch:mainfrom
SSKlearns:main
Open

Fix conceptually incorrect, non-breaking image shape tuple unpacking.#582
SSKlearns wants to merge 1 commit into
facebookresearch:mainfrom
SSKlearns:main

Conversation

@SSKlearns

Copy link
Copy Markdown

In the current implementation, the code unpacks the tensor shape as: B, nc, w, h = x.shape

In PyTorch, the standard memory layout for 4D tensors is NCHW. By assigning the third dimension to W and the fourth to H, the spatial dimensions are logically inverted. For models trained on square images, this has zero impact on performance as H=W.

If this ViT class is used in future research for non-square inputs (e.g., 384×512), the positional embeddings will be calculated using incorrect spatial coordinates. This leads to a misalignment between the input patches and their corresponding positional encodings, potentially degrading model convergence and downstream performance.

I believe this error has propagated from DINO, and is not existent in DINOv3.

@meta-cla meta-cla 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 Feb 7, 2026
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.

1 participant