diff --git a/fastdeploy/input/preprocess.py b/fastdeploy/input/preprocess.py index 16615599b..5b8eb3ccd 100644 --- a/fastdeploy/input/preprocess.py +++ b/fastdeploy/input/preprocess.py @@ -71,17 +71,9 @@ class InputPreprocessor: """ reasoning_parser_obj = None tool_parser_obj = None - try: - from fastdeploy.plugins.reasoning_parser import ( - load_reasoning_parser_plugins, - ) - custom_reasoning_parser = load_reasoning_parser_plugins() - if self.reasoning_parser == "custom_reasoning_parser": - reasoning_parser_obj = custom_reasoning_parser - except: - if self.reasoning_parser: - reasoning_parser_obj = ReasoningParserManager.get_reasoning_parser(self.reasoning_parser) + 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) diff --git a/fastdeploy/plugins/input_processor/__init__.py b/fastdeploy/plugins/input_processor/__init__.py index d7c698f44..eca894f42 100644 --- a/fastdeploy/plugins/input_processor/__init__.py +++ b/fastdeploy/plugins/input_processor/__init__.py @@ -23,5 +23,5 @@ PLUGINS_GROUP = "fastdeploy.input_processor_plugins" def load_input_processor_plugins(): """load_input_processor_plugins""" plugins = load_plugins_by_group(group=PLUGINS_GROUP) - assert len(plugins) <= 1, "Most one plugin is allowed to be loaded." + assert len(plugins) == 1, "Only one plugin is allowed to be loaded." return next(iter(plugins.values()))() diff --git a/fastdeploy/plugins/model_runner/__init__.py b/fastdeploy/plugins/model_runner/__init__.py index 8897abfbc..19ce33ce8 100644 --- a/fastdeploy/plugins/model_runner/__init__.py +++ b/fastdeploy/plugins/model_runner/__init__.py @@ -14,7 +14,7 @@ # limitations under the License. """ -from fastdeploy.plugins.utils import load_plugins_by_group, plugins_loaded +from fastdeploy.plugins.utils import load_plugins_by_group # use for modle runner PLUGINS_GROUP = "fastdeploy.model_runner_plugins" @@ -22,11 +22,6 @@ PLUGINS_GROUP = "fastdeploy.model_runner_plugins" def load_model_runner_plugins(): """load_model_runner_plugins""" - global plugins_loaded - if plugins_loaded: - return - plugins_loaded = True - plugins = load_plugins_by_group(group=PLUGINS_GROUP) - assert len(plugins) <= 1, "Most one plugin is allowed to be loaded." + assert len(plugins) == 1, "Only one plugin is allowed to be loaded." return next(iter(plugins.values()))() diff --git a/fastdeploy/plugins/reasoning_parser/__init__.py b/fastdeploy/plugins/reasoning_parser/__init__.py index bb19e0e70..ba862d02a 100644 --- a/fastdeploy/plugins/reasoning_parser/__init__.py +++ b/fastdeploy/plugins/reasoning_parser/__init__.py @@ -14,7 +14,7 @@ # limitations under the License. """ -from fastdeploy.plugins.utils import load_plugins_by_group +from fastdeploy.plugins.utils import load_plugins_by_group, plugins_loaded # make sure one process only loads plugins once PLUGINS_GROUP = "fastdeploy.reasoning_parser_plugins" @@ -22,6 +22,12 @@ PLUGINS_GROUP = "fastdeploy.reasoning_parser_plugins" def load_reasoning_parser_plugins(): """load_reasoning_parser_plugins""" + global plugins_loaded + if plugins_loaded: + return + plugins_loaded = True + plugins = load_plugins_by_group(group=PLUGINS_GROUP) - assert len(plugins) <= 1, "Most one plugin is allowed to be loaded." - return next(iter(plugins.values()))() + # general plugins, we only need to execute the loaded functions + for func in plugins.values(): + func() diff --git a/fastdeploy/reasoning/__init__.py b/fastdeploy/reasoning/__init__.py index 51f59776e..49c627895 100644 --- a/fastdeploy/reasoning/__init__.py +++ b/fastdeploy/reasoning/__init__.py @@ -14,6 +14,8 @@ # limitations under the License. """ +from fastdeploy.plugins import load_reasoning_parser_plugins + from .abs_reasoning_parsers import ReasoningParser, ReasoningParserManager from .ernie_vl_reasoning_parsers import ErnieVLReasoningParser from .ernie_x1_reasoning_parsers import ErnieX1ReasoningParser @@ -26,3 +28,5 @@ __all__ = [ "Qwen3ReasoningParser", "ErnieX1ReasoningParser", ] + +load_reasoning_parser_plugins() diff --git a/fastdeploy/reasoning/ernie_x1_reasoning_parsers.py b/fastdeploy/reasoning/ernie_x1_reasoning_parsers.py index c75182b01..68e8fef4d 100644 --- a/fastdeploy/reasoning/ernie_x1_reasoning_parsers.py +++ b/fastdeploy/reasoning/ernie_x1_reasoning_parsers.py @@ -1,14 +1,5 @@ +""" # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. -# -# -from collections.abc import Sequence -from typing import Tuple, Union - -from fastdeploy.entrypoints.openai.protocol import ChatCompletionRequest, DeltaMessage -from fastdeploy.reasoning import ReasoningParser, ReasoningParserManager - -# -# # 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 @@ -20,6 +11,13 @@ from fastdeploy.reasoning import ReasoningParser, ReasoningParserManager # 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 collections.abc import Sequence +from typing import Tuple, Union + +from fastdeploy.entrypoints.openai.protocol import ChatCompletionRequest, DeltaMessage +from fastdeploy.reasoning import ReasoningParser, ReasoningParserManager @ReasoningParserManager.register_module("ernie_x1")