[Speculative] Support penalty for spec v2 overlap scheduling (#22049)
This commit is contained in:
@@ -23,6 +23,7 @@ from sglang.srt.model_executor.forward_batch_info import (
|
||||
ForwardMode,
|
||||
)
|
||||
from sglang.srt.model_executor.model_runner import ModelRunner
|
||||
from sglang.srt.sampling.penaltylib.repetition_penalty import apply_scaling_penalties
|
||||
from sglang.srt.server_args import get_global_server_args
|
||||
from sglang.srt.speculative.eagle_utils import verify_tree_greedy_func
|
||||
from sglang.srt.speculative.spec_utils import (
|
||||
@@ -89,6 +90,25 @@ class EagleDraftInputV2Mixin:
|
||||
# Now seq_lens is correct
|
||||
batch.maybe_wait_verify_done()
|
||||
|
||||
# Accumulate penalty
|
||||
# This is a relaxed version of penalties for speculative decoding.
|
||||
if batch.sampling_info.penalizer_orchestrator.is_required:
|
||||
output_ids = torch.tensor(
|
||||
[
|
||||
(
|
||||
req.output_ids[-1]
|
||||
if len(req.output_ids)
|
||||
else req.origin_input_ids[-1]
|
||||
)
|
||||
for req in batch.reqs
|
||||
],
|
||||
dtype=torch.int64,
|
||||
device=batch.device,
|
||||
)
|
||||
batch.sampling_info.penalizer_orchestrator.cumulate_output_tokens(
|
||||
output_ids
|
||||
)
|
||||
|
||||
page_size = batch.token_to_kv_pool_allocator.page_size
|
||||
cur_kv_lens_cpu = []
|
||||
nxt_kv_lens_cpu = []
|
||||
@@ -292,6 +312,28 @@ class EagleVerifyInputV2Mixin:
|
||||
next_token_logits = logits_output.next_token_logits
|
||||
device = batch.input_ids.device
|
||||
|
||||
# Apply penalty
|
||||
# This is a relaxed version of penalties for speculative decoding.
|
||||
if sampling_info.acc_additive_penalties is not None:
|
||||
next_token_logits.add_(
|
||||
torch.repeat_interleave(
|
||||
sampling_info.acc_additive_penalties, self.draft_token_num, dim=0
|
||||
)
|
||||
)
|
||||
if sampling_info.acc_scaling_penalties is not None:
|
||||
apply_scaling_penalties(
|
||||
next_token_logits,
|
||||
torch.repeat_interleave(
|
||||
sampling_info.acc_scaling_penalties, self.draft_token_num, dim=0
|
||||
),
|
||||
)
|
||||
if sampling_info.logit_bias is not None:
|
||||
next_token_logits.add_(
|
||||
torch.repeat_interleave(
|
||||
sampling_info.logit_bias, self.draft_token_num, dim=0
|
||||
)
|
||||
)
|
||||
|
||||
# Apply grammar mask if provided
|
||||
if vocab_mask is not None:
|
||||
assert self.grammar is not None
|
||||
|
||||
Reference in New Issue
Block a user