Skip to content

Replace FusedAttention with FusedAttentionV2 - #873

Merged
AkshitaB merged 2 commits into
mainfrom
akshitab/fused-attn-cleanup
Sep 23, 2026
Merged

AkshitaB merged 2 commits into
mainfrom
akshitab/fused-attn-cleanup

Conversation

@AkshitaB

@AkshitaB AkshitaB commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Replace the original FusedAttention implementation with FusedAttentionV2 everywhere it was selected. Migrate the applicable tests to V2, including comparison with regular attention, RoPE, packed-document masking, and FLOP accounting. Legacy AttentionConfig(name="fused") configs still build through V2, retaining the packed w_qkv / w_out parameter 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 0589a034f with V2 plus the same config/RoPE migration, using unchanged elementwise tolerances rtol=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:

Suite Pass Numerical fail Execution error
FA2 local, including initialization 398 131 0
FA3 local, including initialization 111 90 232
FA2 checkpoint/config/resume 8 0 0
FA3 checkpoint/config/resume 4 0 4
FA2 context parallel, per-rank results 224 72 296
FA3 context parallel, per-rank results 52 28 88

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:

RoPE Output Packed-QKV weight gradient Packed-QKV bias gradient
Full precision 0.00390625 0.03125 0.03125
Low precision, BF16 0.00390625 0.0625 0.125
Low precision, FP16 0.00048828125 0.0078125 0.015625

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, and git diff --check: passed.

  • Focused GPU regression job: 11 passed. The subsequent factory change to ignore the legacy use_flash flag 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.

@AkshitaB AkshitaB changed the title Remove legacy FusedAttention with checkpoint-compatible V2 migration Replace FusedAttention with FusedAttentionV2 Sep 18, 2026
@AkshitaB
AkshitaB merged commit 845bda9 into main Sep 23, 2026
24 checks passed
@AkshitaB
AkshitaB deleted the akshitab/fused-attn-cleanup branch September 23, 2026 17:55
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants