Validate paged-KV host config (tile_n divisible by KV-load thread count)#2615
Open
fxdv wants to merge 1 commit into
Open
Validate paged-KV host config (tile_n divisible by KV-load thread count)#2615fxdv wants to merge 1 commit into
fxdv wants to merge 1 commit into
Conversation
Author
|
Hi @Johnsonms — would you have a moment to review this when convenient? Small host-side validation for the cp.async paged-KV path: fails fast with a clear Includes GPU-free tests in Happy to rebase on latest |
75b3bcf to
6f7fa7f
Compare
6f7fa7f to
0e5d18e
Compare
The cp.async (non-TMA) paged-KV path derives page_entry_per_thread = n_block_size // <KV-load threads> in PagedKVManager.create. When tile_n is not an exact multiple of the loader thread count, the trailing KV rows of each n-block are silently dropped (or page_entry_per_thread hits 0), producing wrong output or an opaque failure deep inside JIT compilation. Validate this in _flash_attn_fwd before compilation: when page_table is set and page_size != tile_n, require tile_n to be divisible by the KV-load thread count (128 on SM90; 128/64 on SM100/SM110 depending on q_stage), and raise a ValueError naming the offending values otherwise. Scoped to the standard SM90/SM100/SM110 forward; the dedicated hd256 kernel and the MLA (qv) path use their own loaders and keep their existing checks. Add tests/cute/test_paged_kv_validation.py: a GPU-free test that runs under FakeTensorMode with a cute.compile sentinel, asserting invalid configs raise ValueError before compilation, valid configs clear the guard, and the TMA path (page_size == tile_n) is unaffected.
0e5d18e to
902af74
Compare
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.
What
Adds a host-side
ValueErrorguard in_flash_attn_fwdfor the cp.async paged-KV load path. It requirestile_n % <kv_load_threads> == 0so thatpage_entry_per_thread = n_block_size // num_threadsinPagedKVManager.createis exact. Without this, a misconfiguredtile_nmakes the page-table load loop run too few (or zero) iterations, so the trailing KV rows of every n-block are silently never fetched — producing wrong output or an opaque failure deep inside JIT compilation.Scope
The guard fires only when:
page_table is not None, andpage_size not in (None, tile_n)), andqv is None), non-hd256 dedicated kernel, arch SM90/SM100/SM110.The KV-load thread count is the loader's thread count, not the interface
num_threads:num_threads_per_warp_group).q_stage == 1(load warps = softmax1, 4 warps), else 64 (load warps 14–15). This mirrorsFlashAttentionForwardSm100'sload_warp_idsselection and thenum_load_threadspassed toPagedKVManager.create.The MLA (
qv) path and the dedicated hd256 kernel use their own KV loaders and keep their existing checks, so they are excluded.Why
Fail fast with a clear, actionable message for vLLM-style paging misconfigurations instead of returning silently-wrong results or surfacing an opaque compilation error.
Test plan
New GPU-free test
tests/cute/test_paged_kv_validation.py(runs underFakeTensorModewith acute.compilesentinel):tile_n=96, cp.async path) → raisesValueErrorbefore compilation,tile_n=128, cp.async path) → clears the guard and reaches compilation,page_size == tile_n) → guard bypassed even withtile_n=96.Validation caveat
The change was validated statically (ruff and AST parse are clean) but the tests were not executed locally: the contributor host is Apple Silicon macOS without torch/CUDA. Running the test suite requires a Linux + CUDA host or CI.