From f0339022c180c8d781228ab7694e23206a3c4f0b Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Thu, 14 May 2026 20:59:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20batch=20=E6=8E=A8=E7=90=86=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E6=B7=BB=E5=8A=A0=20chat=20template=20=E5=92=8C=20sys?= =?UTF-8?q?tem=20prompt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 prompts 列表,对每个输入应用 apply_chat_template - 添加 system message 到对话模板 --- scripts/demo/generate_batch.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/demo/generate_batch.py b/scripts/demo/generate_batch.py index a074976..39c4975 100644 --- a/scripts/demo/generate_batch.py +++ b/scripts/demo/generate_batch.py @@ -24,12 +24,23 @@ def batch_generate(): "请问什么是显卡", ] + prompts = [ + tokenizer.apply_chat_template( + [ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": q}, + ], + tokenize=False, + ) + for q in inputs + ] + engine = InferenceEngine( model=model, tokenizer=tokenizer, ) responses = engine.generate( - prompt=inputs, + prompt=prompts, stream=False, max_tokens=2048, temperature=0.8,