Repository navigation
fix(augmentation): keep inverse mask sampling flags local - #5300
Merged
Merged
Conversation
Ai-Eastern
marked this pull request as ready for review
October 1, 2026 17:03
ducha-aiki
approved these changes
Oct 2, 2026
ducha-aiki
left a comment
Member
There was a problem hiding this comment.
Thanks, @Ai-Eastern. Copying flags at the top of inverse_masks is the first fix option from #5290, and it covers both overrides: resample and align_corners. On the success path the output is unchanged. inverse_inputs already merges kwargs into a copy (override_parameters(..., in_place=False)), so nothing outside the call relied on the in-place writes.
Measured on this branch merged with main 8ee1a67 (torch 2.14, CPU), using the repro from #5290:
- On
main, after the raising inverse, the module keepsResample.NEAREST, and the next image differs from a fresh container by 0.7621. This happens with call-time keys["mask", "input"]and with["mask"]. - On this PR, the flag stays
BILINEARand the difference is 0. - A direct
inverse_masks(..., align_corners=None/False/True)call that raises leavesflagsunchanged. Onmainit leavesresampleat nearest and, forFalse,align_cornersatFalse.
On the tests:
- With your tests overlaid on
main, 8 of the 14 fail. The 6 success-path cases pass there, as expected, becausemainrestores the flags when the inverse does not raise. - On the merged tree all 14 pass on CPU f32, f64, f16 and bf16 (with the known-failure profiles) and on MPS f32.
tests/augmentation/container/,test_base.pyandtest_half_precision_ci.pygive 1893 passed. That includes the RNG audit; your tests sit below the audited line.- Four one-token mutants of
inverse_masksare killed by your tests: dropping the copy, nearest → bilinear, dropping thealign_corners=Nonenormalisation, and normalising toFalse.
The branch merges cleanly with main, and CI is green. Approving.
Posted on behalf of @ducha-aiki by Claude (Opus 5.5).
ducha-aiki
enabled auto-merge (squash)
October 2, 2026 08:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #5290
Copy the flags dictionary inside inverse_masks so temporary mask sampling overrides cannot leak into the caller’s state, including when inverse_inputs raises. Preserve normal interpolation, explicit resample overrides, align_corners=None normalization and the original exception. This does not change the container data-key handling in #5149.
Real regressions cover mask-first and mask-only container inverses, direct calls with shared/separate flags, image processing after an exception, and successful nearest/bilinear inverse sampling with None/False/True align_corners overrides.
Validation by Codex on Linux CPU, Python 3.12.14 and PyTorch 2.9.1+cpu:
The two broader suites ran before a final test-style-only correction; the runtime implementation was unchanged. Focused tests and pre-commit were rerun on the final files. Individual XPASS cases and skip reasons were not captured, and no untouched-base comparison was run. Full-repository tests, GPU/MPS, half precision and Inductor were not run. Pixi was unavailable, so equivalent underlying commands ran in an isolated virtualenv. Remote CI remains unverified.
AI use: Codex investigated the issue, wrote the fix/tests/changelog, ran the listed checks, reviewed the diff and prepared this description. The contributor authorized the scope and publication; the checks were performed by Codex.