[feat] Add opt-in FlashInfer attention backend for Wan - #1799
Open
klhhhhh wants to merge 9 commits into
Open
Conversation
Contributor
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
Contributor
Author
|
The benchmark script. |
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.
Summary
This PR adds an opt-in FlashInfer dense-attention backend for the standard
Wan inference path.
Enable it before constructing the generator:
The implementation calls:
Backend selection remains explicit and model-scoped. This PR adds
FLASHINFERonly to Wan's declaredsupported_attention_backends; it doesnot implicitly treat every layer that supports
FLASH_ATTNasFlashInfer-compatible.
Motivation
FastVideo already depends on
flashinfer-pythonfor other kernel paths, butdoes not expose FlashInfer's dense prefill attention through the common
attention backend interface.
Wan's video DiT recomputes full-sequence Q/K/V at each denoising step, so
FlashInfer's prefill attention API is the relevant dense-attention path rather
than its autoregressive decode API.
Implementation
The new backend:
[Q, K]custom-mask contract.original output dtype, with a warning.
launches one single-request prefill kernel per batch item.
Model scope
The initial validated model scope is:
Wan-AI/Wan2.1-T2V-1.3B-DiffusersThis PR intentionally does not add FlashInfer support to every existing model
that declares
FLASH_ATTN.Other model families, causal Wan variants, encoders, VAEs, and additional
attention shapes will be validated and enabled in follow-up PRs by explicitly
adding
FLASHINFERto their ownsupported_attention_backendsdeclarations.The FlashInfer cuDNN batched dense-attention path
(
cudnn_batch_prefill_with_kv_cache) is also out of scope for this PR and willbe evaluated separately.
Failure behavior
Selection follows FastVideo's existing model-level backend contract:
FLASHINFERsupport.flashinfer-python, pre-sm80 hardware, and unsupported headdimensions fail with explicit errors after a layer has selected FlashInfer.
inference-only error.
Tests
This PR adds coverage for:
Backend behavior
[B, H, Q, K]masks.Selector behavior
FLASHINFERfall back normally.FLASHINFERresolve to the new backend.CUDA platform resolution
flashinfer-python.Real CUDA parity
The GPU test compares the real FlashInfer CUDA kernel against Torch SDPA for:
Example:
Preliminary end-to-end result
Hardware and workload:
Wan-AI/Wan2.1-T2V-1.3B-DiffusersMeasured full-pipeline wall times:
FLASH_ATTNThis produced:
All three measured FlashInfer runs were faster than all three measured
FlashAttention runs in this experiment. The FlashInfer measurements also had
lower run-to-run variance:
This result should be treated as preliminary rather than a final kernel-level
performance claim:
favored the second benchmark arm.
scheduling, and other work outside attention.
backend="auto"; the final internal kernel was not pinned toFA2 or FA3.
A follow-up benchmark will reverse the backend order, disable output saving,
increase the number of measured runs, and profile the attention kernels
separately.
Limitations
Follow-ups
Separate PRs will cover: