Automatic Prefix Caching

部署运行你感兴趣的模型镜像

APC技术,遇到新prompt和老prompt前缀完全相等的,则复用老prompt的KV cache,避免重新计算。

VLLM代码实例:

# set enable_prefix_caching=True to enable APC
llm = LLM(
    model='lmsys/longchat-13b-16k',
    enable_prefix_caching=True
)

 应用场景:

1. 长文档问答。给1个长文档,变换不同的query。则把长文档放到前面,可以复用KV cache。

2. 多轮聊天。多轮对话聊天历史,放到前面,可以复用KV cache。

我的实验:

1. fetch_count>1时,不管是否打开enable_prefix_caching,prompt的KV cache都会被复用。

2. prefill公共前缀较长,且decode output较短时,KV cache复用的威力才能发挥出来。

3. 只要前面有1个字符不同,后面完全相同的部分,也不能被视为公共前缀。因为2个prompt这部分的KV值不相等了。

您可能感兴趣的与本文相关的镜像

Vllm-v0.11.0

Vllm-v0.11.0

Vllm

vLLM是伯克利大学LMSYS组织开源的大语言模型高速推理框架,旨在极大地提升实时场景下的语言模型服务的吞吐与内存使用效率。vLLM是一个快速且易于使用的库,用于 LLM 推理和服务,可以和HuggingFace 无缝集成。vLLM利用了全新的注意力算法「PagedAttention」,有效地管理注意力键和值

Prefix Caching Prefix Caching is a technique to optimize the inference efficiency of generative models. Its core idea is to cache intermediate computation results (KV Cache) of input sequences, avoiding redundant computations and thereby accelerating response times for multiple requests sharing the same prefix. How It Works Prefix Identification: When multiple requests share identical input prefixes (e.g., prompts or initial context), the system caches the intermediate states (KV Cache) corresponding to that prefix. Incremental Computation: For subsequent requests, only the newly added portions (e.g., user-appended input) need computation while reusing cached intermediate results, significantly reducing computational overhead. Enabling Prefix Caching for Service Deployment To enable prefix caching when launching the service, add the parameter enable-prefix-caching. By default, only first-level caching (GPU cache) is enabled. To enable CPU caching, specify the swap-space parameter to allocate CPU cache space (in GB). The size should be set based on available machine memory after model loading. Note: The ERNIE-4.5-VL multimodal model currently does not support prefix caching. For detailed parameter descriptions, refer to the Parameters Documentation. Example launch command: python -m fastdeploy.entrypoints.openai.api_server \ --model "baidu/ERNIE-4.5-21B-A3B-Paddle" \ --port 8180 --engine-worker-queue-port 8181 \ --metrics-port 8182 \ --cache-queue-port 8183 \ --enable-prefix-caching \ --swap-space 50 \ --max-model-len 8192 \ --max-num-seqs 32 Enabling Prefix Caching for Offline Inference Set enable_prefix_caching=True when launching FastDeploy. Enable CPU caching via swap_space based on available machine memory. A test example is provided: demo/offline_prefix_caching_demo.py
07-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值