Skip to content

Commit 77ff00b

Browse files
unamedkrclaude
andcommitted
CLI: reduce tokens to 80, add spinner during generation
- max_new_tokens: 300 → 80 (~100s instead of ~6min on CPU) - Animated spinner (⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏) while generating - Shows estimated time before generation starts - User no longer sees a frozen "A:" with no feedback Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d8def44 commit 77ff00b

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

tools/tq_chat.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,39 @@ def run_chat(question, model, tokenizer):
113113
inputs = tokenizer(text, return_tensors="pt")
114114
prompt_len = inputs["input_ids"].shape[1]
115115

116-
print(f" {C.BOLD}{C.GREEN}A:{C.NC} ", end="", flush=True)
116+
max_tokens = 80 # ~80 tokens ≈ 2 paragraphs, ~100s on CPU
117+
118+
print(f" {C.BOLD}{C.GREEN}A:{C.NC} {C.DIM}(generating ~{max_tokens} tokens, ~{max_tokens*1.3:.0f}s on CPU){C.NC}")
119+
print(f" ", end="", flush=True)
120+
121+
import contextlib, io, threading
122+
123+
# Spinner while generating
124+
stop_spinner = threading.Event()
125+
def spinner():
126+
chars = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
127+
i = 0
128+
while not stop_spinner.is_set():
129+
print(f"\r {C.CYAN}{chars[i % len(chars)]}{C.NC} generating...", end="", flush=True)
130+
stop_spinner.wait(0.1)
131+
i += 1
132+
print(f"\r {C.GREEN}{C.NC} done ")
133+
134+
t = threading.Thread(target=spinner, daemon=True)
135+
t.start()
117136

118-
import contextlib, io
119137
t0 = time.time()
120138
with torch.no_grad(), contextlib.redirect_stderr(io.StringIO()):
121139
out = model.generate(
122140
**inputs,
123-
max_new_tokens=300,
141+
max_new_tokens=max_tokens,
124142
do_sample=True,
125143
temperature=0.7,
126144
top_p=0.9,
127145
)
146+
147+
stop_spinner.set()
148+
t.join()
128149
elapsed = time.time() - t0
129150

130151
answer = tokenizer.decode(out[0][prompt_len:], skip_special_tokens=True)

0 commit comments

Comments
 (0)