Repository navigation
[Core] Configure custom encoder cache managers from VllmConfig - #51251
Conversation
There was a problem hiding this comment.
π‘ 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".
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>
077c7ff to
cedc696
Compare
Signed-off-by: hotTea <958436561@qq.com>
|
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. |
|
cc @gty111 |
| 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 | ||
| ) |
There was a problem hiding this comment.
Can we unify this?
| 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, | |
| ) |
There was a problem hiding this comment.
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>
| 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
|
β @hotTea123, CI is now available for this PR.
|
|
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-filesThen, commit the changes and push to your branch. For future commits, |
Signed-off-by: HMCCMH <chenminghaoscu@163.com>
|
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-filesThen, commit the changes and push to your branch. For future commits, |
Signed-off-by: HMCCMH <chenminghaoscu@163.com>
|
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-filesThen, commit the changes and push to your branch. For future commits, |
Signed-off-by: HMCCMH <chenminghaoscu@163.com>
|
/ci run |
|
β @HMCCMH, Only reviewers with write access can use CI commands before CI is delegated to the PR author. |
|
/ci run |
|
β
Triggered Buildkite CI #83495 for commit |
β¦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>
### 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>
β¦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>
β¦project#51251) Signed-off-by: hotTea <958436561@qq.com> Signed-off-by: HMCCMH <chenminghaoscu@163.com> Co-authored-by: HMCCMH <chenminghaoscu@163.com>
Purpose
Expose custom encoder cache manager configuration through
VllmConfigfor 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_configfield toEncoderCacheManagerConfig.Its contents are interpreted by the selected custom cache manager.
Exposes
ec_manager_configthroughEngineArgs.Adds the
--ec-manager-configCLI 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
VllmConfigto optionally implement:Preserves compatibility with constructor-only custom managers:
Keeps the existing construction paths of built-in
EncoderCacheManagerandEncoderDecoderCacheManagerunchanged.A custom manager is not required to inherit from
EncoderCacheManageror implementfrom_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:
EncoderCacheManagerMetadatafrom the scheduler to workers;However, custom managers were still constructed using only
cache_size, and the encoder cache manager configuration was not consistently exposed through online and offlineEngineArgs.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
Offline inference
manager_configis intentionally opaque to vLLM. Validation and interpretation of manager-specific fields are owned by the selected custom manager.Specifying a non-empty
manager_configwithoutencoder_cache_manager_clsraises a configuration error.