mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 17:11:21 +08:00
6e416c62dd
* to_request_for_infer initial commit * refact to from_chat_completion_request * preprocess use request initial commit * bugfix * processors refact to using request * bug fix * refact Request from_generic_request * post process initial commit * bugfix * postprocess second commit * bugfix * serving_embedding initial commit * serving_reward initial commit * bugfix * replace function name * async_llm initial commit * offline initial commit and fix bug * bugfix * fix async_llm * remove add speculate_metrics into data * fix logprobs bug * fix echo bug * fix bug * fix reasoning_max_tokens * bugfix * bugfix and modify unittest * bugfix and modify unit test * bugfix * bugfix * bugfix * modify unittest * fix error when reasong_content is none for text_processor * remove some unnessary logic * revert removed logic * implement add and set method for RequestOutput and refact code * modify unit test * modify unit test * union process_request and process_request_obj * remove a unit test * union process_response and process_response_obj * support qwen3_vl_processor * modify unittest and remove comments * fix prompt_logprobs * fix codestyle * add v1 * v1 * fix unit test * fix unit test * fix pre-commit * fix * add process request * add process request * fix * fix * fix unit test * fix unit test * fix unit test * fix unit test * fix unit test * remove file * add unit test * add unit test * add unit test * fix unit test * fix unit test * fix * fix --------- Co-authored-by: Jiaxin Sui <95567040+plusNew001@users.noreply.github.com> Co-authored-by: luukunn <981429396@qq.com> Co-authored-by: luukunn <83932082+luukunn@users.noreply.github.com> Co-authored-by: Zhang Yulong <35552275+ZhangYulongg@users.noreply.github.com>
180 lines
8.0 KiB
Python
180 lines
8.0 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 typing import Any, Dict, Optional
|
|
|
|
from fastdeploy.config import ErnieArchitectures, ModelConfig
|
|
from fastdeploy.entrypoints.openai.tool_parsers import ToolParserManager
|
|
from fastdeploy.reasoning import ReasoningParserManager
|
|
from fastdeploy.utils import envs
|
|
|
|
|
|
class InputPreprocessor:
|
|
"""
|
|
Args:
|
|
model_config (ModelConfig):
|
|
Model name or path to the pretrained model. If a model name is provided, it should be a
|
|
key in the Hugging Face Transformers' model registry (https://huggingface.co/models).
|
|
The model will be downloaded from the Hugging Face model hub if necessary.
|
|
If a path is provided, the model will be loaded from that path.
|
|
reasoning_parser (str, optional):
|
|
Reasoning parser type. Defaults to None.
|
|
Flag specifies the reasoning parser to use for extracting reasoning content from the model output
|
|
|
|
Raises:
|
|
ValueError:
|
|
If the model name is not found in the Hugging Face Transformers' model registry and the path does not
|
|
exist.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
model_config: ModelConfig,
|
|
reasoning_parser: str = None,
|
|
limit_mm_per_prompt: Optional[Dict[str, Any]] = None,
|
|
mm_processor_kwargs: Optional[Dict[str, Any]] = None,
|
|
tool_parser: str = None,
|
|
enable_processor_cache: bool = False,
|
|
) -> None:
|
|
self.model_config = model_config
|
|
self.model_name_or_path = self.model_config.model
|
|
self.reasoning_parser = reasoning_parser
|
|
self.limit_mm_per_prompt = limit_mm_per_prompt
|
|
self.mm_processor_kwargs = mm_processor_kwargs
|
|
self.tool_parser = tool_parser
|
|
self.enable_processor_cache = enable_processor_cache
|
|
|
|
def create_processor(self):
|
|
reasoning_parser_obj = None
|
|
tool_parser_obj = None
|
|
|
|
if self.reasoning_parser:
|
|
reasoning_parser_obj = ReasoningParserManager.get_reasoning_parser(self.reasoning_parser)
|
|
if self.tool_parser:
|
|
tool_parser_obj = ToolParserManager.get_tool_parser(self.tool_parser)
|
|
|
|
architecture = self.model_config.architectures[0]
|
|
|
|
try:
|
|
from fastdeploy.plugins.input_processor import load_input_processor_plugins
|
|
|
|
Processor = load_input_processor_plugins()
|
|
self.processor = Processor(
|
|
model_name_or_path=self.model_name_or_path,
|
|
reasoning_parser_obj=reasoning_parser_obj,
|
|
tool_parser_obj=tool_parser_obj,
|
|
)
|
|
except:
|
|
if not self.model_config.enable_mm:
|
|
if not ErnieArchitectures.contains_ernie_arch(architecture):
|
|
if not envs.ENABLE_V1_DATA_PROCESSOR:
|
|
from fastdeploy.input.text_processor import DataProcessor
|
|
else:
|
|
from fastdeploy.input.v1.text_processor import DataProcessor
|
|
|
|
self.processor = DataProcessor(
|
|
model_name_or_path=self.model_name_or_path,
|
|
reasoning_parser_obj=reasoning_parser_obj,
|
|
tool_parser_obj=tool_parser_obj,
|
|
)
|
|
else:
|
|
if not envs.ENABLE_V1_DATA_PROCESSOR:
|
|
from fastdeploy.input.ernie4_5_processor import (
|
|
Ernie4_5Processor,
|
|
)
|
|
else:
|
|
from fastdeploy.input.v1.ernie4_5_processor import (
|
|
Ernie4_5Processor,
|
|
)
|
|
|
|
self.processor = Ernie4_5Processor(
|
|
model_name_or_path=self.model_name_or_path,
|
|
reasoning_parser_obj=reasoning_parser_obj,
|
|
tool_parser_obj=tool_parser_obj,
|
|
)
|
|
else:
|
|
if ErnieArchitectures.contains_ernie_arch(architecture):
|
|
if not envs.ENABLE_V1_DATA_PROCESSOR:
|
|
from fastdeploy.input.ernie4_5_vl_processor import (
|
|
Ernie4_5_VLProcessor,
|
|
)
|
|
else:
|
|
from fastdeploy.input.v1.ernie4_5_vl_processor import (
|
|
Ernie4_5_VLProcessor,
|
|
)
|
|
|
|
self.processor = Ernie4_5_VLProcessor(
|
|
model_name_or_path=self.model_name_or_path,
|
|
limit_mm_per_prompt=self.limit_mm_per_prompt,
|
|
mm_processor_kwargs=self.mm_processor_kwargs,
|
|
reasoning_parser_obj=reasoning_parser_obj,
|
|
tool_parser_obj=tool_parser_obj,
|
|
enable_processor_cache=self.enable_processor_cache,
|
|
)
|
|
elif "PaddleOCRVL" in architecture:
|
|
if not envs.ENABLE_V1_DATA_PROCESSOR:
|
|
from fastdeploy.input.paddleocr_vl_processor import (
|
|
PaddleOCRVLProcessor,
|
|
)
|
|
else:
|
|
from fastdeploy.input.v1.paddleocr_vl_processor import (
|
|
PaddleOCRVLProcessor,
|
|
)
|
|
|
|
self.processor = PaddleOCRVLProcessor(
|
|
config=self.model_config,
|
|
model_name_or_path=self.model_name_or_path,
|
|
limit_mm_per_prompt=self.limit_mm_per_prompt,
|
|
mm_processor_kwargs=self.mm_processor_kwargs,
|
|
reasoning_parser_obj=reasoning_parser_obj,
|
|
)
|
|
elif "Qwen2_5_VL" in architecture:
|
|
if not envs.ENABLE_V1_DATA_PROCESSOR:
|
|
from fastdeploy.input.qwen_vl_processor import QwenVLProcessor
|
|
else:
|
|
from fastdeploy.input.v1.qwen_vl_processor import (
|
|
QwenVLProcessor,
|
|
)
|
|
|
|
self.processor = QwenVLProcessor(
|
|
config=self.model_config,
|
|
model_name_or_path=self.model_name_or_path,
|
|
limit_mm_per_prompt=self.limit_mm_per_prompt,
|
|
mm_processor_kwargs=self.mm_processor_kwargs,
|
|
reasoning_parser_obj=reasoning_parser_obj,
|
|
enable_processor_cache=self.enable_processor_cache,
|
|
)
|
|
elif "Qwen3VL" in architecture:
|
|
if not envs.ENABLE_V1_DATA_PROCESSOR:
|
|
from fastdeploy.input.qwen3_vl_processor import Qwen3VLProcessor
|
|
else:
|
|
from fastdeploy.input.v1.qwen3_vl_processor import (
|
|
Qwen3VLProcessor,
|
|
)
|
|
|
|
self.processor = Qwen3VLProcessor(
|
|
config=self.model_config,
|
|
model_name_or_path=self.model_name_or_path,
|
|
limit_mm_per_prompt=self.limit_mm_per_prompt,
|
|
mm_processor_kwargs=self.mm_processor_kwargs,
|
|
reasoning_parser_obj=reasoning_parser_obj,
|
|
enable_processor_cache=self.enable_processor_cache,
|
|
)
|
|
else:
|
|
raise ValueError(f"Unsupported model processor architecture: {architecture}. ")
|
|
|
|
return self.processor
|