跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[问与答] 本地部署的小 LLM 模型不会自动停止输出,怎么解决?

发表于

想用 langchain + huggingface 上的一些小模型做一些 rag 的测试,随便尝试了 2 个 Qwen/Qwen2-7B-Instructmicrosoft/Phi-3.5-mini-instruct,但我发现他们好像都不知道什么时候应该停止输出。下面举了一些例子

模型和 prompt 的代码,检索器的就不放了:

llm_model = AutoModelForCausalLM.from_pretrained(
    model_name, device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
pipe = pipeline(
    "text-generation",
    model=llm_model,
    tokenizer=tokenizer,
    max_new_tokens=512,
    return_full_text=False,
    do_sample=False,
    temperature=None,
    top_k=None,
    top_p=None,
)

prompt = ChatPromptTemplate.from_template(
    "你是问答任务的助手。使用以下检索到的相关规定来回答问题。如果你不知道答案,就说你不知道。\n\n"
    "问题:{input} \n\n"
    "上下文:\n{context}\n\n"
    "回答:"
)

这个 prompt 我是希望他在回答后面直接回答就可以了,很直接,但是这些模型有时候就很蠢。比如它会往后面补充:

根据上下文,..........

问题:.....
答案:.....

问题:.....
答案:.....

问题:.....
答案:......

就十分容易出现上面这种情况,明明直接回答就好了,但是它一定要把能用的 token 用完才结束,这些小模型的输出 token 里面没有指定什么时候结束的吗?有没有什么解决办法。

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.