serve: DeepSeek-V4.1 thinks at most 32768 tokens when neither the request nor the config names a budget

Same default as Maya #363. For the deepseek41 family only: Service.reasoning_budget() answers 32768 when the request has
no reasoning_budget_tokens / thinking_budget_tokens and the config has no reasoning_budget_tokens at all (a config value,
0 included, wins; a request's 0 turns it off). The existing wrap-up (#123) closes the thinking at the budget, and the
answer-room clamp still cuts it to leave the answer its share of max_tokens. Thinking off and other families unchanged.
Tests in serve/test_dsv41.py: the default, a request's 0 and own value, the config's value and 0, another family, and a
5000-token cap that is wrapped up and answered. serve suite: 1027 tests OK (15 skipped).
This commit is contained in:
Niko1221 committed 2026-10-24 01:20:04 +02:00
1 parent b4418e30df
commit dfe29bce61
2 files changed
+28

No files matched your search

+5
View File
@@ -201,6 +201,7 @@ VISION_START = "<|vision_start|>"
# sets it; 0 turns it off.
REPEAT_STOP_TOKENS = 256
ANSWER_ROOM_MIN_CAP = 1024 # 0.1.45: from this max_tokens on, thinking without a budget is closed early enough to leave room to answer
DS41_DEFAULT_BUDGET = 32768 # DeepSeek-V4.1 only: the thinking budget when neither the request nor the config names one
DS41_SMALL_CAP_MIN = 48 # DeepSeek-V4.1 only: from this max_tokens up to ANSWER_ROOM_MIN_CAP, thinking is capped at half of it
ANSWER_RESERVE_MIN = 512 # #984: the tokens kept for the answer when a thinking budget is cut down to fit max_tokens
# #123: what closes the thinking when it reaches reasoning_budget_tokens (the model's own end-of-thinking tag after it)
@@ -3894,6 +3895,7 @@ class Service:
self.vision_held = False # an elastic encoder holds VRAM the expert cache gave it
self.last_image_at = 0.0 # when an image turn last ended (the elastic encoder's idle)
self.reasoning_loop_recovery = False
self.reasoning_budget_configured = False # the config named reasoning_budget_tokens (0 included): no family default
self.reasoning_budget_tokens = 0 # #123: the config's default thinking budget (0: none)
self.repeat_stop_tokens = REPEAT_STOP_TOKENS # #606: one token this many times in a row ends a reply (0: off)
self.anthropic_think_unasked = True # #278: "anthropic_thinking": "on_request" -> False
@@ -4141,6 +4143,8 @@ class Service:
value = req.get("thinking_budget_tokens")
if value is None:
value = self.reasoning_budget_tokens
if not value and self.family == "deepseek41" and not self.reasoning_budget_configured:
value = DS41_DEFAULT_BUDGET # DeepSeek-V4.1 only, as Maya ships it: no budget anywhere = this one
if isinstance(value, float) and value.is_integer():
value = int(value)
if isinstance(value, bool) or not isinstance(value, int):
@@ -8522,6 +8526,7 @@ def main(argv=None, *, lifecycle_event=None, interrupt_exit_code: int = 0) -> in
svc.repeat_stop_tokens = rs
svc.effort_end = bool(effort_end) # #458: "effort_position": "end" with an engine that has it
if cfg.get("reasoning_budget_tokens") is not None: # #123: a default thinking budget for every request
svc.reasoning_budget_configured = True
try:
svc.reasoning_budget_tokens = cfg["reasoning_budget_tokens"]
budget = svc.reasoning_budget({})
+23
View File
@@ -624,6 +624,29 @@ class SmallCap(ApiBase):
self.assertEqual(json.loads(calls[0]["function"]["arguments"]), {"a": "1"})
self.assertEqual(len(self.engine.last_prompt) > 0, True)
def test_the_family_default_thinking_budget(self):
"""DeepSeek-V4.1 only, as Maya ships it: 32768 thinking tokens when neither the request nor the config names a budget."""
self.start("ok")
self.assertEqual(self.svc.reasoning_budget({}), 32768)
self.assertIsNone(self.svc.reasoning_budget({"reasoning_budget_tokens": 0})) # a request turns it off
self.assertEqual(self.svc.reasoning_budget({"reasoning_budget_tokens": 50}), 50) # and its own wins
self.assertEqual(self.svc.reasoning_budget({"thinking_budget_tokens": 70}), 70)
self.svc.reasoning_budget_tokens, self.svc.reasoning_budget_configured = 90, True
self.assertEqual(self.svc.reasoning_budget({}), 90) # the config's wins
self.svc.reasoning_budget_tokens = 0 # the config says none
self.assertIsNone(self.svc.reasoning_budget({}))
self.svc.reasoning_budget_configured = False
self.svc.set_family(None)
self.assertIsNone(self.svc.reasoning_budget({})) # other families: none
def test_the_default_budget_closes_a_long_thinking(self):
self.start_forever()
status, r = self.chat(max_tokens=5000)
self.assertEqual(status, 200, r)
self.assertEqual(r["choices"][0]["message"]["content"], ThinkForever.ANSWER)
status, r = self.chat(max_tokens=300, reasoning_effort="none") # thinking off: no budget, no wrap-up
self.assertEqual(len(self.engine.prompts), 3)
def test_other_families_keep_the_old_behaviour(self):
self.start_forever()
self.svc.set_family(None)