Repository navigation
Studio int8 folds: do not fold an add with a non-unit alpha - #17794
Merged
Merged
Conversation
The residual, GELU and norm folds in the native W8A8 post-grad pass matched aten.add without reading its alpha kwarg and rebuilt the plain x + y, so torch.add(x, y, alpha=2) folded into x + y and changed the result. _fn now refuses an add whose alpha is not 1, the norm fold refuses a mean with a non-fp32 dtype, and the pass uuid moves to v3 so graphs folded before this check miss the FX graph cache.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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
Follow-up to #17680. The native W8A8 post-grad pass folds
residual + linear(x) * gateinto the GEMM epilogue, but its matcher read only the two positional operands ofaten.add.Tensorand ignored the keyword-onlyalpha. A graph such astorch.add(residual, y * gate, alpha=2)(which isresidual + 2 * y * gate) was folded intoresidual + y * gate, a silent wrong result. The GELU and norm folds had the same gap on the adds they match (1 + tanh(...),a + 0.044715 * a^3,1 + scale,n * (1 + scale) + shift,mean + eps).Changes
_fn(the target check every matcher uses) now rejects an add whosealphais not exactly 1. Every fold rebuilds the unit-coefficient add, so a scaled add simply stays as traced.aten.mean.dimcarrying a non-fp32dtype, since the prologue always computes the fp32 statistic.share.v2toshare.v3, so any FX graph folded before this check misses the cache instead of being reused.The default LTX-2.5 style graphs have no
alphakwarg on these adds, so they fold exactly as before (the existing fold tests are unchanged and pass). The check is compile-time only: it runs while Inductor rewrites the graph and adds no per-call host work.Tests
studio/backend/tests/test_diffusion_native_w8a8_cuda.py:test_folds_refuse_a_scaled_add: for every matched add in the three folds andalphain (2, -1, 0.5), the fold returns 0 and the graph output equals the scaled eager result bit for bit;alpha=1still folds.test_norm_fold_refuses_a_low_precision_meanandtest_pass_uuid_names_the_alpha_aware_folds.origin/mainA standalone repro that installs the real pass in
post_grad_custom_pre_passand runstorch.compile(fullgraph=True)on CPU gave 5 instead of 9 on main foralpha=2; on this branch it gives 9 with 0 folds.No GPU run: default inputs take the same folds as before, so the GPU path is unchanged.