Progress line shows the thinking budget, not max_tokens, while one applies (#984)
This commit is contained in:
1 parent
5a6ef1d768
commit
bce19db445
2 files changed
+35
-3
No files matched your search
+6
-3
@@ -3523,7 +3523,10 @@ class Service:
|
||||
print(f"[strata] reading the prompt: {done} tokens, {el:.0f} s so far", flush=True)
|
||||
else:
|
||||
rate = s["generated"] / max(1e-6, now - s["first_token"])
|
||||
print(f"[strata] {s['phase']}: {s['generated']} of max {s.get('max_tokens')} tokens, {rate:.1f} tok/s, "
|
||||
# #984: while a thinking budget applies, the thinking line shows it, not the request's max_tokens
|
||||
limit = (f"budget {s['thinking_budget']} (max {s.get('max_tokens')})"
|
||||
if s["phase"] == "thinking" and s.get("thinking_budget") else f"max {s.get('max_tokens')}")
|
||||
print(f"[strata] {s['phase']}: {s['generated']} of {limit} tokens, {rate:.1f} tok/s, "
|
||||
f"{el:.0f} s", flush=True)
|
||||
return now
|
||||
|
||||
@@ -3641,7 +3644,7 @@ class Service:
|
||||
self.status["queued"] -= 1
|
||||
st.update(busy=True, phase="reading the prompt", prompt_tokens=len(ids),
|
||||
generated=0, started=time.time(), first_token=None, tool=None, tail="",
|
||||
max_tokens=max_new, reasoning_recoveries=0)
|
||||
max_tokens=max_new, reasoning_recoveries=0, thinking_budget=budget)
|
||||
if par:
|
||||
self.live_reqs[id(st)] = (st, rate)
|
||||
self.status.update(st)
|
||||
@@ -3797,7 +3800,7 @@ class Service:
|
||||
# A forced call (tool_choice) is opened the same way: after the wrap-up, or where the
|
||||
# thinking ended, after the blank line the template puts before a call.
|
||||
if wrap:
|
||||
budget = None
|
||||
budget = st["thinking_budget"] = None
|
||||
text = REASONING_WRAP_UP + (force or "")
|
||||
else:
|
||||
text = "\n" * (2 - (len(tail) - len(tail.rstrip("\n")))) + force
|
||||
|
||||
@@ -3347,6 +3347,35 @@ class ThinkingBudget(unittest.TestCase):
|
||||
self.assertEqual(b["choices"][0]["message"]["reasoning_content"], ThinkingEngine.THOUGHT)
|
||||
self.assertEqual(len(self.engine.prompts), 3)
|
||||
|
||||
def test_the_config_budget_reaches_the_anthropic_and_effort_requests(self):
|
||||
"""#984: a config budget applies to a request that sets no budget of its own, whatever its max_tokens and
|
||||
reasoning_effort say, on the Anthropic route too."""
|
||||
from serve.server import REASONING_WRAP_UP
|
||||
self.svc.reasoning_budget_tokens = 20
|
||||
code, raw = self.post("/v1/messages", {"model": "m", "max_tokens": 3000, "stream": True,
|
||||
"messages": [{"role": "user", "content": "2+2?"}]})
|
||||
self.assertEqual(code, 200)
|
||||
evs = [json.loads(line[6:]) for line in raw.splitlines() if line.startswith("data: {")]
|
||||
thinking = "".join(e["delta"].get("thinking", "") for e in evs if e["type"] == "content_block_delta")
|
||||
self.assertEqual(thinking, ThinkingEngine.THOUGHT[:20] + REASONING_WRAP_UP.split("</think>")[0])
|
||||
code, b = self.openai(max_tokens=3000, reasoning_effort="high")
|
||||
self.assertEqual(code, 200, b)
|
||||
self.assertTrue(b["choices"][0]["message"]["reasoning_content"].startswith(ThinkingEngine.THOUGHT[:20] + "\n"))
|
||||
|
||||
def test_the_thinking_progress_line_shows_the_budget_not_max_tokens(self):
|
||||
"""#984: 'thinking: x of max 6400' read as if the budget was ignored; while a budget applies the line shows it."""
|
||||
st = {"phase": "thinking", "generated": 10, "first_token": time.time() - 1, "started": time.time() - 2,
|
||||
"max_tokens": 6400, "thinking_budget": 2048}
|
||||
out = io.StringIO()
|
||||
with contextlib.redirect_stdout(out):
|
||||
self.svc._progress(0, st=st)
|
||||
self.svc._progress(0, st={**st, "phase": "answering"})
|
||||
self.svc._progress(0, st={**st, "thinking_budget": None})
|
||||
lines = out.getvalue().splitlines()
|
||||
self.assertIn("thinking: 10 of budget 2048 (max 6400) tokens", lines[0])
|
||||
self.assertIn("answering: 10 of max 6400 tokens", lines[1])
|
||||
self.assertIn("thinking: 10 of max 6400 tokens", lines[2])
|
||||
|
||||
def test_a_shared_budget_reaches_a_request_that_sets_none(self):
|
||||
"""The Chat settings shared with other apps may carry a thinking budget too, like max_tokens and the effort."""
|
||||
self.svc.set_shared({"reasoning_budget_tokens": 20})
|
||||
|
||||
Reference in new issue
Block a user