mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2026-11-05 01:07:28 +00:00
[GH-ISSUE #647] LLM Produces Unprompted Responses After Initial Message #475
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/ktransformers#475
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Husamx on GitHub (Feb 24, 2025).
Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/647
Description:
I am using KTransformers to run a multi-GPU server with the DeepSeek-R1 model. The server starts successfully and responds to the first message, but subsequent messages often result in the LLM generating unprompted outputs, as if it is receiving empty or partial messages. I'm not sure what the case is here.
Steps to Reproduce:
Run the server with the following command:
Send the first message to the server via the OpenAI client or OpenWebUI.
Observe the server console:
Send a second message and observe the LLM's response:
Expected Behavior:
The LLM should generate a response based on the user's input for each subsequent message.
Actual Behavior:
After the first message, the LLM sometimes starts generating unprompted outputs, as if it is receiving empty or partial messages.
Request:
Could you please investigate this issue and provide guidance on how to resolve it? Thank you for your assistance.
@ubergarm commented on GitHub (Feb 24, 2025):
@Husamx
嗯…
eb039b7这个提交版本足够新,已包含API修复。正如我在另一个issue中提到的,我使用的是基于
litellm构建的自定义客户端,并在与LLM交互时会正确移除Assistant聊天线程的<think>.*</think>部分。即使在此连续回复十几次(如解答这些问题),也未遇到问题。我注意到open-webui的相关讨论可能与此有关,但坦率地说我对open-webui兴趣不大。
你试过
local_chat.py功能吗?需注意:整个提示必须为单行且不含\n字符,否则会触发多次响应。此外,建议尝试仅使用单GPU而非多GPU配置——这符合我的ktransformers指南所述的使用 方式。或许我会发布一个简化版且运行正常的聊天应用。不过首先我要去散步——今天阳光正好。😎
Husamx
Hrmm...
eb039b7is new enough to contain the API fix.As I mention in the other issue, I am using a custom client built on
litellmand I properly remove the<think></think>section from the Assistant chat thread as I take turns with the LLM. I have no problems even taking a dozen turns as I answer all these questions here.I see some chatter with open-webui that may be related, but honestly I am not very interested in open-webui.
Have you tried the
local_chat.pyfeature? Be careful with it, your entire prompt must be on a single line with no\ncharacters or it will give multiple responses. Also you might try using just a single GPU instead of the multi gpu as that is how I use it as described in my ktransformers guide.Maybe I'll release a simple version of my chat app that works fine. But first I want to take a walk because there is sunshine today. 😎
@Husamx commented on GitHub (Feb 24, 2025):
thanks for your response. I'm also using litellm with the openai client. Actually I'm only testing single turn conversations but with large contexts. Here is the output for an example I copied from LongBench dataset
The first response ending with "... context of her early life and family background." is what I received on the client side. Everything that comes after was only printed on the console.
It looks like my prompt was processed 2 times as the first 2 generations are from the same context. I have no clue what the third generation is about.
@ubergarm commented on GitHub (Feb 24, 2025):
@Husamx
这是一项非常重要的细节,需要明确。我对LongBench并不了解,因此需要先进行查阅:
接下来,请检查您在命令关键部分设置的上下文长度配置(例如模型处理长文本的能力参数),确保与上述任务需求匹配:
坦白说,您期待的输出效果具体应是什么样?目前我不确定是否存在漏洞。注意到您将输出生成限制为3500个token,且出于某种原因禁用了Flash Attention。这是否会导致无法将缓存(cache)量化为q4格式?此外,禁用Flash Attention是否可能影响上下文切换(context shift)及其他相关机制?
建议您重新尝试运行,并参考此指南中的示例命令,确保所有上下文长度参数配置正确。
关键提示:您可通过集成在代码中的R1tokenizer计算当前输入提示(prompt)的token数量。若需简化客户端操作,可参考开源方案(如您当前采用的方式)。在对比预期输出前,请务必明确实际输入的token规模。
最后,潜在漏洞确实可能存在。由于您提供的环境信息较为复杂,目前难以直接定位。若怀疑漏洞存在,建议分析此PR(该提交修复了API端点问题),重点检查上下文溢出(overflow)或超限时的异常触发机制。需说明的是,我本人尚未系统性测试过最大上下文极限。
请持续同步进展,感谢您为社区贡献的力量!
Husamx
This is very important detail to know. I don't know anything about LongBench, let's look it up:
So let's see what you set your context to in the important parts of your command:
Well honestly, what are you expecting the output to be like? I'm not sure there is a bug. I see you limit the output generation to 3500 tokens. You disable flash attention for some reason? Wont that make it not possible to quantize the cache to q4? Disable flash attention might prevent context shift and other things too?
I suggest you try again but this time look at the example command in this guide and make sure you are setting all the context lengths appropriately.
You can figure out the tokens of the prompt you are sending using the R1 tokenizer running in your code, there are some free github repo's to make this easy to do on the client side like how you are doing it. Make sure you know what you are giving it before comparing to what output you expect.
Finally, there may be some bug, I can't tell given there are too many variables with your setup and the information presented. But if you think there is a bug, I suggest you look into theis PR as this guy fixed the API endpoint. Maybe you can find if there is an overflow or issue when exceeding context, but I have not tested the maximum context myself knowingly.
Keep us posted and thanks for contributing to the good of all!
@ceerRep commented on GitHub (Feb 25, 2025):
Do you disabled title-generation, tag generation and auto-complete feature in Open WebUI?
618#issuecomment-2681381587
@ubergarm commented on GitHub (Feb 25, 2025):
@Husamx
Check out this note about very long context on the latest release:
github.com/kvcache-ai/ktransformers@03f8bc9f79@Husamx commented on GitHub (Feb 26, 2025):
Thanks @ubergarm @ceerRep
Yes, it looks like part of the problem was indeed OpenWebUI requesting additional generations. The other issue I faced was subsequent generations were random because of incorrect attention computations. I had previously modified the forward_linux_triton function so the app would run on my Volta GPUs. Hence, why I couldn't use flash attention. But after some debugging I figured out that I just needed to reset the cache between new runs inside KTransformersInterface. It's unfortunate that the latest update
v0.2.2rc1now checks for compute compatibility and forces the use offorward_windows, which is significantly slower.@ErvinXie commented on GitHub (Dec 11, 2025):
This issue has been automatically closed due to inactivity for 60 days.
If you believe this issue is still relevant, please feel free to reopen it with additional information or context.
Thank you for your contribution to KTransformers!
此 issue 因超过 60 天无活动而被自动关闭。
如果您认为此问题仍然存在,请随时重新打开并提供更多信息或上下文。
感谢您对 KTransformers 的贡献!