Skip to content

Commit c1919ff

Browse files
hchingsjoyang-nv
authored andcommitted
fix reasoning parsing
Signed-off-by: Erin Ho <14718778+hchings@users.noreply.github.com>
1 parent c8ba9b4 commit c1919ff

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

nemo_rl/models/generation/trtllm/trtllm_http_server.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434
logger = logging.getLogger(__name__)
3535

3636

37+
def _build_reasoning_parser(
38+
name: str, chat_template_kwargs: dict[str, Any]
39+
) -> Any:
40+
from tensorrt_llm.llmapi.reasoning_parser import ReasoningParserFactory
41+
42+
if name == "deepseek-r1" and "enable_thinking" in chat_template_kwargs:
43+
from tensorrt_llm.llmapi.reasoning_parser import DeepSeekR1Parser
44+
45+
return DeepSeekR1Parser(
46+
reasoning_at_start=bool(chat_template_kwargs["enable_thinking"]),
47+
chat_template_kwargs=chat_template_kwargs,
48+
)
49+
50+
return ReasoningParserFactory.create_reasoning_parser(
51+
name, chat_template_kwargs
52+
)
53+
54+
3755
def create_app(
3856
llm: Any,
3957
tokenizer: Any,
@@ -69,13 +87,7 @@ def create_app(
6987
)
7088

7189
if reasoning_parser is not None:
72-
from tensorrt_llm.llmapi.reasoning_parser import ReasoningParserFactory
73-
74-
# Validate the configured parser when the server starts. A fresh parser is
75-
# created per request below with that request's chat-template arguments.
76-
ReasoningParserFactory.create_reasoning_parser(
77-
reasoning_parser, _server_template_kwargs
78-
)
90+
_build_reasoning_parser(reasoning_parser, _server_template_kwargs)
7991

8092
# Match TRT-LLM's effective EOS set so this adapter can trim every returned
8193
# stop token and its logprob together, preserving multi-turn continuity.
@@ -125,9 +137,7 @@ async def chat_completions(request: Request):
125137
effective_template_kwargs = {**_server_template_kwargs, **per_request_kwargs}
126138

127139
_active_reasoning_parser = (
128-
ReasoningParserFactory.create_reasoning_parser(
129-
reasoning_parser, effective_template_kwargs
130-
)
140+
_build_reasoning_parser(reasoning_parser, effective_template_kwargs)
131141
if reasoning_parser is not None
132142
else None
133143
)

0 commit comments

Comments
 (0)