common/chat : fix LFM2/LFM2.5 reasoning round-trip and <think> leak#24234
Open
tdakhran wants to merge 2 commits into
Open
common/chat : fix LFM2/LFM2.5 reasoning round-trip and <think> leak#24234tdakhran wants to merge 2 commits into
tdakhran wants to merge 2 commits into
Conversation
aldehir
reviewed
Jun 6, 2026
Comment on lines
1672
to
1675
| } else if (extract_reasoning) { | ||
| // Thinking off, but model may still emit <think>, drop it | ||
| reasoning = p.optional(p.literal(THINK_START) + p.until(THINK_END) + p.literal(THINK_END)); | ||
| } |
Contributor
There was a problem hiding this comment.
Let's always parse reasoning but gate it by reasoning format and model (i.e. if the think token exists in the template). Simulating this doesn't gain anything and might seem as if the model is doing nothing.
Contributor
Author
There was a problem hiding this comment.
I like it, pushed one more commit, now reasoning parsing is always enabled if there is <think> in the chat template.
Contributor
|
Looks good, I'll wait for CI to pass before giving approval. Thank you for your contributions! |
aldehir
approved these changes
Jun 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Follow-up on review comment #24178 (review) made by @aldehir.
For LFM2/LFM2.5 models, copy
reasoning_contentintothinking.LFM2.5-8B-A1B is always a reasoning model. The chat template doesn't have a switch to disable it. This leads to a leak of
thinkingintocontentwith reasoning disabled (-rea off). (reported here #24178 (comment)).The workaround is to drop thinking content (as is done for Deepseek).
Additional information
Add more tests, and refactor (unify) test cases for different LFM2/LFM2.5 chat templates.
Requirements