mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
* support mm prefix caching * update code * fix mm_hashes * support encoder cache * add encoder cache * update code * update encoder cache * fix features bug * fix worker bug * support processor cache, need to optimize yet * refactor multimodal data cache * update code * update code * update v1 scheduler * update code * update code * update codestyle * support turn off processor cache and encoder cache * update pre-commit * fix code * solve review * update code * update code * update test case * set processor cache in GiB * update test case * support mm prefix caching for qwen model * fix code style check * update pre-commit * fix unit test * fix unit test * add ci test case * fix rescheduled bug * change text_after_process to prompt_tokens * fix unit test * fix chat template * change model path * [EP] fix adapter bugs (#4572) * Update expert_service.py * Update common_engine.py * Update expert_service.py * fix v1 hang bug (#4573) * fix import image_ops error on some platforms (#4559) * [CLI]Update parameters in bench latecy cli tool and fix collect-env cli tool (#4558) * add collect-env * del files * [Graph Optimization] Add dy_runnable and introduce cudagraph_switch_threshold for cudagraph mode switching (#4578) * add new branch for sot * reorder * fix batch bug * [XPU]Moe uses a new operator (#4585) * [XPU]Moe uses a new operator * [XPU]Moe uses a new operator * update response * [Feature] Support Paddle-OCR (#4396) * init * update code * fix code style & disable thinking * adapt for common_engine.update_mm_requests_chunk_size * use 3d rope * use flash_attn_unpadded * opt siglip * update to be compatible with the latest codebase * fix typo * optim OCR performance * fix bug * fix bug * fix bug * fix bug * normlize name * modify xpu rope * revert logger * fix bug * fix bug * fix bug * support default_v1 * optim performance * fix bug --------- Co-authored-by: root <root@szzj-acg-tge1-fdda9.szzj.baidu.com> Co-authored-by: zhangyue66 <zhangyue66@baidu.com> * [DataProcessor] add reasoning_tokens into usage info (#4520) * add reasoning_tokens into usage info initial commit * add unit tests * modify unit test * modify and add unit tests * fix unit test * move steam usage to processor * modify processor * modify test_logprobs * modify test_logprobs.py * modify stream reasoning tokens accumulation * fix unit test * perf: Optimize task queue communication from engine to worker (#4531) * perf: Optimize task queue communication from engine to worker * perf: get_tasks to numpy * perf: get_tasks remove to_numpy * fix: request & replace ENV * remove test_e2w_perf.py * fix code style --------- Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com> * Clean up ports after processing results (#4587) * [CI] Add /re-run command in PR comments to restart failed CI workflows (#4593) * [Others] api server exits when worker process is dead (#3271) * [fix] fix terminal hangs when worker process is dead * [chore] change sleep time of monitor * [chore] remove redundant comments * update docs --------- Co-authored-by: ApplEOFDiscord <wwy640130@163.com> Co-authored-by: ApplEOFDiscord <31272106+ApplEOFDiscord@users.noreply.github.com> Co-authored-by: ltd0924 <32387785+ltd0924@users.noreply.github.com> Co-authored-by: yinwei <yinwei_hust@163.com> Co-authored-by: JYChen <zoooo0820@qq.com> Co-authored-by: qwes5s5 <45442318+qwes5s5@users.noreply.github.com> Co-authored-by: Ryan <zihaohuang@aliyun.com> Co-authored-by: yyssys <atyangshuang@foxmail.com> Co-authored-by: ming1753 <61511741+ming1753@users.noreply.github.com> Co-authored-by: root <root@szzj-acg-tge1-fdda9.szzj.baidu.com> Co-authored-by: zhangyue66 <zhangyue66@baidu.com> Co-authored-by: kxz2002 <115912648+kxz2002@users.noreply.github.com> Co-authored-by: SunLei <sunlei5788@gmail.com> Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com> Co-authored-by: Zhang Yulong <35552275+ZhangYulongg@users.noreply.github.com> Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com> Co-authored-by: 李泳桦 <39643373+liyonghua0910@users.noreply.github.com>
173 lines
5.1 KiB
Python
173 lines
5.1 KiB
Python
"""
|
|
# 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 enum import Enum
|
|
|
|
from fastdeploy.utils import get_logger
|
|
|
|
logger = get_logger("prefix_cache_manager", "cache_manager.log")
|
|
|
|
|
|
DISABLE_PREFIX_CACHE_MM_MODEL: set[str] = {
|
|
"Ernie5ForCausalLM",
|
|
}
|
|
|
|
|
|
def is_mm_model_disable_prefix_cache(model_config):
|
|
"""
|
|
check if the model architecture is in DISABLE_PREFIX_CACHE_MM_MODEL
|
|
"""
|
|
return model_config._architecture in DISABLE_PREFIX_CACHE_MM_MODEL
|
|
|
|
|
|
class CacheStatus(Enum):
|
|
"""
|
|
cache status enum class
|
|
"""
|
|
|
|
GPU = 0
|
|
SWAP2CPU = 1
|
|
SWAP2GPU = 2
|
|
CPU = 3
|
|
|
|
|
|
class BlockNode:
|
|
"""
|
|
BlockNode: store the information of a block node
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
node_id,
|
|
input_ids,
|
|
input_hash_value,
|
|
depth,
|
|
block_id,
|
|
token_num,
|
|
hash_value,
|
|
last_used_time,
|
|
parent=None,
|
|
shared_count=1,
|
|
reverved_dec_block_ids=[],
|
|
cache_status=CacheStatus.GPU,
|
|
is_persistent=False,
|
|
persistent_shared_count=0,
|
|
):
|
|
"""
|
|
Args:
|
|
node_id: Unique identifier of the node
|
|
depth: Depth of the node
|
|
block_id: Assigned block ID (CPU block ID if on CPU, GPU block ID if on GPU)
|
|
token_num: Number of tokens in the current block
|
|
hash_value: Hash value of the current block
|
|
last_used_time: Timestamp of last usage
|
|
parent: Parent node
|
|
shared_count: Reference count of requests currently using this node
|
|
reserved_dec_block_ids: Pre-allocated block IDs reserved for decoding, formatted as [block_id, block_id,...]
|
|
cache_status: Current cache state (USING, SWAP2CPU, SWAP2GPU, FREE)
|
|
is_persistent: Whether the node is persistently stored
|
|
persistent_shared_count: Reference count of persistent cache requests
|
|
"""
|
|
|
|
self.node_id = node_id
|
|
self.depth = depth
|
|
self.parent = parent
|
|
self.hash_value = hash_value
|
|
self.token_num = token_num
|
|
self.input_ids = input_ids
|
|
self.input_hash_value = input_hash_value
|
|
|
|
self.children = {}
|
|
self.shared_count = shared_count
|
|
self.last_used_time = last_used_time
|
|
self.block_id = block_id
|
|
self.reverved_dec_block_ids = reverved_dec_block_ids
|
|
self.cache_status = cache_status
|
|
self.is_persistent = is_persistent
|
|
self.persistent_shared_count = persistent_shared_count
|
|
self.req_id_set = set()
|
|
|
|
def __lt__(self, other):
|
|
"""
|
|
override the less than operator
|
|
"""
|
|
if self.last_used_time < other.last_used_time:
|
|
return True
|
|
elif self.last_used_time > other.last_used_time:
|
|
return False
|
|
else:
|
|
return self.depth > other.depth
|
|
|
|
def __str__(self):
|
|
"""
|
|
return node info
|
|
"""
|
|
if self.parent is not None:
|
|
parent_node_id = self.parent.node_id
|
|
else:
|
|
parent_node_id = None
|
|
return (
|
|
f"node_id {self.node_id}: depth {self.depth} hash_value {self.hash_value}"
|
|
+ f" shared_count {self.shared_count} is_gpu_leaf_node {self.is_gpu_leaf_node}"
|
|
+ f" is_cpu_leaf_node {self.is_cpu_leaf_node} block_id {self.block_id} "
|
|
+ f"has_in_gpu {self.has_in_gpu} "
|
|
+ f"cache_status {self.cache_status} parent {parent_node_id} with children number "
|
|
+ f"{len(self.children)} req_id_set {self.req_id_set}"
|
|
)
|
|
|
|
@property
|
|
def has_in_gpu(self):
|
|
"""
|
|
check if the node has been allocated in GPU
|
|
"""
|
|
return self.cache_status == CacheStatus.GPU
|
|
|
|
def increment_shared_count(self):
|
|
"""
|
|
increment shared count
|
|
"""
|
|
self.shared_count += 1
|
|
|
|
def decrement_shared_count(self):
|
|
"""
|
|
decrement shared count
|
|
"""
|
|
self.shared_count -= 1
|
|
|
|
@property
|
|
def is_cpu_leaf_node(self):
|
|
"""
|
|
check if the node is a leaf node in CPU
|
|
"""
|
|
if (self.cache_status == CacheStatus.CPU) and (len(self.children) == 0):
|
|
return True
|
|
return False
|
|
|
|
@property
|
|
def is_gpu_leaf_node(self):
|
|
"""
|
|
check if the node is a leaf node in GPU
|
|
"""
|
|
if self.has_in_gpu is False:
|
|
return False
|
|
else:
|
|
if len(self.children) == 0:
|
|
return True
|
|
for child in self.children.values():
|
|
if child.has_in_gpu is True:
|
|
return False
|
|
return True
|