Skip to content

[spec] Misc defensive guards for EAGLE draft KV indexing#27486

Merged
hnyls2002 merged 7 commits into
mainfrom
lsyin/spec-misc-guards
Jun 8, 2026
Merged

[spec] Misc defensive guards for EAGLE draft KV indexing#27486
hnyls2002 merged 7 commits into
mainfrom
lsyin/spec-misc-guards

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

Three independent defensive guards for the EAGLE draft KV-indexing paths. Behavior-preserving for valid configs -- each assert fires only on a real bug or misconfiguration.

Guards

  • multi-layer config assert (MultiLayerEagle*Worker.__init__): assert num_draft_tokens == num_steps + 1 (mirrors the existing eagle_worker_v2 check) so a mismatched config fails loud at startup instead of a later cryptic shape mismatch. This also subsumes the assign_hidden_states_pool seq-offset underflow (which requires extend_len < pool_size, impossible once this invariant holds), so no kernel-level guard is added there.
  • kv_indices int32-overflow guard (draft_kv_indices_buffer_width): assert num_seqs * topk * max_context_len < 2**31 -- the draft kv_indices flat offset is computed in int32, so an extreme batch * topk * context would silently wrap.
  • store_kvcache slot-value fast-fail (JIT CUDA, the hot set_kv_buffer write path): a stale / out-of-range slot id would otherwise cause an illegal-address crash displaced into a victim kernel (hard to attribute). The kernel now assert(0 <= index < size_limit) before the write -- always-on (the kvcache JIT compiles without NDEBUG), no host sync, and it fails at the culprit with a clear message instead of a displaced IMA. (pool_size arg renamed to size_limit; size_limit = self.size + self.page_size = cache rows = real slots + the reserved padding slot.)

move_kv_cache, the other slot-value consumer, keeps relying on its existing async maybe_detect_oob probe (no in-kernel change).


CI States

Latest PR Test (Base): ✅ Run #27108922233
Latest PR Test (Extra): ✅ Run #27108922191

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

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

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

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

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

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

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/spec/eagle/test_spec_eagle_fa3.py

@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 introduces bounds checking and validation to prevent illegal memory accesses (IMA) and integer overflows in KV cache operations and speculative decoding. Specifically, it adds a pool_size parameter to bound slot values during KV cache stores and moves, asserts proper draft token configurations for multi-layer EAGLE workers, and guards against int32 overflows in flat offset calculations. Feedback on these changes suggests casting pool_size to the source tensor's data type in Triton to avoid potential type mismatches, and wrapping an inner loop in assign_hidden_states_pool_kernel with a conditional block to optimize performance and simplify masking.

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 thread python/sglang/srt/mem_cache/triton_ops/cache_move.py Outdated
Comment thread python/sglang/srt/speculative/triton_ops/multi_layer_eagle.py Outdated
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_spec_eagle_topk_page.py test_spec_eagle_fa3.py test_spec_eagle_triton.py test_deepseek_v3_fp4_mtp_small.py

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_spec_eagle_topk_page.py test_spec_eagle_fa3.py test_spec_eagle_triton.py test_deepseek_v3_fp4_mtp_small.py:

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

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

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/spec/eagle/test_spec_eagle_fa3.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/spec/eagle/test_deepseek_v3_fp4_mtp_small.py

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci extra

@hnyls2002
hnyls2002 merged commit 6365d6f into main Jun 8, 2026
237 of 251 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/spec-misc-guards branch June 8, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant