Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Releases before 0.10.0 are in the

- Fixed constrained JSON (`responseFormat`) ignoring the grammar after a `ThinkingBudget` closes a template-opened thought on native llama.cpp (Qwen3.5 and similar), and the same for required tool calls on templates whose grammar takes that thought.
- Fixed a required tool call on Seed-OSS being unconstrained after a `ThinkingBudget` closes a thought the model opened, on native llama.cpp ([#1958](https://github.com/leehack/llamadart/issues/1958)).
- Aligned the default WebGPU bridge assets to `v0.1.84`: constrained JSON (`responseFormat`) and Seed-OSS required tool calls stay constrained after a `ThinkingBudget` closes a thought on WebGPU, and older assets throw `LlamaUnsupportedException` for that combination ([#1954](https://github.com/leehack/llamadart/issues/1954)). Web keeps native llama.cpp `v0.9.0` parity (upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`) and `@litert-lm/core@0.19.0`. Manifest SHA-256: `55abeb377597148156059a8ee5400f2314c6254ad91b57db65b709e304c0dea0`.
- Aligned the default WebGPU bridge assets to `v0.1.84`: constrained JSON (`responseFormat`) and required tool calls that take the thought stay constrained after a `ThinkingBudget` closes it on WebGPU, and older assets throw `LlamaUnsupportedException` for that combination ([#1954](https://github.com/leehack/llamadart/issues/1954)). Web keeps native llama.cpp `v0.9.0` parity (upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`) and `@litert-lm/core@0.19.0`. Manifest SHA-256: `55abeb377597148156059a8ee5400f2314c6254ad91b57db65b709e304c0dea0`.

## 0.19.7

Expand Down
3 changes: 2 additions & 1 deletion doc/webgpu_bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ physical playback, intelligibility or speaker-reference fidelity.
([llama-web-bridge#213](https://github.com/leehack/llama-web-bridge/pull/213)).
llamadart sends it, as native does, only when `grammarLazy` is off and the
grammar takes the thought (`ToolCallGrammarUtils.keepsAppliedThroughThought`:
constrained JSON on Qwen3.5, required tool calls on Seed-OSS), and throws
a `think-body` or `seed-thought` root, as in `responseFormat` and required
tool calls), and throws
`LlamaUnsupportedException` for that combination on assets without the flag.
Every other request omits `pauseGrammar` and is unchanged.

Expand Down
6 changes: 3 additions & 3 deletions lib/src/backends/webgpu/webgpu_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1955,9 +1955,9 @@ class WebGpuLlamaBackend
ToolCallGrammarUtils.keepsAppliedThroughThought(grammar);
if (keepGrammarApplied && !capabilities.thinkingBudgetPauseGrammar) {
throw LlamaUnsupportedException(
'WebGPU thinking-budget control with a grammar that stays applied '
'through the thought (responseFormat on Qwen3.5, required tool calls '
'on Seed-OSS) needs bridge assets v0.1.84+ whose '
'WebGPU thinking-budget control with an eager grammar that takes the '
'thought (responseFormat or required tool calls on templates that '
'open or model one) needs bridge assets v0.1.84+ whose '
'getCompletionCapabilities() reports thinkingBudgetPauseGrammar; '
'the loaded core pauses every grammar while the model reasons, so '
'the reply would not be constrained.',
Expand Down
5 changes: 3 additions & 2 deletions lib/src/backends/webgpu/webgpu_errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ final RegExp _bridgeArgument = RegExp(

final RegExp _bridgeUnsupportedCompletion = RegExp(
r'^The loaded WebGPU core does not support CompletionOptions\.'
r'(?:presencePenalty|minP|thinkingBudget|grammarLazy|grammarRoot|penaltyPromptTokensWithGrammar|speculativeDecoding)'
r'(?:presencePenalty|minP|thinkingBudget\.pauseGrammar|thinkingBudget|grammarLazy|grammarRoot|penaltyPromptTokensWithGrammar|speculativeDecoding)'
r'(?: or CompletionOptions\.'
r'(?:presencePenalty|minP|thinkingBudget|grammarLazy|grammarRoot|penaltyPromptTokensWithGrammar|speculativeDecoding))*\.$',
r'(?:presencePenalty|minP|thinkingBudget\.pauseGrammar|thinkingBudget|grammarLazy|grammarRoot|penaltyPromptTokensWithGrammar|speculativeDecoding))*\.$',
);

/// Classifies request rejections without reclassifying unknown runtime errors.
Expand All @@ -78,6 +78,7 @@ LlamaException? webGpuBridgeRequestError(
final message = webGpuBridgeErrorText(error, sourceUrls: sourceUrls);
if (name == 'Error' &&
(message.contains('CompletionOptions.grammar') ||
message.contains('CompletionOptions.thinkingBudget') ||
message.contains(
'CompletionOptions.penaltyPromptTokensWithGrammar',
)) &&
Expand Down
13 changes: 6 additions & 7 deletions lib/src/core/models/inference/generation_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,14 @@ class GenerationParams {
/// Optional llama.cpp-style limit for tokens generated inside a reasoning
/// block.
///
/// The native llama.cpp backend keeps a grammar that takes the
/// template-opened thought itself (a root starting with `think-body`) or
/// models the thought the model opens (Seed-OSS's required-call root,
/// starting with `seed-thought`) applied while budgeted reasoning is
/// active. It pauses every other grammar, lazy grammars included, until
/// reasoning has ended. Native LiteRT-LM applies it to chat generation on
/// The native llama.cpp backend keeps an eager grammar whose root takes the
/// thought (`think-body` or `seed-thought`, as in response-format and
/// required tool-call grammars on templates that open or model a thought)
/// applied while budgeted reasoning is active. It pauses every lazy grammar,
/// whatever its root, and every other grammar until reasoning has ended. Native LiteRT-LM applies it to chat generation on
/// bundles with a thinking channel, which it closes with the bundle's own
/// end marker; it rejects a zero budget and [ThinkingBudget.forcedMessage].
/// WebGPU bridges that report `thinkingBudget` support it and pause grammars
/// WebGPU bridges that report `thinkingBudget` support it and treat grammars
/// the same way as native llama.cpp; keeping a grammar applied through the
/// thought needs assets that report `thinkingBudgetPauseGrammar` (v0.1.84+),
/// and older assets reject that combination.
Expand Down
6 changes: 3 additions & 3 deletions skills/llamadart-web/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ in the llamadart-getting-started and llamadart-chat-streaming skills.
unless `withTextHistory()` is used and the loaded runtime supports them. Unreported
controls throw `LlamaUnsupportedException`; `engine.runtime` names the
runtime, so never sniff the `.litertlm` extension after loading.
- A `ThinkingBudget` with a grammar that stays applied through the thought
(`responseFormat` on Qwen3.5, required calls on Seed-OSS) needs assets that
report `thinkingBudgetPauseGrammar`; older assets throw
- A `ThinkingBudget` with an eager grammar that takes the thought
(`responseFormat` or required tool calls on templates that open or model
one) needs assets that report `thinkingBudgetPauseGrammar`; older assets throw
`LlamaUnsupportedException`.
- `engine.supportsNextTokenScoring` and
`engine.supportsStatePersistence`.
Expand Down
36 changes: 36 additions & 0 deletions test/integration/thinking_budget_grammar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,40 @@ thought-text ::= [^d]*
}
}
});

test('a lazy grammar constrains the reply once the thought closes', () async {
for (final budget in [0, 3]) {
final chunks = await backend
.generate(
context,
prompt,
GenerationParams(
maxTokens: 48,
temp: 0,
seed: 1,
penalty: 1,
grammar: 'root ::= " a" [a-z ]*\n',
grammarLazy: true,
grammarTriggers: const [
GenerationGrammarTrigger.typed(
type: GrammarTriggerType.word,
value: ' a',
),
],
thinkingBudget: ThinkingBudget(
maxTokens: budget,
startTag: '<think>',
endTag: '</think>',
),
),
)
.toList();

expect(
utf8.decode(chunks.expand((chunk) => chunk).toList()),
matches(RegExp(r'</think>.* a[a-z ]*$', dotAll: true)),
reason: 'budget $budget',
);
}
});
}
8 changes: 8 additions & 0 deletions test/unit/backends/webgpu/webgpu_errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ void main() {
'The loaded WebGPU core does not support CompletionOptions.penaltyPromptTokensWithGrammar.',
isA<LlamaUnsupportedException>(),
),
(
'The loaded WebGPU core does not support CompletionOptions.thinkingBudget.',
isA<LlamaUnsupportedException>(),
),
(
'The loaded WebGPU core does not support CompletionOptions.thinkingBudget.pauseGrammar.',
isA<LlamaUnsupportedException>(),
),
(
'The loaded WebGPU core does not support CompletionOptions.grammarLazy.',
isA<LlamaUnsupportedException>(),
Expand Down
41 changes: 41 additions & 0 deletions test/unit/tooling/docs_changelog_drift_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,45 @@ void main() {
isEmpty,
);
});

test('names the first differing line and a whitespace-only difference', () {
final problems = docsChangelogDriftProblems(
{'0.2.0': '- Fix a.\n- Fix b.\n'},
{'0.2.0': '- Fix a.\n- Fix b.\n'},
);

expect(problems, hasLength(1));
expect(
problems.single,
allOf(
contains('only in whitespace'),
contains('first differing line 2'),
contains('`- Fix b.`'),
),
);
expect(
docsChangelogDriftProblems(
{'0.2.0': '- Fix a.\n'},
{'0.2.0': '- Fix c.\n'},
).single,
allOf(contains('in content'), contains('first differing line 1')),
);
});

test('requires the prescribed bridge wording on the docs page', () {
for (final docsLine in [
'* Keep default WebGPU bridge assets at `v1` (unchanged from 0.1.0).\n',
bridgeCore,
]) {
final problems = docsChangelogDriftProblems(
{'0.2.0': bridgeCore},
{'0.2.0': docsLine},
);

expect(problems, hasLength(1), reason: docsLine);
expect(problems.single, contains('bridge line must read'));
}
expect(docsChangelogDriftProblems({}, {'0.2.0': bridgeCore}), hasLength(1));
expect(docsChangelogDriftProblems({}, {'Unreleased': bridgeCore}), isEmpty);
});
}
50 changes: 43 additions & 7 deletions tool/testing/verify_release_docs_versions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -992,23 +992,59 @@ String _normalizedBridgeLines(String body) => body
.join('\n')
.trimRight();

/// The first line where [core] and [docs] differ, numbered from 1, and
/// whether they differ only in whitespace.
String _firstDifference(String core, String docs) {
final coreLines = core.split('\n');
final docsLines = docs.split('\n');
final count = coreLines.length > docsLines.length
? coreLines.length
: docsLines.length;
var index = 0;
while (index < count &&
index < coreLines.length &&
index < docsLines.length &&
coreLines[index] == docsLines[index]) {
index++;
}
final whitespaceOnly =
core.replaceAll(RegExp(r'\s+'), '') ==
docs.replaceAll(RegExp(r'\s+'), '');
String line(List<String> lines) =>
index < lines.length ? '`${lines[index]}`' : '(missing)';
return '${whitespaceOnly ? 'only in whitespace' : 'in content'}; first '
'differing line ${index + 1}: CHANGELOG.md ${line(coreLines)}, docs '
'page ${line(docsLines)}';
}

/// Released sections that [docs] keeps from [core] but words differently.
///
/// Both changelogs are edited by hand and union-merge, so nothing else keeps
/// a retained release's bullets identical.
/// a retained release's bullets identical. The docs page must use its
/// prescribed bridge wording (`- ` marker, no "the"), which normalising both
/// sides would otherwise let a `*` or "the default" through.
List<String> docsChangelogDriftProblems(
Map<String, String> core,
Map<String, String> docs,
) {
final normalized = _normalizedBridgeLines;
return [
for (final MapEntry(key: heading, value: body) in docs.entries)
if (heading != 'Unreleased' &&
core.containsKey(heading) &&
normalized(core[heading]!) != normalized(body))
'$_docsChangelog `## $heading` differs from CHANGELOG.md; keep the '
'bullets of every retained release identical (apart from the bullet '
'marker and "the" on the WebGPU bridge line).',
if (heading != 'Unreleased') ...[
for (final line in body.split('\n'))
if (_bridgeBulletLine.hasMatch(line) &&
(line.startsWith('* ') ||
line.contains('the default WebGPU bridge assets')))
'$_docsChangelog `## $heading` bridge line must read "- ... '
'default WebGPU bridge assets ..." (a `-` marker, no "the"): '
'`$line`',
if (core.containsKey(heading) &&
normalized(core[heading]!) != normalized(body))
'$_docsChangelog `## $heading` differs from CHANGELOG.md '
'${_firstDifference(normalized(core[heading]!), normalized(body))}'
'; keep the bullets of every retained release identical (apart '
'from the bullet marker and "the" on the WebGPU bridge line).',
],
];
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/changelog/recent-releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ validate against the exact release tag notes.

- Fixed constrained JSON (`responseFormat`) ignoring the grammar after a `ThinkingBudget` closes a template-opened thought on native llama.cpp (Qwen3.5 and similar), and the same for required tool calls on templates whose grammar takes that thought.
- Fixed a required tool call on Seed-OSS being unconstrained after a `ThinkingBudget` closes a thought the model opened, on native llama.cpp ([#1958](https://github.com/leehack/llamadart/issues/1958)).
- Aligned default WebGPU bridge assets to `v0.1.84`: constrained JSON (`responseFormat`) and Seed-OSS required tool calls stay constrained after a `ThinkingBudget` closes a thought on WebGPU, and older assets throw `LlamaUnsupportedException` for that combination ([#1954](https://github.com/leehack/llamadart/issues/1954)). Web keeps native llama.cpp `v0.9.0` parity (upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`) and `@litert-lm/core@0.19.0`. Manifest SHA-256: `55abeb377597148156059a8ee5400f2314c6254ad91b57db65b709e304c0dea0`.
- Aligned default WebGPU bridge assets to `v0.1.84`: constrained JSON (`responseFormat`) and required tool calls that take the thought stay constrained after a `ThinkingBudget` closes it on WebGPU, and older assets throw `LlamaUnsupportedException` for that combination ([#1954](https://github.com/leehack/llamadart/issues/1954)). Web keeps native llama.cpp `v0.9.0` parity (upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`) and `@litert-lm/core@0.19.0`. Manifest SHA-256: `55abeb377597148156059a8ee5400f2314c6254ad91b57db65b709e304c0dea0`.

## 0.19.7

Expand Down
15 changes: 6 additions & 9 deletions website/docs/guides/generation-and-streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,12 @@ templates. Raw `engine.generate(...)` calls must provide both delimiters in
`ThinkingBudget`. A budget of `0` immediately forces the end delimiter. On
Qwen3-Coder XML templates (Qwen3.5, Nemotron 3 Nano, StepFun 3.5 Flash) the
forced text is a line break before the end delimiter, as llama.cpp forces it.
On native llama.cpp, a grammar that takes the template-opened thought itself
(its root starts with `think-body`, as for `responseFormat` on Qwen3.5), or one
that models the thought the model opens (the Seed-OSS required-call grammar,
whose root starts with `seed-thought`), stays applied while the model reasons,
so it also constrains the reply after a spent budget. Other grammars, such as a
typical caller `grammar` or a lazy grammar, wait until the thought closes.
WebGPU still pauses every grammar during
budgeted reasoning
([#1954](https://github.com/leehack/llamadart/issues/1954)).
On native llama.cpp and WebGPU, an eager grammar whose root takes the thought
(`think-body` or `seed-thought`, as in `responseFormat` and required tool-call
grammars on templates that open or model a thought) stays applied while the
model reasons, so it also constrains the reply after a spent budget. Every lazy
grammar, whatever its root, and every other grammar, such as a typical caller
`grammar`, waits until the thought closes.
Native llama.cpp, WebGPU bridges that report `thinkingBudget` and native
LiteRT-LM chat generation on bundles with a thinking channel support a budget
(see [Runtime parameters](../configuration/runtime-parameters)); other
Expand Down
8 changes: 4 additions & 4 deletions website/docs/platforms/webgpu-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ The feature-by-runtime table is in the
probe reports `penaltyPromptTokens`), as native llama.cpp does. `ToolChoice.auto` requests that skip the lazy tool-call
grammar keep the prompt out, as native does under that grammar
([llama-web-bridge#187](https://github.com/leehack/llama-web-bridge/pull/187)).
A thinking budget is text-only. As on native llama.cpp, a thinking budget keeps a
grammar applied through the thought when that grammar takes it (constrained JSON
on Qwen3.5, required tool calls on Seed-OSS) and pauses every other grammar until
reasoning ends; the former needs assets whose probe reports
A thinking budget is text-only. As on native llama.cpp, a thinking budget keeps an
eager grammar applied through the thought when its root takes it (`think-body`
or `seed-thought`, as in `responseFormat` and required tool calls) and pauses
every lazy and every other grammar until reasoning ends; the former needs assets whose probe reports
`thinkingBudgetPauseGrammar` (`v0.1.84+`) and throws `LlamaUnsupportedException`
without it. A LoRA adapter is a `ModelSource` whose URL the bridge downloads once
per model load (a `ModelSource.path` is a URL relative to the document, or a `blob:` URL), through Cache Storage unless the URL carries credentials; reload
Expand Down
Loading