Conversation
fa2/fa3 share transformers' single flash_attention_forward entry and dispatch to the concrete kernel at call time via config._attn_implementation. Register the SP wrapper under the fa3 key as well (exact-key registry lookup would otherwise silently train without SP), and add the fa3 leaf to zigzag ring attention via flash_attn_interface (gradients through dq/dk/dv buffer mutation). Also log the requested vs resolved attn_implementation at model build. Verified on H800: fa3/fa2 training curves match to bf16 noise on Qwen3-0.6B (ring, ulysses) and Qwen3.5-4B (ulysses), transformers 4.57.0 and 5.15.1.
Companion to dadb3f0 which moved the helper out of vllm_sampler_tq; the stale import broke test collection in CI.
meichangsu1
reviewed
Sep 29, 2026
| local_flash_attn, dist_attn=DistributedAttention(None, self)) | ||
| for _impl in FLASH_ATTENTION_IMPLS: | ||
| ALL_ATTENTION_FUNCTIONS[_impl] = partial( | ||
| local_flash_attn, dist_attn=DistributedAttention(None, self)) |
Collaborator
There was a problem hiding this comment.
有 dropout 但是用了fa3 就报错吧;还有就是做一下精度对齐,前向loss和反向梯度都和sdpa 比一下
Contributor
Author
There was a problem hiding this comment.
精度对齐(H800,fa3 vs fa2,单卡 varlen,H=8 D=128,LENS=[100,300,512],transformers=5.15.1):
| 检查项 | 结果 |
|---|---|
| out 数值 | max|Δ|=3.91e-03 |
| lse 数值 | max|Δ|=4.77e-07 |
| dq 数值 | max|Δ|=3.91e-03 |
| dk 数值 | max|Δ|=7.81e-03 |
| dv 数值 | max|Δ|=3.91e-03 |
unit test:
| 测试 | 结果 |
|---|---|
| sp_only_multi_sample | PASS |
| sp_only_multi_sample_masked | PASS |
| cp_only | PASS |
| cp_sp | PASS |
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.
PR type
PR information
Add FlashAttention-3 support for CUDA and ring attn.
Experiment results
1a. Qwen3-0.6B × transformers 5.15.1
1b. Qwen3.5-4B × transformers 5.15.1
1c. Qwen3-0.6B × transformers 4.57.0