MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / InputPreprocessor

Class InputPreprocessor

fastdeploy/input/preprocess.py:25–180  ·  view source on GitHub ↗

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 hu

Source from the content-addressed store, hash-verified

23
24
25class InputPreprocessor:
26 """
27 Args:
28 model_config (ModelConfig):
29 Model name or path to the pretrained model. If a model name is provided, it should be a
30 key in the Hugging Face Transformers' model registry (https://huggingface.co/models).
31 The model will be downloaded from the Hugging Face model hub if necessary.
32 If a path is provided, the model will be loaded from that path.
33 reasoning_parser (str, optional):
34 Reasoning parser type. Defaults to None.
35 Flag specifies the reasoning parser to use for extracting reasoning content from the model output
36
37 Raises:
38 ValueError:
39 If the model name is not found in the Hugging Face Transformers' model registry and the path does not
40 exist.
41 """
42
43 def __init__(
44 self,
45 model_config: ModelConfig,
46 reasoning_parser: str = None,
47 limit_mm_per_prompt: Optional[Dict[str, Any]] = None,
48 mm_processor_kwargs: Optional[Dict[str, Any]] = None,
49 tool_parser: str = None,
50 enable_processor_cache: bool = False,
51 ) -> None:
52 self.model_config = model_config
53 self.model_name_or_path = self.model_config.model
54 self.reasoning_parser = reasoning_parser
55 self.limit_mm_per_prompt = limit_mm_per_prompt
56 self.mm_processor_kwargs = mm_processor_kwargs
57 self.tool_parser = tool_parser
58 self.enable_processor_cache = enable_processor_cache
59
60 def create_processor(self):
61 reasoning_parser_obj = None
62 tool_parser_obj = None
63
64 if self.reasoning_parser:
65 reasoning_parser_obj = ReasoningParserManager.get_reasoning_parser(self.reasoning_parser)
66 if self.tool_parser:
67 tool_parser_obj = ToolParserManager.get_tool_parser(self.tool_parser)
68
69 architecture = self.model_config.architectures[0]
70
71 try:
72 from fastdeploy.plugins.input_processor import load_input_processor_plugins
73
74 Processor = load_input_processor_plugins()
75 self.processor = Processor(
76 model_name_or_path=self.model_name_or_path,
77 reasoning_parser_obj=reasoning_parser_obj,
78 tool_parser_obj=tool_parser_obj,
79 mm_processor_kwargs=self.mm_processor_kwargs,
80 )
81 except:
82 if not self.model_config.enable_mm:

Callers 4

create_data_processorMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected