Skip to content

feat: add non-greedy MTP sampling kernels - #623

Open
cl-vv-h wants to merge 1 commit into
sgl-project:mainfrom
cl-vv-h:feature/npu-mtp-non-greedy-kernels
Open

feat: add non-greedy MTP sampling kernels#623
cl-vv-h wants to merge 1 commit into
sgl-project:mainfrom
cl-vv-h:feature/npu-mtp-non-greedy-kernels

Conversation

@cl-vv-h

@cl-vv-h cl-vv-h commented Jul 27, 2026

Copy link
Copy Markdown

Motivation

NPU MTP verification currently supports greedy verification, but non-greedy
requests do not have a corresponding probability-sampling path. This can make
temperature, top_k, and top_p ineffective during speculative
verification.

With GLM-4.7-Flash on GPQA, enabling non-greedy MTP previously reduced the
observed accuracy from approximately ~70% to ~50%.

Modifications

  • Add sequential top-k then top-p probability renormalization.
  • Add target-only non-greedy speculative sampling for general EAGLE trees.
  • Add classic rejection sampling for tree_topk=1 linear chains:
    • accept draft token x with min(1, p(x) / q(x));
    • sample from relu(p - q) after the first rejection;
    • sample from the target distribution when all drafts are accepted.
  • Use block-wise vocabulary reduction and inverse-CDF sampling for large
    vocabularies.
  • Export the new sampling APIs from sgl_kernel_npu.sample.
  • Keep the rejection loop-carried cur_prob_row explicitly typed as int64
    for Triton SSA type consistency.

Supported Scope

  • Target-only sampling supports general EAGLE trees with tree_topk >= 1.
  • Classic rejection sampling supports tree_topk=1 linear chains.
  • Probability tensors use FP32 at the kernel boundary.
  • Existing greedy sampling code and behavior are unchanged.
  • Unsupported shapes, dtypes, devices, and topologies fail explicitly.

Tests

export PYTHONPATH="$PWD/python/sgl_kernel_npu:${PYTHONPATH:-}"
python -m pytest -q -s \
  tests/python/sgl_kernel_npu/test_speculative_probability.py \
  tests/python/sgl_kernel_npu/test_tree_speculative_sampling_target_only.py \
  tests/python/sgl_kernel_npu/test_chain_speculative_sampling.py

The tests cover probability renormalization, general-tree target-only
sampling, classic rejection chains, early rejection, all-accepted requests,
acceptance thresholds, and vocabularies up to 151552 tokens.

Accuracy

Model: GLM-4.7-Flash
Dataset: GPQA_Diamond

Configuration Before After
NPU MTP target-only ~50% ~70%
NPU MTP rejection (tree_topk=1) ~50% ~70%

Performance

Mode Result
Target-only No measurable performance impact
Classic rejection No measurable performance impact

Checklist

  • Code formatting checks completed.
  • Unit tests completed.
  • Accuracy check completed.
  • Performance check completed.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@cl-vv-h
cl-vv-h marked this pull request as draft July 27, 2026 06:26
@cl-vv-h
cl-vv-h marked this pull request as ready for review July 27, 2026 06:27
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

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