[ngram] use SGLANG_NGRAM_FORCE_GREEDY_VERIFY to control verify method (#13153)

Co-authored-by: a4zhangfei <a4zhangfei@qq.com>
This commit is contained in:
Zhihao Zhang
2025-11-12 21:07:33 +08:00
committed by GitHub
co-authored by a4zhangfei
parent 2d531946db
commit 9c1c5c6d7d
3 changed files with 10 additions and 9 deletions
+5 -6
View File
@@ -15,6 +15,7 @@ from dataclasses import dataclass
import torch.nn.functional as F
from sglang.srt.environ import envs
from sglang.srt.layers.attention.utils import create_flashinfer_kv_indices_triton
from sglang.srt.layers.logits_processor import LogitsProcessorOutput
from sglang.srt.layers.sampler import apply_custom_logit_processor
@@ -408,7 +409,9 @@ class NgramVerifyInput(SpecInput):
)
# Sample tokens. Force greedy sampling on AMD
is_all_greedy = sampling_info.is_all_greedy
is_all_greedy = (
sampling_info.is_all_greedy or envs.SGLANG_NGRAM_FORCE_GREEDY_VERIFY.get()
)
if (not is_all_greedy) and (not TREE_SPEC_KERNEL_AVAILABLE):
logger.warning(
"Tree speculative sampling kernel unavailable (likely AMD/HIP build). "
@@ -419,11 +422,7 @@ class NgramVerifyInput(SpecInput):
self._greedy_verify(batch, logits_output)
else:
# NOTE: Compared with greedy_verify, the performance of _sampling_verify is relatively poor.
logger.warning(
"Currently Ngram speculative sampling forces to use greedy verification."
)
self._greedy_verify(batch, logits_output)
# self._sampling_verify(batch, logits_output, sampling_info)
self._sampling_verify(batch, logits_output, sampling_info)
self._fill_requests(batch, logits_output)