Skip to content

CBv2: stop-string scope that excludes reasoning and tool-call spans - #375

Merged
davidtai merged 4 commits into
mainfrom
fix/reasoning-stop-scope-exclude-on-2beb401f
Nov 3, 2026
Merged

davidtai merged 4 commits into
mainfrom
fix/reasoning-stop-scope-exclude-on-2beb401f

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 31, 2026 •

Copy link
Copy Markdown

Proposed changes

Engine half of Layr-Labs/d-inference#1650. Provider side: that PR, which pins this branch. Target: 0.10.7.

Gemma 4 and <think>-format models stream reasoning, tool-call frames and the answer through one detokenized stream, like GPT-OSS. A client stop string that the reasoning contained ended the request before any answer: finish_reason: "stop", reasoning only, no content.

CBv2StopStringScope gains a second shape, init(excluding:startingInside:): stops match everywhere except inside the given spans (opener through the first closer, markers included). startingInside covers prompts that already opened the first span (Qwen prefills <think>\n). Whitespace that begins a run of matchable text cannot complete a stop on its own, so the blank line a model writes after </think> is not the answer's "\n\n". Unscoped and answer-span matching are unchanged.

Commits: d0c3a8e2 (the scope), 5ffbb801 (review pass: simpler excluded-span release; single-stop chunking test), then a merge of main 7933a0fa, so this branch's head is 7f00abc4. The branch name still carries its original base.

Evidence, recorded with the provider PR on Darkbloom provider 0.10.4 as the before:

  • gemma-4-26b-qat-4bit, reasoning on, 36 prompts: stop: ["."] and stop: ["\n\n"] each gave empty content on 36/36 requests, every one proven cut inside the thought. With this scope and the provider change: 0/36, and each answer equals the full answer cut at its first stop.
  • StopHoldback differentials from the commit messages: 200,000 cases of unscoped and answer-span matching against the previous StopHoldback, identical; 300,000 cases (unscoped, Harmony, excluded, excluded starting inside) across the review pass, identical.
  • New tests in Tests/MLXLMTests/CBv2SamplingTests.swift.

Limitations:

  • The engine diff was measured on earlier bases (2beb401f and before). The merge of main brings in only AffineQuantizedVectors: rows in registers for a verify window on M5 Ultra #373 (AffineQuantizedVectors), which touches no stop path. On 7f00abc4: the CBv2Sampling test classes, 55 of 55 pass locally; CI passes here; live results on 36 prompts are on the provider PR (empty answers 36 of 36 on master, 0 of 36 here).
  • One machine (M3 Ultra) for the live runs.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes (not run)
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed) (the provider PR carries the docs)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: the code, tests, measurements and this description were produced by Claude (Claude Code, Opus 5.5). The agent opened this draft at the repository owner's request. A human has not yet reviewed the code or this description.

🤖 Generated with Claude Code

jonathan308 and others added 3 commits October 30, 2026 02:20
Gemma 4 and <think>-format models stream their reasoning, tool-call frames
and the answer through one detokenized stream, like GPT-OSS. A client stop
string that the reasoning contained ended the request before any answer:
finish .stop, reasoning only, no content.

CBv2StopStringScope gains a second shape, init(excluding:startingInside:):
stops match everywhere except inside the given spans (opener through the
first closer, markers included). startingInside covers prompts that already
opened the first span (Qwen prefills "<think>\n"). Whitespace that begins a
run of matchable text cannot complete a stop on its own, so the blank line a
model writes after </think> is not the answer's "\n\n". The scope now stores
matching: .inside (the existing answer-span shape, same initializer) or
.outside; unscoped and answer-span matching are unchanged (200,000-case
differential against the previous StopHoldback: identical).

Recorded on Darkbloom provider 0.10.4 with gemma-4-26b-qat-4bit, reasoning
on, 36 prompts: stop ["."] and ["\n\n"] each gave empty content on 36/36
requests, every one proven cut inside the thought. The provider change that
sets this scope brings both to 0/36, and each answer equals the full answer
cut at its first stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the review pass on the excluded-span scope:
- ingestExcluding enters a span as soon as its opener is found, then
  releases up to the tail held for stops and openers, like ingestScoped.
  A 300,000-case differential against 95e1d2b (unscoped, Harmony,
  excluded, excluded starting inside) is identical.
- The randomized chunking test draws one stop per trial. With several
  stops, one that starts earlier but completes in a later chunk loses to
  one completed first; unscoped matching behaves the same, and it is not
  what the test checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai
davidtai merged commit 196c5d3 into main Nov 3, 2026
37 of 38 checks passed
@davidtai
davidtai deleted the fix/reasoning-stop-scope-exclude-on-2beb401f branch November 3, 2026 12:23
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.

2 participants