Skip to content

[inductor] Deterministic mode: turn off Triton FMA contraction, emit explicit FMAs - #204322

Closed
eellison wants to merge 5 commits into
gh/eellison/1131/basefrom
gh/eellison/1131/head
Closed

eellison wants to merge 5 commits into
gh/eellison/1131/basefrom
gh/eellison/1131/head

Conversation

@eellison

@eellison eellison commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes in progress PR is being worked on by the author, until the automated review accepts it Merged module: inductor release notes: inductor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants