[Reasoning] Support for speculative decoding with thinking budget (#34668)

Signed-off-by: rishitdholakia13 <rishit+github@cohere.com>
Signed-off-by: rishitdholakia13 <123388671+rishitdholakia13@users.noreply.github.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
rishitdholakia13
2026-04-29 06:14:52 +00:00
committed by GitHub
co-authored by Nick Hill Cyrus Leung
parent 8a8c9b564e
commit 68dd7db810
12 changed files with 1143 additions and 365 deletions
+16 -1
View File
@@ -364,9 +364,13 @@ class Sampler(nn.Module):
any_penalties_or_bad_words = (
bool(bad_words_token_ids) or not sampling_metadata.no_penalties
)
holder = sampling_metadata.thinking_budget_state_holder
needs_thinking_combine = holder is not None and holder.has_tracked_requests()
output_token_ids = sampling_metadata.output_token_ids
if predict_bonus_token and any_penalties_or_bad_words:
if predict_bonus_token and (
any_penalties_or_bad_words or needs_thinking_combine
):
# Combine base outputs with spec tokens when speculative decoding
# is enabled.
output_token_ids = self._combine_outputs_with_spec_tokens(
@@ -388,6 +392,17 @@ class Sampler(nn.Module):
# Apply penalties (e.g., freq_penalties).
logits = self.apply_penalties(logits, sampling_metadata, output_token_ids)
if holder is not None and holder.has_tracked_requests():
holder.update_state(
output_token_ids,
sampling_metadata.spec_token_ids,
repeat_indices=None,
)
logits = holder.apply_to_logits(
logits,
predict_bonus_token,
sampling_metadata.spec_token_ids,
)
return logits
@staticmethod