Skip to content

Commit bd2eaad

Browse files
fix(mac chat): raise default --max-new-tokens 256->1024 + show stop reason (eos/max/loop)
User hit truncation ('断掉') on a long PoW explanation: exactly 256 tokens = the old default cap. Raise default to 1024 and surface the stop reason each turn (WARN when it's the max-new-tokens cap), so truncation is obvious and tunable. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
1 parent f55427a commit bd2eaad

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

scripts/chat_mlx_kakeya.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def main() -> int:
8585
ap.add_argument("--full-window", type=int, default=8192,
8686
help="Resident window for the full-attention (exact) layers "
8787
"— large = effectively full context (S5 recall carrier).")
88-
ap.add_argument("--max-new-tokens", type=int, default=256)
88+
ap.add_argument("--max-new-tokens", type=int, default=1024,
89+
help="Generation cap. Long explanations can need 1500+; raise "
90+
"this if answers get cut off ('断掉').")
8991
ap.add_argument("--repetition-penalty", type=float, default=1.3,
9092
help="Penalize repeated tokens to stop greedy loops (1.0 = off).")
9193
ap.add_argument("--thinking", action="store_true",
@@ -164,9 +166,11 @@ def _iter():
164166
yield first
165167
yield from stream
166168

169+
stop_reason = "max" # generator exhausts at max_tokens unless we break
167170
for tok_id, _ in _iter():
168171
t = int(tok_id)
169172
if t in eos:
173+
stop_reason = "eos"
170174
break
171175
toks.append(t)
172176
full = tok.decode(toks, skip_special_tokens=True)
@@ -175,11 +179,13 @@ def _iter():
175179
on_delta(delta)
176180
shown = full
177181
if _is_degenerate_loop(full): # true back-to-back repeat → stop
182+
stop_reason = "loop"
178183
break
179184
dt = max(time.time() - t0, 1e-9)
180185
return {
181186
"text": tok.decode(toks, skip_special_tokens=True),
182187
"n_tokens": len(toks),
188+
"stop_reason": stop_reason,
183189
"decode_tps": round(len(toks) / dt, 2),
184190
"resident_kv_bytes": int(total_kv_bytes(cache)),
185191
"resident_kv_seq_len_first_layer": int(cache_seq_length(cache)),
@@ -246,9 +252,11 @@ def _iter():
246252
sys.stdout.write("\n")
247253
sys.stdout.flush()
248254
history.append({"role": "assistant", "content": info["text"]})
255+
warn = (" [WARN: hit --max-new-tokens; raise it for longer answers]"
256+
if info["stop_reason"] == "max" else f" [stopped: {info['stop_reason']}]")
249257
_log(f"{info['n_tokens']} tok, {info['decode_tps']} tok/s, "
250258
f"resident bounded-KV {info['resident_kv_bytes']/1e6:.1f} MB "
251-
f"(sliding layers capped at sink+window={args.sink}+{args.window})")
259+
f"(sliding capped at sink+window={args.sink}+{args.window}){warn}")
252260
return 0
253261

254262

0 commit comments

Comments
 (0)