Skip to content

[Core] Configure custom encoder cache managers from VllmConfig - #51251

Merged
Isotr0py merged 7 commits into
vllm-project:mainfrom
hotTea123:encoder-cache-vllm-config
Aug 13, 2026
Merged

Isotr0py merged 7 commits into
vllm-project:mainfrom
hotTea123:encoder-cache-vllm-config

Conversation

@hotTea123

@hotTea123 hotTea123 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Expose custom encoder cache manager configuration through VllmConfig for both online and offline inference.

Custom encoder cache managers may require policy-specific parameters in addition to the encoder cache size. This PR provides a generic configuration path while preserving compatibility with existing built-in and constructor-only cache managers.

Changes

This PR:

  • Adds an opaque manager_config field to EncoderCacheManagerConfig.
    Its contents are interpreted by the selected custom cache manager.

  • Exposes ec_manager_config through EngineArgs.

  • Adds the --ec-manager-config CLI option for online serving.

  • Supports the same configuration through LLM(ec_manager_config=...) for offline inference.

  • Resolves custom encoder cache managers using fully qualified class names.

  • Allows custom managers that need the complete VllmConfig to optionally implement:

    @classmethod
    def from_vllm_config(
        cls,
        *,
        cache_size: int,
        vllm_config: VllmConfig,
    ):
        ...
  • Preserves compatibility with constructor-only custom managers:

    manager_cls(cache_size=cache_size)
  • Keeps the existing construction paths of built-in EncoderCacheManager and EncoderDecoderCacheManager unchanged.

A custom manager is not required to inherit from EncoderCacheManager or implement from_vllm_config, as long as it satisfies the interfaces consumed by the scheduler and model runner.

Relationship to #48218

This PR is a follow-up to #48218, which was merged as commit 833483f.

#48218 introduced the generic encoder cache manager extension foundation, including:

  • selecting a custom encoder cache manager by fully qualified class name;
  • passing EncoderCacheManagerMetadata from the scheduler to workers;
  • overridable model-runner hooks for encoder cache lookup, storage, eviction, and request cleanup.

However, custom managers were still constructed using only cache_size, and the encoder cache manager configuration was not consistently exposed through online and offline EngineArgs.

This PR completes the configuration path without changing the lifecycle hooks introduced by #48218. Hardware-specific cache policies remain implemented in their corresponding platform plugins.

Usage

Online inference

vllm serve MODEL \
  --ec-manager-config '{
    "encoder_cache_manager_cls":
      "vllm_ascend.ec_manager.score_ec_manager.ScoreEncoderCacheManager",
    "manager_config": {
      "cpu_cache_slots": 100000,
      "max_clock": 15,
      "clock_decay_every": 64,
      "watermark": 0.2,
      "promote_percentile": 0.2
    }
  }'

Offline inference

from vllm import LLM

llm = LLM(
    model="MODEL",
    ec_manager_config={
        "encoder_cache_manager_cls": (
            "vllm_ascend.ec_manager.score_ec_manager."
            "ScoreEncoderCacheManager"
        ),
        "manager_config": {
            "cpu_cache_slots": 100000,
            "max_clock": 15,
            "clock_decay_every": 64,
            "watermark": 0.2,
            "promote_percentile": 0.2,
        },
    },
)

manager_config is intentionally opaque to vLLM. Validation and interpretation of manager-specific fields are owned by the selected custom manager.

Specifying a non-empty manager_config without encoder_cache_manager_cls raises a configuration error.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork β€” automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 077c7ff007

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vllm/v1/core/sched/scheduler.py Resolved
Expose encoder cache manager configuration through EngineArgs and let custom managers initialize from VllmConfig while preserving the default cache-size-only behavior.

Signed-off-by: hotTea <958436561@qq.com>
@hotTea123
hotTea123 force-pushed the encoder-cache-vllm-config branch from 077c7ff to cedc696 Compare August 6, 2026 13:30
Signed-off-by: hotTea <958436561@qq.com>
@HMCCMH

HMCCMH commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Hello, reviewers. This PR is now ready for review, but it currently lacks the "ready" label to trigger the codex review and CI tests. Could the reviewers help add the label? Thank you very much.

@ywang96

ywang96 commented Aug 11, 2026

Copy link
Copy Markdown
Member

cc @gty111

@Isotr0py Isotr0py self-assigned this Aug 11, 2026
Comment thread vllm/v1/core/sched/scheduler.py Outdated
Comment on lines +238 to +247
from_vllm_config = getattr(manager_cls_obj, "from_vllm_config", None)
if from_vllm_config is not None:
self.encoder_cache_manager = from_vllm_config(
cache_size=encoder_cache_size,
vllm_config=vllm_config,
)
else:
self.encoder_cache_manager = manager_cls_obj(
cache_size=encoder_cache_size
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we unify this?

Suggested change
from_vllm_config = getattr(manager_cls_obj, "from_vllm_config", None)
if from_vllm_config is not None:
self.encoder_cache_manager = from_vllm_config(
cache_size=encoder_cache_size,
vllm_config=vllm_config,
)
else:
self.encoder_cache_manager = manager_cls_obj(
cache_size=encoder_cache_size
)
self.encoder_cache_manager = manager_cls_obj.create_manager(
cache_size=encoder_cache_size,
vllm_config=vllm_config,
)

@HMCCMH HMCCMH Aug 11, 2026 •

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.

Hi, you are right.

We have added the @classmethod-level create_manager function to the EncoderCacheManager class in vllm/v1/core/encoder_cache_manager.py to support this method. In addition, in the downstream vllm-ascend, we can use return cls(cache_size=cache_size, vllm_config=vllm_config) to extend the corresponding return to support the initialization requirements of different types of managers.

And if you think this implementation is okay, we further modify the initial description.

Signed-off-by: HMCCMH <chenminghaoscu@163.com>
Comment thread vllm/v1/core/sched/scheduler.py Outdated
Comment on lines 237 to 244
if manager_cls_obj is not None:
self.encoder_cache_manager = manager_cls_obj(cache_size=encoder_cache_size)
self.encoder_cache_manager = manager_cls_obj.create_manager(
cache_size=encoder_cache_size,
vllm_config=vllm_config
)
else:
self.encoder_cache_manager = (
EncoderDecoderCacheManager(cache_size=encoder_cache_size)

@HMCCMH HMCCMH Aug 12, 2026 •

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.

If we add @classmethod-level create_manager,maybe we can just change the manager_cls_obj and unify the initialization of self.encoder_cache_manager like this?
if manager_cls_obj is None:
manager_cls_obj = (
EncoderDecoderCacheManager
if self.is_encoder_decoder
else EncoderCacheManager
)
self.encoder_cache_manager = manager_cls_obj.create_manager(
cache_size=encoder_cache_size,
vllm_config=vllm_config
)
Do you think it's okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes. I think it's good for me.

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.

Okay okay. We have already changed it. You could review it. If it's okay, please set "ready" label for this PR. Then we can trigger CI tests.

Signed-off-by: HMCCMH <chenminghaoscu@163.com>
@gty111 gty111 added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 12, 2026
@github-actions

Copy link
Copy Markdown

βœ… @hotTea123, CI is now available for this PR.

  • /ci run starts a CI build.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /ci cancel cancels scheduled or running CI builds for this PR branch.

@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Hi @hotTea123, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Signed-off-by: HMCCMH <chenminghaoscu@163.com>
@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Hi @hotTea123, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Signed-off-by: HMCCMH <chenminghaoscu@163.com>
@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Hi @hotTea123, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Signed-off-by: HMCCMH <chenminghaoscu@163.com>
@HMCCMH

HMCCMH commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

/ci run

@github-actions

Copy link
Copy Markdown

❌ @HMCCMH, Only reviewers with write access can use CI commands before CI is delegated to the PR author.

@hotTea123

Copy link
Copy Markdown
Contributor Author

/ci run

@github-actions

Copy link
Copy Markdown

βœ… Triggered Buildkite CI #83495 for commit 1d5bfcfc9cc8.

@HMCCMH

HMCCMH commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

@ywang96 @Isotr0py @gty111 Hi, reviewers. The code seems to be fine and it has passed all the tests. Could you please review the code again? If you think it's okay, could you mark it as "approved"? If there are still any issues with the code, we will promptly modify it and respond to you.

@Isotr0py
Isotr0py merged commit 7bbbf7c into vllm-project:main Aug 13, 2026
7 checks passed
zufangzhu pushed a commit to zufangzhu/vllm that referenced this pull request Aug 24, 2026
…project#51251)

Signed-off-by: hotTea <958436561@qq.com>
Signed-off-by: HMCCMH <chenminghaoscu@163.com>
Co-authored-by: HMCCMH <chenminghaoscu@163.com>
Signed-off-by: Zhu, Zufang <zufang.zhu@intel.com>
wangxiyuan pushed a commit to vllm-project/vllm-ascend that referenced this pull request Aug 29, 2026
### What this PR does / why we need it?

This PR introduces a hierarchical embedding cache management mechanism
for multimodal encoder outputs on vllm-ascend.

Specifically, it extends the current single-level device-side embedding
cache with:
- a two-level cache hierarchy (NPU/HBM + CPU/DRAM),
- utility-aware cache promotion/eviction,
- asynchronous cache migration from CPU to NPU,
- temporary on-demand cache staging for non-promoted entries.

The motivation is that the existing embedding cache behavior is
optimized for direct device residency, but in multimodal workloads
encoder outputs can have highly heterogeneous reuse patterns,
recomputation costs, and memory footprints. Keeping all cached
embeddings in NPU memory can lead to low-value entries occupying
expensive HBM space, while directly evicting them may cause unnecessary
recomputation.

This PR adds a score-based cache manager that tracks cache residency,
reference state, and reclaimability, and uses these signals to:
- keep newly generated embeddings in CPU memory by default,
- promote only high-value entries to NPU memory,
- evict low-value reclaimable entries under NPU memory pressure,
- fetch CPU-resident embeddings into temporary device buffers when
promotion is not worthwhile.

At the runner side, the PR also adds asynchronous handling for
promotion, eviction, and temporary CPU-to-NPU fetches, so cache movement
is decoupled from the main inference path as much as possible.

Overall, this change is needed to improve embedding cache efficiency and
memory utilization for multimodal inference on Ascend, especially when
encoder outputs are large and reuse is uneven.

### Does this PR introduce _any_ user-facing change?

Yes, in a backward-compatible and opt-in manner. The score-based policy
is enabled by selecting `ScoreEncoderCacheManager` through vLLM's
`ec_manager_config`.

For online inference, pass `--ec-manager-config`. For offline inference,
pass `ec_manager_config` to `LLM`. In both cases, set
`encoder_cache_manager_cls` to
`vllm_ascend.ec_manager.score_ec_manager.ScoreEncoderCacheManager` and
configure policy parameters under `manager_config`.

The manager consumes `manager_config` through `create_manager`. Users
can control CPU cache capacity, clock decay, promotion policy, and
eviction thresholds. When the Score manager is not selected, existing
behavior remains unchanged.

Selecting the Score manager changes cache residency decisions, memory
usage patterns, and performance characteristics for multimodal
workloads, but does not introduce a separate Ascend configuration API.

### How was this patch tested?

This patch was primarily tested with end-to-end multimodal inference
runs on vllm-ascend with the new cache manager enabled.

Test coverage included:
- first-time multimodal requests that generate encoder outputs and place
them into CPU cache,
- repeated requests hitting device-resident cached embeddings,
- repeated requests hitting CPU-resident cached embeddings and
triggering promotion,
- repeated requests hitting CPU-resident cached embeddings without
promotion and using temporary device cache,
- request completion paths that release references and make cache
entries reclaimable,
- cache pressure scenarios that trigger NPU eviction and CPU-side
reclaim,
- mixed request execution to verify cache state consistency and absence
of stale entries.

We also verified:
- successful end-to-end inference correctness with cache hits and
misses,
- no crashes during async promotion/eviction paths,
- correct cleanup of temporary cache entries after request completion,
- stable execution under repeated request scheduling.

Dedicated unit tests cover manager selection, configuration validation,
CPU/NPU cache lifecycle, promotion, eviction, and reset behavior.
Integrated runtime validation remains focused on Ascend devices.

vLLM related PR: 
vllm-project/vllm#48218
vllm-project/vllm#51251

Special thanks to Wang Qing @sereinnwang for the valuable contributions
and support to this work.

---------

Signed-off-by: hotTea <958436561@qq.com>
Signed-off-by: hanxi-java <634498162@qq.com>
Signed-off-by: HMCCMH <chenminghaoscu@163.com>
Signed-off-by: he-code-he-he <gaohexu@huawei.com>
Co-authored-by: hanxi-java <634498162@qq.com>
Co-authored-by: HMCCMH <chenminghaoscu@163.com>
Co-authored-by: he-code-he-he <gaohexu@huawei.com>
Lethobenthos20 pushed a commit to Lethobenthos20/vllm-ascend that referenced this pull request Sep 4, 2026
…ct#7500)

### What this PR does / why we need it?

This PR introduces a hierarchical embedding cache management mechanism
for multimodal encoder outputs on vllm-ascend.

Specifically, it extends the current single-level device-side embedding
cache with:
- a two-level cache hierarchy (NPU/HBM + CPU/DRAM),
- utility-aware cache promotion/eviction,
- asynchronous cache migration from CPU to NPU,
- temporary on-demand cache staging for non-promoted entries.

The motivation is that the existing embedding cache behavior is
optimized for direct device residency, but in multimodal workloads
encoder outputs can have highly heterogeneous reuse patterns,
recomputation costs, and memory footprints. Keeping all cached
embeddings in NPU memory can lead to low-value entries occupying
expensive HBM space, while directly evicting them may cause unnecessary
recomputation.

This PR adds a score-based cache manager that tracks cache residency,
reference state, and reclaimability, and uses these signals to:
- keep newly generated embeddings in CPU memory by default,
- promote only high-value entries to NPU memory,
- evict low-value reclaimable entries under NPU memory pressure,
- fetch CPU-resident embeddings into temporary device buffers when
promotion is not worthwhile.

At the runner side, the PR also adds asynchronous handling for
promotion, eviction, and temporary CPU-to-NPU fetches, so cache movement
is decoupled from the main inference path as much as possible.

Overall, this change is needed to improve embedding cache efficiency and
memory utilization for multimodal inference on Ascend, especially when
encoder outputs are large and reuse is uneven.

### Does this PR introduce _any_ user-facing change?

Yes, in a backward-compatible and opt-in manner. The score-based policy
is enabled by selecting `ScoreEncoderCacheManager` through vLLM's
`ec_manager_config`.

For online inference, pass `--ec-manager-config`. For offline inference,
pass `ec_manager_config` to `LLM`. In both cases, set
`encoder_cache_manager_cls` to
`vllm_ascend.ec_manager.score_ec_manager.ScoreEncoderCacheManager` and
configure policy parameters under `manager_config`.

The manager consumes `manager_config` through `create_manager`. Users
can control CPU cache capacity, clock decay, promotion policy, and
eviction thresholds. When the Score manager is not selected, existing
behavior remains unchanged.

Selecting the Score manager changes cache residency decisions, memory
usage patterns, and performance characteristics for multimodal
workloads, but does not introduce a separate Ascend configuration API.

### How was this patch tested?

This patch was primarily tested with end-to-end multimodal inference
runs on vllm-ascend with the new cache manager enabled.

Test coverage included:
- first-time multimodal requests that generate encoder outputs and place
them into CPU cache,
- repeated requests hitting device-resident cached embeddings,
- repeated requests hitting CPU-resident cached embeddings and
triggering promotion,
- repeated requests hitting CPU-resident cached embeddings without
promotion and using temporary device cache,
- request completion paths that release references and make cache
entries reclaimable,
- cache pressure scenarios that trigger NPU eviction and CPU-side
reclaim,
- mixed request execution to verify cache state consistency and absence
of stale entries.

We also verified:
- successful end-to-end inference correctness with cache hits and
misses,
- no crashes during async promotion/eviction paths,
- correct cleanup of temporary cache entries after request completion,
- stable execution under repeated request scheduling.

Dedicated unit tests cover manager selection, configuration validation,
CPU/NPU cache lifecycle, promotion, eviction, and reset behavior.
Integrated runtime validation remains focused on Ascend devices.

vLLM related PR: 
vllm-project/vllm#48218
vllm-project/vllm#51251

Special thanks to Wang Qing @sereinnwang for the valuable contributions
and support to this work.

---------

Signed-off-by: hotTea <958436561@qq.com>
Signed-off-by: hanxi-java <634498162@qq.com>
Signed-off-by: HMCCMH <chenminghaoscu@163.com>
Signed-off-by: he-code-he-he <gaohexu@huawei.com>
Co-authored-by: hanxi-java <634498162@qq.com>
Co-authored-by: HMCCMH <chenminghaoscu@163.com>
Co-authored-by: he-code-he-he <gaohexu@huawei.com>
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
…project#51251)

Signed-off-by: hotTea <958436561@qq.com>
Signed-off-by: HMCCMH <chenminghaoscu@163.com>
Co-authored-by: HMCCMH <chenminghaoscu@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants