[feat] Add FlashInfer attention backend support for MiniMax H3 - #1832
Open
klhhhhh wants to merge 21 commits into
Open
[feat] Add FlashInfer attention backend support for MiniMax H3#1832klhhhhh wants to merge 21 commits into
klhhhhh wants to merge 21 commits into
Conversation
Contributor
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
Contributor
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.
Dependency
This PR depends on the following PRs and should be reviewed and merged after both of them:
Dependency order:
PR #1799 introduces the shared opt-in
FLASHINFERattention backend usingsingle_prefill_with_kv_cache.PR #1827 extends that backend with the optional
cudnn_batch_prefill_with_kv_cacheimplementation.This PR enables MiniMax H3 to use the shared FlashInfer backend introduced by
those PRs. It does not duplicate the FlashInfer kernel implementation.
Summary
This PR adds opt-in FlashInfer attention support for MiniMax H3.
MiniMax H3 already uses FastVideo's shared
DistributedAttentionabstraction.Its attention tensors follow the BSHD contract expected by the existing
FlashInfer backend:
H3 also uses a head dimension of 128 and dense non-causal self-attention, which
is compatible with both FlashInfer implementations provided by the dependency
PRs.
The integration applies to:
DistributedAttentionUsage
Use the FlashInfer single-request implementation:
Use the FlashInfer cuDNN implementation:
The integration remains opt-in and does not change the default MiniMax H3
attention backend.
Implementation
Declare FlashInfer support for MiniMax H3
This PR adds
AttentionBackendEnum.FLASHINFERto:The supported backend list becomes:
Because
MiniMaxH3Attentionalready constructsDistributedAttention, noseparate FlashInfer call is added to the H3 model forward.
The resulting dispatch path is:
Preserve H3-specific attention behavior
MiniMax H3 rotates only 96 of its 128 attention-head channels.
The H3 model continues to apply its Q/K RMSNorm and partial RoPE before calling
DistributedAttention. FlashInfer therefore receives the same normalized androtated Q/K tensors as the existing Torch SDPA and FlashAttention paths.
No H3 packing, RoPE, projection, or output logic is changed by this PR.
Files changed
fastvideo/configs/models/dits/minimax_h3.pyAdds
AttentionBackendEnum.FLASHINFERto the backends supported byMiniMaxH3ArchConfig.fastvideo/tests/transformers/test_minimax_h3_fusion_routing.pyAdds a regression test verifying that MiniMax H3 continues to declare
FlashInfer support.
fastvideo/tests/transformers/test_minimax_h3_flashinfer.pyAdds MiniMax H3-specific FlashInfer integration tests covering:
MiniMaxH3AttentiontoDistributedAttentionFLASHINFERbackendTests
Run the model-routing and CUDA parity tests with:
The CUDA parity test constructs real
MiniMaxH3Attentionlayers and comparesthe complete attention output against Torch SDPA for both:
This is a model-level attention integration test rather than a direct
FlashInfer kernel-only test.
Scope
This PR covers MiniMax H3 dense-attention routing and model-level numerical
parity.
It does not yet include:
Performance considerations
MiniMax H3 packs text, conditioning, audio, and video tokens into one long
attention sequence. In common inference configurations, this packed document
uses an attention batch size of one.
As a result, the FlashInfer single-request implementation may be more suitable
for typical H3 inference than the cuDNN batched implementation. Both paths
remain explicitly selectable so that they can be evaluated on real H3
workloads before choosing any model-specific default.
Follow-ups
FlashAttention.
implementation for batch-size-one packed attention.