Skip to content

[KVCache] Support environment variable overrides for AttentionStore c…#7455

Open
jackyYang6 wants to merge 1 commit intoPaddlePaddle:developfrom
jackyYang6:kvcache/as-config
Open

[KVCache] Support environment variable overrides for AttentionStore c…#7455
jackyYang6 wants to merge 1 commit intoPaddlePaddle:developfrom
jackyYang6:kvcache/as-config

Conversation

@jackyYang6
Copy link
Copy Markdown
Contributor

Motivation

AttentionStore's namespace, pod_name, and model_version are currently only configurable via constructor arguments. In K8s deployments, these values are typically derived from Pod environment variables (e.g., MODEL_ID, FD_POD_NAME, KVCACHE_VERSION). Without environment variable overrides, deployment configuration is inflexible.

Modifications

Modified file: fastdeploy/cache_manager/transfer_factory/mooncake_store/attention_store.py

Added environment variable overrides for AttentionStoreConfig fields before SDK initialization in AttentionStore.__init__:

self.config.namespace = os.getenv("MODEL_ID", self.config.namespace)
self.config.pod_name = os.getenv("FD_POD_NAME", self.config.pod_name)
self.config.model_version = os.getenv("KVCACHE_VERSION", self.config.model_version)
  • When environment variables are not set, the original constructor defaults are preserved (no behavior change).
  • Environment variables take precedence over constructor arguments when set.

Usage or Command

Set the corresponding environment variables before launching the service:

export MODEL_ID=my-model
export FD_POD_NAME=my-pod-0
export KVCACHE_VERSION=v1

Accuracy Tests

Not applicable — this change does not affect model outputs.

Checklist

  • Add at least a tag in the PR title.
  • 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
Copy link
Copy Markdown

paddle-bot bot commented Apr 17, 2026

Thanks for your contribution!

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

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

🤖 AI Code Review | 2026-04-17 11:36 CST

📋 Review 摘要

PR 概述:为 AttentionStoreConfignamespacepod_namemodel_version 字段新增环境变量覆盖能力,方便 K8s 部署场景。
变更范围cache_manager/transfer_factory/mooncake_store/attention_store.py
影响面 TagKVCache

问题

级别 文件 概述
🟡 建议 attention_store.py:66-69 日志在环境变量覆盖之前打印,记录的配置值与实际使用值不一致

详细说明

当前代码在第 66 行先打印了 self.config,然后在第 67-69 行才用环境变量覆盖 namespace/pod_name/model_version。这意味着日志中记录的是覆盖前的值,而非实际传给 AttentionStoreSDK 的值。在 K8s 环境排查问题时,这会导致日志与实际行为不一致,增加调试难度。

建议:将环境变量覆盖逻辑移到 logger.info 之前,或者在覆盖之后补充一条日志记录最终生效的配置:

self.config.namespace = os.getenv("MODEL_ID", self.config.namespace)
self.config.pod_name = os.getenv("FD_POD_NAME", self.config.pod_name)
self.config.model_version = os.getenv("KVCACHE_VERSION", self.config.model_version)
logger.info(f"[INIT] Start initializing AttentionStoreSDK with config: {self.config}")

总体评价

变更简洁明确,环境变量优先于构造函数参数的策略符合 K8s 部署惯例,且未设置环境变量时保持原有默认行为,不会引入 breaking change。建议修正日志打印顺序以确保可观测性准确。

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@e952720). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...transfer_factory/mooncake_store/attention_store.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7455   +/-   ##
==========================================
  Coverage           ?   73.47%           
==========================================
  Files              ?      398           
  Lines              ?    54979           
  Branches           ?     8613           
==========================================
  Hits               ?    40398           
  Misses             ?    11873           
  Partials           ?     2708           
Flag Coverage Δ
GPU 73.47% <25.00%> (?)

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.


try:
self.config.namespace = os.getenv("MODEL_ID", self.config.namespace)
self.config.pod_name = os.getenv("FD_POD_NAME", self.config.pod_name)
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.

这个Pod Name 需要和上报给IC 和 IM 的pod name 对齐吗?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已确认不依赖此作为索引

Copy link
Copy Markdown
Collaborator

@hong19860320 hong19860320 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants