Repository navigation
Replace FusedAttention with FusedAttentionV2 - #873
Merged
Merged
Conversation
YashasSamaga
approved these changes
Sep 19, 2026
jason718
added a commit
that referenced
this pull request
Sep 26, 2026
Second merge of main into this sync branch, taking main from 0589a03 to 718d08f. Conflicts: - nn/attention/__init__.py: take main's removal of FusedAttention (#873). Vision's only changes to it were NotImplementedError guards for or_mask/and_mask/position_ids; FusedAttentionV2 subclasses Attention and already threads position_ids. Keep vision's Dict import. - nn/transformer/model.py: activation checkpointing preserves RNG state when dropout is active (vision, #828) or EMO routing needs segment IDs (main, #872), which also resolves main's "preserve RNG state if dropout is active" TODO.
This was referenced Sep 26, 2026
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.
Replace the original
FusedAttentionimplementation withFusedAttentionV2everywhere it was selected. Migrate the applicable tests to V2, including comparison with regular attention, RoPE, packed-document masking, and FLOP accounting. LegacyAttentionConfig(name="fused")configs still build through V2, retaining the packedw_qkv/w_outparameter layout, explicit backend selection, and the original FlashAttention 2 default. The migration does not mutate the saved config.Legacy fused RoPE maps to regular RoPE. This preserves checkpoint loading, but not numerical equivalence: outputs and especially low-precision RoPE gradients can differ, so resumed training can follow a different trajectory. The compatibility path warns about this, and the changelog documents it. Direct imports of the removed class must switch to V2.
Also update the
llama_like(fused_ops=True)factory, remove obsolete type checks and HF conversion's fused-only GPU restriction, and retain regression tests for serialized legacy configs, block overrides, strict packed-weight loading, and AdamW state. No official training script selects the original implementation. The local audit scripts and reports are excluded from this PR.Parity results
The pre-removal audit compared the original implementation at
0589a034fwith V2 plus the same config/RoPE migration, using unchanged elementwise tolerancesrtol=0.02,atol=0.002. Coverage included BF16/FP16, native and autocast parameters, bias/clipping, all RoPE scaling variants, full/low-precision RoPE, supplied buffers, dropout/eval, packed documents without RoPE, representative geometries, initialization, compilation, and two-GPU context parallelism.Main matrix and checkpoint jobs:
All 176 FA2 and 32 runnable FA3 no-RoPE local cases passed; outputs were exactly equal. FA2 full-precision RoPE passed 181/192 cases; low-precision RoPE passed 40/160 (all 80 BF16 cases failed). Runnable FA3 full-precision RoPE passed 78/88; low-precision BF16 passed 0/80. Most failures were in gradients. Maximum absolute differences across FA2 cases:
The original-versus-original control passed all 528 FA2 cases at the same tolerances. The RoPE differences above exceed that control's numerical acceptance gate; this PR accepts and documents the change rather than claiming universal parity.
Two-GPU FSDP checkpoint checks passed all four FA2 and two BF16 FA3 configurations, loading into both sharded and replicated V2. Loaded model/optimizer tensors matched exactly, and resumed steps passed. These were generated legacy-format fixtures, not independently obtained production checkpoints; arbitrary pickled modules and a two-rank-to-one-rank restart were not tested.
Isolated compilation and ring follow-up: FA2 had 15 passes and one RoPE bias-gradient failure (max absolute difference 0.0031932); FA3 BF16 had seven passes and one illegal CUDA access in the original implementation. One no-RoPE/no-dropout zig-zag ring case passed on both ranks before a subsequent dropout case segfaulted; ring coverage remains incomplete. Initial ring errors were dependency import failures. FA3 execution errors came from disabled FP16 kernels and a missing packed-varlen entry point in the test image. FA4 parity is not applicable: the original implementation rejects FA4's lack of packed-QKV support. No performance or long-run training equivalence is claimed.
Validation
Local attention suite: 114 passed, 1,009 skipped for unavailable hardware/dependencies.
Legacy transformer config regression: passed; block override and transformer FLOP tests: two passed.
Ruff over
src/, mypy over all 556 source files, formatting checks on changed Python files, andgit diff --check: passed.Focused GPU regression job: 11 passed. The subsequent factory change to ignore the legacy
use_flashflag was verified by the local config regression.Migrated V2 tests: local subset passed (6 passed, 4 GPU tests skipped); GPU replacement regression job: all 15 tests passed.