Skip to content

[NPU] Enable non-greedy MTP sampling - #32495

Merged
sglang-npu-bot merged 8 commits into
sgl-project:mainfrom
cl-vv-h:feature/npu-mtp-non-greedy-sampling
Sep 8, 2026
Merged

sglang-npu-bot merged 8 commits into
sgl-project:mainfrom
cl-vv-h:feature/npu-mtp-non-greedy-sampling

Conversation

@cl-vv-h

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

Copy link
Copy Markdown
Contributor

Motivation

NPU MTP verification currently uses greedy argmax for non-greedy requests.
Consequently, temperature, top_k, and top_p do not take effect during
speculative verification.

With GLM-4.7-Flash on GPQA, enabling non-greedy MTP reduced the observed
accuracy from approximately ~70% to ~50%. This PR enables
probability-based non-greedy MTP sampling on NPU.

Modifications

  • Add an explicit NPU non-greedy branch in eagle_sample.
  • Keep NPU-specific sampling logic in
    srt/hardware_backend/npu/speculative/mtp_sampling.py.
  • Apply temperature scaling and sequential top-k/top-p probability
    renormalization.
  • Support target-only sampling for general EAGLE trees and classic rejection
    sampling for tree_topk=1 chains.
  • Validate input topology and probability tensors before dispatching kernels.
  • Preserve the existing greedy path and fail explicitly for unsupported
    non-greedy configurations.

Sampling algorithm and kernel unit tests are covered in sgl-kernel-npu; no
duplicate SGLang-local test is added.

Accuracy Tests

Model: GLM-4.7-Flash
Dataset: GPQA

Configuration Sampling Before After
NPU TP/TP+EP without MTP temperature=1, top_p=0.95 ~70% ~70%
NPU TP+MTP/TP+EP+MTP temperature=1, top_p=0.95 ~50% ~70%
NPU MTP greedy temperature=0, top_p=1 ~50% ~50%

The non-greedy MTP accuracy recovered to the expected range, while existing
non-MTP and greedy behavior remained unchanged.
before:
image

after:
image

Speed Tests and Profiling

Check Result
End-to-end throughput No measurable performance impact
End-to-end latency No measurable performance impact

Checklist


CI States

Latest PR Test (Base): ❌ Run #33240931809
Latest PR Test (Extra): ❌ Run #33240931714
Latest PR Test (AMD ROCm 7.2): ❌ Run #33240931803

@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.

npu_mtp_non_greedy_sample,
)

predict, accept_index, num_correct_drafts = npu_mtp_non_greedy_sample(

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.

Is there too much isolation here? Are there too many duplicate codes in the newly added files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. NPU now shares the existing non-greedy sampling flow, with only backend-specific operator selection and tensor preparation kept in the NPU branch. The duplicated implementation have been removed.

@github-actions github-actions Bot added documentation Improvements or additions to documentation npu labels Aug 6, 2026
sampling_info.top_ps, verify_input.draft_token_num, dim=0
),
)
maybe_detect_nan(

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.

same as 797

chain_speculative_sampling_triton
if use_rejection_sampling
else tree_speculative_sampling_target_only
)

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.

Run the import as command to normalize the names of the methods invoked by the NPU and GPU. That is, you can write the names only once.
sampling_fn = (
chain_speculative_sampling_triton
if use_rejection_sampling
else tree_speculative_sampling_target_only

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. Changes here have been minimized.

@cl-vv-h
cl-vv-h force-pushed the feature/npu-mtp-non-greedy-sampling branch from 26ce82a to 36d0350 Compare August 11, 2026 06:44
@sglang-npu-bot

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@cl-vv-h

cl-vv-h commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

1 similar comment
@cl-vv-h

cl-vv-h commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@cl-vv-h

cl-vv-h commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

3 similar comments
@cl-vv-h

cl-vv-h commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@cl-vv-h

cl-vv-h commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@cl-vv-h

cl-vv-h commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@sglang-npu-bot
sglang-npu-bot merged commit dfd9b5c into sgl-project:main Sep 8, 2026
561 of 747 checks passed
mqhc2020 pushed a commit to mqhc2020/sglang that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation npu run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants