Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

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

Niko1221dfe29bce61df
diff --git a/serve/server.py b/serve/server.py
index 920cd35bc..5fa70820e 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -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({})
diff --git a/serve/test_dsv41.py b/serve/test_dsv41.py
index f9f13a854..04b4d2bb8 100644
--- a/serve/test_dsv41.py
+++ b/serve/test_dsv41.py
@@ -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)