Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Findings (1): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/204321
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 Cancelled Jobs, 1 Unclassified FailureAs of commit 9ccea8e with merge base 304eed3 ( 🟢 GREEN LIGHT - PR approved to be merged without human review:
reason: UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Automated review of 18dbec9: nothing blocking; ready for human review.
The PR changes online_softmax_reduce_scalar_combine to select exp(delta) with tl.where(rhs_mask, ..., 0.0) instead of multiplying by a 0/1 mask, dropping one multiply per element, and the review confirms it is bitwise-equivalent. Recommendation: Approve; the only remaining point, about duplicated max/delta code, is labeled non-blocking.
⚪ 1 non-blocking finding
Duplicated max/delta logic (non-blocking, carried over from the last review, no reply yet). Lines 475-480 copy the max/delta code of online_softmax_reduce (lines 419-424) with only the variable names changed: the max2_strict/max2 choice, the tl.expand_dims call, and the -inf guard on delta. online_softmax_reduce is still used through online_softmax_reduce_final_reduction (triton.py:6883) by the persistent, looped-vector and cooperative paths. If one copy changes later (e.g. the -inf guard), the looped scalar path would silently disagree with those paths. Fix: add a small @ triton.jit helper that returns (max, delta) and have each caller keep its own sum line, as max_with_first_index and online_softmax_combine_with_sum already do. Triton inlines jit callees, so the speedup is kept. Also, the strict_signed_zero branch at lines 475-476 can't be reached from codegen, because use_scalar_accumulators (triton.py:5851) turns the scalar path off under config.strict_signed_zero. If the copy stays, that branch could be dropped instead of being duplicated.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
[ghstack-poisoned]
|
Rebased |
|
Starting merge as part of PR stack under #204322 |
1 similar comment
|
Starting merge as part of PR stack under #204322 |
…explicit FMAs (#204322) **Problem** #202218 added `triton.enable_fp_fusion`: with it off, Inductor's Triton kernels round every multiply and add separately, so results no longer depend on the block size or `num_warps` that autotuning, coordinate descent or the default heuristic picks. Deterministic mode itself still left contraction on, so a deterministic-mode run could still produce different bits depending on which pointwise config timing picked. **Change** - Deterministic mode (and `batch_invariant`) now compiles Inductor's generated Triton kernels with `enable_fp_fusion=False`, via a new `triton_fp_fusion_enabled()` helper in `utils.py` used by `triton_meta_common`. - The multiply-adds in `triton_helpers` are written as explicit `tl.fma`, so they keep a single rounding regardless of the contraction setting: `welford_reduce`, `welford_combine`, `online_softmax_combine(_with_sum)`, and `rand_eager_kernel` (bit-neutral there, since `inv = 2**-32` makes the product exact). - Templates (matmul, flex attention) build their own `triton_meta` and keep Triton's contraction. In deterministic mode their config is already chosen without benchmarking. Under `batch_invariant` alone, templates and their fused epilogues are not covered by this PR. **Numerics outside deterministic mode** The `tl.fma` calls in `triton_helpers` are unconditional. In modes where contraction was already off before this PR (`triton.enable_fp_fusion=False`, `emulate_precision_casts`, and `numerics="strict"` / `strict_pointwise`, which imply it), welford (`var_mean`, `layer_norm`) and online-softmax results can change in the last bit. With contraction on (the default), Triton was already free to form these FMAs. **Performance** Turning contraction off costs speed in deterministic mode only; default mode is unchanged. On better-benchmark (1724 kernels, H100, Nov 2 nightly), `triton.enable_fp_fusion=False` measured +0.25% geomean. The slowdowns are concentrated in a few latency-bound reductions where a product feeding an add is no longer fused, e.g. two softmax kernels (~+30%), a `var_mean` (~+12%) and a `sum` (~+10%). These per-kernel numbers were measured on an earlier revision of this PR; the kernels were attributed to contraction being off, not to the helper changes. The online-softmax change below this PR (#204321) recovers the cross-entropy kernels (`amax_sum_sum_a97be2219d64`: 1782 us in deterministic mode today -> 1378 us). Note: without the Dynamo fix at the bottom of this stack (#204320), `config.deterministic` set alone is turned off after the first compiled frame. **Test plan** ``` python test/inductor/test_deterministic.py python test/inductor/test_triton_helpers.py ``` - `test_fp_fusion`: deterministic mode turns off `enable_fp_fusion`; the flag alone still works as before. - `test_pointwise_config_numerics` runs with deterministic mode alone and with `triton.enable_fp_fusion=False` alone: forcing XBLOCK=128 vs 256 by timing gives bitwise-equal outputs. - `test_kernel_online_softmax_combine`: reference updated to the explicit-FMA form. This change was authored with an AI assistant (Claude Code), with the change and tests reviewed in the session. Pull Request resolved: #204322 Approved by: https://github.com/mlazos ghstack dependencies: #204320, #204321
Stack from ghstack (oldest at bottom):
Change
online_softmax_reduce_scalar_combine(used by looped online-softmax reductions, e.g. log_softmax/cross-entropy over a large vocabulary) summedexp(delta)weighted by a 0/1 mask:online_softmax_reduce(rhs, tl.where(mask, 1.0, 0.0), ...), i.e.tl.sum(mask * exp(delta)). It now selects with the mask:tl.sum(tl.where(mask, exp(delta), 0.0)).The result is bitwise the same: the mask is exactly 0 or 1,
acc + 1.0 * eandfma(1.0, e, acc)both equalacc + e, and masked lanes are-inf, soexpthere is finite and0.0 * e == 0. The multiply per element goes away. With FMA contraction off (deterministic mode in the next PR, ortriton.enable_fp_fusion=False) that multiply was a separate FMUL feeding each add of the in-thread sum, which made these kernels about 10% slower.Performance (H100, 2026-11-02 nightly, better-benchmark cross-entropy kernels from HF models, two runs each)
amax_sum_sum_fb4ae0eb915famax_sum_sum_52903d400fefamax_sum_sum_a97be2219d64amax_sum_sum_81caaa5dd022With the next PR in this stack (deterministic mode, contraction off),
amax_sum_sum_a97be2219d64goes from 1782 us (deterministic mode today) to 1378 us, andamax_sum_sum_fb4ae0eb915ffrom 2257 us to 1341 us.Test plan
python test/inductor/test_online_softmax.py(75 tests) passes, with the default config and withTORCHINDUCTOR_ENABLE_FP_FUSION=0. Outputs of the four kernels above are bitwise equal before and after the change.This change was authored with an AI assistant (Claude Code), with the change and tests reviewed in the session.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo