llama.cpp 服务器:当'prompt >= ctx'时,避免完全提示求值,

uemypmqf  于 2个月前  发布在  其他
关注(0)|答案(2)|浏览(94)

当使用服务器进行多轮聊天时,不久之后提示符将超过上下文大小,当前的方法通过减去n_keep来截断提示符的一半:
llama.cpp/examples/server/server.cpp
第1969行到第1983行
| | if (slot.ga_n == 1 && slot.n_prompt_tokens >= slot.n_ctx) { |
| | constint n_left = slot.n_ctx - slot.params.n_keep; |
| | |
| | constint n_block_size = n_left / 2; |
| | constint erased_blocks = (slot.n_prompt_tokens - slot.params.n_keep - n_block_size) / n_block_size; |
| | |
| | std::vector<llama_token> new_tokens( |
| | prompt_tokens.begin(), |
| | prompt_tokens.begin() + slot.params.n_keep); |
| | |
| | new_tokens.insert( |
| | new_tokens.end(), |
| | prompt_tokens.begin() + slot.params.n_keep + erased_blocks * n_block_size, |
| | prompt_tokens.end()); |
| | |
通过这样做,common_part将仅匹配n_keep个标记(当cache_prompt为true时):
llama.cpp/examples/server/server.cpp
第2011行到第2016行
| | slot.n_past = common_part(slot.cache_tokens, prompt_tokens); |
| | |
| | // 将提示符推入采样上下文(不应用语法) |
| | for (int i = 0; i < slot.n_past; ++i) { |
| | llama_sampling_accept(slot.ctx_sampling, ctx, slot.cache_tokens[i], false); |
| | } |
从技术上讲,这不是完整的提示评估,n_keep不会重新评估,但如果可能的话,最好避免这种情况,特别是因为提示评估在CPU上很慢。

wn9m85ua

wn9m85ua1#

你好@ggerganov和@prfd,我刚加入这个仓库并想尝试解决这个问题,但需要更多的澄清——问题是提示在评估公共部分之前被截断,这意味着我们只使用之前计算的令牌n_keep吗?如果是这样的话,适当的解决方案是在common_part函数调用之后截断吗?

rbpvctlc

rbpvctlc2#

你好@ggerganov和@prfd,我刚加入这个仓库,想尝试解决这个问题,但需要更多的澄清--问题是,提示在评估公共部分之前被截断,这意味着我们只使用之前计算的令牌n_keep吗?如果是这样的话,适当的解决方案是在common_part函数调用之后截断吗?
我已经在#6958上查看过了。

相关问题