Repository navigation
fix(rocm): make aiter_attn work for dense calls and honor causal / softmax_scale - #1708
Open
menglcai-amd wants to merge 2 commits into
Open
menglcai-amd wants to merge 2 commits into
menglcai-amd wants to merge 2 commits into
Conversation
Ulysses calls the attention backend with cu_seqlens=None. aiter_attn always used the varlen kernel, so it failed. When cu_seqlens_q is None, use aiter.flash_attn_func instead. The varlen path does not change. Signed-off-by: menglcai <menglcai@amd.com>
menglcai-amd
marked this pull request as ready for review
November 13, 2026 07:58
Signed-off-by: menglcai <menglcai@amd.com>
Author
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.



Problem
aiter_attnalways callsaiter.flash_attn_varlen_func. This kernel needscu_seqlens. Ulysses sequence parallel does not givecu_seqlens:UlyssesAttnWeight._dense_attention_kwargs()setscu_seqlens_qandcu_seqlens_kvtoNone. Thus,"attn_type": "aiter_attn"with Ulysses stops with this error:I found this problem when I ran MiniMax-H3-Image with
configs/minimax_h3_image/minimax_h3_image_tp_sp.jsonand"attn_type": "aiter_attn".Fix
When
cu_seqlens_qisNone,aiter_attncalls the dense kernelaiter.flash_attn_func. A 3-D input(S, H, D)gets a batch dimension of 1. The output shape is(B * S, H * D), the same as the shape fromtorch_sdpa. Theflash_attn3backend inlightx2v/common/ops/attn/flash_attn.py(lines 202-207) also calls its dense kernel for a 3-D input.When a caller gives
cu_seqlens,aiter_attnuses the varlen kernel as before. Other platforms do not load this file.aiter_attnnow also passescausalandsoftmax_scalefrom the caller to both aiter calls (dense and varlen). Before this change, aiter always usedcausal=Falseand the default scale. The Qwen3-VL text encoder of MiniMax-H3-Image calls attention withcausal=True, so withqwen3vl_attn_type: aiter_attnthe prompt embedding was wrong. The comment below shows the effect on the output image. Callers that pass neither value get the same result as before.Validation
PLATFORM=amd_rocmCorrectness: I compared
aiter_attnwithtorch_sdpathrough the LightX2V attention classes. Inputs are random bf16 tensors on one GCD.cu_seqlensgiven (no change)End to end: MiniMax-H3-Image T2I, 4096x4096, 6 steps, seed 42, with the prompt from
scripts/minimax_h3_image/run_minimax_h3_image_t2i_tp_sp.sh. The config isminimax_h3_image_tp_sp.json(TP2 x SP2, 4 GCDs). Onlyattn_typeis different. The times come from the rank 0 profiler log. I did one run for each case.Before this change, the
aiter_attncase stops with the error above. With this change, the image is correct. Theaiter_attnimage and thetorch_sdpaimage show the same scene. Some small details are different.Kernel: I measured one GCD with the per-rank attention shape of the run above: B=1, S=16896, H=14, D=128, bf16, no mask. The value is the mean of 10 iterations after 3 warmup iterations, with CUDA events.
torch.nn.functional.scaled_dot_product_attentionaiter.flash_attn_func