Skip to content

fix(data): correct GaussianBlur probability semantics#342

Open
Ace3Z wants to merge 1 commit into
facebookresearch:mainfrom
Ace3Z:fix/gaussian-blur-probability-inversion
Open

fix(data): correct GaussianBlur probability semantics#342
Ace3Z wants to merge 1 commit into
facebookresearch:mainfrom
Ace3Z:fix/gaussian-blur-probability-inversion

Conversation

@Ace3Z

@Ace3Z Ace3Z commented May 24, 2026

Copy link
Copy Markdown

Closes #286.

GaussianBlur in dinov3/data/transforms.py was passing 1 - p to v2.RandomApply. The existing comment was wrong about how RandomApply works: it uses p as the probability of applying the transform, not the probability of returning the original image. So GaussianBlur(p=1.0) actually never blurred and GaussianBlur(p=0.0) always did. @mseitzer confirmed this in the issue, including the downstream effect that one global crop was never being blurred at training time.

Removed the 1 - p inversion so the class does what its parameter name says. Then swapped the call site values in augmentations.py to preserve the actual behavior used to train released DINOv3 and DINOv2 checkpoints (as requested in the issue thread). The mapping is p=1.0 -> p=0.0, p=0.1 -> p=0.9, p=0.5 unchanged. Added a one line comment so the next reader doesn't wonder why these don't match BYOL Table 6.

To sanity check that behavior is preserved, I ran the full DataAugmentationDINO pipeline on 200 random images with paired seeds and hashed all 14 crops per image, comparing against main. Zero mismatches across 2800 tensor hashes. The all-True mask the unfixed code passed is mathematically equivalent to None for the attention path, so this is a code cleanup, not a distribution change.

The same bug exists in DINOv2 (dinov2/data/transforms.py). Someone else has it on PR #411 over there.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 24, 2026
The `GaussianBlur` transform in `dinov3/data/transforms.py` passed `1 - p`
to `torchvision.transforms.v2.RandomApply`, inverting the meaning of `p`:
calling `GaussianBlur(p=1.0)` actually never blurred the image, while
`GaussianBlur(p=0.0)` blurred every image. Maintainer `@mseitzer`
confirmed the bug in facebookresearch#286: one global crop was never blurred at training
time despite the nominal `p=1.0`, and view 2 was blurred ~90% of the time
despite a nominal `p=0.1`.

Remove the `1 - p` inversion so `GaussianBlur(p=X)` actually applies blur
with probability `X`, matching `v2.RandomApply`'s documented semantics.

The augmentation call sites in `dinov3/data/augmentations.py` were
inverted in the same commit to preserve the de-facto behavior used to
train released DINOv3 / DINOv2 checkpoints (per the maintainer's
direction to "align the code of the augmentations with the actual
behavior"). A comment documents why the nominal probabilities differ
from BYOL Table 6.

Add `tests/test_gaussian_blur_probability.py` with four cases that pass
against the fix and fail against the previous inversion (3 of 4 fail on
`origin/main`).

Closes facebookresearch#286
@Ace3Z Ace3Z force-pushed the fix/gaussian-blur-probability-inversion branch from 9df8e1b to d13bc80 Compare May 25, 2026 08:46
@Ace3Z

Ace3Z commented May 29, 2026

Copy link
Copy Markdown
Author

Friendly ping @patricklabatut. This is a small fix for #286 (the GaussianBlur probability inversion) that @mseitzer confirmed in the thread. It preserves the behavior of released checkpoints. Whenever you have a moment, would appreciate a review.

@Ace3Z

Ace3Z commented May 29, 2026

Copy link
Copy Markdown
Author

Friendly ping. @patricklabatut, would you have a moment to take a look? Small probability semantics fix in GaussianBlur. Happy to address any feedback.

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 Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inverted probability while applying Gaussian

1 participant