mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
Some checks failed
CE Compile Job / ce_job_pre_check (push) Has been cancelled
CE Compile Job / print_ce_job_pre_check_outputs (push) Has been cancelled
CE Compile Job / FD-Clone-Linux (push) Has been cancelled
CE Compile Job / Show Code Archive Output (push) Has been cancelled
CE Compile Job / BUILD_SM8090 (push) Has been cancelled
CE Compile Job / BUILD_SM8689 (push) Has been cancelled
CE Compile Job / CE_UPLOAD (push) Has been cancelled
Deploy GitHub Pages / deploy (push) Has been cancelled
* success run ngram * Revert "[Code Simplification] remove cum_offsets (#3410)" This reverts commit32b39620bc. * success run ngram5 tp4 42bs * success run ngram5 tp4 42bs * mtp draft commit * add decorator for target model * enable draft model in cudagraph v0.5 * revert revrt cum_offset * enable target model in cudagraph v0.9 And clean debug code * Revert "success run ngram" This reverts commit8351e83993. * add reverted code * enable target model in cudagraph v0.9 * solve comment * fix bid < 0 * Enable Target Model Padding And Draft Model in cudagraph * solve problem * delete rebuild padding debug note * fast compile * Add capture list for mtp * success run 256 tp1 mtp * Enable Lite TP2 Bsz256 * realy enable tp2 bsz 256 * fix problem * Solve problem for Draft model in cudagraph * Solve comment * replace emptytensor as zeros * Solve comments * Revert "fast compile" This reverts commit834639a7ff. * fix bug * fix merge bug * fix typo * fix bug --------- Co-authored-by: lizexu <2694294196@qq.com> Co-authored-by: littledgg <1658565283@qq.com> Co-authored-by: zeroRains <linjunlu@zerorains.top> Co-authored-by: gongshaotian <gstain5555@outlook.com>
90 lines
3.1 KiB
Python
90 lines
3.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 abc import ABC, abstractmethod
|
|
from copy import deepcopy
|
|
from typing import Any
|
|
|
|
import paddle.distributed as dist
|
|
|
|
from fastdeploy import envs
|
|
from fastdeploy.config import FDConfig
|
|
from fastdeploy.utils import spec_logger
|
|
|
|
|
|
class Proposer(ABC):
|
|
"""
|
|
Proposer Base Class.
|
|
|
|
Used to provide an extensible interface for draft tokens within
|
|
the speculative decoding framework
|
|
"""
|
|
|
|
def __init__(self, fd_config: FDConfig):
|
|
"""
|
|
Init Speculative proposer
|
|
"""
|
|
fd_config.parallel_config.tp_group = None
|
|
self.fd_config = deepcopy(fd_config)
|
|
fd_config.parallel_config.tp_group = dist.get_group(
|
|
fd_config.parallel_config.data_parallel_rank + envs.FD_TP_GROUP_GID_OFFSET
|
|
)
|
|
self.fd_config.parallel_config.tp_group = dist.get_group(
|
|
fd_config.parallel_config.data_parallel_rank + envs.FD_TP_GROUP_GID_OFFSET
|
|
)
|
|
self.parallel_config = self.fd_config.parallel_config
|
|
self.model_config = self.fd_config.model_config
|
|
self.speculative_config = self.fd_config.speculative_config
|
|
self.cache_config = self.fd_config.cache_config
|
|
self.quant_config = self.fd_config.quant_config
|
|
self.graph_opt_config = self.fd_config.graph_opt_config
|
|
self.scheduler_config = self.fd_config.scheduler_config
|
|
|
|
self.max_num_seqs = self.scheduler_config.max_num_seqs
|
|
self.max_model_len = self.parallel_config.max_model_len
|
|
self.speculative_method = self.speculative_config.method
|
|
self.max_draft_token_num = self.speculative_config.num_speculative_tokens
|
|
self.num_model_steps = self.speculative_config.num_model_steps
|
|
|
|
self.max_ngram_size = self.speculative_config.max_ngram_size
|
|
self.min_ngram_size = self.speculative_config.min_ngram_size
|
|
|
|
spec_logger.info(f"Speculate config: {self.speculative_config}")
|
|
|
|
def run(self, *args, **kwargs) -> Any:
|
|
"""
|
|
Unified entry point for all proposer types.
|
|
Dispatches to subclass-specific logic via `_run_impl`.
|
|
"""
|
|
return self._run_impl(*args, **kwargs)
|
|
|
|
@abstractmethod
|
|
def _run_impl(self, *args, **kwargs) -> Any:
|
|
"""
|
|
Implementation for different method
|
|
"""
|
|
raise NotImplementedError
|
|
|
|
def is_chunk_prefill_enabled(self) -> bool:
|
|
"""
|
|
Check whether chunk-based prefill is enabled.
|
|
Default is False.
|
|
|
|
Returns:
|
|
bool: True if chunk prefill is enabled; False otherwise.
|
|
"""
|
|
return False
|