Skip to content

[WIP] Reasoning parser for LFM2.5 #4307

Open
przepeck wants to merge 11 commits into
mainfrom
przepeck/lfm2_reasoning_parser
Open

[WIP] Reasoning parser for LFM2.5 #4307
przepeck wants to merge 11 commits into
mainfrom
przepeck/lfm2_reasoning_parser

Conversation

@przepeck

Copy link
Copy Markdown
Collaborator

🛠 Summary

CVS-188930
Reasoning Parser for LFM2.5

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

Copilot AI review requested due to automatic review settings June 22, 2026 08:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial support for selecting an LFM2 reasoning parser in OVMS LLM output processing, wiring it into the runtime parser factory and Bazel build graph.

Changes:

  • Register "lfm2" as a supported reasoningParserName in OutputParser.
  • Introduce Lfm2ReasoningParser (currently a thin wrapper over Qwen3ReasoningParser) with requiresStreamingWithSpecialTokens() enabled.
  • Add a Bazel ovms_cc_library target for the new header and include it in output_parsers deps.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/llm/io_processing/output_parser.cpp Adds "lfm2" reasoning parser selection path.
src/llm/io_processing/lfm2/lfm2_reasoning_parser.hpp Introduces the LFM2 reasoning parser wrapper class.
src/llm/BUILD Adds/links the new parser target into the output_parsers build target.

Comment thread src/llm/io_processing/lfm2/lfm2_reasoning_parser.hpp Outdated
Comment thread src/llm/BUILD
Comment thread src/llm/io_processing/output_parser.cpp Outdated
Comment on lines +209 to +210
} else if (reasoningParserName == "lfm2") {
reasoningParser = std::make_unique<Lfm2ReasoningParser>(tokenizer);

@mzegla mzegla left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we mention available parsers in the docs. Please update documentation as well.

@przepeck przepeck force-pushed the przepeck/lfm2_reasoning_parser branch from 2c12a41 to d6f1911 Compare June 23, 2026 08:30
protected:
static const int64_t toolCallStartTokenId = 124905; // <|tool_call_start|>
static const int64_t toolCallEndTokenId = 124906; // <|tool_call_end|>
static const int64_t reasoningEndTokenId = 124902; // </think>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it? Feels like we are leaking responsibilities here.

Comment on lines +55 to +56
explicit Lfm2ToolParser(ov::genai::Tokenizer& tokenizer, int64_t botTokenId = 10, int64_t eotTokenId = 11) :
BaseOutputParser(tokenizer), botTokenId(botTokenId), eotTokenId(eotTokenId) {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are bending the LFM2 parser beyond the standard with those changes. Now some internal consts are static and some are not + the constructor is different. Not in line with other parsers.
For now I see two possibilities:

  • have full implementation for LFM2.5, maybe we some extracted functions shared with LFM2, but not exact calls from parent
  • make such change for all parsers (drop static fields, accept reading it from somewhere instead of hardcoded in the class)

I think option 2 would be worth considering during refactor, but since it would likely require broad correctness checks it might be quicker to go with option 1 for now.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will go with first option then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants