Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demos/common/export_models/export_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def add_common_arguments(parser):
parser_text.add_argument('--max_prompt_len', required=False, type=int, default=None, help='Sets NPU specific property for maximum number of tokens in the prompt. '
'Not effective if target device is not NPU', dest='max_prompt_len')
parser_text.add_argument('--prompt_lookup_decoding', action='store_true', help='Set pipeline to use prompt lookup decoding', dest='prompt_lookup_decoding')
parser_text.add_argument('--reasoning_parser', choices=["qwen3", "gptoss"], help='Set the type of the reasoning parser for reasoning content extraction', dest='reasoning_parser')
parser_text.add_argument('--tool_parser', choices=["llama3", "phi4", "hermes3", "mistral", "qwen3coder", "gptoss", "devstral", "lfm2"], help='Set the type of the tool parser for tool calls extraction', dest='tool_parser')
parser_text.add_argument('--reasoning_parser', choices=["qwen3", "gptoss", "lfm2.5", "gemma4"], help='Set the type of the reasoning parser for reasoning content extraction', dest='reasoning_parser')
parser_text.add_argument('--tool_parser', choices=["llama3", "phi4", "hermes3", "mistral", "qwen3coder", "gptoss", "devstral", "lfm2", "lfm2.5", "gemma4"], help='Set the type of the tool parser for tool calls extraction', dest='tool_parser')
parser_text.add_argument('--enable_tool_guided_generation', action='store_true', help='Enables enforcing tool schema during generation. Requires setting tool_parser', dest='enable_tool_guided_generation')

parser_embeddings_ov = subparsers.add_parser('embeddings_ov', help='export model for embeddings endpoint with directory structure aligned with OpenVINO tools')
Expand Down
6 changes: 6 additions & 0 deletions docs/llm/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,15 @@ __Tool parsers:__
- `devstral`
- `gptoss`
- `qwen3coder`
- `lfm2`
- `lfm2.5`
- `gemma4`

__Reasoning parsers:__
- `qwen3`
- `gptoss`
- `lfm2.5`
- `gemma4`

Note that using `tools` might require a chat template other than the original.
We recommend using templates from the [vLLM repository](https://github.com/vllm-project/vllm/tree/main/examples) for `hermes3`, `llama3`, `phi4`, `mistral`, `devstral`, `gptoss`, and `qwen3coder` models (if available). Save the selected template as `chat_template.jinja` in the model directory and it will be used instead of the default one. If a template is not available for your model, please refer to the model's documentation or use the default template provided by the model server.
Expand Down
4 changes: 2 additions & 2 deletions docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ Task specific parameters for different tasks (text generation/image generation/e
| `--max_prompt_len` | `integer` | Sets NPU specific property for maximum number of tokens in the prompt. |
| `--kv_cache_precision` | `string` | Reduced kv cache precision to `u8` lowers the cache size consumption. Accepted values: `u8` or empty (default). |
| `--model_distribution_policy` | `string` | TENSOR_PARALLEL distributes tensor to multiple sockets/devices and processes it in parallel. PIPELINE_PARALLEL distributes different tensors to process by each device. Accepted values: `TENSOR_PARALLEL`, `PIPELINE_PARALLEL` or empty (default). |
| `--reasoning_parser` | `string` | Type of parser to use for reasoning content extraction from model output. Currently supported: [qwen3, gptoss, gemma4] |
| `--tool_parser` | `string` | Type of parser to use for tool calls extraction from model output. Currently supported: [llama3, phi4, hermes3, mistral, qwen3coder, gptoss, devstral, lfm2, gemma4] |
| `--reasoning_parser` | `string` | Type of parser to use for reasoning content extraction from model output. Currently supported: [qwen3, gptoss, lfm2.5, gemma4] |
| `--tool_parser` | `string` | Type of parser to use for tool calls extraction from model output. Currently supported: [llama3, phi4, hermes3, mistral, qwen3coder, gptoss, devstral, lfm2, lfm2.5, gemma4] |
| `--enable_tool_guided_generation` | `bool` | Enables enforcing tool schema during generation. Requires setting response parser. Default: false. |

### Image generation
Expand Down
11 changes: 11 additions & 0 deletions prepare_llm_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ MISTRAL_MODEL="mistralai/Mistral-7B-Instruct-v0.3"
GPT_OSS_MODEL="openai/gpt-oss-20b"
DEVSTRAL_MODEL="unsloth/Devstral-Small-2507"
LFM2_MODEL="LiquidAI/LFM2-2.6B"
LFM25_MODEL="LiquidAI/LFM2.5-8B-A1B"
GEMMA4_MODEL="OpenVINO/gemma-4-E4B-it-int4-ov"

if [ "$(python3 -c 'import sys; print(sys.version_info[1])')" -le "8" ]; then echo "Prepare models with python > 3.8."; exit 1 ; fi
Expand Down Expand Up @@ -220,6 +221,16 @@ if [ ! -f "$1/$LFM2_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$LFM2_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$LFM25_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$LFM25_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$LFM25_MODEL
convert_tokenizer $LFM25_MODEL --with_detokenizer -o $1/$LFM25_MODEL
fi
if [ ! -f "$1/$LFM25_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$LFM25_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$GEMMA4_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$GEMMA4_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
Expand Down
1 change: 1 addition & 0 deletions spelling-whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ demos/vlm_npu/README.md:157: mane ==> main, many, maine
demos/vlm_npu/README.md:218: mane ==> main, many, maine
demos/integration_with_OpenWebUI/README.md:423: Buildin ==> Building, Build in
src/test/llm/output_parsers/lfm2_output_parser_test.cpp
src/test/llm/output_parsers/lfm25_output_parser_test.cpp
windows_parse_tests.bat:35: seh ==> she
windows_parse_tests.bat:119: SEH ==> SHE
windows_parse_tests.bat:123: SEH ==> SHE
Expand Down
47 changes: 44 additions & 3 deletions src/llm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ ovms_cc_library(
)

ovms_cc_library(
name = "io_processing_lfm2_tool_parser",
hdrs = ["io_processing/lfm2/lfm2_tool_parser.hpp"],
srcs = ["io_processing/lfm2/lfm2_tool_parser.cpp"],
name = "io_processing_lfm2_utils",
hdrs = ["io_processing/lfm2/lfm2_utils.hpp"],
srcs = ["io_processing/lfm2/lfm2_utils.cpp"],
deps = [
"@com_github_tencent_rapidjson//:rapidjson",
"//src/port:rapidjson_document",
Expand All @@ -203,6 +203,29 @@ ovms_cc_library(
],
visibility = ["//visibility:public"],
)

ovms_cc_library(
name = "io_processing_lfm2_tool_parser",
hdrs = ["io_processing/lfm2/lfm2_tool_parser.hpp"],
srcs = ["io_processing/lfm2/lfm2_tool_parser.cpp"],
deps = [
":io_processing_lfm2_utils",
],
visibility = ["//visibility:public"],
)


ovms_cc_library(
name = "io_processing_lfm25_tool_parser",
hdrs = ["io_processing/lfm2/lfm25_tool_parser.hpp"],
srcs = ["io_processing/lfm2/lfm25_tool_parser.cpp"],
deps = [
":io_processing_lfm2_utils",
"//src:libovmslogging",
],
visibility = ["//visibility:public"],
)

ovms_cc_library(
name = "io_processing_gemma4_tool_parser",
hdrs = ["io_processing/gemma4/gemma4_tool_parser.hpp", "io_processing/gemma4/gemma4_reasoning_parser.hpp"],
Expand Down Expand Up @@ -236,6 +259,22 @@ ovms_cc_library(
visibility = ["//visibility:public"],
)

ovms_cc_library(
name = "io_processing_lfm25_reasoning_parser",
hdrs = ["io_processing/lfm2/lfm25_reasoning_parser.hpp"],
srcs = ["io_processing/lfm2/lfm25_reasoning_parser.cpp"],
deps = [
"@com_github_tencent_rapidjson//:rapidjson",
"//src/port:rapidjson_document",
"//src:libovmslogging",
"//src:libovmsstring_utils",
":io_processing_utils",
":io_processing_base_output_parser",
"//third_party:genai",
],
visibility = ["//visibility:public"],
)

ovms_cc_library( # TODO split further so we don't have to recompile everything when changing one parser ...
name = "output_parsers",
hdrs = [
Expand Down Expand Up @@ -271,8 +310,10 @@ ovms_cc_library( # TODO split further so we don't have to recompile everything w
":io_processing_parser_config_validation",
":io_processing_qwen3coder_tool_parser",
":io_processing_lfm2_tool_parser",
":io_processing_lfm25_tool_parser",
":io_processing_gemma4_tool_parser",
":io_processing_qwen3_reasoning_parser",
":io_processing_lfm25_reasoning_parser",
":io_processing_utils",
":apis_tool_schema_wrapper",
],
Expand Down
69 changes: 69 additions & 0 deletions src/llm/io_processing/lfm2/lfm25_reasoning_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//*****************************************************************************
// Copyright 2026 Intel Corporation
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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 <openvino/genai/tokenizer.hpp>
#include <string>
#include <vector>

#include "src/port/rapidjson_document.hpp"

#include "../../../logging.hpp"
#include "lfm25_reasoning_parser.hpp"
#include "../utils.hpp"

namespace ovms {
void Lfm25ReasoningParser::parse(ParsedOutput& parsedOutput, const std::vector<int64_t>& generatedTokens) {
auto startReasoningIt = std::find(generatedTokens.begin(), generatedTokens.end(), reasoningStartTokenId);
auto endReasoningIt = std::find(generatedTokens.begin(), generatedTokens.end(), reasoningEndTokenId);

if (startReasoningIt == generatedTokens.end() || endReasoningIt == generatedTokens.end() || startReasoningIt >= endReasoningIt) {
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "Lfm25ReasoningParser: Reasoning start or end token not found in the generated tokens, or in wrong order. Start token found: {}, End token found: {}, Start position: {}, End position: {}",
startReasoningIt != generatedTokens.end(), endReasoningIt != generatedTokens.end(), std::distance(generatedTokens.begin(), startReasoningIt), std::distance(generatedTokens.begin(), endReasoningIt));
return;
}

auto startPos = std::distance(generatedTokens.begin(), startReasoningIt);
auto endPos = std::distance(generatedTokens.begin(), endReasoningIt);

std::string reasoningContent = tokenizer.decode(std::vector<int64_t>(startPos + generatedTokens.begin() + 1, endPos + generatedTokens.begin()), ov::genai::skip_special_tokens(true));

parsedOutput.reasoning = reasoningContent;
}

std::optional<rapidjson::Document> Lfm25ReasoningParser::parseChunk(const std::string& chunk, const std::vector<int64_t>& tokens, ov::genai::GenerationFinishReason finishReason) {
if (tokens.empty()) {
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "Received empty tokens for Lfm25ReasoningParser");
return std::nullopt;
}

if (std::find(tokens.begin(), tokens.end(), reasoningStartTokenId) != tokens.end() ||
std::find(tokens.begin(), tokens.end(), reasoningEndTokenId) != tokens.end()) {
return std::nullopt;
} else {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.String("delta");
writer.StartObject();
writer.String("reasoning_content");
writer.String(chunk.c_str());
writer.EndObject();
writer.EndObject();
rapidjson::Document doc;
doc.Parse(buffer.GetString());
return doc;
}
}
} // namespace ovms
54 changes: 54 additions & 0 deletions src/llm/io_processing/lfm2/lfm25_reasoning_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//*****************************************************************************
// Copyright 2026 Intel Corporation
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.
//*****************************************************************************
#pragma once
#include "../base_output_parser.hpp"
#include <vector>
#include <string>

namespace ovms {
class Lfm25ReasoningParser : public BaseOutputParser {
protected:
const std::string parsingStartTag = "<think>";
const std::string parsingEndTag = "</think>";

const int64_t reasoningStartTokenId = 124901; // <think>
const int64_t reasoningEndTokenId = 124902; // </think>

public:
Lfm25ReasoningParser() = delete;
explicit Lfm25ReasoningParser(ov::genai::Tokenizer& tokenizer) :
BaseOutputParser(tokenizer) {}

void parse(ParsedOutput& parsedOutput, const std::vector<int64_t>& generatedTokens) override;
std::optional<rapidjson::Document> parseChunk(const std::string& chunk, const std::vector<int64_t>& tokens, ov::genai::GenerationFinishReason finishReason) override;
const std::vector<std::string>& getParsingStartTags() const override {
static const std::vector<std::string> parsingStartTags{this->parsingStartTag};
return parsingStartTags;
}
const std::vector<std::string>& getSpecialParsingStartTags() const override {
static const std::vector<std::string> specialParsingStartTags{};
return specialParsingStartTags;
}
const std::string& getParsingEndTag() const override {
return parsingEndTag;
}

// It may be removed after changing logic in Lfm2ToolParser to use tokens in streaming instead of chunk content, both tool parser and reasoning parser need to have the same value for this function
bool requiresStreamingWithSpecialTokens() const override {
return true;
}
};
} // namespace ovms
107 changes: 107 additions & 0 deletions src/llm/io_processing/lfm2/lfm25_tool_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//*****************************************************************************
// Copyright 2026 Intel Corporation
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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 "lfm25_tool_parser.hpp"

namespace ovms {

const std::string Lfm25ToolParser::TOOL_CALL_START_TAG = "<|tool_call_start|>";
const std::string Lfm25ToolParser::TOOL_CALL_END_TAG = "<|tool_call_end|>";

const int64_t Lfm25ToolParser::toolCallStartTokenId = 124905; // <|tool_call_start|>
const int64_t Lfm25ToolParser::toolCallEndTokenId = 124906; // <|tool_call_end|>
const int64_t Lfm25ToolParser::reasoningEndTokenId = 124902; // </think>

bool Lfm25ToolParser::parseNewContent() {
switch (this->currentState) {
case State::Content: {
return parseInContentState(this->streamingContent, this->streamingPosition, this->currentState, TOOL_CALL_START_TAG, TOOL_CALL_END_TAG);
}
case State::ToolCallStarted: {
auto wasParsedCorrectly = parseInToolCallState(this->streamingContent, this->toolCall, this->streamingPosition, this->currentState);
if (wasParsedCorrectly) {
this->toolCallIndex++;
}
return wasParsedCorrectly;
}
case State::ToolCallParameters: {
return parseToolCallParametersState(this->streamingContent, this->toolCall, this->streamingPosition, this->currentState);
}
case State::ToolCallEnded: {
return parseInToolCallEndedState(this->streamingContent, this->streamingPosition, this->currentState, TOOL_CALL_END_TAG);
}
case State::AfterToolCall:
break;
}
return false;
}

std::optional<rapidjson::Document> Lfm25ToolParser::parseChunk(const std::string& chunk, const std::vector<int64_t>& /*tokens*/, ov::genai::GenerationFinishReason finishReason) {
if (chunk.empty()) {
return std::nullopt;
}

this->streamingContent += chunk;

if (parseNewContent()) {
if (this->currentState == State::ToolCallParameters) {
return BaseOutputParser::wrapFirstDelta(this->toolCall.name, this->toolCallIndex);
}
if (this->currentState == State::ToolCallEnded) {
return wrapDeltaArgs(this->toolCall.arguments, this->toolCallIndex);
}
if (this->currentState == State::Content) {
size_t contentEnd = this->streamingContent.find(TOOL_CALL_START_TAG, this->streamingPosition);
std::string content;
if (contentEnd != std::string::npos) {
content = this->streamingContent.substr(this->streamingPosition, contentEnd - this->streamingPosition);
} else {
content = this->streamingContent.substr(this->streamingPosition);
}
this->streamingPosition += content.size();
cutEOSFromContent(content);

if (!content.empty()) {
return wrapDeltaContent(content);
}
}
if (this->currentState == State::AfterToolCall) {
this->currentState = State::Content;
}
}

if (finishReason != ov::genai::GenerationFinishReason::NONE) {
if ((this->currentState == State::ToolCallParameters || this->currentState == State::ToolCallEnded) && !this->toolCall.arguments.empty()) {
return wrapDeltaArgs(this->toolCall.arguments, this->toolCallIndex);
}

if (this->currentState == State::Content && this->streamingPosition < this->streamingContent.size()) {
auto content = this->streamingContent.substr(this->streamingPosition);
this->streamingPosition += content.size();
cutEOSFromContent(content);

if (!content.empty()) {
return wrapDeltaContent(content);
}
}
}

return std::nullopt;
}

void Lfm25ToolParser::parse(ParsedOutput& parsedOutput, const std::vector<int64_t>& generatedTokens) {
parseUnaryResponse(parsedOutput, generatedTokens, tokenizer, toolCallStartTokenId, toolCallEndTokenId, reasoningEndTokenId);
}
} // namespace ovms
Loading