Skip to content

Commit d381fa8

Browse files
authored
fix reasoning parsers plugin (#4104)
1 parent d2ab369 commit d381fa8

File tree

6 files changed

+26
-31
lines changed

6 files changed

+26
-31
lines changed

fastdeploy/input/preprocess.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,9 @@ def create_processor(self):
7171
"""
7272
reasoning_parser_obj = None
7373
tool_parser_obj = None
74-
try:
75-
from fastdeploy.plugins.reasoning_parser import (
76-
load_reasoning_parser_plugins,
77-
)
7874

79-
custom_reasoning_parser = load_reasoning_parser_plugins()
80-
if self.reasoning_parser == "custom_reasoning_parser":
81-
reasoning_parser_obj = custom_reasoning_parser
82-
except:
83-
if self.reasoning_parser:
84-
reasoning_parser_obj = ReasoningParserManager.get_reasoning_parser(self.reasoning_parser)
75+
if self.reasoning_parser:
76+
reasoning_parser_obj = ReasoningParserManager.get_reasoning_parser(self.reasoning_parser)
8577
if self.tool_parser:
8678
tool_parser_obj = ToolParserManager.get_tool_parser(self.tool_parser)
8779

fastdeploy/plugins/input_processor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
def load_input_processor_plugins():
2424
"""load_input_processor_plugins"""
2525
plugins = load_plugins_by_group(group=PLUGINS_GROUP)
26-
assert len(plugins) <= 1, "Most one plugin is allowed to be loaded."
26+
assert len(plugins) == 1, "Only one plugin is allowed to be loaded."
2727
return next(iter(plugins.values()))()

fastdeploy/plugins/model_runner/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,14 @@
1414
# limitations under the License.
1515
"""
1616

17-
from fastdeploy.plugins.utils import load_plugins_by_group, plugins_loaded
17+
from fastdeploy.plugins.utils import load_plugins_by_group
1818

1919
# use for modle runner
2020
PLUGINS_GROUP = "fastdeploy.model_runner_plugins"
2121

2222

2323
def load_model_runner_plugins():
2424
"""load_model_runner_plugins"""
25-
global plugins_loaded
26-
if plugins_loaded:
27-
return
28-
plugins_loaded = True
29-
3025
plugins = load_plugins_by_group(group=PLUGINS_GROUP)
31-
assert len(plugins) <= 1, "Most one plugin is allowed to be loaded."
26+
assert len(plugins) == 1, "Only one plugin is allowed to be loaded."
3227
return next(iter(plugins.values()))()

fastdeploy/plugins/reasoning_parser/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@
1414
# limitations under the License.
1515
"""
1616

17-
from fastdeploy.plugins.utils import load_plugins_by_group
17+
from fastdeploy.plugins.utils import load_plugins_by_group, plugins_loaded
1818

1919
# make sure one process only loads plugins once
2020
PLUGINS_GROUP = "fastdeploy.reasoning_parser_plugins"
2121

2222

2323
def load_reasoning_parser_plugins():
2424
"""load_reasoning_parser_plugins"""
25+
global plugins_loaded
26+
if plugins_loaded:
27+
return
28+
plugins_loaded = True
29+
2530
plugins = load_plugins_by_group(group=PLUGINS_GROUP)
26-
assert len(plugins) <= 1, "Most one plugin is allowed to be loaded."
27-
return next(iter(plugins.values()))()
31+
# general plugins, we only need to execute the loaded functions
32+
for func in plugins.values():
33+
func()

fastdeploy/reasoning/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
"""
1616

17+
from fastdeploy.plugins import load_reasoning_parser_plugins
18+
1719
from .abs_reasoning_parsers import ReasoningParser, ReasoningParserManager
1820
from .ernie_vl_reasoning_parsers import ErnieVLReasoningParser
1921
from .ernie_x1_reasoning_parsers import ErnieX1ReasoningParser
@@ -26,3 +28,5 @@
2628
"Qwen3ReasoningParser",
2729
"ErnieX1ReasoningParser",
2830
]
31+
32+
load_reasoning_parser_plugins()

fastdeploy/reasoning/ernie_x1_reasoning_parsers.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1+
"""
12
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
2-
#
3-
#
4-
from collections.abc import Sequence
5-
from typing import Tuple, Union
6-
7-
from fastdeploy.entrypoints.openai.protocol import ChatCompletionRequest, DeltaMessage
8-
from fastdeploy.reasoning import ReasoningParser, ReasoningParserManager
9-
10-
#
11-
#
123
# Licensed under the Apache License, Version 2.0 (the "License"
134
# you may not use this file except in compliance with the License.
145
# You may obtain a copy of the License at
@@ -20,6 +11,13 @@
2011
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2112
# See the License for the specific language governing permissions and
2213
# limitations under the License.
14+
"""
15+
16+
from collections.abc import Sequence
17+
from typing import Tuple, Union
18+
19+
from fastdeploy.entrypoints.openai.protocol import ChatCompletionRequest, DeltaMessage
20+
from fastdeploy.reasoning import ReasoningParser, ReasoningParserManager
2321

2422

2523
@ReasoningParserManager.register_module("ernie_x1")

0 commit comments

Comments
 (0)