FIX: (NSA) Compute topk_indices_offset when NSA prefill flashmla_sparse is used with FP8 KV cache#20606
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a specific runtime error that caused the system to crash when a particular combination of KV cache type (FP8) and prefill backend ( Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a crash that occurs when using the flashmla_sparse NSA prefill backend with an FP8 KV cache. The root cause is that topk_indices_offset was not being computed for decode steps following a prefill, leading to a RuntimeError. The fix correctly computes this offset within the is_decode_or_idle() branch by setting it to cu_seqlens_k[:-1]. This change is logical and effectively resolves the bug, allowing inference to proceed correctly in the specified configuration. The implementation is clean and well-commented.
|
@JackChuang I think the root cause is, when we are running decoding batches, the |
|
Also can you please post the result of gsm8k 20shots/GPQA after this change |
f1a3c71 to
0ad8ae9
Compare
|
@Fridge003 Thanks for your inputs! I've modified the code according to your inputs. Please check again. Thank you again! Accuracy test Thanks to @rainj-me for providing input on the NSA/MTP part. |
|
@Fridge003 Thanks for your approval! If there's nothing else that needs to be addressed, could you help merge this PR? Thanks. |
Can be merged after passing CIs |
|
@JackChuang Please fix lint |
Use mode-aware topk transform and guard missing ragged offsets - Pass forward_mode into topk transform method selection. - Force PAGED transform on decode when flashmla_sparse+fp8 would otherwise use RAGGED. - Add a clear RuntimeError if RAGGED fused transform is called without topk_indices_offset. If you want an even shorter one-liner: Signed-off-by: Ho-Ren (Jack) Chuang <horenchuang@bytedance.com>
0ad8ae9 to
c9dd583
Compare
|
@Fridge003 Got it. Thanks! |
|
/rerun-stage stage-c-large-8-gpu-h200 |
|
❌ Stage NVIDIA stages:
AMD stages:
Other stages will be added soon. For now, use |
|
/rerun-stage stage-c-test-8-gpu-h200 |
|
/rerun-stage stage-c-test-4-gpu-b200 |
|
✅ Triggered |
|
✅ Triggered |
…se is used with FP8 KV cache (#20606) Signed-off-by: Ho-Ren (Jack) Chuang <horenchuang@bytedance.com>
…se is used with FP8 KV cache (sgl-project#20606) Signed-off-by: Ho-Ren (Jack) Chuang <horenchuang@bytedance.com>
…se is used with FP8 KV cache (sgl-project#20606) Signed-off-by: Ho-Ren (Jack) Chuang <horenchuang@bytedance.com>
…se is used with FP8 KV cache (sgl-project#20606) Signed-off-by: Ho-Ren (Jack) Chuang <horenchuang@bytedance.com>
Motivation
When using the flashmla_sparse NSA prefill backend with FP8 KV cache, topk_indices_offset is never computed outside the normal EXTEND forward mode, causing a crash in forward_extend(). Rather than letting this silently crash the server, this PR ensures topk_indices_offset is always correctly computed whenever TopkTransformMethod.RAGGED is active, allowing inference to proceed normally.
Root Cause
The bug is triggered by any configuration that satisfies:
This is GPU architecture-independent and affects both SM90 (Hopper/H200) and SM100 (Blackwell/B200). Short prompts that manually select flashmla_sparse will hit the crash as when the backend is forced explicitly — rather than degrading gracefully or falling back.
Error log:
Fix/Modification
With this fix, running FP8 + nsa prefill flashmla_sparse across all prompt lengths — including short prompts that would previously crash — now works correctly without any accuracy or performance impact.
Tested
Machine: H200*8
Request: income=3500, outcome=1500
Model: DeepSeek-V3.2-Exp
Accuracy test results - gsm8k
Results
Accuracy: 0.985
Invalid: 0.000
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci