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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Releases before 0.10.0 are in the
- Fixed Android LiteRT-LM GPU generation failing with "Can not find OpenCL library on this device" when the app does not declare `libOpenCL.so` or the device has no loadable OpenCL: the runtime (`v0.19.1-5`) links the WebGPU sampler again. Affects 0.18.0 through 0.19.9 on Android ([#1998](https://github.com/leehack/llamadart/issues/1998)).
- Aligned the default WebGPU bridge assets to `v0.1.85`: a page without cross-origin isolation now fails at once with a `LlamaUnsupportedException` naming COOP/COEP `require-corp` instead of waiting minutes for a generic init timeout, and Firefox CPU runs (`gpuLayers: 0`) no longer create the WebGPU backend (stories15M, 32 tokens: 640 to 762 tok/s against 10 before) ([#1025](https://github.com/leehack/llamadart/issues/1025)).
- `ComputeDevice.gpu` on Web now names why WebGPU was not used (for example `adapter_missing_shader_f16`: Chrome on Linux with NVIDIA needs driver 615.71 or newer); documented the measured Safari 27, Firefox 160 and NVIDIA L4 results ([#1025](https://github.com/leehack/llamadart/issues/1025)).
- Native LiteRT-LM strict `responseFormat` now also runs on the Android arm64 GPU, through OpenCL on a Galaxy S24 and a Pixel 9 Pro with Qwen3 and Gemma 4; `ComputeDevice.auto` on Android no longer needs `ComputeDevice.cpu` for it ([#174](https://github.com/leehack/llamadart/issues/174)).

Runtime baseline: native llama.cpp `v0.9.0` and Web use upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`; native LiteRT-LM uses `v0.19.1-5` and stable-diffusion uses `v0.3.0-3`. Web LiteRT-LM uses `@litert-lm/core@0.19.0`. Manifest SHA-256: `6767783edd85e14853a8a79cd6ce53d53f4eb2d99aeb62601014bd68c1b6b7b3`.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ concrete engine; see [shared lifecycle ownership](https://llamadart.leehack.com/

LFM2 Python-style tool calls use declared argument types and preserve copied string backslashes; see [tool calling](https://llamadart.leehack.com/docs/guides/tool-calling). The automatic grammar preserves copied singleton string spellings and can use an existing Python arguments wrapper for unambiguous JSON-escaped string values. Foreign XML closing tags remain raw diagnostics with no executable calls.
Native llama.cpp applies schema-directed lazy grammar to LFM2 automatic Python tool calls. Web additionally requires bridge assets v0.1.82+ with a loaded-core prompt-penalty capability; older runtimes reject before inference.
Native LiteRT-LM enforces strict JSON Schema output for Qwen3 and Gemma 4 on the macOS arm64 CPU and GPU, the iOS arm64 CPU and the Android arm64, Linux and Windows CPU, and for Qwen3 on the iOS arm64 GPU (Gemma 4 cannot create a GPU engine there; per-host model evidence in the structured-output guide), for the schemas llama.cpp's GBNF converter also enforces; see [structured output](https://llamadart.leehack.com/docs/guides/generation-and-streaming#structured-json-output) and the [support matrix](https://llamadart.leehack.com/docs/platforms/support-matrix).
Native LiteRT-LM enforces strict JSON Schema output for Qwen3 and Gemma 4 on the macOS arm64 CPU and GPU, the iOS arm64 CPU, the Android arm64 CPU and GPU, and the Linux and Windows CPU, and for Qwen3 on the iOS arm64 GPU (Gemma 4 cannot create a GPU engine there; per-host model evidence in the structured-output guide), for the schemas llama.cpp's GBNF converter also enforces; see [structured output](https://llamadart.leehack.com/docs/guides/generation-and-streaming#structured-json-output) and the [support matrix](https://llamadart.leehack.com/docs/platforms/support-matrix).
LFM2 replies cut off at a reported length limit expose raw `partialToolCalls` diagnostics separately from executable calls and history. LFM2 tool markers inside reasoning stay in reasoning and produce no executable calls. Explicit parallel-tool requests reach supported Dart tool grammars even when template probes do not recognize parallel history.

## Install
Expand Down
71 changes: 71 additions & 0 deletions doc/cross_platform_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,77 @@ Debug, legacy Qwen3 0.6B artifact `555579ff…`, matrix `matrix-1da3zj25gmeu1`
- An earlier attempt (`matrix-1tcmnx5y9bnqv`) stopped at the 10-minute model
download deadline with 260777210 of 614236160 bytes, before any case.

## Android arm64 strict JSON Schema on CPU and GPU (2026-11-13)

`chat-app-litert-json-schema` (`integration_test/litert_lm_json_schema_e2e_test.dart`)
on Firebase Test Lab physical devices: Galaxy S24 (`SC-51E`, API 36, Adreno 750)
and Pixel 9 Pro (`caiman`, API 35, Mali-G715), Android Debug, LiteRT-LM
`v0.19.1-4`, Qwen3-0.6B (`c5f39b41…`) and Gemma 4 E2B (`18193810…`)
([#174](https://github.com/leehack/llamadart/issues/174)). Every run is graded
by the placement-aware verifier `plan-174-verify-run-v2.py` (kept with the
lane's evidence, not in this repository): adversarial control, sentinel, wide contract,
thinking (Gemma 4 reasons then returns the schema reply; Qwen3 is refused),
`length` cutoff, and a placement rule. A matrix SUCCESS is not a verdict.

CPU (Set A), built from clean `8b02e858` on LiteRT-LM `v0.19.1-4`; these
runs were not repeated on `v0.19.1-5` (six runtime library hashes equal across
bundles). Every verdict passes, and a CPU run logs no GPU placement record:

| Run | Device | Model | Matrix | Verdict |
| --- | --- | --- | --- | --- |
| Q1 | S24 | Gemma 4 E2B | `matrix-4cw1locmczjwa` | pass |
| Q2 | Pixel 9 Pro | Gemma 4 E2B | `matrix-3reobpfs0m0kb` | pass |
| Q3 | S24 | Qwen3-0.6B | `matrix-2nx5z8imv2k0n` | pass |
| Q4 | Pixel 9 Pro | Qwen3-0.6B | `matrix-2zvjhqdr0de42` | pass |
| Q5 | Pixel 9 Pro | Qwen3-0.6B, GPU | `matrix-31tdpnpwt4e1v` | pass (expected refusal) |

Q5 pinned the gate this change lifts: `ComputeDevice.gpu` on `android_arm64`
threw `Native JSON Schema chat is not qualified for the LiteRT-LM gpu backend
on android_arm64; load with ComputeDevice.cpu.` and created no engine.

GPU, through OpenCL (the chat app declares `libOpenCL.so`), from a diagnostic
export of `e9e9b7ec` with only that gate lifted. The proof of GPU execution is
the process's `Loaded OpenCL library with dlopen.` record, written by the
OpenCL top-k sampler on the first sampled step (absent on CPU runs), with no
GPU failure marker. The runtime has no CPU fallback for an explicit GPU load.

| Run | Device | Model | Matrix | Verdict |
| --- | --- | --- | --- | --- |
| P1 | S24 | Gemma 4 E2B | `matrix-2ookix0pxweon` | pass |
| P2 | Pixel 9 Pro | Gemma 4 E2B | `matrix-268m3krw5mqvq` | pass |
| P3 | Pixel 9 Pro | Qwen3-0.6B | `matrix-1sr0irhj7bn7z` | pass |
| P5 | S24 | Qwen3-0.6B | `matrix-37dakitvwn7l2` | pass |

P4 (S24, Gemma 4 CPU, `matrix-17qqq5s25xjpv`) passed with no GPU record. The
earlier S24 refusal of a Qwen3-0.6B GPU engine was measured on the WebGPU
route (Dawn's 128 MiB storage binding); on the OpenCL route P5 passed.

WebGPU route (app without the `libOpenCL.so` declaration), S24 with Gemma 4:
one hardware `Selected adapter:` Vulkan record, no OpenCL record, passed with
the `v0.19.1-5` Android runtime prepared in
[#1998](https://github.com/leehack/llamadart/issues/1998). Before `v0.19.1-5`
that route created the engine and failed the first generation.

Set B, on the PR head `a9c83d50` ([#2006](https://github.com/leehack/llamadart/pull/2006),
clean bundles, LiteRT-LM `v0.19.1-5`, `libLiteRtLm.so` `9926197b…`), graded with
the same verifier. Each OpenCL run logs one `Loaded OpenCL library with dlopen.`
record in the test process; W2c's app omits the `libOpenCL.so` declaration (a
diagnostic build with two local patches) and logs one Mali-G715 Vulkan
`Selected adapter:` record and no OpenCL record:

| Run | Device | Model | Route | Matrix | Verdict |
| --- | --- | --- | --- | --- | --- |
| G1 | S24 | Gemma 4 E2B | OpenCL | `matrix-1pazpgoveixfn` | pass |
| G2 | Pixel 9 Pro | Gemma 4 E2B | OpenCL | `matrix-3s1bjvwl8zpab` | pass |
| G3 | Pixel 9 Pro | Qwen3-0.6B | OpenCL | `matrix-156uu35j2hqqq` | pass |
| G4 | S24 | Qwen3-0.6B | OpenCL | `matrix-2lsagjnnx8p85` | pass |
| W2c | Pixel 9 Pro | Gemma 4 E2B | WebGPU | `matrix-1jad235n0mlpa` | pass |

Limits: the OpenCL record appears once per process, so it proves one sampled
step rather than each request; the shipped binary is not attested against the
sources read; the Pixel has no system-side GPU telemetry; Set B ran on a Debug app and the
CPU runs on `v0.19.1-4`. The runs cover one schema contract and two models, not every model or driver.

## Planned platform/backend coverage

Inspect the model/use-case coverage catalog without downloading models or
Expand Down
4 changes: 2 additions & 2 deletions doc/litert_lm_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ backend, not the registry:
real-model-tested rendered-prompt compatibility path, but its handler grammar
is still not applied by LiteRT-LM and must not be reported as grammar support.
- **Native JSON Schema uses its own provider.** Canonical Qwen3 text chat and
Gemma 4 chat with its bundle template, on macOS/iOS arm64 CPU and GPU and
the Android arm64, Linux x64/arm64 and Windows x64 CPU, pass the
Gemma 4 chat with its bundle template, on macOS/iOS and Android arm64 CPU and GPU and
the Linux x64/arm64 and Windows x64 CPU, pass the
schema directly to LLGuidance after constructing the model's provider. The
schema must sit in the subset both LLGuidance and the GBNF converter enforce.
Gemma 4 may think first; Qwen3 must disable thinking. Tools, media, custom
Expand Down
2 changes: 1 addition & 1 deletion lib/src/backends/litert_lm/litert_lm_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const String _liteRtLmVideoUnsupportedMessage =
const _jsonSchemaQualifiedBackendsByAbi = <Abi, Set<String>>{
Abi.macosArm64: {'cpu', 'gpu'},
Abi.iosArm64: {'cpu', 'gpu'},
Abi.androidArm64: {'cpu'},
Abi.androidArm64: {'cpu', 'gpu'},
Abi.linuxX64: {'cpu'},
Abi.linuxArm64: {'cpu'},
Abi.windowsX64: {'cpu'},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schema_version": 1,
"description": "Source-derived obligation inventory only. Public LiteRT-LM C API 1.0 activation has compiled-fixture default-client/service/speech dispatch, cancellation and reload controls in litert_lm_v1_public_qualification_test.dart; actual public rows bind chat-litert-cpu and reviewed ASR inputs separately. These model-free controls do not qualify artifacts, devices or new capability families; adoption remains https://github.com/leehack/llamadart/issues/1677. Existing pack bindings do not assert execution, platform/backend qualification or completeness of every semantic branch. Exemptions remain open work. Native LiteRT-LM catalog 10 S01 records capability admission only; the maintained litert-lm-json-schema local scenario supplies per-model (Qwen3-0.6B, Gemma 4 E2B) CPU and GPU enforcement, schema-contract and Gemma 4 thinking evidence on each qualified host. Validation-pack qualification of the widened contract and of non-macOS hosts remains https://github.com/leehack/llamadart/issues/174.",
"description": "Source-derived obligation inventory only. Public LiteRT-LM C API 1.0 activation has compiled-fixture default-client/service/speech dispatch, cancellation and reload controls in litert_lm_v1_public_qualification_test.dart; actual public rows bind chat-litert-cpu and reviewed ASR inputs separately. These model-free controls do not qualify artifacts, devices or new capability families; adoption remains https://github.com/leehack/llamadart/issues/1677. Existing pack bindings do not assert execution, platform/backend qualification or completeness of every semantic branch. Exemptions remain open work. Native LiteRT-LM catalog 10 S01 records capability admission only; the maintained litert-lm-json-schema local scenario (and chat-app-litert-json-schema on Android devices) supplies per-model (Qwen3-0.6B, Gemma 4 E2B) CPU and GPU enforcement, schema-contract and Gemma 4 thinking evidence on each qualified host, now including Android arm64 CPU and GPU on a Galaxy S24 and a Pixel 9 Pro, run by chat-app-litert-json-schema. Validation-pack qualification of the widened contract and of non-macOS hosts remains https://github.com/leehack/llamadart/issues/174.",
"packs": [
{
"id": "batching",
Expand Down
4 changes: 2 additions & 2 deletions skills/llamadart-chat-streaming/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ modalities and speculative strategies before offering them.
`engine.createStructuredJson`; it constrains decoding and validates the
final output. Native LiteRT-LM supports Qwen3 (canonical text template) and
Gemma 4 (bundle template) on macOS/iOS arm64 CPU and GPU (Gemma 4 cannot
create an iOS GPU engine; on Android load with `ComputeDevice.cpu`) and the
Android arm64, Linux x64/arm64 and Windows x64 CPU after provider admission (other
create an iOS GPU engine) and the Android arm64 CPU and GPU, and the
Linux x64/arm64 and Windows x64 CPU after provider admission (other
hosts, accelerators and NPU throw; per-host model evidence is in the
structured-output guide), for schemas that both the GBNF converter and LiteRT-LM's
LLGuidance enforce (nested objects, arrays, `$ref`, `anyOf`, anchored
Expand Down
74 changes: 67 additions & 7 deletions test/unit/backends/litert_lm/litert_lm_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,22 @@ void main() {
Future<void> expectRefused(
String backend, {
bool beforeEngine = true,
String? hint,
}) async {
await expectLater(
service.prepareJsonSchemaChat(),
throwsA(
isA<LlamaUnsupportedException>().having(
(e) => e.message,
'message',
contains('not qualified for the LiteRT-LM $backend'),
),
isA<LlamaUnsupportedException>()
.having(
(e) => e.message,
'message',
contains('not qualified for the LiteRT-LM $backend'),
)
.having(
(e) => e.message,
'hint',
hint == null ? anything : contains(hint),
),
),
);
expect(client.createConversationCount, 0);
Expand All @@ -195,7 +202,7 @@ void main() {
const expected = <Abi, Set<String>>{
Abi.macosArm64: {'cpu', 'gpu'},
Abi.iosArm64: {'cpu', 'gpu'},
Abi.androidArm64: {'cpu'},
Abi.androidArm64: {'cpu', 'gpu'},
Abi.androidX64: {},
Abi.linuxX64: {'cpu'},
Abi.linuxArm64: {'cpu'},
Expand Down Expand Up @@ -233,7 +240,7 @@ void main() {
);
}
}
for (final abi in [Abi.linuxX64, Abi.windowsX64, Abi.androidArm64]) {
for (final abi in [Abi.linuxX64, Abi.windowsX64]) {
test(
'refuses the deprecated gpu backend override on $abi',
skip: hostHasGpu ? null : 'needs a host with a LiteRT-LM GPU backend',
Expand Down Expand Up @@ -274,6 +281,59 @@ void main() {
expect(client.lastBackend, 'cpu');
},
);
for (final fallsBack in [false, true]) {
test(
'admits an automatic load on androidArm64 that '
'${fallsBack ? 'falls back to the CPU' : 'runs on the GPU'}',
skip: liteRtLmDefaultNativeBackendForCurrentPlatform() == 'gpu'
? null
: 'needs a host whose automatic LiteRT-LM backend is the GPU',
() async {
final gpu = _FakeLiteRtLmRuntimeClient(
initializeError: fallsBack
? LiteRtLmEngineCreateError('delegate init failed.')
: null,
)..jsonSchemaSupport = true;
final cpu = _FakeLiteRtLmRuntimeClient()..jsonSchemaSupport = true;
final clients = [gpu, if (fallsBack) cpu];
var next = 0;
service.dispose();
service = LiteRtLmService(
clientFactory: () => clients[next++],
probeGpuAdapters: () => hardwareGpu,
useTempCacheDir: false,
);
await service.loadModel(
'${tempDir.path}/Qwen3-0.6B.litertlm',
const ModelParams(),
);
debugLiteRtLmAbiOverride = Abi.androidArm64;
await service.prepareJsonSchemaChat();
final active = fallsBack ? cpu : gpu;
expect(active.lastBackend, fallsBack ? 'cpu' : 'gpu');
expect(active.lastJsonSchemaConfig, isTrue);
for (final c in clients) {
final unused = c.generated.stream.drain<void>();
await c.generated.close();
await unused;
}
},
);
}
test(
'names the qualified devices in a refusal',
skip: hostHasGpu ? null : 'needs a host with a LiteRT-LM GPU backend',
() async {
service.dispose();
service = tableService();
await service.loadModel(
'${tempDir.path}/Qwen3-0.6B.litertlm',
const ModelParams(liteRtLmBackend: LiteRtLmBackendPreference.gpu),
);
debugLiteRtLmAbiOverride = Abi.linuxX64;
await expectRefused('gpu', hint: '; load with ComputeDevice.cpu.');
},
);
test('a reload repeats admission', () async {
service.dispose();
service = tableService();
Expand Down
1 change: 1 addition & 0 deletions website/docs/changelog/recent-releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ validate against the exact release tag notes.
- Fixed Android LiteRT-LM GPU generation failing with "Can not find OpenCL library on this device" when the app does not declare `libOpenCL.so` or the device has no loadable OpenCL: the runtime (`v0.19.1-5`) links the WebGPU sampler again. Affects 0.18.0 through 0.19.9 on Android ([#1998](https://github.com/leehack/llamadart/issues/1998)).
- Aligned default WebGPU bridge assets to `v0.1.85`: a page without cross-origin isolation now fails at once with a `LlamaUnsupportedException` naming COOP/COEP `require-corp` instead of waiting minutes for a generic init timeout, and Firefox CPU runs (`gpuLayers: 0`) no longer create the WebGPU backend (stories15M, 32 tokens: 640 to 762 tok/s against 10 before) ([#1025](https://github.com/leehack/llamadart/issues/1025)).
- `ComputeDevice.gpu` on Web now names why WebGPU was not used (for example `adapter_missing_shader_f16`: Chrome on Linux with NVIDIA needs driver 615.71 or newer); documented the measured Safari 27, Firefox 160 and NVIDIA L4 results ([#1025](https://github.com/leehack/llamadart/issues/1025)).
- Native LiteRT-LM strict `responseFormat` now also runs on the Android arm64 GPU, through OpenCL on a Galaxy S24 and a Pixel 9 Pro with Qwen3 and Gemma 4; `ComputeDevice.auto` on Android no longer needs `ComputeDevice.cpu` for it ([#174](https://github.com/leehack/llamadart/issues/174)).

Runtime baseline: native llama.cpp `v0.9.0` and Web use upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`; native LiteRT-LM uses `v0.19.1-5` and stable-diffusion uses `v0.3.0-3`. Web LiteRT-LM uses `@litert-lm/core@0.19.0`. Manifest SHA-256: `6767783edd85e14853a8a79cd6ce53d53f4eb2d99aeb62601014bd68c1b6b7b3`.

Expand Down
3 changes: 2 additions & 1 deletion website/docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ This enables library discovery, not model/device qualification. A GPU engine
can still fail because of driver or buffer limits. `ComputeDevice.auto`
retries on the CPU with a warning; `ComputeDevice.gpu` fails instead. Check
the active backend and [Android limitations](../platforms/known-platform-issues#android)
before reporting GPU acceleration.
before reporting GPU acceleration. Strict `responseFormat` is admitted on the
Android arm64 GPU as well as the CPU.

## Web

Expand Down
5 changes: 3 additions & 2 deletions website/docs/guides/generation-and-streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,12 @@ macOS x64 and LiteRT-LM Web, refuses it before loading an engine.
| --- | --- | --- |
| macOS arm64 | CPU, GPU | Qwen3 and Gemma 4, CPU and GPU |
| iOS arm64 | CPU, GPU | Simulator only: Qwen3 CPU and GPU, Gemma 4 CPU; Gemma 4 cannot create a GPU engine there |
| Android arm64 | CPU | Emulator only: Qwen3 CPU; Gemma 4 not yet run |
| Android arm64 | CPU, GPU | Galaxy S24 and Pixel 9 Pro: Qwen3 and Gemma 4, CPU and GPU (OpenCL); Gemma 4 GPU also on the S24's WebGPU route |
| Linux x64, Linux arm64, Windows x64 | CPU | Qwen3 and Gemma 4, CPU |

On Android, `ComputeDevice.auto` resolves to the GPU, which strict output
refuses; load with `ComputeDevice.cpu` there.
now admits. An engine that fails to start on the GPU retries on the CPU, which
it also admits.

Native LiteRT-LM accepts only schemas that both the GBNF converter above and
LiteRT-LM's LLGuidance provider enforce alike, so every schema it accepts is
Expand Down
Loading
Loading