[Feature] [KVCache] support file_store kv cache backend - #6188
Conversation
|
Thanks for your contribution! |
There was a problem hiding this comment.
Pull request overview
该 PR 旨在为 KVCache 磁盘缓存新增一个基于文件系统持久化的存储后端(FileStore),作为 Mooncake / AttentionStore 之外的第三种可选后端,并在 cache_transfer_manager 中接入读写流程与参数支持。
Changes:
- 新增 FileStore KVCacheStorage 实现(本地文件落盘 / 读取 / 清理 / 查询)。
- 将 FileStore 接入 cache_transfer_manager(新增 backend 选项与 file_path 参数)。
- 扩展 Engine CLI 的
--kvcache-storage-backend选项,并更新示例脚本。
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| fastdeploy/engine/args_utils.py | CLI 参数 --kvcache-storage-backend 增加 file 选项。 |
| fastdeploy/cache_manager/transfer_factory/file_store/file_store.py | 新增 FileStore 后端的核心实现。 |
| fastdeploy/cache_manager/transfer_factory/file_store/init.py | 暴露 FileStore / FileStoreConfig。 |
| fastdeploy/cache_manager/transfer_factory/init.py | 将 FileStore 加入 transfer_factory 导出。 |
| fastdeploy/cache_manager/cache_transfer_manager.py | 增加 file 后端初始化、读写分支与 --kvcache_file_path 参数。 |
| examples/cache_storage/run.sh | 示例脚本中 stop.sh 调用被注释。 |
| elif args.kvcache_storage_backend == "file": | ||
| logger.info("Start initialize file store...") | ||
| self.storage_backend = FileStore( | ||
| namespace=self.model_id, | ||
| tp_rank=self.rank, | ||
| tp_size=self.n_ranks, | ||
| file_path=args.kvcache_file_path, | ||
| ) | ||
| self._init_storage_buffer(args) | ||
| logger.info("Initialized file store successfully") |
There was a problem hiding this comment.
新增 file 存储后端分支(初始化 + read/write 逻辑)目前缺少单测覆盖。仓库已有 tests/cache_manager/test_cache_transfer_manager.py 覆盖其他分支逻辑,建议补充针对 kvcache_storage_backend=="file" 的用例(可通过 mock FileStore.batch_get/batch_set 与 swap_cache_layout 调用来验证读写流程与成功块统计)。
juncaipeng
left a comment
There was a problem hiding this comment.
coplit的comments,也一一看下
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6188 +/- ##
==========================================
Coverage ? 67.13%
==========================================
Files ? 387
Lines ? 51390
Branches ? 8009
==========================================
Hits ? 34500
Misses ? 14418
Partials ? 2472
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…#6188) * fix(examples): comment out stop.sh to avoid error when script is missing * feat: add file_store support for cache manager * [fix] fix multi gpu transfer * [fix] fix global kvcache transfer * [Feature] [KVCache] support file_store kv cache backend * chore: update FileStore according to PR comments * fix: remove comments * fix: add swap_cache_layout for file store * fix: remove rank key * fix: Switch KV cache storage to pure file mode * Temporarily disable support for Tensor types * fix: remove args --kvcache_file_path & add envs FILE_BACKEND_STORAGE_DIR * fixx: Simplify cache_transfer_manager.py * fix: fix syntax bug * fix: Simplify file_store.py * fix: Use the key directly as the filename * fix: Simplify set() * fix: Simplify cache_transfer_manager.py & file_store.py * fix: Only support load to cpu buffer * feat: add FileStore backend for cache transfer * fix: guard zmq import
…#6188) * fix(examples): comment out stop.sh to avoid error when script is missing * feat: add file_store support for cache manager * [fix] fix multi gpu transfer * [fix] fix global kvcache transfer * [Feature] [KVCache] support file_store kv cache backend * chore: update FileStore according to PR comments * fix: remove comments * fix: add swap_cache_layout for file store * fix: remove rank key * fix: Switch KV cache storage to pure file mode * Temporarily disable support for Tensor types * fix: remove args --kvcache_file_path & add envs FILE_BACKEND_STORAGE_DIR * fixx: Simplify cache_transfer_manager.py * fix: fix syntax bug * fix: Simplify file_store.py * fix: Use the key directly as the filename * fix: Simplify set() * fix: Simplify cache_transfer_manager.py & file_store.py * fix: Only support load to cpu buffer * feat: add FileStore backend for cache transfer * fix: guard zmq import
…#6188) * fix(examples): comment out stop.sh to avoid error when script is missing * feat: add file_store support for cache manager * [fix] fix multi gpu transfer * [fix] fix global kvcache transfer * [Feature] [KVCache] support file_store kv cache backend * chore: update FileStore according to PR comments * fix: remove comments * fix: add swap_cache_layout for file store * fix: remove rank key * fix: Switch KV cache storage to pure file mode * Temporarily disable support for Tensor types * fix: remove args --kvcache_file_path & add envs FILE_BACKEND_STORAGE_DIR * fixx: Simplify cache_transfer_manager.py * fix: fix syntax bug * fix: Simplify file_store.py * fix: Use the key directly as the filename * fix: Simplify set() * fix: Simplify cache_transfer_manager.py & file_store.py * fix: Only support load to cpu buffer * feat: add FileStore backend for cache transfer * fix: guard zmq import
Motivation
Modifications
Usage or Command
python -m fastdeploy.entrypoints.openai.api_server \ --model "PaddlePaddle/ERNIE-4.5-0.3B-Paddle" \ --port 8300 \ --metrics-port 8301 \ --engine-worker-queue-port 8302 \ --cache-queue-port 8303 \ --max-model-len 32768 \ --max-num-seqs 32 \ --kvcache-storage-backend file \ --enable-prefix-cachingAccuracy Tests
test script
cd tests/ce/accuracy_cases python gsm8k.pytest result
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.