Repository navigation
[Fea] beam search sm8x support - #407
Conversation
Greptile SummaryThis PR enables
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to the jagged prefill fast path and the return-value handling correctly matches FA2's interface. The Mode 1 switch from cute to FA2 is mechanically correct: FA2's flash_attn_varlen_func returns a plain tensor (not a tuple), so dropping the tuple-unpack is right. The max_seqlen argument is properly typed as int, guarded by an assertion, and threaded through all call sites. Test gating is logically consistent — only tests that exercise cute FA paths (Mode 2/3) are skipped on A100, while test_generate_beam_decode_e2e intentionally runs ungated. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["JaggedFlashAttnBlock.prefill()"] --> B{cu_seqlens set?}
B -- Yes --> C["Mode 1: Jagged varlen\nflash_attn.flash_attn_interface\nflash_attn_varlen_func\n✅ SM80+ (FA2)"]
B -- No --> D{arbitrary_func set?}
D -- Yes --> E["Mode 2: Arbitrary mask\nflash_attn.cute.interface\nflash_attn_func\n⚠️ SM90+ only"]
D -- No --> F["Mode 3: Dense causal\nflash_attn.cute.interface\nflash_attn_func\n⚠️ SM90+ only"]
C --> G["max_seqlen required\n(FA2 needs explicit value)"]
G --> J["attn_flat = flash_attn_varlen_func(...)"]
E --> K["attn_out, _ = flash_attn_func(...)"]
F --> L["attn_out, _ = flash_attn_func(...)"]
Reviews (3): Last reviewed commit: "refactor(sid_gr/tests): consolidate SM90..." | Re-trigger Greptile |
The cute `flash_attn.cute.interface.flash_attn_varlen_func` hard-asserts
compute_capability in [9, 10], blocking A100. The jagged prefill we use
in `generate_beam_decode()` is plain causal over `[history+BOS]` packed
via `cu_seqlens` — no arbitrary mask — which standard FA2
(`flash_attn.flash_attn_interface.flash_attn_varlen_func`) supports
natively on SM80+. FA2 is shipped pre-built in the nvcr pytorch base
image (flash_attn_2_cuda.so already on PYTHONPATH), so the swap is a
local import change plus the `max_seqlen_q/k` positional args that FA2
requires (cute could infer from `cu_seqlens`; FA2 cannot).
After the swap, `generate_beam_decode()` runs end-to-end on A100:
- prefill via FA2 (SM80+)
- decode via Jerry's beam_decode_attn kernel (SM8x supported per its
README arch table)
The baseline `generate()` path and the dense Mode-3 prefill fallback
still use cute FA (arbitrary mask / causal-dense), so they remain
SM90+ only. Test gating for those is added in a follow-up commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: Runchu Zhao <[email protected]>
After the fast-path swap to FA2, the only remaining cute FA call sites
are:
- `JaggedGPTLayer.forward()` arbitrary-mask path (baseline
`generate()` and training)
- `JaggedGPTLayer.prefill()` Mode-3 dense causal fallback
(`use_jagged_kv=False`)
Both go through `flash_attn.cute.interface` which asserts
compute_capability in [9, 10], so any test that exercises them crashes
on A100. Gate those tests on a new `_SM90_AVAILABLE` flag so the A100
CI lane can run the fast-path and unit coverage without hitting the
assert.
Gated:
- `test_generate_is_deterministic` — baseline `m.generate()`
- `test_generate_vs_generate_beam_decode_regression_guard` —
runs baseline as part of the regression compare
- `test_generate_beam_decode_jagged_kv_matches_dense` — exercises
Mode-3 dense for the comparison side
- `TestJaggedGPTLayerPrefillDecode::test_prefill_returns_kv_cache` —
calls `layer.prefill(x)` without `cu_seqlens`, hitting Mode-3
- `test_model_smoke.py` entire file — both tests forward through
the cute arbitrary-mask path
Fast-path E2E, decode-beam smoke, variable-length history padding, and
all pure-Python unit tests remain unconditionally collected and now
pass on A100.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: Runchu Zhao <[email protected]>
The arch detection helper was duplicated in test_model_smoke.py and test_beam_decode_generate.py. Single source of truth in test_utils keeps the check coherent if it ever needs to handle multi-GPU rank selection or switch CUDA APIs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Runchu Zhao <[email protected]>
f1c5872 to
db8810e
Compare
Description
flash_attn.cute→flash_attn(upstream FA2). FA2 ships pre-built inthe nvcr base image, supports SM80+. Zero Dockerfile change.
generate()+ Mode-3 dense prefill) on_SM90_AVAILABLEso the A100 CI lane skips them.Effect
generate_beam_decode()runs end-to-end on A100. Training + baseline still SM90+ (out of scope).Checklist