Replaces cherry-picked upstream_ref with complete source trees. xllm/ — Iluvatar official C++ inference engine (15MB, 1470 files) Complete: kernels → layers → models → runtime → scheduler → api Excluded: .git, binary images, third_party submodule checkouts ds_vllm/ — Iluvatar official vllm fork (8MB, 703 files) Included: csrc/ (ALL CUDA kernels), fused_moe/, qwen3_5 model, _custom_ops Excluded: tests, benchmarks, docs, examples (not needed for reference) Critical call chains now fully traceable: MoE: moe_topk_softmax_kernels.cuh → ixformer.h → fused_moe.cpp → layer GDN: qwen3_gated_delta_net_base.cpp → qwen3_5_gated_delta_net.cpp Attention: ixformer.h → xllm_paged_attention → attention.cpp
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
|
Copyright 2024 The ScaleLLM Authors. All Rights Reserved.
|
|
|
|
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
|
|
|
|
https://github.com/jd-opensource/xllm/blob/main/LICENSE
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
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.
|
|
==============================================================================*/
|
|
|
|
#include "xllm/parser/reasoning_parser.h"
|
|
|
|
#include <glog/logging.h>
|
|
|
|
namespace xllm {
|
|
|
|
ReasoningParser::ReasoningParser(const std::string& model_type,
|
|
bool stream_reasoning,
|
|
bool force_reasoning) {
|
|
detector_ = DetectorRegistry::get_instance().get_detector(
|
|
model_type, stream_reasoning, force_reasoning);
|
|
}
|
|
|
|
ReasoningResult ReasoningParser::parse_non_stream(const std::string& text) {
|
|
return detector_->detect_and_parse(const_cast<std::string&>(text));
|
|
}
|
|
|
|
ReasoningResult ReasoningParser::parse_stream_chunk(
|
|
const std::string& chunk_text) {
|
|
return detector_->parse_streaming_increment(
|
|
const_cast<std::string&>(chunk_text));
|
|
}
|
|
|
|
std::string ReasoningParser::get_parser_auto(const std::string& parser,
|
|
const std::string& model_type) {
|
|
if (parser.empty()) {
|
|
return "";
|
|
}
|
|
auto& registry = DetectorRegistry::get_instance();
|
|
if (parser == "auto") {
|
|
// find the reasoning parser that supports the model type
|
|
std::string parser_name =
|
|
registry.get_parser_name_by_model_type(model_type);
|
|
LOG(INFO) << "Using reasoning parser: " << parser_name
|
|
<< " for model type: " << model_type;
|
|
return parser_name;
|
|
} else {
|
|
// check if the reasoning parser is supported
|
|
if (registry.has_detector(parser)) {
|
|
return parser;
|
|
}
|
|
LOG(FATAL) << "Unsupported reasoning parser: " << parser
|
|
<< ". Supported parsers are: "
|
|
<< registry.get_supported_parsers();
|
|
return "";
|
|
}
|
|
}
|
|
|
|
} // namespace xllm
|