Skip to content

Add support for Olmo 3 reasoning parser#26039

Closed
soldni wants to merge 7 commits intovllm-project:mainfrom
soldni:main
Closed

Add support for Olmo 3 reasoning parser#26039
soldni wants to merge 7 commits intovllm-project:mainfrom
soldni:main

Conversation

@soldni
Copy link
Copy Markdown
Contributor

@soldni soldni commented Oct 1, 2025

Purpose

This PR adds support for parsing reasoning traces for the Olmo 3 family of models. (support for models has been already merged in #24534).

Olmo models use <think> and </think> string to bracket their reasoning traces; however, unlike Qwen or Deepseek families, the strings are not special tokens in the vocabulary, therefore requiring a new parser.

Test Plan

This PR includes tests to verify that the parser behaves as expected. Existing tests should not be impacted.

Test Result

Run tests:

pytest tests/reasoning/test_olmo3_reasoning_parser.py

Test output:

============================= test session starts ==============================
platform linux -- Python 3.12.11, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/ec2-user/vllm
configfile: pyproject.toml
plugins: anyio-4.11.0, forked-1.6.0, cov-7.0.0, shard-0.1.2, asyncio-1.2.0, timeout-2.4.0, rerunfailures-16.0.1, mock-3.15.1, buildkite-test-collector-0.1.9, subtests-0.14.2, hypothesis-6.140.2, schemathesis-4.1.4, hydra-core-1.3.2, typeguard-4.4.4
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 14 items
Running 14 items in this shard

tests/reasoning/test_olmo3_reasoning_parser.py ..............            [100%]

============================== 14 passed in 3.50s ==============================

Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

soldni and others added 7 commits September 29, 2025 13:13
Signed-off-by: Luca Soldaini <luca@soldaini.net>
Signed-off-by: Luca Soldaini <luca@soldaini.net>
Signed-off-by: Luca Soldaini <luca@soldaini.net>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 1, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a reasoning parser for Olmo 3 models. The implementation includes a new parser class, Olmo3ReasoningParser, which handles both streaming and non-streaming outputs by operating on strings to find <think> and </think> tags. Unit tests are also included to verify the parser's behavior. The overall approach is sound, but I've found a critical issue in the string overlap detection logic that could lead to incorrect parsing under certain tokenization scenarios. The rest of the changes, including the test cases and module exports, look good.

Comment on lines +61 to +73
for i in range(len(a) - 1, 1, -1):
if a[-i:] == b[:i]:
ind_a = Indices(len(a) - i, len(a))
ind_b = Indices(0, i)
return (ind_b, ind_a) if swap else (ind_a, ind_b)

# third check: does the beginning of a overlap with
# the end of b?
for i in range(len(a) - 1, 1, -1):
if b[-i:] == a[:i]:
ind_a = Indices(0, i)
ind_b = Indices(len(b) - i, len(b))
return (ind_b, ind_a) if swap else (ind_a, ind_b)
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.

critical

The loops for detecting string overlaps miss single-character overlaps. The range function's stop parameter is exclusive. Using 1 as the stop value in range(len(a) - 1, 1, -1) means the loop will not execute for an overlap of length 1.

For example, if checking for an overlap between "...a" and "b..." where the overlap is a single character, the current implementation would fail. This could cause the parser to miss <think> or </think> tags if they are split across tokens in a way that results in a single-character overlap.

To fix this, the stop value in the range calls should be 0 to include checks for overlaps of length 1.

Suggested change
for i in range(len(a) - 1, 1, -1):
if a[-i:] == b[:i]:
ind_a = Indices(len(a) - i, len(a))
ind_b = Indices(0, i)
return (ind_b, ind_a) if swap else (ind_a, ind_b)
# third check: does the beginning of a overlap with
# the end of b?
for i in range(len(a) - 1, 1, -1):
if b[-i:] == a[:i]:
ind_a = Indices(0, i)
ind_b = Indices(len(b) - i, len(b))
return (ind_b, ind_a) if swap else (ind_a, ind_b)
for i in range(len(a) - 1, 0, -1):
if a[-i:] == b[:i]:
ind_a = Indices(len(a) - i, len(a))
ind_b = Indices(0, i)
return (ind_b, ind_a) if swap else (ind_a, ind_b)
# third check: does the beginning of a overlap with
# the end of b?
for i in range(len(a) - 1, 0, -1):
if b[-i:] == a[:i]:
ind_a = Indices(0, i)
ind_b = Indices(len(b) - i, len(b))
return (ind_b, ind_a) if swap else (ind_a, ind_b)

@soldni soldni closed this Oct 1, 2025
@soldni
Copy link
Copy Markdown
Contributor Author

soldni commented Oct 1, 2025

Will open a new one with DSO.

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.

1 participant