-
Notifications
You must be signed in to change notification settings - Fork 749
[Feature][KVCache] Implement Cache Manager V1 with GPU + CPU Cache Support (1/n) #7097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jiang-Jia-Jun
merged 32 commits into
PaddlePaddle:develop
from
kevincheng2:feature/cache_manager_v1_rebase
Apr 21, 2026
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
71600d5
[Feature][KVCache] Support cache manager v1 architecture
kevincheng2 2dbbb05
Update cache manager and related modules
kevincheng2 f602a38
chore: update cache_manager and related modules
kevincheng2 a0c3ad6
fix: add node to evictable set in complete_swap_to_device
kevincheng2 f4f0fac
feat: update cache manager v1 and related modules
kevincheng2 fe82b08
feat(cache): add cache controller v1 implementation
kevincheng2 c174b53
feat(cache_manager): update cache manager v1
kevincheng2 244ce1e
fix(cache_manager): 修复 swap_cache H2D/D2H 方向的 block_ids 逻辑并清理 Forward…
kevincheng2 fae77e8
feat(cache_manager): refactor cache manager v1 and optimize swap ops
kevincheng2 5d6e615
[KVCache][MTP] 支持 cache_manager_v1 下的 MTP KV Cache 初始化及多模态 hash
kevincheng2 17e6abb
fix(cache_manager): multi-GPU fix, mm hash boundary fix, and remove b…
kevincheng2 d66c569
[BugFix][KVCache] fix List import and move write_policy normalization…
kevincheng2 1e19a2f
[BugFix][KVCache] fix pre-commit code style issues
kevincheng2 9205f59
[Feature][KVCache] update cache_manager_v1 modules
kevincheng2 9def013
[Feature][KVCache] add BatchRequest.from_tasks and refactor worker ta…
kevincheng2 31e3db2
[Feature][KVCache] add NUMA affinity for host cache and skip swap cac…
kevincheng2 1656225
[BugFix][KVCache] fix unittest failures for cache_manager_v1
kevincheng2 1e4210b
[BugFix][KVCache] remove debug logging code
kevincheng2 8d3665b
[BugFix][KVCache] fix cupy device id caching and pickle for _match_re…
kevincheng2 dcb0fb1
fix(test): fix unit test errors for _trigger_preempt and wakeup with MTP
kevincheng2 ad8b57b
[BugFix][KVCache] fix gpu_free_block_list returning wrong block IDs
kevincheng2 9c23ca5
[BugFix][KVCache] 修复 gpu_free_block_list 返回 int 导致 TypeError
kevincheng2 80eef02
[KVCache][CacheManager] 适配 V1 CacheManager 的 pause/sleep/free_cache 操作
kevincheng2 d11d518
[BugFix][KVCache] fix missing enable_cache_manager_v1 in test mocks a…
kevincheng2 c897dd5
[BugFix][KVCache] simplify _free_blocks in ResourceManagerV1 for non-…
kevincheng2 5ec085a
[KVCache][Optimization][BugFix] fix and optimize block_pool, cache_ma…
kevincheng2 a2fd4f4
[BugFix][KVCache] Fix BlockPool.allocate returns all blocks when num_…
kevincheng2 d67065e
[KVCache][Test] add unit tests for cache_manager v1 modules
kevincheng2 b844056
Merge branch 'develop' into feature/cache_manager_v1_rebase
Jiang-Jia-Jun 54a4ebb
Merge branch 'develop' into feature/cache_manager_v1_rebase
kevincheng2 9ab9078
Merge branch 'develop' into feature/cache_manager_v1_rebase
Jiang-Jia-Jun a34a5d9
Merge branch 'develop' into feature/cache_manager_v1_rebase
kevincheng2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """ | ||
| # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License" | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
|
|
||
| from .base import KVCacheBase | ||
| from .cache_controller import CacheController | ||
| from .cache_manager import CacheManager | ||
| from .cache_utils import LayerDoneCounter, LayerSwapTimeoutError | ||
| from .metadata import ( | ||
| AsyncTaskHandler, | ||
| BlockNode, | ||
| CacheBlockMetadata, | ||
| CacheStatus, | ||
| MatchResult, | ||
| PDTransferMetadata, | ||
| StorageConfig, | ||
| StorageMetadata, | ||
| StorageType, | ||
| TransferConfig, | ||
| TransferResult, | ||
| TransferStatus, | ||
| TransferTask, | ||
| TransferType, | ||
| ) | ||
| from .storage import create_storage_connector, create_storage_scheduler | ||
| from .transfer import create_transfer_connector | ||
| from .transfer_manager import CacheTransferManager | ||
|
|
||
| __all__ = [ | ||
| # Base classes | ||
| "KVCacheBase", | ||
| # Managers | ||
| "CacheManager", | ||
| "CacheController", | ||
| "CacheTransferManager", | ||
| # Exceptions | ||
| "LayerSwapTimeoutError", | ||
| # Utils | ||
| "LayerDoneCounter", | ||
| # Metadata | ||
| "CacheBlockMetadata", | ||
| "BlockNode", | ||
| "CacheStatus", | ||
| "TransferTask", | ||
| "TransferStatus", | ||
| "TransferConfig", | ||
| "TransferResult", | ||
| "AsyncTaskHandler", | ||
| "MatchResult", | ||
| "StorageMetadata", | ||
| "PDTransferMetadata", | ||
| "StorageConfig", | ||
| "StorageType", | ||
| "TransferType", | ||
| # Factory functions | ||
| "create_storage_scheduler", | ||
| "create_storage_connector", | ||
| "create_transfer_connector", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """ | ||
| # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License" | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from fastdeploy.config import FDConfig | ||
|
|
||
|
|
||
| class KVCacheBase(ABC): | ||
| """ | ||
| Abstract base class for KV cache management. | ||
|
|
||
| This class defines the common interface for cache management operations. | ||
| Subclasses (CacheManager and CacheController) implement specific behaviors | ||
| based on their roles in the system. | ||
|
|
||
| CacheManager (Scheduler process): | ||
| - Manages DeviceBlockPool and HostBlockPool | ||
| - Handles block allocation and release | ||
| - Coordinates storage operations via StorageScheduler | ||
|
|
||
| CacheController (Worker process): | ||
| - Manages cache transfer operations | ||
| - Handles layer-by-layer transfer synchronization | ||
| - Coordinates cross-node transfer via TransferConnector | ||
| """ | ||
|
|
||
| def __init__(self, config: "FDConfig"): | ||
| """ | ||
| Initialize the KV cache base. | ||
|
|
||
| Args: | ||
| config: FDConfig instance containing all fastdeploy configuration | ||
| """ | ||
| self.config = config | ||
|
|
||
| # Extract configuration from FDConfig | ||
| self.model_config = config.model_config | ||
| self.cache_config = config.cache_config | ||
| self.quant_config = config.quant_config | ||
| self.parallel_config = config.parallel_config | ||
|
|
||
| self._initialized = False | ||
|
|
||
| @abstractmethod | ||
| def reset_cache(self) -> bool: | ||
| """ | ||
| Reset the cache state. | ||
|
|
||
| This method should be implemented by subclasses to reset their | ||
| specific cache state (e.g., clear block pools, reset transfer state). | ||
|
|
||
| Returns: | ||
| True if reset was successful, False otherwise | ||
| """ | ||
| pass | ||
|
|
||
| def is_initialized(self) -> bool: | ||
| """ | ||
| Check if the cache has been initialized. | ||
|
|
||
| Returns: | ||
| True if initialized, False otherwise | ||
| """ | ||
| return self._initialized |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.