From a9c83d50227400d50e146130e10ce01cdbb9a15b Mon Sep 17 00:00:00 2001 From: leehack Date: Sat, 14 Nov 2026 04:15:52 -0500 Subject: [PATCH 1/2] Admit LiteRT-LM strict JSON Schema on the Android arm64 GPU (#174) Galaxy S24 and Pixel 9 Pro runs of Qwen3 and Gemma 4 passed on the CPU and, through OpenCL, the GPU. Updates the admission table, tests, docs, skill, coverage registry and changelogs. --- CHANGELOG.md | 1 + README.md | 2 +- doc/cross_platform_validation.md | 54 +++++++++++++++++++ doc/litert_lm_templates.md | 4 +- .../backends/litert_lm/litert_lm_service.dart | 2 +- .../assets/capability_coverage.json | 2 +- skills/llamadart-chat-streaming/SKILL.md | 4 +- .../litert_lm/litert_lm_service_test.dart | 4 +- website/docs/changelog/recent-releases.md | 1 + website/docs/getting-started/installation.md | 3 +- .../docs/guides/generation-and-streaming.md | 5 +- .../docs/maintainers/feature-validation.md | 5 ++ .../docs/platforms/known-platform-issues.md | 6 +++ website/docs/platforms/support-matrix.md | 2 +- 14 files changed, 82 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de1772e88..ee5484ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. 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`. diff --git a/README.md b/README.md index 262a66591..f89218132 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/doc/cross_platform_validation.md b/doc/cross_platform_validation.md index 8ea0852bd..0cab401ef 100644 --- a/doc/cross_platform_validation.md +++ b/doc/cross_platform_validation.md @@ -1601,6 +1601,60 @@ 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 `plan-174-verify-run-v2.py`: 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, built from clean `8b02e858` (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. + +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 and no WebGPU run. +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 diff --git a/doc/litert_lm_templates.md b/doc/litert_lm_templates.md index 9fbf69c86..327a6f8e3 100644 --- a/doc/litert_lm_templates.md +++ b/doc/litert_lm_templates.md @@ -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 diff --git a/lib/src/backends/litert_lm/litert_lm_service.dart b/lib/src/backends/litert_lm/litert_lm_service.dart index 378ac9a28..779e5d2fc 100644 --- a/lib/src/backends/litert_lm/litert_lm_service.dart +++ b/lib/src/backends/litert_lm/litert_lm_service.dart @@ -64,7 +64,7 @@ const String _liteRtLmVideoUnsupportedMessage = const _jsonSchemaQualifiedBackendsByAbi = >{ Abi.macosArm64: {'cpu', 'gpu'}, Abi.iosArm64: {'cpu', 'gpu'}, - Abi.androidArm64: {'cpu'}, + Abi.androidArm64: {'cpu', 'gpu'}, Abi.linuxX64: {'cpu'}, Abi.linuxArm64: {'cpu'}, Abi.windowsX64: {'cpu'}, diff --git a/packages/llamadart_validation/assets/capability_coverage.json b/packages/llamadart_validation/assets/capability_coverage.json index 4d4e509a8..7e5852342 100644 --- a/packages/llamadart_validation/assets/capability_coverage.json +++ b/packages/llamadart_validation/assets/capability_coverage.json @@ -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 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. Validation-pack qualification of the widened contract and of non-macOS hosts remains https://github.com/leehack/llamadart/issues/174.", "packs": [ { "id": "batching", diff --git a/skills/llamadart-chat-streaming/SKILL.md b/skills/llamadart-chat-streaming/SKILL.md index c8251340a..0e1d204a0 100644 --- a/skills/llamadart-chat-streaming/SKILL.md +++ b/skills/llamadart-chat-streaming/SKILL.md @@ -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 diff --git a/test/unit/backends/litert_lm/litert_lm_service_test.dart b/test/unit/backends/litert_lm/litert_lm_service_test.dart index d317e33fb..776a57753 100644 --- a/test/unit/backends/litert_lm/litert_lm_service_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_service_test.dart @@ -195,7 +195,7 @@ void main() { const expected = >{ Abi.macosArm64: {'cpu', 'gpu'}, Abi.iosArm64: {'cpu', 'gpu'}, - Abi.androidArm64: {'cpu'}, + Abi.androidArm64: {'cpu', 'gpu'}, Abi.androidX64: {}, Abi.linuxX64: {'cpu'}, Abi.linuxArm64: {'cpu'}, @@ -233,7 +233,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', diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 0d860c095..0ebd2041f 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -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. 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`. diff --git a/website/docs/getting-started/installation.md b/website/docs/getting-started/installation.md index d109174d6..1b9fe6557 100644 --- a/website/docs/getting-started/installation.md +++ b/website/docs/getting-started/installation.md @@ -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 diff --git a/website/docs/guides/generation-and-streaming.md b/website/docs/guides/generation-and-streaming.md index 0c39102b0..86e29a751 100644 --- a/website/docs/guides/generation-and-streaming.md +++ b/website/docs/guides/generation-and-streaming.md @@ -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 diff --git a/website/docs/maintainers/feature-validation.md b/website/docs/maintainers/feature-validation.md index dc2fce9d8..31c3a32c9 100644 --- a/website/docs/maintainers/feature-validation.md +++ b/website/docs/maintainers/feature-validation.md @@ -69,6 +69,11 @@ Web adoption still need separate validation coverage, smoke commands and contribution notes for LiteRT-LM chat templates are in `doc/litert_lm_templates.md`. +Native strict JSON Schema output is qualified on Android arm64 CPU and GPU by +the `chat-app-litert-json-schema` scenario on a Galaxy S24 and a Pixel 9 Pro; +the run record is in +[`doc/cross_platform_validation.md`](https://github.com/leehack/llamadart/blob/main/doc/cross_platform_validation.md#android-arm64-strict-json-schema-on-cpu-and-gpu-2026-11-13). + ## Speech to text Qwen3-ASR 0.6B Q8_0 was validated on WAV up to 33 s, and on MP3 and FLAC diff --git a/website/docs/platforms/known-platform-issues.md b/website/docs/platforms/known-platform-issues.md index 086582c47..950771559 100644 --- a/website/docs/platforms/known-platform-issues.md +++ b/website/docs/platforms/known-platform-issues.md @@ -134,6 +134,12 @@ feature. For which runtime supports which feature, see the [#1677](https://github.com/leehack/llamadart/issues/1677). `ModelParams(device: ComputeDevice.cpu)` skips the GPU attempt. Gemma 4 E2B has separate GPU evidence; it does not qualify Qwen3. +- Strict `responseFormat` on the Android arm64 GPU passed on a Galaxy S24 + (Adreno 750) and a Pixel 9 Pro (Mali-G715) with Gemma 4 E2B and Qwen3-0.6B + through the OpenCL route the manifest request above enables, and on the S24 + with Gemma 4 through WebGPU. It inherits the limits above: a device whose + GPU engine cannot start fails under `ComputeDevice.gpu` and runs on the CPU + under `auto`. - Android NPU depends on the device SoC, the `.litertlm` bundle and the LiteRT dispatch libraries (`LiteRtLmModelParams.dispatchLibDir`). If native LiteRT-LM cannot create an NPU engine, use `cpu` or `gpu`. diff --git a/website/docs/platforms/support-matrix.md b/website/docs/platforms/support-matrix.md index a545533a2..47054556d 100644 --- a/website/docs/platforms/support-matrix.md +++ b/website/docs/platforms/support-matrix.md @@ -156,7 +156,7 @@ native and web. Model architecture support depends on the pinned runtime; see | Row split (`ModelSplitMode.row`) | Needs llama.cpp split buffer types, which no bundled backend provides; a load on a bundled GPU backend whose module loads (Metal, CUDA, HIP, Vulkan, OpenCL), with `GpuBackend.blas` or `GpuBackend.cpu`, with `auto` on Android, the iOS simulator and macOS x86_64 (which runs on the CPU), or that falls back to the CPU because the requested backend is missing or Vulkan is refused, throws `LlamaUnsupportedException` before the model loads, so use `ModelSplitMode.layer`; a bundled module that fails to load or finds no device loads row on the CPU instead ([#1576](https://github.com/leehack/llamadart/issues/1576)) | No | No | No | | Renamed legacy Qwen3 thinking switch | N/A: GGUF metadata | N/A: GGUF metadata | `chatTemplate: liteRtLmQwen3ChatTemplate`; requires native template setter | Canonical override throws at load: no template setter in `@litert-lm/core@0.19.0` | | Thinking budget | Text-only, without speculative decoding, when the native reasoning-budget export resolves | Text-only, with bridge assets whose `getCompletionCapabilities()` reports `thinkingBudget` ([llama-web-bridge#144](https://github.com/leehack/llama-web-bridge/pull/144)); otherwise rejected | Native chat, without speculative decoding, on bundles whose first response channel is a thinking channel (Gemma 4); bounds that channel only; `0` and `forcedMessage` rejected | No | -| Strict `responseFormat` | Yes | Yes, without tools | macOS arm64 CPU/GPU, iOS arm64 CPU/GPU (simulator runs; Gemma 4 GPU fails engine creation), Android arm64 CPU (emulator run with Qwen3 only; Gemma 4 admitted, not yet run), Linux x64/arm64 and Windows x64 CPU; every other host, GPU or NPU refused, admitted Qwen3 (canonical text template) or Gemma 4 (bundle template) model; the schema subset both GBNF and LLGuidance enforce (nested objects, arrays, `$ref`, `anyOf`, anchored patterns, `uuid`/`date` formats, bounds); thinking with Gemma 4 only; no tools/media/speculation/caller stops | No | +| Strict `responseFormat` | Yes | Yes, without tools | macOS arm64 CPU/GPU, iOS arm64 CPU/GPU (simulator runs; Gemma 4 GPU fails engine creation), Android arm64 CPU/GPU (Galaxy S24 and Pixel 9 Pro runs with Qwen3 and Gemma 4; the GPU through OpenCL), Linux x64/arm64 and Windows x64 CPU; every other host, GPU or NPU refused, admitted Qwen3 (canonical text template) or Gemma 4 (bundle template) model; the schema subset both GBNF and LLGuidance enforce (nested objects, arrays, `$ref`, `anyOf`, anchored patterns, `uuid`/`date` formats, bounds); thinking with Gemma 4 only; no tools/media/speculation/caller stops | No | | Lazy grammar | Yes | Yes when the loaded bridge reports `lazyGrammar`; otherwise first-token `root` only | No GBNF grammar | No GBNF grammar | | Presence penalty | Yes | With bridge assets whose `getCompletionCapabilities()` reports `presencePenalty` ([llama-web-bridge#140](https://github.com/leehack/llama-web-bridge/pull/140)); otherwise rejects a non-zero value | Yes, without speculative decoding; counts only tokens of the current send | No: rejects a non-zero value | | Min-P | Yes | With bridge assets whose `getCompletionCapabilities()` reports `minP` ([llama-web-bridge#140](https://github.com/leehack/llama-web-bridge/pull/140)); otherwise rejects a non-zero value | No: rejects a non-zero value | No: rejects a non-zero value | From 27b580e69b356b1230d5faec4520453f8a729804 Mon Sep 17 00:00:00 2001 From: leehack Date: Sat, 14 Nov 2026 04:59:17 -0500 Subject: [PATCH 2/2] Test automatic Android strict-output admission and close audit P3s (#174) Cover ComputeDevice.auto on the GPU and on a CPU fallback, the load-with hint in the refusal, and record Set B plus the CPU runtime version. --- CHANGELOG.md | 2 +- doc/cross_platform_validation.md | 25 +++++-- .../assets/capability_coverage.json | 2 +- .../litert_lm/litert_lm_service_test.dart | 70 +++++++++++++++++-- website/docs/changelog/recent-releases.md | 2 +- 5 files changed, 89 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee5484ff7..85b83da62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +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. +- 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`. diff --git a/doc/cross_platform_validation.md b/doc/cross_platform_validation.md index 0cab401ef..ef40251e6 100644 --- a/doc/cross_platform_validation.md +++ b/doc/cross_platform_validation.md @@ -1608,11 +1608,13 @@ 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 `plan-174-verify-run-v2.py`: adversarial control, sentinel, wide contract, +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, built from clean `8b02e858` (six runtime library hashes equal across +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 | @@ -1650,10 +1652,25 @@ 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 and no WebGPU run. -The runs cover one schema contract and two models, not every model or driver. +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 diff --git a/packages/llamadart_validation/assets/capability_coverage.json b/packages/llamadart_validation/assets/capability_coverage.json index 7e5852342..092251782 100644 --- a/packages/llamadart_validation/assets/capability_coverage.json +++ b/packages/llamadart_validation/assets/capability_coverage.json @@ -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, now including Android arm64 CPU and GPU on a Galaxy S24 and a Pixel 9 Pro. 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", diff --git a/test/unit/backends/litert_lm/litert_lm_service_test.dart b/test/unit/backends/litert_lm/litert_lm_service_test.dart index 776a57753..3d27a5968 100644 --- a/test/unit/backends/litert_lm/litert_lm_service_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_service_test.dart @@ -177,15 +177,22 @@ void main() { Future expectRefused( String backend, { bool beforeEngine = true, + String? hint, }) async { await expectLater( service.prepareJsonSchemaChat(), throwsA( - isA().having( - (e) => e.message, - 'message', - contains('not qualified for the LiteRT-LM $backend'), - ), + isA() + .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); @@ -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(); + 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(); diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 0ebd2041f..ae50bba07 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -17,7 +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. +- 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`.