Skip to content

Fix flaky image processor backend equivalence tests: configurable mean tolerance - #51110

Merged
ydshieh merged 1 commit into
mainfrom
fix-flaky-backend-equivalence-mean-atol
Nov 23, 2026
Merged

ydshieh merged 1 commit into
mainfrom
fix-flaky-backend-equivalence-mean-atol

Conversation

@ydshieh

@ydshieh ydshieh commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

The image processor backend-equivalence tests fail occasionally in PR CI:

  • CohereCompassImageProcessingTest::test_backends_equivalence_batched
  • GotOcr2ProcessingTest::test_backends_equivalence_crop_to_patches
  • Ovis2ProcessingTest::test_backends_equivalence_crop_to_patches

They fail with e.g. AssertionError: 0.00508 not less than or equal to 0.005. Seen 3 times in PR CI between 2026-11-19 and 2026-11-20; all 3 jobs ran pillow==13.0.0.

Why: Pillow 13

This comes from the same Pillow 13 change as #50105 / #50170 / #50327 / #50510: Pillow 13 can reverse the order of the two bicubic resize passes (python-pillow/Pillow#9549). Those PRs raised backend_equivalence_atol, the max per-pixel tolerance (0.1 -> 0.5). But the change also raises the mean difference, and that check (mean(|pil - torchvision|) <= 5e-3 in _assert_tensors_equivalence, hard-coded) was not adjusted.

Mean |pil - torchvision| per class, current main, torchvision 0.29.2, same random inputs as the tests:

Pillow 12.3.0: max (400 inputs) Pillow 13.0.0: max
GotOcr2 1.2e-4 5.30e-3 (2000 inputs; CI: 5.40e-3)
Ovis2 1.2e-4 5.35e-3 (2000 inputs)
CohereCompass 1.2e-4 5.23e-3 (2 x 400 inputs)

The 3 tests on main (300 runs each, pytest-flakefinder): Pillow 13: 2 / 900 failed; Pillow 12: 0 / 900.

Fix

  • Add a backend_equivalence_mean_atol class attribute (default 5e-3, so nothing changes for other models). _assert_tensors_equivalence uses it unless mean_atol is passed explicitly.
  • Set it to 1e-2 for these 3 test classes. Under Pillow 13 the tail stops around 5.3-5.4e-3 (no value above 6e-3 in 4000 GotOcr2 + Ovis2 samples). So 1e-2 is about 2x the worst case, while still about 80x above the Pillow 12 level, so a real processor bug would still show up.

Verification (Pillow 13.0.0, CPU, pytest-flakefinder, -n 16)

3 tests
before (main) 6 / 900 failed
after 0 / 4500 failed

The 4 image-processing test files (got_ocr2, ovis2, cohere_compass, llava): 107 passed, 18 skipped.

🤖 Generated with Claude Code

…n tolerance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: cohere_compass, got_ocr2, ovis2

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ydshieh
ydshieh marked this pull request as ready for review November 23, 2026 12:21
@ydshieh
ydshieh merged commit 95eb510 into main Nov 23, 2026
125 of 127 checks passed
@ydshieh
ydshieh deleted the fix-flaky-backend-equivalence-mean-atol branch November 23, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants