Skip to content

🧠 两小时从 0 训出你的 64M 大模型。Train your own 64M LLM from scratch in 2 hours.

fix: eval_llm.py Ctrl+C 退出异常修复

wbbeyourself9fa620e2e509
diff --git a/eval_llm.py b/eval_llm.py
index 9359ca8..8588898 100755
--- a/eval_llm.py
+++ b/eval_llm.py
@@ -64,7 +64,14 @@ def main():
input_mode = int(input('[0] 自动测试\n[1] 手动输入\n'))
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
- prompt_iter = prompts if input_mode == 0 else iter(lambda: input('💬: '), '')
+ def _next_prompt():
+ try:
+ return input('💬: ')
+ except (EOFError, KeyboardInterrupt):
+ print()
+ return ''
+
+ prompt_iter = prompts if input_mode == 0 else iter(_next_prompt, '')
for prompt in prompt_iter:
setup_seed(random.randint(0, 31415926))
if input_mode == 0: print(f'💬: {prompt}')