Skip to content

[Feature] [KVCache] support file_store kv cache backend - #6188

Merged
Jiang-Jia-Jun merged 29 commits into
PaddlePaddle:developfrom
Moonchild1227:feature/file-store
Feb 3, 2026
Merged

Jiang-Jia-Jun merged 29 commits into
PaddlePaddle:developfrom
Moonchild1227:feature/file-store

Conversation

@Moonchild1227

@Moonchild1227 Moonchild1227 commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • add FileStore persistence backend for KVCache disk caching
  • wait cache_transfer_manager inited
  • Adds a third KVCache storage backend in addition to Mooncake and AttentionStore

Modifications

  • cache_transfer_manager.py
  • file_store.py

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-caching 

Accuracy Tests

test script

cd tests/ce/accuracy_cases
python gsm8k.py 

test result

  • base line
🎯 Evaluation Complete: Accuracy = 3.33% (23/690)
平均准确率:3.91%
  • file store
🎯 Evaluation Complete: Accuracy = 4.06% (28/690)
平均准确率:3.62%

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[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]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot

paddle-bot Bot commented Jan 23, 2026

Copy link
Copy Markdown

Thanks for your contribution!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 调用被注释。

Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
Comment on lines +261 to +270
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")

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增 file 存储后端分支(初始化 + read/write 逻辑)目前缺少单测覆盖。仓库已有 tests/cache_manager/test_cache_transfer_manager.py 覆盖其他分支逻辑,建议补充针对 kvcache_storage_backend=="file" 的用例(可通过 mock FileStore.batch_get/batch_set 与 swap_cache_layout 调用来验证读写流程与成功块统计)。

Copilot generated this review using guidance from repository custom instructions.
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated

@juncaipeng juncaipeng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coplit的comments,也一一看下

Comment thread fastdeploy/config.py Outdated
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py Outdated
Comment thread fastdeploy/cache_manager/transfer_factory/file_store/file_store.py
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
juncaipeng
juncaipeng previously approved these changes Jan 29, 2026

@juncaipeng juncaipeng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
Comment thread fastdeploy/cache_manager/cache_transfer_manager.py Outdated
@codecov-commenter

codecov-commenter commented Jan 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.34884% with 137 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@85db063). Learn more about missing BASE report.

Files with missing lines Patch % Lines
..._manager/transfer_factory/file_store/file_store.py 19.25% 130 Missing ⚠️
fastdeploy/cache_manager/cache_transfer_manager.py 12.50% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #6188   +/-   ##
==========================================
  Coverage           ?   67.13%           
==========================================
  Files              ?      387           
  Lines              ?    51390           
  Branches           ?     8009           
==========================================
  Hits               ?    34500           
  Misses             ?    14418           
  Partials           ?     2472           
Flag Coverage Δ
GPU 67.13% <20.34%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

juncaipeng
juncaipeng previously approved these changes Feb 2, 2026
@Jiang-Jia-Jun
Jiang-Jia-Jun merged commit 39dc4b0 into PaddlePaddle:develop Feb 3, 2026
19 of 24 checks passed
kesmeey pushed a commit to kesmeey/FastDeploy that referenced this pull request Feb 22, 2026
…#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
chang-wenbin pushed a commit to chang-wenbin/FastDeploy that referenced this pull request Mar 2, 2026
…#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
xiaoguoguo626807 pushed a commit to xiaoguoguo626807/FastDeploy that referenced this pull request May 7, 2026
…#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants