Unverified Commit 295964e3 authored by nachiketb-nvidia's avatar nachiketb-nvidia Committed by GitHub
Browse files

chore: add more reasoning and tool call parsers explicitly, remove unecessary files (#2785)


Signed-off-by: default avatarnachiketb <nachiketb@nvidia.com>
parent a1ca39a9
......@@ -29,6 +29,18 @@ DYNAMO_ARGS: Dict[str, Dict[str, Any]] = {
"default": 0,
"help": "Maximum number of times a request may be migrated to a different engine worker",
},
"tool-call-parser": {
"flags": ["--dyn-tool-call-parser"],
"type": str,
"default": None,
"help": "Tool call parser name for the model. Available options: 'hermes', 'nemotron_deci', 'llama3_json', 'mistral', 'phi4', 'pythonic'.",
},
"reasoning-parser": {
"flags": ["--dyn-reasoning-parser"],
"type": str,
"default": None,
"help": "Reasoning parser name for the model. Available options: 'basic', 'deepseek_r1', 'gpt_oss', 'kimi', 'step3', 'qwen3', 'nemotron_deci', 'mistral'.",
},
}
......@@ -75,20 +87,6 @@ def parse_args(args: list[str]) -> Config:
"--version", action="version", version=f"Dynamo Backend SGLang {__version__}"
)
# To avoid name conflicts with different backends, adoped prefix "dyn-" for dynamo specific args
parser.add_argument(
"--dyn-tool-call-parser",
type=str,
default=None,
help="Tool call parser name for the model. Available options: 'hermes', 'nemotron_deci', 'llama3_json', 'mistral', 'phi4'.",
)
parser.add_argument(
"--dyn-reasoning-parser",
type=str,
default=None,
help="Reasoning parser name for the model. Available options: 'basic', 'deepseek_r1', 'gpt_oss'.",
)
# Dynamo args
for info in DYNAMO_ARGS.values():
parser.add_argument(
......
......@@ -274,13 +274,13 @@ def cmd_line_args():
"--dyn-tool-call-parser",
type=str,
default=None,
help="Tool call parser name for the model. Available options: 'hermes', 'nemotron_deci', 'llama3_json', 'mistral', 'phi4'.",
help="Tool call parser name for the model. Available options: 'hermes', 'nemotron_deci', 'llama3_json', 'mistral', 'phi4', 'pythonic'.",
)
parser.add_argument(
"--dyn-reasoning-parser",
type=str,
default=None,
help="Reasoning parser name for the model. Available options: 'basic', 'deepseek_r1', 'gpt_oss'.",
help="Reasoning parser name for the model. Available options: 'basic', 'deepseek_r1', 'gpt_oss', 'kimi', 'step3', 'qwen3', 'nemotron_deci', 'mistral'.",
)
args = parser.parse_args()
......
......@@ -111,13 +111,13 @@ def parse_args() -> Config:
"--dyn-tool-call-parser",
type=str,
default=None,
help="Tool call parser name for the model. Available options: 'hermes', 'nemotron_deci', 'llama3_json', 'mistral', 'phi4'.",
help="Tool call parser name for the model. Available options: 'hermes', 'nemotron_deci', 'llama3_json', 'mistral', 'phi4', 'pythonic'.",
)
parser.add_argument(
"--dyn-reasoning-parser",
type=str,
default=None,
help="Reasoning parser name for the model. Available options: 'basic', 'deepseek_r1', 'gpt_oss'.",
help="Reasoning parser name for the model. Available options: 'basic', 'deepseek_r1', 'gpt_oss', 'kimi', 'step3', 'qwen3', 'nemotron_deci', 'mistral'.",
)
parser = AsyncEngineArgs.add_cli_args(parser)
......
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
use super::base_parser::BasicReasoningParser;
use crate::ParserResult;
use crate::ReasoningParser;
#[derive(Default, Debug, Clone)]
pub struct DeepseekR1ReasoningParser {
base: BasicReasoningParser,
}
impl DeepseekR1ReasoningParser {
pub fn new() -> Self {
Self {
base: BasicReasoningParser::new(
"<think>".to_string(),
"</think>".to_string(),
true,
true,
),
}
}
}
impl ReasoningParser for DeepseekR1ReasoningParser {
fn parse_reasoning_streaming_incremental(
&mut self,
text: &str,
token_ids: &[u32],
) -> ParserResult {
self.base
.parse_reasoning_streaming_incremental(text, token_ids)
}
fn detect_and_parse_reasoning(&mut self, text: &str, token_ids: &[u32]) -> ParserResult {
self.base.detect_and_parse_reasoning(text, token_ids)
}
}
......@@ -2,12 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
mod base_parser;
mod deepseek_r1_parser;
mod gpt_oss_parser;
// Re-export main types and functions for convenience
pub use base_parser::BasicReasoningParser;
pub use deepseek_r1_parser::DeepseekR1ReasoningParser;
pub use gpt_oss_parser::GptOssReasoningParser;
#[derive(Debug, Clone, Default)]
......@@ -57,8 +55,13 @@ pub trait ReasoningParser: Send + std::fmt::Debug {
#[non_exhaustive]
pub enum ReasoningParserType {
DeepseekR1,
Step3,
Basic,
GptOss,
Qwen,
NemotronDeci,
Kimi,
Mistral,
}
#[derive(std::fmt::Debug)]
......@@ -83,18 +86,42 @@ impl ReasoningParser for ReasoningParserWrapper {
impl ReasoningParserType {
pub fn get_reasoning_parser(self) -> ReasoningParserWrapper {
let basic_parser =
BasicReasoningParser::new("<think>".into(), "</think>".into(), false, true);
let force_reasoning_basic_parser =
BasicReasoningParser::new("<think>".into(), "</think>".into(), true, true);
match self {
ReasoningParserType::DeepseekR1 => ReasoningParserWrapper {
parser: Box::new(DeepseekR1ReasoningParser::new()),
parser: Box::new(force_reasoning_basic_parser),
},
ReasoningParserType::Step3 => ReasoningParserWrapper {
parser: Box::new(force_reasoning_basic_parser),
},
ReasoningParserType::Basic => ReasoningParserWrapper {
parser: Box::new(basic_parser),
},
ReasoningParserType::Qwen => ReasoningParserWrapper {
parser: Box::new(basic_parser),
},
ReasoningParserType::NemotronDeci => ReasoningParserWrapper {
parser: Box::new(basic_parser),
},
ReasoningParserType::Kimi => ReasoningParserWrapper {
parser: Box::new(BasicReasoningParser::new(
"<think>".into(),
"</think>".into(),
"think".into(),
"/think".into(),
false,
true,
)),
},
ReasoningParserType::Mistral => ReasoningParserWrapper {
parser: Box::new(BasicReasoningParser::new(
"[THINK]".into(),
"[/THINK]".into(),
true,
true,
)),
},
ReasoningParserType::GptOss => match GptOssReasoningParser::new() {
Ok(parser) => ReasoningParserWrapper {
parser: Box::new(parser),
......@@ -122,6 +149,11 @@ impl ReasoningParserType {
"deepseek_r1" => Self::DeepseekR1.get_reasoning_parser(),
"basic" => Self::Basic.get_reasoning_parser(),
"gpt_oss" => Self::GptOss.get_reasoning_parser(),
"qwen3" => Self::Qwen.get_reasoning_parser(),
"nemotron_deci" => Self::NemotronDeci.get_reasoning_parser(),
"kimi" => Self::Kimi.get_reasoning_parser(),
"step3" => Self::Step3.get_reasoning_parser(),
"mistral" => Self::Mistral.get_reasoning_parser(),
_ => {
tracing::warn!(
"Unknown reasoning parser type '{}', falling back to Basic Reasoning Parser",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment