Skip to content

Fix NaN in triton EAGLE spec-v2 draft-extend CUDA graph at topk>1 (wrong qo_indptr stride)#27545

Merged
hnyls2002 merged 2 commits into
mainfrom
lsyin/triton-v2-draft-extend-stride
Jun 8, 2026
Merged

Fix NaN in triton EAGLE spec-v2 draft-extend CUDA graph at topk>1 (wrong qo_indptr stride)#27545
hnyls2002 merged 2 commits into
mainfrom
lsyin/triton-v2-draft-extend-stride

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

The draft-extend CUDA-graph metadata built qo_indptr with a per-req stride of num_steps+1, but the runner lays out num_draft_tokens tokens/req. For topk>1 these differ, so at bs>1 each req's queries read from the wrong offset -> NaN (bs==1 and eager are unaffected). Use num_draft_tokens for the v2 draft-extend path.


CI States

Latest PR Test (Base): ❌ Run #27126544910
Latest PR Test (Extra): ❌ Run #27126543998

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the _update_draft_extend_buffers method in triton_backend.py to use self.num_draft_tokens instead of self.speculative_num_steps + 1 when the V2 draft-extend forward mode is active. The reviewer identified a critical omission where max_extend_len in _build_cuda_graph_forward_metadata is still hardcoded to self.speculative_num_steps + 1, which could lead to an underestimated Triton attention kernel grid size and incorrect outputs when topk > 1.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +439 to +443
num_tokens_per_bs = (
self.num_draft_tokens
if forward_mode.is_draft_extend_v2()
else self.speculative_num_steps + 1
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While updating num_tokens_per_bs to use self.num_draft_tokens for the V2 draft-extend path is correct, there is a corresponding omission in _build_cuda_graph_forward_metadata (around line 903).\n\nCurrently, max_extend_len is still hardcoded to self.speculative_num_steps + 1 for all draft-extend modes:\npython\n elif forward_mode.is_draft_extend(include_v2=True):\n return ForwardMetadata(\n attn_logits=None,\n attn_lse=None,\n max_extend_len=self.speculative_num_steps + 1,\n\nWhen forward_mode.is_draft_extend_v2() is active and topk > 1, self.num_draft_tokens can be larger than self.speculative_num_steps + 1. If max_extend_len is too small, the Triton attention kernel grid size (which is computed as triton.cdiv(max_len_extend, BLOCK_M)) will be underestimated, causing some query blocks to not be launched and resulting in unprocessed tokens or incorrect outputs.\n\nPlease update _build_cuda_graph_forward_metadata to also use self.num_draft_tokens for the V2 draft-extend path:\npython\n elif forward_mode.is_draft_extend(include_v2=True):\n return ForwardMetadata(\n attn_logits=None,\n attn_lse=None,\n max_extend_len=(\n self.num_draft_tokens\n if forward_mode.is_draft_extend_v2()\n else self.speculative_num_steps + 1\n ),\n

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_spec_eagle_triton.py test_spec_eagle_topk.py test_spec_eagle_topk_page.py

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_spec_eagle_triton.py test_spec_eagle_topk.py test_spec_eagle_topk_page.py:

🚀 1-gpu-5090 (3 tests): ✅ View workflow run

cd test/ && python3 registered/spec/eagle/test_spec_eagle_triton.py
cd test/ && python3 registered/spec/eagle/test_spec_eagle_topk.py
cd test/ && python3 registered/spec/eagle/test_spec_eagle_topk_page.py

@hnyls2002
hnyls2002 merged commit 57ea09b into main Jun 8, 2026
89 of 101 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/triton-v2-draft-extend-stride branch June 8, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant