Skip to content

fix(ds4): enforce sparse top-k row-length contract - #431

Merged
lukealonso merged 1 commit into
local-inference-lab:dev/infernal-invocationfrom
voipmonitor:fix/ii-ds4-topk-row-contract-20260818
Aug 21, 2026
Merged

lukealonso merged 1 commit into
local-inference-lab:dev/infernal-invocationfrom
voipmonitor:fix/ii-ds4-topk-row-contract-20260818

Conversation

@voipmonitor

Copy link
Copy Markdown

Resulting behavior

DeepSeek V4 sparse-indexer row lengths now obey one contract across metadata production and top-k consumption:

  • graph-padding rows produce non-negative per-token context lengths;
  • persistent top-k reads at most min(logits.stride(0), max_seq_len) scores from each row;
  • cooperative top-k treats a non-positive row length as an empty row;
  • a persistent CTA group advances its radix histogram ring only when the assigned row uses the radix path.

Valid row lengths and selected top-k sets are unchanged.

Technical reason

Uniform MTP metadata computed seq_len - max_decode_len + token_offset + 1. A CUDA-graph padding request with seq_len == 0 therefore produced -1 for its first token. The top-k kernels consume row lengths in unsigned indexing decisions, so the negative value could select scores from a non-empty row instead of returning -1 padding.

Persistent CTA groups also indexed their triple-buffered histogram by every assigned row. A short row does not execute radix selection, so counting it advanced the ring without initializing that generation. A later long row assigned to the same group could consume stale histogram state.

The implementation adapts the applicable contracts from upstream vLLM #49139 and #51538 to the Infernal Invocation metadata and B12X integration.

Compatibility

  • Scope: DeepSeek V4 sparse MLA metadata and the shared persistent/cooperative top-k kernels.
  • CUDA graph compatibility: preserved; buffers and launch shapes are unchanged.
  • Model arithmetic: unchanged for rows whose declared lengths are within bounds.
  • Performance: the hot path adds integer bounds operations only; no allocation, copy, or synchronization is introduced.

Validation

Status: implemented. Compiled C++ kernel qualification is part of the Infernal Invocation release image build because an existing image contains the previous _C extension.

  • ruff check and ruff format: pass.
  • CPU metadata tests: 2 passed.
  • SM120 Triton producer reproducer on RTX PRO 6000 Blackwell:
    • packaged r16 source: [-1, 0, 4, 5], expected-contract assertion failed;
    • patched source over the same image: [0, 0, 4, 5], passed.
  • Added compiled-kernel regression coverage for:
    • persistent histogram reuse after a short row;
    • negative graph-padding lengths;
    • row lengths beyond both the physical stride and active sequence bound.

The compiled-kernel tests must pass against the release-built extension before image publication.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@voipmonitor, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b11cfa15-20c7-4b7a-bd25-2ddaf1f66c83

📥 Commits

Reviewing files that changed from the base of the PR and between 6dc2f51 and 03cccf4.

📒 Files selected for processing (5)
  • csrc/libtorch_stable/cooperative_topk.cuh
  • csrc/libtorch_stable/persistent_topk.cuh
  • tests/kernels/test_top_k_per_row.py
  • tests/model_executor/layers/test_sparse_attn_indexer_b12x.py
  • vllm/v1/attention/backends/mla/indexer.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lukealonso
lukealonso merged commit 171d821 into local-inference-lab:dev/infernal-invocation Aug 21, 2026
4 of 5 checks passed
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.

2 participants