Repository navigation
CBv2: stop-string scope that excludes reasoning and tool-call spans - #375
Merged
Merged
Conversation
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>
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.
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.CBv2StopStringScopegains a second shape,init(excluding:startingInside:): stops match everywhere except inside the given spans (opener through the first closer, markers included).startingInsidecovers 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 ofmain7933a0fa, so this branch's head is7f00abc4. 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: ["."]andstop: ["\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.StopHoldbackdifferentials from the commit messages: 200,000 cases of unscoped and answer-span matching against the previousStopHoldback, identical; 300,000 cases (unscoped, Harmony, excluded, excluded starting inside) across the review pass, identical.Tests/MLXLMTests/CBv2SamplingTests.swift.Limitations:
2beb401fand before). The merge ofmainbrings in only AffineQuantizedVectors: rows in registers for a verify window on M5 Ultra #373 (AffineQuantizedVectors), which touches no stop path. On7f00abc4: theCBv2Samplingtest 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).Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes (not run)AI usage
accurately describes the code changes.
🤖 Generated with Claude Code