Skip to content
Closed
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Releases before 0.10.0 are in the

## Unreleased

- `engine.getContextSize()` on LiteRT-LM Web `withTextHistory()` loads returns the context size the runtime's executor enforces when its load probe finds one below the requested size, such as Qwen3 0.6B's 4096 on WASM CPU, instead of the requested `ModelParams.contextSize` ([#1861](https://github.com/leehack/llamadart/issues/1861)).

## 0.19.4

- Keep the default WebGPU bridge assets at `v0.1.83` (unchanged from 0.19.3).
Expand Down
2 changes: 1 addition & 1 deletion lib/src/backends/litert_lm/litert_lm_backend_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class LiteRtLmBackend
@override
Future<int> getContextSize(int contextHandle) async {
_requireContextHandle(contextHandle);
return _modelParams?.contextSize ?? 0;
return _reportedContextTokens ?? _modelParams?.contextSize ?? 0;
}

@override
Expand Down
23 changes: 23 additions & 0 deletions test/unit/backends/litert_lm/litert_lm_backend_web_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,29 @@ void main() {
}
});

test('the context size is the executor limit its probe found, else the '
'requested size', () async {
for (final (executorTokens, expected) in <(int?, int)>[
(4096, 4096),
(null, 65536),
]) {
_installCountingFakeEngine(
counts: (turn, budget) => turn == 0
? (decoded: budget, total: 20)
: (decoded: 100, total: 200),
maxNumTokens: 65536,
executorTokens: executorTokens,
);
final engine = LlamaEngine(spi.LlamaBackend.withTextHistory());
await engine.loadModelFromUrl(
'model.litertlm',
modelParams: const ModelParams(contextSize: 65536),
);
expect(await engine.getContextSize(), expected);
await engine.dispose();
}
});

test('an automatic tool loop runs a call from a finished reply and '
'answers from its result', () async {
final ran = <Object?>[];
Expand Down
2 changes: 2 additions & 0 deletions website/docs/changelog/recent-releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ validate against the exact release tag notes.

## Unreleased

- `engine.getContextSize()` on LiteRT-LM Web `withTextHistory()` loads returns the context size the runtime's executor enforces when its load probe finds one below the requested size, such as Qwen3 0.6B's 4096 on WASM CPU, instead of the requested `ModelParams.contextSize` ([#1861](https://github.com/leehack/llamadart/issues/1861)).

## 0.19.4

- Keep default WebGPU bridge assets at `v0.1.83` (unchanged from 0.19.3).
Expand Down
Loading