Fix flaky ReplaceTrivialConvWithLinear pass validation tolerance (#18482)#18482
Merged
meta-codesync[bot] merged 1 commit intopytorch:mainfrom Mar 25, 2026
Merged
Conversation
Contributor
|
@hsharma35 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D98001101. |
This PR needs a
|
DrJessop
approved these changes
Mar 25, 2026
…orch#18482) Summary: The `test_replace_conv2d_with_linear` and `test_replace_conv1d_with_linear` tests validate that replacing trivial convolutions with linear ops produces numerically equivalent outputs. Both operations compute the same dot product (sum of element-wise products), but conv accumulates across spatial dimensions (C,H,W) while linear accumulates over a flattened K dimension. With K=294 (conv2d: 6*7*7) or K=672 (conv1d: 96*7) fp32 terms, different accumulation orders produce diffs up to ~1.2e-05 due to non-associativity of floating-point addition. This is not a correctness issue — the mathematical operation is identical. Relax rtol from 1e-05 to 2e-05 to accommodate fp32 accumulation order differences while remaining tight enough to catch real bugs. Reviewed By: DrJessop Differential Revision: D98001101
5c7745a to
3360b25
Compare
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.
Summary:
The
test_replace_conv2d_with_linearandtest_replace_conv1d_with_lineartests validate that replacing trivial convolutions with linear ops produces
numerically equivalent outputs. Both operations compute the same dot product
(sum of element-wise products), but conv accumulates across spatial dimensions
(C,H,W) while linear accumulates over a flattened K dimension. With K=294
(conv2d: 677) or K=672 (conv1d: 96*7) fp32 terms, different accumulation
orders produce diffs up to ~1.2e-05 due to non-associativity of floating-point
addition.
This is not a correctness issue — the mathematical operation is identical.
Relax rtol from 1e-05 to 2e-05 to accommodate fp32 accumulation order
differences while remaining tight enough to catch real bugs.
Reviewed By: DrJessop
Differential Revision: D98001101