-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[https://nvbugs/6705472][feat] FA4 variable-length cross-attention #18973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
o-stoner
wants to merge
10
commits into
NVIDIA:main
Choose a base branch
from
o-stoner:user/o-stoner/visual-gen-variable-len-attn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
171d8d9
add FA4 cu_seqlens varlen cross-attention support
o-stoner 7c6b417
trim varlen attention tests
o-stoner 2cc7e14
avoid forced host-device sync in pack_ragged_kv, fix varlen cross-att…
o-stoner 4813317
padded q, varlen k/v for better perf
o-stoner 5120115
speed up pack_ragged_kv: host-side cumsum, cache cu_seqlens_kv by kv_…
o-stoner 60bb3e8
add production-scale and cache correctness tests for varlen cross-att…
o-stoner fdaac48
drop public varlen_cfg knob, cache cu_seqlens_kv/max_seqlen_kv
o-stoner ffedc89
add varlen attention test to CI
o-stoner 98f85b7
rename TestPackRaggedKvCache to TestPackRaggedKvMetadataCache
o-stoner 476ae55
Merge branch 'main' into user/o-stoner/visual-gen-variable-len-attn
o-stoner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For FA4, cu_seqlens_kv and max_seqlen_kv depend on the sequence lengths, so we could prepare them once per length layout and reuse them across layers/denoising steps
Could we follow the metadata preparation/cache pattern already used by the FlashInfer backend in #18174? Its batched prefill implementation uses shared attention_metadata_state to avoid rebuilding metadata and replanning on every compatible attention call. Or, with this attn_metadata refactor PR merged, it might be easier to update for FA4 backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
cu_seqlens_kv/max_seqlen_kvcaching keyed on the length layout, stored in the same sharedattention_metadata_statepattern as #18174 (get-or-compute-store instead of rebuilding on every call).pack_ragged_kvnow takes that state as an optional param and reuses the cached tensors on a hit. Covered byTestPackRaggedKvMetadataCacheandTestVarlenKvCacheSharedAcrossModel, but not yet hooked up into any model's forward pass since we don't use variable-length cross-attention by default anywhere yet