From d2456becf1d96093ac3a7e7b09137d7fbbdf0ca6 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:34:07 -0500 Subject: [PATCH 1/9] Raise the Apple companions' Flutter floor to 3.38.6 (#1834) (#1841) Squash of #1841 at 345ada90b1bc315b16ac9819c5e60282f71bf48b against merge-base ec4bf4f89dc224296ec0c8e6201ff13a3339e51e. --- CHANGELOG.md | 1 + README.md | 2 +- example/chat_app/pubspec.lock | 2 +- packages/llamadart_litert_lm_flutter/pubspec.yaml | 2 +- packages/llamadart_llama_cpp_flutter/pubspec.yaml | 2 +- packages/llamadart_stable_diffusion_flutter/pubspec.yaml | 2 +- website/docs/changelog/recent-releases.md | 1 + website/docs/getting-started/installation.md | 2 +- 8 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 587e3a678..67df337c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). +- Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). ## 0.19.0 diff --git a/README.md b/README.md index d6c6e29f3..021bfe0fe 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ dart pub get flutter pub get ``` -Requirements: Dart SDK `>=3.10.7`; for Flutter apps, Flutter SDK `>=3.38.0`, +Requirements: Dart SDK `>=3.10.7`; for Flutter apps, Flutter SDK `>=3.38.6`, iOS deployment target `16.4` and macOS deployment target `14.0` or newer. Consumers need no local C++ toolchain: the package build hook resolves native runtime archives on first build or run. Windows and other per-platform notes: diff --git a/example/chat_app/pubspec.lock b/example/chat_app/pubspec.lock index 515b0d178..eabf42f1d 100644 --- a/example/chat_app/pubspec.lock +++ b/example/chat_app/pubspec.lock @@ -1097,4 +1097,4 @@ packages: version: "3.1.3" sdks: dart: ">=3.11.0-0 <4.0.0" - flutter: ">=3.38.4 <4.0.0" + flutter: ">=3.38.6 <4.0.0" diff --git a/packages/llamadart_litert_lm_flutter/pubspec.yaml b/packages/llamadart_litert_lm_flutter/pubspec.yaml index f1fac89a0..eb21c89d8 100644 --- a/packages/llamadart_litert_lm_flutter/pubspec.yaml +++ b/packages/llamadart_litert_lm_flutter/pubspec.yaml @@ -12,7 +12,7 @@ topics: environment: sdk: ^3.10.7 - flutter: ">=3.38.0" + flutter: ">=3.38.6" dependencies: flutter: diff --git a/packages/llamadart_llama_cpp_flutter/pubspec.yaml b/packages/llamadart_llama_cpp_flutter/pubspec.yaml index bfed72869..5375a41f5 100644 --- a/packages/llamadart_llama_cpp_flutter/pubspec.yaml +++ b/packages/llamadart_llama_cpp_flutter/pubspec.yaml @@ -12,7 +12,7 @@ topics: environment: sdk: ^3.10.7 - flutter: ">=3.38.0" + flutter: ">=3.38.6" dependencies: flutter: diff --git a/packages/llamadart_stable_diffusion_flutter/pubspec.yaml b/packages/llamadart_stable_diffusion_flutter/pubspec.yaml index e84a6b779..1d6859aa2 100644 --- a/packages/llamadart_stable_diffusion_flutter/pubspec.yaml +++ b/packages/llamadart_stable_diffusion_flutter/pubspec.yaml @@ -12,7 +12,7 @@ topics: environment: sdk: ^3.10.7 - flutter: ">=3.38.0" + flutter: ">=3.38.6" dependencies: flutter: diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index ee3a9944e..0d34d35b9 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -16,6 +16,7 @@ validate against the exact release tag notes. - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). +- Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). ## 0.19.0 diff --git a/website/docs/getting-started/installation.md b/website/docs/getting-started/installation.md index 9dfb42692..ee36c15b6 100644 --- a/website/docs/getting-started/installation.md +++ b/website/docs/getting-started/installation.md @@ -10,7 +10,7 @@ For Genkit or Flutter Edge AI integration setup, see ## Requirements - Dart SDK `>= 3.10.7` -- Flutter SDK `>= 3.38.0` (if you build Flutter apps) +- Flutter SDK `>= 3.38.6` (if you build Flutter apps) - Flutter iOS apps: deployment target `16.4` or newer - Flutter macOS apps: deployment target `14.0` or newer - Windows: nothing extra for llama.cpp and LiteRT-LM, which bundle the From 58c8e4021e1c14b525fdd3620c0ad8c774ca0c93 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:34:12 -0500 Subject: [PATCH 2/9] Explain which chat template LiteRT-LM bundles render (#1836) (#1842) Squash of #1842 at 278b8dba731d1d6b9e87aba8c5fadbf610338b7b against merge-base ec4bf4f89dc224296ec0c8e6201ff13a3339e51e. --- skills/llamadart-tool-calling/SKILL.md | 4 +++- website/docs/getting-started/model-families.md | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/skills/llamadart-tool-calling/SKILL.md b/skills/llamadart-tool-calling/SKILL.md index 639301fbf..85f5ac9f3 100644 --- a/skills/llamadart-tool-calling/SKILL.md +++ b/skills/llamadart-tool-calling/SKILL.md @@ -190,7 +190,9 @@ description: >- LiteRT-LM Qwen 3 text bundle the runtime renders that template, and from `v0.18.0` hands it each message's `content` as a list of `{"type": "text", "text": ...}` parts, so read both the string and the - list shape. + list shape. Other native `.litertlm` requests render the bundle's embedded + template, so `engine.chatTemplate(...)` shows only the file-name template + that drives parsing, not the exact prompt. - Gemma 2/3/3n and legacy Mistral templates retry a failed tool-result render with consecutive results as one user turn. A user message immediately after those results is appended with a newline on that retry. Stored history and diff --git a/website/docs/getting-started/model-families.md b/website/docs/getting-started/model-families.md index 74e47e607..d875bba43 100644 --- a/website/docs/getting-started/model-families.md +++ b/website/docs/getting-started/model-families.md @@ -15,9 +15,10 @@ model's chat template. (`tokenizer.chat_template`, or `tokenizer.chat_template.tool_use` when tools are passed) and detects its format from marker strings, in llama.cpp's priority order. It does not look at the model name or architecture. -- **`.litertlm`:** bundles do not expose their template, so llamadart picks - one from the file name: `gemma-4`, `gemma-3n`, `gemma-3`/`gemma-2`, `qwen3` - or `qwen2.5`. Set `ModelParams.chatTemplate` to override it. +- **`.litertlm`:** the native runtime does not expose the bundle's template, + so llamadart picks one from the file name (`gemma-4`, `gemma-3n`, + `gemma-3`/`gemma-2`, `qwen3` or `qwen2.5`) for format detection and output + parsing. Set `ModelParams.chatTemplate` to override it. - **No match:** the template renders as-is, with no tool-call or reasoning parsing. If you pass tools, llamadart adds a generic JSON tool-call instruction instead. @@ -25,6 +26,10 @@ model's chat template. To see what a model will receive, render the prompt with `engine.chatTemplate(...)`; see [Chat templates and output parsing](../guides/chat-template-and-parsing). +For native `.litertlm` this shows the file-name template, which the runtime +renders only for text-only requests to Qwen3 bundles. Every other request, +including Qwen3.5, Gemma and any request with media, renders the bundle's +embedded template, so the native prompt can differ. ## Evidence levels From 07c2a1d9e33f3437dd9868fb4ee1ea0f182e2ba9 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:34:20 -0500 Subject: [PATCH 3/9] Record LiteRT-LM thinking as N/A for bundle templates that cannot think (#1833) Squash of #1833 at eda933ead7a7d7f82c2439aff0bc24461aa5a652 against merge-base ec4bf4f89dc224296ec0c8e6201ff13a3339e51e. --- doc/testing_matrix.md | 6 +- .../litert_lm_chat_features_smoke_test.dart | 46 +++++++++++ test/unit/tooling/test_matrix_test.dart | 14 ++++ tool/litert_lm_chat_features_smoke.dart | 79 +++++++++++++++++-- tool/testing/test_matrix.dart | 4 +- .../docs/getting-started/model-families.md | 13 ++- 6 files changed, 153 insertions(+), 9 deletions(-) diff --git a/doc/testing_matrix.md b/doc/testing_matrix.md index 2947d60c0..8ae551cd6 100644 --- a/doc/testing_matrix.md +++ b/doc/testing_matrix.md @@ -762,7 +762,11 @@ files stay in its suite-owned temporary directory. Record source revision, runtime artifact identity and device with the result. This row qualifies image wiring, history and lifecycle for this model and CPU; it does not qualify audio, thinking, GPU or perceptual quality generally. The -independent `litert-lm-chat-features-smoke` retains its thinking oracle. +independent `litert-lm-chat-features-smoke` retains its thinking oracle. It +records the thinking row as `not_applicable` (with the reason) when the loaded +bundle's chat template never reads `enable_thinking` and always closes the +think block, as the Qwen3.5 `_int8`, `-VL_int8` and `_int8_gpu_composite_v0190` +bundles do. ### LiteRT-LM lifecycle regression diff --git a/test/unit/tooling/litert_lm_chat_features_smoke_test.dart b/test/unit/tooling/litert_lm_chat_features_smoke_test.dart index c81339ba1..f1dec3cc6 100644 --- a/test/unit/tooling/litert_lm_chat_features_smoke_test.dart +++ b/test/unit/tooling/litert_lm_chat_features_smoke_test.dart @@ -196,6 +196,52 @@ void main() { }, ); + group('thinkingSupportForTemplate', () { + const closedAlways = + '{%- if m.role == "assistant" %}\n\n\n\n{% endif -%}' + '{%- if add_generation_prompt %}<|im_start|>assistant\n' + '\n\n\n\n{% endif -%}'; + const honoursSwitch = + '{%- if add_generation_prompt %}<|im_start|>assistant\n' + '{%- if enable_thinking is defined and enable_thinking is false %}' + '\n\n\n\n{%- else %}\n{%- endif %}' + '{% endif -%}'; + + test('reports a template that always closes the think block as N/A', () { + final support = smoke.thinkingSupportForTemplate(closedAlways); + expect(support.canProduceThinking, isFalse); + expect(support.reason, contains('enable_thinking')); + }); + + test('keeps the assertion for a template that reads enable_thinking', () { + expect( + smoke.thinkingSupportForTemplate(honoursSwitch).canProduceThinking, + isTrue, + ); + }); + + test('keeps the assertion when only history closes the think block', () { + const openInPrompt = + '{%- if m.role == "assistant" %}\n\n\n\n{% endif -%}' + '{%- if add_generation_prompt %}<|im_start|>assistant\n\n' + '{% endif -%}'; + expect( + smoke.thinkingSupportForTemplate(openInPrompt).canProduceThinking, + isTrue, + ); + }); + + test('keeps the assertion without a readable or closed-think template', () { + expect(smoke.thinkingSupportForTemplate(null).canProduceThinking, isTrue); + expect( + smoke + .thinkingSupportForTemplate('<|im_start|>assistant\n\n') + .canProduceThinking, + isTrue, + ); + }); + }); + test('prints usage and exits 64 without a model path', () async { final smoke = await compileDartScript( 'tool/litert_lm_chat_features_smoke.dart', diff --git a/test/unit/tooling/test_matrix_test.dart b/test/unit/tooling/test_matrix_test.dart index e332cc5f5..926fc83c5 100644 --- a/test/unit/tooling/test_matrix_test.dart +++ b/test/unit/tooling/test_matrix_test.dart @@ -560,6 +560,20 @@ void main() { }, ); + test('documents the LiteRT-LM chat smoke thinking N/A', () { + final row = testMatrixRows.singleWhere( + (row) => row.id == 'litert-lm-chat-features-smoke', + ); + + expect( + row.covers.replaceAll(RegExp(r'\s+'), ' '), + contains( + 'not_applicable with a reason when the bundle template always ' + 'closes the think block, as for the Qwen3.5 int8 bundles', + ), + ); + }); + test('includes targeted local model smoke rows', () { final ids = testMatrixRows.map((row) => row.id).toSet(); diff --git a/tool/litert_lm_chat_features_smoke.dart b/tool/litert_lm_chat_features_smoke.dart index 0e9abd54c..5a2f548f7 100644 --- a/tool/litert_lm_chat_features_smoke.dart +++ b/tool/litert_lm_chat_features_smoke.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:llamadart/backend.dart'; import 'package:llamadart/llamadart.dart'; +import 'package:llamadart/src/backends/litert_lm/litert_lm_bundle_template.dart'; import 'audio_chat_smoke_support.dart'; import 'litert_lm_tokenizer_fixture.dart'; @@ -83,6 +84,9 @@ Future main(List args) async { ); final toolLoopCutoff = await _runToolLoopCutoffScenario(engine); + final thinkingSupport = thinkingSupportForTemplate( + readLiteRtLmBundleChatTemplate(modelPath), + ); final thinking = await _runScenario( engine: engine, messages: const [ @@ -229,7 +233,13 @@ Future main(List args) async { 'plain': plain.toJson(), 'cutoff': cutoff.toJson(), 'toolLoopCutoff': toolLoopCutoff, - 'thinking': thinking.toJson(), + 'thinking': { + if (!thinkingSupport.canProduceThinking) ...{ + 'status': 'not_applicable', + 'reason': thinkingSupport.reason, + }, + ...thinking.toJson(), + }, 'textHistory': textHistory.toJson(), 'sessionStructuredOutput': sessionStructuredOutput, 'toolCall': toolCall.toJson(), @@ -254,6 +264,7 @@ Future main(List args) async { plain: plain, cutoff: cutoff, thinking: thinking, + thinkingSupport: thinkingSupport, textHistory: textHistory, toolCall: toolCall, requiredUnsupportedExpected: requiredUnsupportedExpected, @@ -331,10 +342,45 @@ Future> runSessionStructuredOutputScenario( return result; } +/// Whether the chat template a loaded bundle renders can produce thinking. +class ThinkingSupport { + const ThinkingSupport.supported() : canProduceThinking = true, reason = null; + + const ThinkingSupport.unsupported(String this.reason) + : canProduceThinking = false; + + final bool canProduceThinking; + final String? reason; +} + +final RegExp _closedThinkBlock = RegExp(r'\s*'); + +/// Judges [template], the chat template embedded in a loaded bundle. +/// +/// A heuristic for the known always-closed shape: a template that never +/// mentions `enable_thinking` and closes an empty think block in its generation +/// prompt is treated as unable to think. Any other template, or an unreadable +/// one, keeps the thinking assertion. +ThinkingSupport thinkingSupportForTemplate(String? template) { + final generationStart = template?.lastIndexOf('add_generation_prompt') ?? -1; + if (template == null || + generationStart < 0 || + template.contains('enable_thinking') || + !_closedThinkBlock.hasMatch(template.substring(generationStart))) { + return const ThinkingSupport.supported(); + } + return const ThinkingSupport.unsupported( + 'the bundle chat template never reads enable_thinking and its generation ' + 'prompt always closes an empty block, so it cannot ' + 'produce thinking', + ); +} + void _verifyResult({ required _ScenarioResult plain, required _ScenarioResult cutoff, required _ScenarioResult thinking, + required ThinkingSupport thinkingSupport, required _ScenarioResult textHistory, required _RequiredToolScenarioResult toolCall, required bool requiredUnsupportedExpected, @@ -365,11 +411,32 @@ void _verifyResult({ '${cutoff.finishReason}, not length.', ); } - if (thinking.thinking.trim().isEmpty) { - throw StateError('LiteRT-LM thinking scenario produced no thinking delta.'); - } - if (thinking.content.trim().isEmpty) { - throw StateError('LiteRT-LM thinking scenario produced no visible answer.'); + if (thinkingSupport.canProduceThinking) { + if (thinking.thinking.trim().isEmpty) { + throw StateError( + 'LiteRT-LM thinking scenario produced no thinking delta.', + ); + } + if (thinking.content.trim().isEmpty) { + throw StateError( + 'LiteRT-LM thinking scenario produced no visible answer.', + ); + } + } else { + if (thinking.thinking.trim().isNotEmpty) { + throw StateError( + 'LiteRT-LM thinking scenario produced a thinking delta although its ' + 'template cannot think.', + ); + } + if (thinking.content.trim().isEmpty) { + throw StateError( + 'LiteRT-LM thinking scenario produced no visible answer.', + ); + } + stdout.writeln( + 'N/A litert_lm_chat_features thinking: ${thinkingSupport.reason}', + ); } if (!textHistory.content.contains('PINE') || textHistory.thinking.isNotEmpty || diff --git a/tool/testing/test_matrix.dart b/tool/testing/test_matrix.dart index 6cd9fce82..f35eff45c 100644 --- a/tool/testing/test_matrix.dart +++ b/tool/testing/test_matrix.dart @@ -1285,7 +1285,9 @@ const List testMatrixRows = [ covers: 'real .litertlm chat, stop and maxTokens length finish reasons, an ' 'automatic tool loop cut off at maxTokens, thinking channel ' - 'reassembly, streaming tool calls, and optional byte-backed audio ' + 'reassembly (reported not_applicable with a reason when the bundle ' + 'template always closes the think block, as for the Qwen3.5 int8 ' + 'bundles), streaming tool calls, and optional byte-backed audio ' 'question answering with an exact expected answer', command: 'dart run tool/testing/run_local_e2e.dart --scenario ' diff --git a/website/docs/getting-started/model-families.md b/website/docs/getting-started/model-families.md index d875bba43..8742ed56c 100644 --- a/website/docs/getting-started/model-families.md +++ b/website/docs/getting-started/model-families.md @@ -43,7 +43,7 @@ embedded template, so the native prompt can differ. | Family | Artifacts | Detected format | Evidence | Example repo | | --- | --- | --- | --- | --- | -| Qwen3.5 | GGUF, `.litertlm` | Qwen3-Coder XML (GGUF); Qwen3 template (`.litertlm`) | Validated: GGUF on CPU, Metal, CUDA, Vulkan and WebGPU; LiteRT-LM on CPU and GPU | `ggml-org/Qwen3.5-0.8B-GGUF`, `litert-community/Qwen3.5-0.8B` | +| Qwen3.5 | GGUF, `.litertlm` | Qwen3-Coder XML (GGUF); bundle's own template (`.litertlm`) | Validated: GGUF on CPU, Metal, CUDA, Vulkan and WebGPU; LiteRT-LM on CPU and GPU (no thinking, see below) | `ggml-org/Qwen3.5-0.8B-GGUF`, `litert-community/Qwen3.5-0.8B` | | Gemma 4 | GGUF, `.litertlm` | Gemma 4 | Validated: GGUF and LiteRT-LM | `unsloth/gemma-4-E2B-it-GGUF`, `litert-community/gemma-4-E2B-it-litert-lm` | | Qwen3 | GGUF, `.litertlm` | Hermes | Validated: LiteRT-LM. Template-tested: GGUF | `litert-community/Qwen3-0.6B` | | Gemma 3, 3n, 2 | GGUF, `.litertlm` | Gemma (generic JSON tool calls) | Validated: LiteRT-LM. Template-tested: GGUF | `litert-community/Gemma3-1B-IT` | @@ -81,6 +81,17 @@ thought channel or Mistral's `[THINK]`, the parser returns reasoning separately from the reply. See [Text generation and streaming](../guides/generation-and-streaming). +Qwen3.5 `.litertlm` bundles render their own embedded chat template +([#1134](https://github.com/leehack/llamadart/issues/1134)), so +`ModelParams.chatTemplate` is ignored for these files. The +`Qwen3.5-0.8B_int8`, `Qwen3.5-0.8B-VL_int8` and +`Qwen3.5-0.8B_int8_gpu_composite_v0190` bundles (LiteRT-LM 0.19 and earlier) +close an empty `` block in the generation prompt and never read +`enable_thinking`, so `enableThinking: true` produces no reasoning there. The +`Qwen3.5-0.8B_dynamic_wi8_afp32` bundle reads `enable_thinking` but needs +LiteRT-LM 0.20.0 or later, so it fails on the pinned 0.19.1 runtime. Use the +GGUF for Qwen3.5 thinking; Qwen3 and Gemma 4 `.litertlm` bundles support it. + ## Vision and audio GGUF vision and audio need a matching projector (`mmproj`) file. Gemma 4 E2B From 99ece415dd3168cdcc023ff946e8d524647ab86b Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:34:21 -0500 Subject: [PATCH 4/9] Pin Windows pending-delete removal for remove and prune (#1837) (#1839) Squash of #1839 at 403835bb120abce840b06c979d17f0cc95997a51 against merge-base b78008cf31fbf6c967e1cc5bf2c557764c2072d3. --- .../io/model_download_manager_io.dart | 7 ++- ..._download_manager_io_concurrency_test.dart | 5 +- ...odel_download_manager_io_removal_test.dart | 48 ++++++++++++++++--- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lib/src/platform/io/model_download_manager_io.dart b/lib/src/platform/io/model_download_manager_io.dart index 1376513ce..c5eb430ba 100644 --- a/lib/src/platform/io/model_download_manager_io.dart +++ b/lib/src/platform/io/model_download_manager_io.dart @@ -798,6 +798,10 @@ class DefaultModelDownloadManager implements ModelDownloadManager { } } + // A path whose resolution is denied (errno 5) and whose type also reads as + // `notFound` (for example a parent ACL denial) is walked past like a missing + // one. The operation then fails later, as an access denial on create or + // write, or a cache miss for cacheOnly; it never reports success. String _cacheLockKey(Directory cacheDirectory) { var ancestor = path.normalize(path.absolute(cacheDirectory.path)); final missing = []; @@ -1861,7 +1865,8 @@ enum _Removal { removed, inUse, skipped } /// with `ERROR_ACCESS_DENIED`, and so does the attribute query behind /// [FileSystemEntity.type], which reports that failure as /// [FileSystemEntityType.notFound]; callers tell it from a real denial by -/// that type. +/// that type. A different ACL denial can read as `notFound` too; see +/// `_cacheLockKey` for what happens then. bool _mayBeWindowsDeletePending(FileSystemException error) => Platform.isWindows && error.osError?.errorCode == 5; diff --git a/test/unit/platform/io/model_download_manager_io_concurrency_test.dart b/test/unit/platform/io/model_download_manager_io_concurrency_test.dart index 99022b5ed..b2930f12c 100644 --- a/test/unit/platform/io/model_download_manager_io_concurrency_test.dart +++ b/test/unit/platform/io/model_download_manager_io_concurrency_test.dart @@ -35,7 +35,10 @@ void main() { }); setUp(() async { - root = await Directory.systemTemp.createTemp('llamadart_cache_lock_'); + final created = await Directory.systemTemp.createTemp( + 'llamadart_cache_lock_', + ); + root = Directory(await created.resolveSymbolicLinks()); addTearDown(() => root.delete(recursive: true)); server = await _HoldingServer.start(); addTearDown(server.close); diff --git a/test/unit/platform/io/model_download_manager_io_removal_test.dart b/test/unit/platform/io/model_download_manager_io_removal_test.dart index 8f866ee6d..912edffc9 100644 --- a/test/unit/platform/io/model_download_manager_io_removal_test.dart +++ b/test/unit/platform/io/model_download_manager_io_removal_test.dart @@ -136,13 +136,15 @@ void main() { return finishDelete; } - Future clear() => - IOOverrides.runWithIOOverrides(manager.clear, overrides); + Future withOverrides(Future Function() body) => + IOOverrides.runWithIOOverrides(body, overrides); - /// Starts [clear] and holds it at the removal lock, after it has checked - /// the entry, until the returned function runs. + Future clear() => withOverrides(manager.clear); + + /// Starts [operation] and holds it at the removal lock, after it has + /// checked the entry, until the returned function runs. Future<({Future clearing, void Function() proceed})> - clearHeldAtRemovalLock() async { + heldAtRemovalLock(Future Function() operation) async { final waiting = Completer(); final proceed = Completer(); modelCacheEntryLocker = (lockPath, {required throwIfCancelled}) async { @@ -163,15 +165,24 @@ void main() { } } - final clearing = clear(); + final clearing = withOverrides(operation); addTearDown(() async { release(); await clearing.then((_) {}, onError: (Object _) {}); }); - await waiting.future; + await waiting.future.timeout( + const Duration(seconds: 10), + onTimeout: () => throw StateError( + 'The operation never reached the .removal.lock: it no longer takes ' + 'the lock this test holds it at.', + ), + ); return (clearing: clearing, proceed: release); } + Future<({Future clearing, void Function() proceed})> + clearHeldAtRemovalLock() => heldAtRemovalLock(manager.clear); + void expectOnlyLocksLeftOnceDeleted(void Function() finishDelete) { finishDelete(); expect( @@ -212,6 +223,29 @@ void main() { expectOnlyLocksLeftOnceDeleted(finishDelete); }); + test('is skipped by remove when the deletion happens while it waits for ' + 'the removal lock', () async { + final cacheKey = (await manager.list()).single.cacheKey; + final held = await heldAtRemovalLock(() => manager.remove(cacheKey)); + final finishDelete = markPendingDelete(); + held.proceed(); + + await held.clearing; + expectOnlyLocksLeftOnceDeleted(finishDelete); + }); + + test('is skipped by prune when the deletion happens while it waits for ' + 'the removal lock', () async { + final held = await heldAtRemovalLock( + () => manager.prune(maxAge: Duration.zero), + ); + final finishDelete = markPendingDelete(); + held.proceed(); + + await held.clearing; + expectOnlyLocksLeftOnceDeleted(finishDelete); + }); + test('is not skipped when the entry still reads as a directory: clear ' 'reports the access denial', () async { markPendingDelete(); From e7547a2c800bd42508e25999c612de51f26a277d Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:34:21 -0500 Subject: [PATCH 5/9] Pin Chrome supervisor exit precedence and post-done wait (#1837 a-d) (#1840) Squash of #1840 at 73c66a089e1eb99053e61032bd000e429d1aa29d against merge-base ec4bf4f89dc224296ec0c8e6201ff13a3339e51e. --- test/ci/test_supervise_chrome_test.py | 128 +++++++++++++++++- .../tooling/chrome_test_supervisor_test.dart | 3 +- tool/ci/supervise_chrome_test.py | 12 +- 3 files changed, 136 insertions(+), 7 deletions(-) diff --git a/test/ci/test_supervise_chrome_test.py b/test/ci/test_supervise_chrome_test.py index 5d876b927..beb86c3f6 100644 --- a/test/ci/test_supervise_chrome_test.py +++ b/test/ci/test_supervise_chrome_test.py @@ -85,10 +85,11 @@ def setUp(self): self.addCleanup(self.temp.cleanup) self.output = Path(self.temp.name) / 'diagnostics' - def command(self, program, timeout=3, shutdown=0.25, reporter=False): - options = (['--reporter-file', str(self.reporter), '--post-done-seconds', '0.3'] + def command(self, program, timeout=3, shutdown=0.25, reporter=False, post_done=0.3, + script=SCRIPT): + options = (['--reporter-file', str(self.reporter), '--post-done-seconds', str(post_done)] if reporter else []) - return [sys.executable, str(SCRIPT), '--output-dir', str(self.output), + return [sys.executable, str(script), '--output-dir', str(self.output), '--timeout-seconds', str(timeout), '--shutdown-seconds', str(shutdown), '--cleanup-seconds', '0.5', '--snapshot-seconds', '0.1', *options, '--', sys.executable, '-c', program] @@ -111,8 +112,20 @@ def browser_then(self, done, browser_seconds, then): f"subprocess.Popen([{str(browser)!r}, '{browser_seconds}'])\n" f"{then}\n") - def run_fixture(self, program, **options): - result = subprocess.run(self.command(program, **options), + def patched_supervisor(self, patch): + """A launcher that runs the production supervisor with `patch(module)` applied.""" + launcher = Path(self.temp.name) / 'launcher.py' + launcher.write_text( + 'import importlib.util, sys\n' + f'spec = importlib.util.spec_from_file_location("supervisor", {str(SCRIPT)!r})\n' + 'module = importlib.util.module_from_spec(spec)\n' + 'spec.loader.exec_module(module)\n' + f'{patch}\n' + 'sys.exit(module.main())\n') + return launcher + + def run_fixture(self, program, script=SCRIPT, **options): + result = subprocess.run(self.command(program, script=script, **options), capture_output=True, timeout=8) return result, json.loads((self.output / 'result.json').read_text()) @@ -165,6 +178,44 @@ def test_caller_pipes_keep_their_blocking_mode_after_the_supervisor_exits(self): done = subprocess.run([sys.executable, '-c', script], capture_output=True, timeout=8) self.assertEqual(done.stdout.split()[-2:], [b'True', b'False'], done.stderr) + def test_stale_reporter_error_keeps_the_caller_stderr_blocking(self): + self.reporter.write_text('{"type":"done","success":true}\n') + script = ("import os,subprocess,sys\n" + f"subprocess.run({self.command('pass', reporter=True)!r}, stdout=sys.stdout, stderr=sys.stderr)\n" + "print(os.get_blocking(2))") + done = subprocess.run([sys.executable, '-c', script], capture_output=True, timeout=8) + self.assertEqual(done.stdout.split()[-1:], [b'True'], done.stderr) + + def test_stale_reporter_error_cannot_delay_or_change_the_exit(self): + self.reporter.write_text('{"type":"done","success":true}\n') + full_read, full_write = os.pipe() + os.set_blocking(full_write, False) + try: + while True: + os.write(full_write, b'x' * 65536) + except BlockingIOError: + pass + os.set_blocking(full_write, True) + broken_read, broken_write = os.pipe() + os.close(broken_read) + try: + for name, stderr in [('full pipe', full_write), ('broken pipe', broken_write)]: + with self.subTest(name): + child = subprocess.run(self.command('pass', reporter=True), + stdout=subprocess.DEVNULL, stderr=stderr, timeout=3) + self.assertEqual(child.returncode, 125) + finally: + for descriptor in (full_read, full_write, broken_write): + os.close(descriptor) + + def test_stale_reporter_error_survives_a_non_utf8_path(self): + self.reporter.parent.joinpath(os.fsdecode(b'bad\xff.jsonl')).write_text('{}\n') + command = self.command('pass', reporter=True) + command[command.index('--reporter-file') + 1] = str(self.reporter.parent / os.fsdecode(b'bad\xff.jsonl')) + child = subprocess.run(command, capture_output=True, timeout=3) + self.assertEqual(child.returncode, 125, child.stderr) + self.assertIn(b'bad\\udcff.jsonl', child.stderr) + def test_closed_stdout_cannot_redirect_the_echo_into_events(self): child = subprocess.run( self.command("print('echoed output')"), @@ -273,11 +324,70 @@ def test_reporter_result_never_replaces_a_real_cli_exit(self): self.assertTrue(result['reporter_success']) self.assert_clean(result) + def test_the_supervisor_waits_post_done_seconds_before_recovering(self): + child, result = self.run_fixture(self.browser_then( + {'type': 'done', 'success': True}, 0.05, 'import time; time.sleep(.5); raise SystemExit(7)'), + reporter=True, post_done=2, shutdown=1) + self.assertEqual(child.returncode, 7, child.stderr) + self.assertEqual(result['cli_exit_code'], 7) + self.assertFalse(result['browser_close_stall']) + self.assert_clean(result) + + def test_recovery_happens_no_earlier_than_post_done_seconds_after_done(self): + child, result = self.run_fixture(self.browser_then( + {'type': 'done', 'success': True}, 0.05, 'import time; time.sleep(5)'), + reporter=True, post_done=0.6) + self.assertEqual(child.returncode, 0, child.stderr) + self.assertTrue(result['browser_close_stall']) + at = {event['event']: event['elapsed_seconds'] for event in self.events()} + self.assertGreaterEqual(at['browser_close_stall'] - at['reporter_done'], 0.6) + + def test_leftover_owned_processes_after_a_recovered_stall_exit_125(self): + launcher = self.patched_supervisor('module.deliver = lambda row, number: False') + child, result = self.run_fixture(self.browser_then( + {'type': 'done', 'success': True}, 0.05, 'import time; time.sleep(2)'), + reporter=True, script=launcher) + self.assertEqual(child.returncode, 125, child.stderr) + self.assertTrue(result['browser_close_stall']) + self.assertNotEqual(result['owned_processes_remaining'], []) + self.assertFalse(result['passed']) + + def test_a_surviving_process_alone_fails_a_recovered_stall(self): + launcher = self.patched_supervisor('module.deliver = lambda row, number: False') + child, result = self.run_fixture(self.browser_then( + {'type': 'done', 'success': True}, 0.05, + 'import os,time; os.close(1); os.close(2); time.sleep(2)'), + reporter=True, script=launcher) + self.assertEqual(child.returncode, 125, child.stderr) + self.assertTrue(result['browser_close_stall']) + self.assertTrue(result['stdout_eof'] and result['stderr_eof']) + self.assertNotEqual(result['owned_processes_remaining'], []) + + def test_missing_output_eof_after_a_recovered_stall_exits_125(self): + lingerer = Path(self.temp.name) / 'lingerer' + lingerer.write_text(f'#!{sys.executable}\nimport sys,time; time.sleep(2)\n') + lingerer.chmod(0o755) + launcher = self.patched_supervisor( + 'table = module.process_table\n' + 'module.process_table = lambda: {pid: row for pid, row in table().items()\n' + " if row['comm'] != 'lingerer'}") + child, result = self.run_fixture(self.browser_then( + {'type': 'done', 'success': True}, 0.05, + f"subprocess.Popen([{str(lingerer)!r}]); import time; time.sleep(2)"), + reporter=True, script=launcher) + self.assertEqual(child.returncode, 125, child.stderr) + self.assertTrue(result['browser_close_stall']) + self.assertEqual(result['owned_processes_remaining'], []) + self.assertFalse(result['stdout_eof'] and result['stderr_eof']) + self.assertFalse(result['passed']) + def test_a_stale_reporter_file_does_not_start_the_command(self): self.reporter.write_text('{"type":"done","success":true}\n') child = subprocess.run(self.command('raise SystemExit(0)', reporter=True), capture_output=True, timeout=3) self.assertEqual(child.returncode, 125) + self.assertIn(str(self.reporter).encode(), child.stderr) + self.assertIn(b'Stale reporter file', child.stderr) self.assertFalse(self.output.exists()) def test_cli_exit_is_distinct_from_inherited_pipe_eof(self): @@ -402,6 +512,13 @@ def test_launch_error_keeps_evidence_without_the_secret_bearing_path(self): class WorkflowTest(unittest.TestCase): + def test_post_done_default_stays_thirty_seconds_for_every_workflow_caller(self): + source = SCRIPT.read_text() + self.assertIn("'--post-done-seconds', type=positive_seconds, default=30)", source) + self.assertIn('reporter_file=None, post_done=30)', source) + for workflow in (ROOT / '.github/workflows').glob('*.yml'): + self.assertNotIn('--post-done-seconds', workflow.read_text(), workflow.name) + def test_model_store_keeps_failure_gates_and_uploads_before_job_cancellation(self): workflow = (ROOT / '.github/workflows/ci.yml').read_text() lane = workflow.split('\n model-store:\n', 1)[1].split('\n analyze:\n', 1)[0] @@ -432,6 +549,7 @@ def test_web_chat_chrome_tests_take_only_their_own_reporter_result(self): step = lane[chrome:upload] self.assertIn('python3 ../../tool/ci/supervise_chrome_test.py', step) self.assertIn('--timeout-seconds 600 --', step) + self.assertNotIn('--post-done-seconds', step) report = '$RUNNER_TEMP/chat-app-chrome/reporter.jsonl' self.assertIn(f'--reporter-file "{report}"', step) self.assertIn(f'--file-reporter "json:{report}"', step) diff --git a/test/unit/tooling/chrome_test_supervisor_test.dart b/test/unit/tooling/chrome_test_supervisor_test.dart index d93a6db2c..151bfcf17 100644 --- a/test/unit/tooling/chrome_test_supervisor_test.dart +++ b/test/unit/tooling/chrome_test_supervisor_test.dart @@ -17,8 +17,9 @@ void main() { 'test/ci', '-p', 'test_supervise_chrome_test.py', - ], timeout: const Duration(seconds: 20)); + ], timeout: const Duration(seconds: 60)); expect(result.exitCode, 0, reason: '${result.stdout}\n${result.stderr}'); }, + timeout: const Timeout(Duration(seconds: 90)), ); } diff --git a/tool/ci/supervise_chrome_test.py b/tool/ci/supervise_chrome_test.py index 539029882..e3109ed00 100644 --- a/tool/ci/supervise_chrome_test.py +++ b/tool/ci/supervise_chrome_test.py @@ -119,6 +119,10 @@ def observe_exit(pid): else 128 + result.si_status) +class StaleReporterError(RuntimeError): + pass + + class ReporterEvents: """Incrementally reads a package:test JSON file reporter (`--file-reporter json:`).""" @@ -177,7 +181,8 @@ def supervise(command, output, timeout, shutdown, cleanup, snapshot_interval, raise RuntimeError('Cannot establish child subreaper') reserve_standard_descriptors() if reporter_file is not None and reporter_file.exists(): - raise RuntimeError('A stale reporter file would settle the result early') + raise StaleReporterError( + f'Stale reporter file {reporter_file} would settle the result early; remove it') output.mkdir(parents=True, exist_ok=False) started = time.monotonic() stopped = [] @@ -419,6 +424,11 @@ def main(): return supervise(command, args.output_dir, args.timeout_seconds, args.shutdown_seconds, args.cleanup_seconds, args.snapshot_seconds, args.reporter_file, args.post_done_seconds) + except StaleReporterError as error: + blocking = os.get_blocking(2) + echo('stderr', f'::error::{error}\n'.encode(errors='backslashreplace')) + os.set_blocking(2, blocking) + return 125 except Exception: # A stalled CI output pipe must not delay failure or process retirement. return 125 From 7b6523f32c8c57441257275efe47e7243512cf6a Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:34:34 -0500 Subject: [PATCH 6/9] Refuse LiteRT-LM GPU on Linux when every Vulkan device is software (#1831) Squash of #1831 at e51e76cbdef304939837c0e640e8d05372538302 against merge-base ec4bf4f89dc224296ec0c8e6201ff13a3339e51e. --- CHANGELOG.md | 1 + .../litert_lm/litert_lm_gpu_adapter.dart | 256 ++++++++++++++++++ .../backends/litert_lm/litert_lm_service.dart | 68 ++++- skills/llamadart-getting-started/SKILL.md | 2 + .../litert_lm/litert_lm_gpu_adapter_test.dart | 205 ++++++++++++++ .../litert_lm/litert_lm_service_test.dart | 228 ++++++++++++++++ website/docs/changelog/recent-releases.md | 1 + .../docs/platforms/known-platform-issues.md | 10 +- website/docs/platforms/support-matrix.md | 6 +- website/docs/troubleshooting/common-issues.md | 16 +- 10 files changed, 775 insertions(+), 18 deletions(-) create mode 100644 lib/src/backends/litert_lm/litert_lm_gpu_adapter.dart create mode 100644 test/unit/backends/litert_lm/litert_lm_gpu_adapter_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 67df337c5..4d2d5d16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). +- Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). - Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). diff --git a/lib/src/backends/litert_lm/litert_lm_gpu_adapter.dart b/lib/src/backends/litert_lm/litert_lm_gpu_adapter.dart new file mode 100644 index 000000000..eaf8e0be1 --- /dev/null +++ b/lib/src/backends/litert_lm/litert_lm_gpu_adapter.dart @@ -0,0 +1,256 @@ +import 'dart:convert'; +import 'dart:ffi'; + +import 'package:ffi/ffi.dart'; + +/// `VK_PHYSICAL_DEVICE_TYPE_CPU`: a software rasterizer such as Mesa +/// llvmpipe (lavapipe) or SwiftShader. +const int vulkanPhysicalDeviceTypeCpu = 4; + +const int _vkStructureTypeInstanceCreateInfo = 1; +const int _vkSuccess = 0; + +// sizeof(VkPhysicalDeviceProperties) is 824 on LP64; the extra room keeps a +// driver that writes a larger struct from overrunning the buffer. +const int _physicalDevicePropertiesBytes = 2048; +const int _deviceTypeOffset = 16; +const int _deviceNameOffset = 20; +const int _deviceNameCapacity = 256; + +/// One Vulkan physical device as the system Vulkan loader reports it. +final class LiteRtLmVulkanAdapter { + /// Creates the facts of the device called [name]. + const LiteRtLmVulkanAdapter({required this.name, required this.deviceType}); + + /// `VkPhysicalDeviceProperties.deviceName`. + final String name; + + /// `VkPhysicalDeviceProperties.deviceType`, a `VkPhysicalDeviceType`. + final int deviceType; + + /// Whether the device is a CPU (software) implementation. + bool get isSoftware => deviceType == vulkanPhysicalDeviceTypeCpu; +} + +/// The Vulkan devices LiteRT-LM's Linux GPU backend can choose from. +/// +/// That backend runs WebGPU (Dawn) on the system Vulkan loader and picks a +/// software adapter only when no hardware one is present. +final class LiteRtLmVulkanAdapters { + /// The loader listed [devices]. + const LiteRtLmVulkanAdapters.devices(List this.devices) + : unavailableReason = null; + + /// The devices could not be listed, for [unavailableReason]. + const LiteRtLmVulkanAdapters.unavailable(String this.unavailableReason) + : devices = null; + + /// The devices, or `null` when they are unknown. + final List? devices; + + /// Why [devices] is `null`. + final String? unavailableReason; + + /// The devices when every one is software, so the GPU backend can only + /// select a software adapter; otherwise `null`, including when no device + /// is listed or the probe was unavailable. + List? get softwareOnly { + final listed = devices; + if (listed == null || listed.isEmpty) return null; + return listed.every((device) => device.isSoftware) ? listed : null; + } +} + +typedef _CreateInstanceNative = + Int32 Function(Pointer, Pointer, Pointer>); +typedef _EnumeratePhysicalDevicesNative = + Int32 Function(Pointer, Pointer, Pointer>); +typedef _GetPhysicalDevicePropertiesNative = + Void Function(Pointer, Pointer); +typedef _DestroyInstanceNative = Void Function(Pointer, Pointer); + +final class _VkInstanceCreateInfo extends Struct { + @Uint32() + external int sType; + external Pointer pNext; + @Uint32() + external int flags; + external Pointer pApplicationInfo; + @Uint32() + external int enabledLayerCount; + external Pointer> ppEnabledLayerNames; + @Uint32() + external int enabledExtensionCount; + external Pointer> ppEnabledExtensionNames; +} + +/// The Vulkan 1.0 loader entry points the adapter probe calls. +final class LiteRtLmVulkanLoader { + /// Creates a loader from resolved functions. + const LiteRtLmVulkanLoader({ + required this.createInstance, + required this.enumeratePhysicalDevices, + required this.getPhysicalDeviceProperties, + required this.destroyInstance, + }); + + /// The Linux Vulkan loader's soname. + static const String libraryName = 'libvulkan.so.1'; + + /// Resolves the entry points from [libraryName], or returns `null` when it + /// cannot be opened or lacks one. [openLibrary] replaces + /// [DynamicLibrary.open]. + static LiteRtLmVulkanLoader? tryOpen({ + DynamicLibrary Function(String name)? openLibrary, + }) { + try { + final library = (openLibrary ?? DynamicLibrary.open)(libraryName); + return LiteRtLmVulkanLoader( + createInstance: library + .lookupFunction< + _CreateInstanceNative, + int Function(Pointer, Pointer, Pointer>) + >('vkCreateInstance'), + enumeratePhysicalDevices: library + .lookupFunction< + _EnumeratePhysicalDevicesNative, + int Function( + Pointer, + Pointer, + Pointer>, + ) + >('vkEnumeratePhysicalDevices'), + getPhysicalDeviceProperties: library + .lookupFunction< + _GetPhysicalDevicePropertiesNative, + void Function(Pointer, Pointer) + >('vkGetPhysicalDeviceProperties'), + destroyInstance: library + .lookupFunction< + _DestroyInstanceNative, + void Function(Pointer, Pointer) + >('vkDestroyInstance'), + ); + } on ArgumentError { + return null; + } + } + + /// `vkCreateInstance(createInfo, allocator, instance)`. + final int Function( + Pointer createInfo, + Pointer allocator, + Pointer> instance, + ) + createInstance; + + /// `vkEnumeratePhysicalDevices(instance, count, devices)`. + final int Function( + Pointer instance, + Pointer count, + Pointer> devices, + ) + enumeratePhysicalDevices; + + /// `vkGetPhysicalDeviceProperties(device, properties)`. + final void Function(Pointer device, Pointer properties) + getPhysicalDeviceProperties; + + /// `vkDestroyInstance(instance, allocator)`. + final void Function(Pointer instance, Pointer allocator) + destroyInstance; + + /// Lists the physical devices through a short-lived instance. + LiteRtLmVulkanAdapters listAdapters() { + final createInfo = calloc<_VkInstanceCreateInfo>(); + final instanceOut = calloc>(); + final count = calloc(); + try { + createInfo.ref.sType = _vkStructureTypeInstanceCreateInfo; + final created = createInstance(createInfo.cast(), nullptr, instanceOut); + if (created != _vkSuccess) { + return LiteRtLmVulkanAdapters.unavailable( + 'vkCreateInstance returned $created', + ); + } + final instance = instanceOut.value; + try { + return _listDevices(instance, count); + } finally { + destroyInstance(instance, nullptr); + } + } finally { + calloc.free(count); + calloc.free(instanceOut); + calloc.free(createInfo); + } + } + + LiteRtLmVulkanAdapters _listDevices( + Pointer instance, + Pointer count, + ) { + final counted = enumeratePhysicalDevices(instance, count, nullptr); + if (counted != _vkSuccess) { + return LiteRtLmVulkanAdapters.unavailable( + 'vkEnumeratePhysicalDevices returned $counted', + ); + } + if (count.value == 0) return const LiteRtLmVulkanAdapters.devices([]); + final handles = calloc>(count.value); + final properties = calloc(_physicalDevicePropertiesBytes); + try { + final listed = enumeratePhysicalDevices(instance, count, handles); + // VK_INCOMPLETE means more devices exist than were written; a partial + // list could look software-only, so it counts as unavailable. + if (listed != _vkSuccess) { + return LiteRtLmVulkanAdapters.unavailable( + 'vkEnumeratePhysicalDevices returned $listed', + ); + } + final devices = []; + for (var index = 0; index < count.value; index++) { + properties + .asTypedList(_physicalDevicePropertiesBytes) + .fillRange(0, _physicalDevicePropertiesBytes, 0); + getPhysicalDeviceProperties(handles[index], properties.cast()); + devices.add( + LiteRtLmVulkanAdapter( + name: _deviceName(properties + _deviceNameOffset), + deviceType: (properties + _deviceTypeOffset).cast().value, + ), + ); + } + return LiteRtLmVulkanAdapters.devices(List.unmodifiable(devices)); + } finally { + calloc.free(properties); + calloc.free(handles); + } + } +} + +String _deviceName(Pointer name) { + final bytes = name.asTypedList(_deviceNameCapacity); + final end = bytes.indexOf(0); + return utf8.decode( + bytes.sublist(0, end < 0 ? _deviceNameCapacity : end), + allowMalformed: true, + ); +} + +/// Lists the Vulkan devices of the system loader; unavailable when the +/// loader cannot be opened or queried. +/// +/// Listing loads the system's Vulkan drivers into the process, as the GPU +/// backend itself does, so probe only when that backend is about to start. +LiteRtLmVulkanAdapters probeLiteRtLmVulkanAdapters({ + DynamicLibrary Function(String name)? openLibrary, +}) { + final loader = LiteRtLmVulkanLoader.tryOpen(openLibrary: openLibrary); + return loader == null + ? const LiteRtLmVulkanAdapters.unavailable( + 'the Vulkan loader ${LiteRtLmVulkanLoader.libraryName} could not be ' + 'opened', + ) + : loader.listAdapters(); +} diff --git a/lib/src/backends/litert_lm/litert_lm_service.dart b/lib/src/backends/litert_lm/litert_lm_service.dart index 26aa86c46..795558ad4 100644 --- a/lib/src/backends/litert_lm/litert_lm_service.dart +++ b/lib/src/backends/litert_lm/litert_lm_service.dart @@ -28,6 +28,7 @@ import '../native/model_format_probe.dart'; import 'litert_lm_bundle_template.dart'; import 'litert_lm_cache.dart'; import 'litert_lm_embedding.dart'; +import 'litert_lm_gpu_adapter.dart'; import 'litert_lm_chat_template.dart'; import 'litert_lm_chat_templates.dart'; import 'litert_lm_model_link.dart'; @@ -38,6 +39,20 @@ import 'litert_lm_legacy_service_client.dart'; import 'litert_lm_sampler_params.dart'; const int _gemma4DefaultVisualTokenBudget = 280; + +// Probed once per isolate, on the first GPU load: each probe creates a Vulkan +// instance, and the installed drivers do not change while the process runs. +final LiteRtLmVulkanAdapters _systemVulkanAdapters = + probeLiteRtLmVulkanAdapters(); + +/// Test-only replacement for the system Vulkan loader probe that a Linux +/// service without injected clients runs before a GPU load. +LiteRtLmVulkanAdapters Function()? debugLiteRtLmSystemVulkanAdaptersOverride; + +LiteRtLmVulkanAdapters _systemVulkanAdaptersProbe() => + debugLiteRtLmSystemVulkanAdaptersOverride?.call() ?? _systemVulkanAdapters; + +bool _isLinuxAbi(Abi abi) => abi == Abi.linuxX64 || abi == Abi.linuxArm64; const String _liteRtLmVideoUnsupportedMessage = 'LiteRT-LM video input is not supported through llamadart. ' 'Extract and send image frames instead.'; @@ -103,6 +118,9 @@ class LiteRtLmService { /// [runtimeClientFactory] injects a version-specific internal client together /// with its metadata and finish-reason probes. It is exclusive with the legacy /// [clientFactory]; neither changes the production runtime selection. + /// [probeGpuAdapters] lists the Vulkan devices a GPU engine can use; by + /// default the system Vulkan loader on Linux when neither factory is + /// injected, and nothing otherwise. LiteRtLmService({ LiteRtLmRuntimeClient Function()? clientFactory, LiteRtLmRuntimeClientContract Function()? runtimeClientFactory, @@ -114,7 +132,15 @@ class LiteRtLmService { LiteRtLmBundleFirstChannelReader? readBundleFirstChannel, String? finishReasonProbeLibraryPath, bool Function()? jsonSchemaPlatformSupported, - }) : _jsonSchemaPlatformSupported = + LiteRtLmVulkanAdapters Function()? probeGpuAdapters, + }) : _probeGpuAdapters = + probeGpuAdapters ?? + (_isLinuxAbi(liteRtLmGateAbi()) && + clientFactory == null && + runtimeClientFactory == null + ? _systemVulkanAdaptersProbe + : null), + _jsonSchemaPlatformSupported = jsonSchemaPlatformSupported ?? (() => Platform.isMacOS && Abi.current() == Abi.macosArm64), _clientFactory = @@ -149,6 +175,7 @@ class LiteRtLmService { } final LiteRtLmRuntimeClientContract Function() _clientFactory; + final LiteRtLmVulkanAdapters Function()? _probeGpuAdapters; final LiteRtLmBundleCapabilitiesReader _readBundleCapabilities; final LiteRtLmBundleChatTemplateReader _readBundleChatTemplate; final LiteRtLmBundleFirstChannelReader _readBundleFirstChannel; @@ -254,6 +281,13 @@ class LiteRtLmService { params, backendOverride: backendOverride, ); + final automaticBackend = + params.device == ComputeDevice.auto && + params.liteRtLmBackend.nativeName == null && + normalizeLiteRtLmNativeBackendOverride(backendOverride) == null; + final engineBackend = resolvedBackend == liteRtLmGpuBackend + ? _gpuBackendForAdapters(automatic: automaticBackend) + : resolvedBackend; if (params.liteRtLmEmbeddingEngine) { liteRtLmEnsureNativeEmbeddingsQualified(); ensureLiteRtLmNativeEmbeddingBackend(resolvedBackend); @@ -274,12 +308,9 @@ class LiteRtLmService { _modelPath = path; _modelLink = modelLink; _modelParams = params; - _activeBackend = resolvedBackend; + _activeBackend = engineBackend; _loadedBackend = resolvedBackend; - _automaticBackend = - params.device == ComputeDevice.auto && - params.liteRtLmBackend.nativeName == null && - normalizeLiteRtLmNativeBackendOverride(backendOverride) == null; + _automaticBackend = automaticBackend; _activeSpeculativeDecoding = null; _workingAudioBackend = null; _bundleCapabilities = null; @@ -1755,6 +1786,31 @@ class LiteRtLmService { return stopIndex; } + /// The backend for a GPU request: the GPU unless every Vulkan device is + /// software, on which the GPU backend can silently return wrong text + /// (#572). Then an automatic choice runs on the CPU and an explicit one + /// fails. + String _gpuBackendForAdapters({required bool automatic}) { + final software = _probeGpuAdapters?.call().softwareOnly; + if (software == null) return liteRtLmGpuBackend; + final names = software.map((device) => '"${device.name}"').join(', '); + if (automatic) { + _warn( + 'LiteRT-LM found only software Vulkan devices ($names) under ' + 'ComputeDevice.auto; running on the CPU. Install the GPU vendor\'s ' + 'Vulkan driver to use the GPU.', + ); + return liteRtLmCpuBackend; + } + throw LlamaUnsupportedException( + 'LiteRT-LM GPU on ${liteRtLmGateAbi()} needs a hardware Vulkan ' + 'device, but every Vulkan device here is a software rasterizer ' + '(VK_PHYSICAL_DEVICE_TYPE_CPU: $names), on which the GPU backend can ' + 'return wrong text. Install the GPU vendor\'s Vulkan driver, or load ' + 'with ComputeDevice.cpu.', + ); + } + String _resolveBackendName(ModelParams params, {String? backendOverride}) { final device = params.device; if (device != ComputeDevice.auto) { diff --git a/skills/llamadart-getting-started/SKILL.md b/skills/llamadart-getting-started/SKILL.md index 7b7ba6148..cfe5f6d74 100644 --- a/skills/llamadart-getting-started/SKILL.md +++ b/skills/llamadart-getting-started/SKILL.md @@ -154,6 +154,8 @@ interface does not establish backend/model support; read `await engine.capabilit to start on the CPU with a warning (`getBackendName()` then reports `LiteRT-LM cpu`) and throws the GPU error if the CPU fails too. If `auto` already selects CPU, an engine-create failure has no second attempt. + On Linux, when every Vulkan device is software (llvmpipe, SwiftShader), + LiteRT-LM GPU throws at load and a GPU hint under `auto` loads on the CPU. Backend-SPI context recreation preserves a successful CPU fallback when reusing the load's automatic GPU hints. Leave `device` at `auto` for each runtime's default. diff --git a/test/unit/backends/litert_lm/litert_lm_gpu_adapter_test.dart b/test/unit/backends/litert_lm/litert_lm_gpu_adapter_test.dart new file mode 100644 index 000000000..b03e23843 --- /dev/null +++ b/test/unit/backends/litert_lm/litert_lm_gpu_adapter_test.dart @@ -0,0 +1,205 @@ +@TestOn('vm') +library; + +import 'dart:convert'; +import 'dart:ffi'; + +import 'package:ffi/ffi.dart'; +import 'package:llamadart/src/backends/litert_lm/litert_lm_gpu_adapter.dart'; +import 'package:test/test.dart'; + +void main() { + group('LiteRtLmVulkanAdapters.softwareOnly', () { + const llvmpipe = LiteRtLmVulkanAdapter( + name: 'llvmpipe (LLVM 20.1.2, 256 bits)', + deviceType: 4, + ); + const swiftShader = LiteRtLmVulkanAdapter( + name: 'SwiftShader Device (Subzero)', + deviceType: 4, + ); + + test('lists the devices when every one is a CPU device', () { + const adapters = LiteRtLmVulkanAdapters.devices([llvmpipe, swiftShader]); + expect(adapters.softwareOnly, [llvmpipe, swiftShader]); + }); + + for (final (name, type) in [ + ('other', 0), + ('integrated', 1), + ('discrete', 2), + ('virtual', 3), + ]) { + test('is null beside a $name GPU', () { + final adapters = LiteRtLmVulkanAdapters.devices([ + llvmpipe, + LiteRtLmVulkanAdapter(name: 'gpu', deviceType: type), + ]); + expect(adapters.softwareOnly, isNull); + }); + } + + test('is null without devices or facts', () { + expect(const LiteRtLmVulkanAdapters.devices([]).softwareOnly, isNull); + expect( + const LiteRtLmVulkanAdapters.unavailable('no loader').softwareOnly, + isNull, + ); + }); + }); + + group('LiteRtLmVulkanLoader.listAdapters', () { + late _FakeVulkan vulkan; + + setUp(() => vulkan = _FakeVulkan()); + tearDown(() => vulkan.dispose()); + + test('reads each device name and type from VkPhysicalDeviceProperties', () { + vulkan.devices = [ + ('llvmpipe (LLVM 20.1.2, 256 bits)', 4), + ('NVIDIA L4', 2), + ]; + + final adapters = vulkan.loader.listAdapters(); + + expect(adapters.unavailableReason, isNull); + expect( + [ + for (final device in adapters.devices!) + (device.name, device.deviceType), + ], + [('llvmpipe (LLVM 20.1.2, 256 bits)', 4), ('NVIDIA L4', 2)], + ); + expect(vulkan.createInfoStructureType, 1); + expect(vulkan.destroyedInstances, 1); + }); + + test('is unavailable when the loader reports VK_INCOMPLETE', () { + vulkan.devices = [('llvmpipe', 4), ('NVIDIA L4', 2)]; + vulkan.countedDevices = 1; + + final adapters = vulkan.loader.listAdapters(); + + expect(adapters.devices, isNull); + expect( + adapters.unavailableReason, + 'vkEnumeratePhysicalDevices returned 5', + ); + expect(vulkan.destroyedInstances, 1); + }); + + test('lists no device when the loader reports none', () { + final adapters = vulkan.loader.listAdapters(); + + expect(adapters.devices, isEmpty); + expect(vulkan.destroyedInstances, 1); + }); + + test('is unavailable when the instance cannot be created', () { + vulkan.createResult = -9; + + final adapters = vulkan.loader.listAdapters(); + + expect(adapters.devices, isNull); + expect(adapters.unavailableReason, 'vkCreateInstance returned -9'); + expect(vulkan.destroyedInstances, 0); + }); + + test('is unavailable when the devices cannot be enumerated', () { + vulkan.enumerateResult = -3; + + final adapters = vulkan.loader.listAdapters(); + + expect(adapters.devices, isNull); + expect( + adapters.unavailableReason, + 'vkEnumeratePhysicalDevices returned -3', + ); + expect(vulkan.destroyedInstances, 1); + }); + }); + + group('probeLiteRtLmVulkanAdapters', () { + test('is unavailable when the loader cannot be opened', () { + String? opened; + final adapters = probeLiteRtLmVulkanAdapters( + openLibrary: (name) { + opened = name; + throw ArgumentError('not found'); + }, + ); + + expect(opened, 'libvulkan.so.1'); + expect(adapters.devices, isNull); + expect(adapters.unavailableReason, contains('libvulkan.so.1')); + }); + + test('is unavailable when the library lacks the entry points', () { + final adapters = probeLiteRtLmVulkanAdapters( + openLibrary: (_) => DynamicLibrary.process(), + ); + + expect(adapters.devices, isNull); + }); + }); +} + +/// A Vulkan loader whose instance and devices are Dart memory. +final class _FakeVulkan { + final Pointer _instance = calloc(); + final List> _handles = []; + + List<(String, int)> devices = []; + int createResult = 0; + int enumerateResult = 0; + + /// The count the first call reports when it is below [devices], as when a + /// device appears between the two calls. + int? countedDevices; + int? createInfoStructureType; + int destroyedInstances = 0; + + LiteRtLmVulkanLoader get loader => LiteRtLmVulkanLoader( + createInstance: (createInfo, allocator, instance) { + createInfoStructureType = createInfo.cast().value; + if (createResult == 0) instance.value = _instance.cast(); + return createResult; + }, + enumeratePhysicalDevices: (instance, count, handles) { + expect(instance, _instance.cast()); + if (enumerateResult != 0) return enumerateResult; + if (handles == nullptr) { + count.value = countedDevices ?? devices.length; + return 0; + } + final written = count.value < devices.length + ? count.value + : devices.length; + for (var index = 0; index < written; index++) { + final handle = calloc()..value = index; + _handles.add(handle); + handles[index] = handle.cast(); + } + count.value = written; + return written < devices.length ? 5 : 0; + }, + getPhysicalDeviceProperties: (device, properties) { + final (name, type) = devices[device.cast().value]; + final bytes = properties.cast(); + (bytes + 16).cast().value = type; + final encoded = utf8.encode(name); + (bytes + 20).asTypedList(256).setAll(0, encoded); + }, + destroyInstance: (instance, allocator) { + expect(instance, _instance.cast()); + destroyedInstances++; + }, + ); + + void dispose() { + for (final handle in _handles) { + calloc.free(handle); + } + calloc.free(_instance); + } +} 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 684723703..6cba98cba 100644 --- a/test/unit/backends/litert_lm/litert_lm_service_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_service_test.dart @@ -13,6 +13,7 @@ import 'package:llamadart/src/backends/backend.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_bundle_template.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_cache.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_chat_templates.dart'; +import 'package:llamadart/src/backends/litert_lm/litert_lm_gpu_adapter.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_platform.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_service.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_runtime.dart'; @@ -3529,6 +3530,233 @@ void main() { }); }); + group('GPU loads on software Vulkan adapters', () { + final records = []; + const llvmpipe = LiteRtLmVulkanAdapter( + name: 'llvmpipe (LLVM 20.1.2, 256 bits)', + deviceType: vulkanPhysicalDeviceTypeCpu, + ); + const discreteGpu = LiteRtLmVulkanAdapter(name: 'NVIDIA L4', deviceType: 2); + const softwareOnly = LiteRtLmVulkanAdapters.devices([llvmpipe]); + var probes = 0; + + setUp(() { + records.clear(); + probes = 0; + LlamaLogger.instance.setLevel(LlamaLogLevel.warn); + LlamaLogger.instance.setHandler(records.add); + }); + + tearDown(() { + LlamaLogger.instance.setLevel(LlamaLogLevel.none); + LlamaLogger.instance.setHandler(null); + }); + + bool skipWithoutGpu() { + if (liteRtLmNativeGpuSupportedOnCurrentPlatform()) return false; + markTestSkipped('No LiteRT-LM GPU backend on this platform.'); + return true; + } + + LiteRtLmService serviceWith( + _FakeLiteRtLmRuntimeClient client, + LiteRtLmVulkanAdapters adapters, + ) => LiteRtLmService( + clientFactory: () => client, + useTempCacheDir: false, + probeGpuAdapters: () { + probes++; + return adapters; + }, + ); + + for (final (name, params, backendOverride) in [ + ('ComputeDevice.gpu', const ModelParams(device: ComputeDevice.gpu), null), + ( + 'LiteRtLmBackendPreference.gpu', + const ModelParams(liteRtLmBackend: LiteRtLmBackendPreference.gpu), + null, + ), + ('the deprecated gpu backend override', const ModelParams(), 'gpu'), + ]) { + test('$name fails to load with a typed error', () async { + if (skipWithoutGpu()) return; + final client = _FakeLiteRtLmRuntimeClient(); + final service = serviceWith(client, softwareOnly); + try { + await expectLater( + service.loadModel( + modelFile.path, + params, + backendOverride: backendOverride, + ), + throwsA( + isA().having( + (error) => error.message, + 'message', + allOf( + contains('needs a hardware Vulkan device'), + contains('"llvmpipe (LLVM 20.1.2, 256 bits)"'), + contains('VK_PHYSICAL_DEVICE_TYPE_CPU'), + contains('ComputeDevice.cpu'), + ), + ), + ), + ); + expect(probes, 1); + expect(client.lastBackend, isNull); + expect(records, isEmpty); + } finally { + service.dispose(); + } + }); + } + + test('a ComputeDevice.auto GPU hint runs on the CPU with a ' + 'warning', () async { + if (skipWithoutGpu()) return; + final client = _FakeLiteRtLmRuntimeClient(); + final service = serviceWith(client, softwareOnly); + try { + const params = ModelParams(preferredBackend: GpuBackend.vulkan); + final model = await service.loadModel(modelFile.path, params); + expect(service.getActiveBackendName(), 'LiteRT-LM cpu'); + await startEngine(service, client, model, params); + + expect(client.lastBackend, 'cpu'); + expect(records, hasLength(1)); + expect(records.single.level, LlamaLogLevel.warn); + expect( + records.single.message, + allOf( + contains('only software Vulkan devices'), + contains('"llvmpipe (LLVM 20.1.2, 256 bits)"'), + contains('ComputeDevice.auto'), + contains('running on the CPU'), + ), + ); + } finally { + service.dispose(); + } + }); + + for (final (name, adapters) in [ + ( + 'a hardware adapter beside llvmpipe', + const LiteRtLmVulkanAdapters.devices([llvmpipe, discreteGpu]), + ), + ('no listed adapter', const LiteRtLmVulkanAdapters.devices([])), + ( + 'an unavailable probe', + const LiteRtLmVulkanAdapters.unavailable('no loader'), + ), + ]) { + test('ComputeDevice.gpu with $name starts a GPU engine', () async { + if (skipWithoutGpu()) return; + final client = _FakeLiteRtLmRuntimeClient(); + final service = serviceWith(client, adapters); + try { + const params = ModelParams(device: ComputeDevice.gpu); + final model = await service.loadModel(modelFile.path, params); + await startEngine(service, client, model, params); + + expect(probes, 1); + expect(client.lastBackend, 'gpu'); + expect(records, isEmpty); + } finally { + service.dispose(); + } + }); + } + + group('default probe selection', () { + var systemProbes = 0; + + setUp(() { + systemProbes = 0; + debugLiteRtLmSystemVulkanAdaptersOverride = () { + systemProbes++; + return softwareOnly; + }; + }); + + tearDown(() { + debugLiteRtLmSystemVulkanAdaptersOverride = null; + debugLiteRtLmAbiOverride = null; + }); + + test('a Linux service with the production client probes the system ' + 'loader', () async { + debugLiteRtLmAbiOverride = Abi.linuxX64; + final service = LiteRtLmService(useTempCacheDir: false); + try { + await expectLater( + service.loadModel( + modelFile.path, + const ModelParams(device: ComputeDevice.gpu), + ), + throwsA(isA()), + ); + expect(systemProbes, 1); + } finally { + service.dispose(); + } + }); + + for (final (name, abi, injected) in [ + ('a macOS service', Abi.macosArm64, null), + ('a Windows service', Abi.windowsX64, null), + ('a Linux service with a client factory', Abi.linuxX64, 'legacy'), + ( + 'a Linux service with a runtime client factory', + Abi.linuxX64, + 'runtime', + ), + ]) { + test('$name does not probe the system loader', () async { + debugLiteRtLmAbiOverride = abi; + final service = switch (injected) { + 'legacy' => LiteRtLmService( + clientFactory: _FakeLiteRtLmRuntimeClient.new, + useTempCacheDir: false, + ), + 'runtime' => LiteRtLmService( + runtimeClientFactory: () => + throw StateError('this test creates no engine'), + useTempCacheDir: false, + ), + _ => LiteRtLmService(useTempCacheDir: false), + }; + try { + await service.loadModel( + modelFile.path, + const ModelParams(device: ComputeDevice.gpu), + ); + expect(service.getActiveBackendName(), 'LiteRT-LM gpu'); + expect(systemProbes, 0); + } finally { + service.dispose(); + } + }); + } + }); + + test('a CPU load does not probe the adapters', () async { + final client = _FakeLiteRtLmRuntimeClient(); + final service = serviceWith(client, softwareOnly); + try { + const params = ModelParams(device: ComputeDevice.cpu); + final model = await service.loadModel(modelFile.path, params); + await startEngine(service, client, model, params); + + expect(probes, 0); + expect(client.lastBackend, 'cpu'); + } finally { + service.dispose(); + } + }); + }); + for (final readOnly in [true, false]) { final device = readOnly ? ComputeDevice.cpu : ComputeDevice.gpu; test('an unlinked bundle in a directory the process ' diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 0d34d35b9..a8a4d0203 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -15,6 +15,7 @@ validate against the exact release tag notes. - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). +- Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). - Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). diff --git a/website/docs/platforms/known-platform-issues.md b/website/docs/platforms/known-platform-issues.md index c714c2061..0a03f3fd9 100644 --- a/website/docs/platforms/known-platform-issues.md +++ b/website/docs/platforms/known-platform-issues.md @@ -75,9 +75,13 @@ feature. For which runtime supports which feature, see the though `checkLoad`, which opens no runtime, reports them as supported; `v0.19.0` and `v0.19.1` expose the same C API 1.0 as `v0.19.1-1`, so the load gate cannot tell them apart. -- Linux x64 LiteRT-LM GPU needs a hardware Vulkan driver. On Mesa llvmpipe - alone it answers a few prompts, then crashes the process; use `cpu` on such - hosts ([#572](https://github.com/leehack/llamadart/issues/572)). +- Linux x64 LiteRT-LM GPU needs a hardware Vulkan driver. When every Vulkan + device is a software rasterizer (Mesa llvmpipe/lavapipe, SwiftShader), an + explicit GPU load throws `LlamaUnsupportedException` and a GPU hint under + `auto` runs on the CPU with a warning, because small models can run there + and return wrong text. `checkLoad`, which opens no driver, still reports + such a GPU load as supported, and if the system Vulkan loader cannot be + queried the load proceeds ([#572](https://github.com/leehack/llamadart/issues/572)). - Windows x64 LiteRT-LM GPU needs `dxil.dll` and `dxcompiler.dll`, which the pinned runtime bundles. Its GPU accelerator and sampler load `webgpu_dawn.dll`, which the hook bundles. Windows Qwen3 0.6B GPU execution diff --git a/website/docs/platforms/support-matrix.md b/website/docs/platforms/support-matrix.md index 45db41cf7..d1bae93e1 100644 --- a/website/docs/platforms/support-matrix.md +++ b/website/docs/platforms/support-matrix.md @@ -111,8 +111,10 @@ retry is CPU execution and does not qualify a GPU path. Under `auto`, `gpuLayers: 0` or a CPU or BLAS `preferredBackend` selects the CPU on both llama.cpp and LiteRT-LM, and a GPU `preferredBackend` (Vulkan, Metal, CUDA, OpenCL or HIP) selects the LiteRT-LM GPU backend. On Linux x64 -and Windows x64, the LiteRT-LM GPU backend is not CUDA; use `device: cpu` on -hosts without a hardware Vulkan driver. Windows arm64 has no LiteRT-LM +and Windows x64, the LiteRT-LM GPU backend is not CUDA. On Linux x64 it needs +a hardware Vulkan driver: with only software Vulkan devices (llvmpipe, +lavapipe, SwiftShader) explicit `gpu` throws `LlamaUnsupportedException` and +a GPU hint under `auto` runs on the CPU. Windows arm64 has no LiteRT-LM runtime. The deprecated `liteRtLmBackend` selector works until 1.0; an unavailable choice there throws `LlamaModelException`. diff --git a/website/docs/troubleshooting/common-issues.md b/website/docs/troubleshooting/common-issues.md index 982adba1d..2c3ecd804 100644 --- a/website/docs/troubleshooting/common-issues.md +++ b/website/docs/troubleshooting/common-issues.md @@ -178,13 +178,15 @@ They disable the cooperative-matrix Vulkan paths for that process and can reduce Vulkan performance; use them only when the driver crashes or reports device loss there. -### LiteRT-LM GPU crashes on Linux without a hardware Vulkan driver - -With only Mesa llvmpipe (the runtime logs `Selected adapter: llvmpipe ... -adapterType=CPU / Software`), LiteRT-LM can load the model and answer -the first prompts, then segfault in `libvulkan_lvp.so` and take the process -down. There is no load error to fall back from, so hosts with Mesa but no -vendor ICD must use `device: ComputeDevice.cpu` +### LiteRT-LM GPU is refused on Linux without a hardware Vulkan driver + +When the only Vulkan devices are software rasterizers such as Mesa llvmpipe +(the runtime would log `Selected adapter: llvmpipe ... adapterType=CPU / +Software`), `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load +and a GPU `preferredBackend` under `auto` runs on the CPU with a warning. +On such an adapter LiteRT-LM fails for larger models and can return wrong +text for small ones. Install the GPU vendor's Vulkan driver to use the GPU, +or load with `device: ComputeDevice.cpu` ([#572](https://github.com/leehack/llamadart/issues/572)). ## Wrong or garbled GPU output From 810d9a298a3fac2f55adf3cfbdce2a2ce2e6e660 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:35:06 -0500 Subject: [PATCH 7/9] Require the in-process LiteRT marker for Linux and Windows LiteRT-LM embeddings (#1830) Squash of #1830 at 0296fd585eac2aa26f1b10a2e141560f33542d9e against merge-base b78008cf31fbf6c967e1cc5bf2c557764c2072d3. Conflict resolutions: - website/docs/platforms/known-platform-issues.md, "## Linux and Windows", custom-runtime bullet tail and the Linux x64 GPU bullet (vs #1831): #1830's embeddings-marker paragraph replaces the legacy `v0.18.x` refusal paragraph, followed by #1831's rewritten Linux x64 software-Vulkan GPU bullet (replacing the old llvmpipe-crash bullet). --- CHANGELOG.md | 2 + README.md | 6 +- doc/litert_lm_c_api_v1_migration.md | 2 +- doc/litert_lm_v1_adoption.md | 24 +++-- doc/multimodal_embeddings_litert.md | 9 +- .../litert_lm/litert_lm_c_api_version.dart | 17 +++- .../litert_lm/litert_lm_platform.dart | 40 +++++++- .../backends/litert_lm/litert_lm_runtime.dart | 6 +- .../litert_lm/litert_lm_runtime_facade.dart | 7 +- .../backends/litert_lm/litert_lm_service.dart | 2 +- .../litert_lm_v1_runtime_client.dart | 11 ++- lib/src/hook/native_release_pins.dart | 20 ++-- .../llamadart_litert_lm_flutter/CHANGELOG.md | 4 + .../llamadart_litert_lm_flutter/README.md | 2 +- .../llamadart_litert_lm_flutter/Package.swift | 16 +-- .../assets/capability_coverage.json | 2 +- .../lib/android_litert_qualification.dart | 6 +- .../native/android_litert/README.md | 15 +-- .../android_litert_qualification_test.dart | 2 +- skills/llamadart-embeddings/SKILL.md | 4 +- skills/llamadart-getting-started/SKILL.md | 4 +- skills/llamadart-speech/SKILL.md | 2 +- .../multimodal_embedding_litert_e2e_test.dart | 12 ++- test/fixtures/litert_lm/c_api_v1_embedding.c | 8 ++ test/fixtures/litert_lm/c_api_version.c | 6 ++ .../litert_lm_c_api_version_test.dart | 17 +++- .../litert_lm_embedding_native_test.dart | 2 +- .../litert_lm/litert_lm_service_test.dart | 2 +- .../litert_lm_v1_embedding_test.dart | 99 ++++++++++++++++++- .../io/runtime_setup_report_io_test.dart | 2 +- .../tooling/check_webgpu_bridge_tag_test.dart | 2 +- .../tooling/litert_lm_library_smoke_test.dart | 7 +- .../sync_native_release_pins_script_test.dart | 2 +- tool/litert_lm_library_smoke.dart | 2 +- tool/macos_litert_lm_prepare_app.sh | 4 +- website/docs/changelog/recent-releases.md | 2 + website/docs/guides/embeddings.md | 4 +- .../docs/maintainers/native-and-web-sync.md | 10 +- .../docs/platforms/known-platform-issues.md | 18 ++-- website/docs/platforms/native-build-hooks.md | 2 +- website/docs/platforms/support-matrix.md | 10 +- 41 files changed, 320 insertions(+), 94 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d2d5d16f..25cd197db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). - Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). +- Refuse LiteRT-LM native embeddings on Linux and Windows with `LlamaUnsupportedException` unless the runtime reports LiteRT linked in process (litert-lm-native `v0.19.1-2` or later), so a custom `v0.19.0` or `v0.19.1` runtime no longer crashes creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). +- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). - Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). diff --git a/README.md b/README.md index 021bfe0fe..6a07a0fd4 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ Current default runtime pins: | Runtime | Pin | | --- | --- | | Native llama.cpp / GGUF | `leehack/llamadart-native@v0.9.0` | -| Native LiteRT-LM / `.litertlm` | `leehack/litert-lm-native@v0.19.1-1` | +| Native LiteRT-LM / `.litertlm` | `leehack/litert-lm-native@v0.19.1-2` | | Web llama.cpp / GGUF | `leehack/llama-web-bridge-assets@v0.1.83` | | Web LiteRT-LM / `.litertlm` | `@litert-lm/core@0.19.0` | @@ -170,8 +170,8 @@ Native LiteRT-LM uses a lazy ABI-aware client for direct calls, services and speech. The public selector admits legacy runtimes and C API 1.0.x; unknown or future versions are refused before engine calls. The pinned runtime is published native -[v0.19.1-1](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-1), -owner source `82d4ae1c` / upstream `7a03724c`. The selected loader requires +[v0.19.1-2](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-2), +owner source `0b15fb34` / upstream `7a03724c`. The selected loader requires macOS 14+ before owned library loads, including legacy libraries and custom paths. Web LiteRT-LM uses `@litert-lm/core@0.19.0`. diff --git a/doc/litert_lm_c_api_v1_migration.md b/doc/litert_lm_c_api_v1_migration.md index 511ed81b1..00632de12 100644 --- a/doc/litert_lm_c_api_v1_migration.md +++ b/doc/litert_lm_c_api_v1_migration.md @@ -3,7 +3,7 @@ The public lazy client, default services and speech worker now select legacy runtimes or admitted C API 1.0.x through shared discovery. Unknown, malformed or future C API versions are refused before engine calls. Owner pins and the -companion select published v0.19.1-1; C API 1 first shipped in core and +companion select published v0.19.1-2; C API 1 first shipped in core and companions `0.18.0` (#1677). [Current adoption coverage and gates](litert_lm_v1_adoption.md) describe the selected implementation; [the migration guide](../MIGRATION.md) covers upgrades. diff --git a/doc/litert_lm_v1_adoption.md b/doc/litert_lm_v1_adoption.md index 5035f3681..4e63a6eb7 100644 --- a/doc/litert_lm_v1_adoption.md +++ b/doc/litert_lm_v1_adoption.md @@ -3,9 +3,9 @@ The public lazy facade, default service probes and speech worker now share ABI-aware discovery. Public production selection now admits C API 1.0.x; unknown/future versions remain unsupported. The native hook and Apple companion -source now pin published [v0.19.1-1](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-1), -owner `82d4ae1c` / upstream `7a03724cece417f1724c923b3d527b4319730841`, which -keeps C API 1.0.0 and the v0.19.0 exports. The adoption below used published +source now pin published [v0.19.1-2](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-2), +owner `0b15fb34` / upstream `7a03724cece417f1724c923b3d527b4319730841`, which +keeps C API 1.0.0 and the v0.19.0 exports and adds the in-process LiteRT marker. The adoption below used published [v0.19.0](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.0), owner `f173fe9b` / upstream `83ce6067f2e2a3fb697556928f93936693ded971`. All 21 public owner assets were independently matched to the qualified bytes. @@ -70,8 +70,18 @@ completion was present, and the unchanged decoder accepted the journal plus 15 sidecars extracted from its lossless envelopes. Native GPU and both public corrected-auto lifetimes initialized OpenCL with full `LITERT_CL` delegation (1306/1306 decode, 1358/1358 prefill) and no CPU fallback. The four legacy -semantic failures are unchanged. The qualifier binding now admits only -`v0.19.1`. +semantic failures are unchanged. + +It passed again on v0.19.1-2 (matrix `matrix-wmalbq6nz437a`, run +`pr1830-litert0191-2-s24-20261108`, source `3dd5356d`, 2026-11-08). That +Android arm64 bundle (`1b72d7f6`) differs from v0.19.1 only in +`libLiteRtLm.so` (`bdab4d4a` to `9a56e701`), which adds the exported in-process +LiteRT marker. The APK packaged the archive libraries byte-identically. The +results match v0.19.1: 20/20 PASS, six lifetimes closed, completion present, +the unchanged decoder accepted journal `a71fb3b3` plus 15 extracted sidecars, +full `LITERT_CL` delegation with no CPU fallback, and the same four legacy +semantic failures. The qualifier binding admits `v0.19.1`, `v0.19.1-1` (same +Android binaries) and `v0.19.1-2`. ## Required coverage @@ -145,7 +155,7 @@ internal qualification/integration boundary. Pass an isolate-sendable factory that constructs the selected ABI client from the provided library path inside the receiving isolate. Both the support probe and the streaming worker use it. The default speech factory uses the public ABI-aware selector; independent ASR -bridge admission remains required. The source pin now uses published v0.19.1-1; +bridge admission remains required. The source pin now uses published v0.19.1-2; owner ASR smokes remain distinct from the accepted seven-case public default-worker Whisper Tiny CPU campaign. Its source landed in #1748; other models and devices retain their separate gates. @@ -215,7 +225,7 @@ calling the legacy-only count setter. Direct settings that request an enforced legacy capacity still fail explicitly. These source/fixture checks do not by themselves establish image/audio -semantics or qualify hardware. Public C API 1.0 selection and the v0.19.1-1 source +semantics or qualify hardware. Public C API 1.0 selection and the v0.19.1-2 source pin are enabled independently; media qualification remains per model/platform. ## Internal thinking-budget admission diff --git a/doc/multimodal_embeddings_litert.md b/doc/multimodal_embeddings_litert.md index 42533757f..66882389b 100644 --- a/doc/multimodal_embeddings_litert.md +++ b/doc/multimodal_embeddings_litert.md @@ -174,10 +174,11 @@ external weight for buffer id 2147483863 (tensor 1451)`. on Linux and crashes the process on Windows x64 ([#1367](https://github.com/leehack/llamadart/issues/1367), [litert-lm-native#111](https://github.com/leehack/litert-lm-native/issues/111)). - A legacy runtime without `litert_lm_get_api_version` (`v0.18.x`) is - refused before any native embedding call. C API 1.0 runtimes older than - `v0.19.1-1` (`v0.19.0`, `v0.19.1`) look the same as `v0.19.1-1`, so a - custom `LLAMADART_LITERT_LM_LIB_DIR` must be `v0.19.1-1` or later. + C API 1.0 runtimes `v0.19.0` and `v0.19.1` look the same as `v0.19.1-1`, so + Linux and Windows embeddings require + `litert_lm_native_in_process_litert_abi_version` to report 1, first shipped + in `v0.19.1-2`. Any other runtime, including `v0.18.x` and `v0.19.1-1`, is + refused with `LlamaUnsupportedException` before any native embedding call. - **Native GPU:** fail before native engine creation. `v0.18.0-3` has a WebGPU accelerator/absl ABI mismatch that crashed the upstream-only reference as well as the prototype. The upstream repair is diff --git a/lib/src/backends/litert_lm/litert_lm_c_api_version.dart b/lib/src/backends/litert_lm/litert_lm_c_api_version.dart index 084d6918d..cf9225439 100644 --- a/lib/src/backends/litert_lm/litert_lm_c_api_version.dart +++ b/lib/src/backends/litert_lm/litert_lm_c_api_version.dart @@ -26,7 +26,7 @@ typedef _GetApiVersionDart = if (status != 0 || parts[0] != 1 || parts[1] != 0 || parts[2] < 0) { throw LlamaUnsupportedException( 'LiteRT-LM rejects C API ${parts[0]}.${parts[1]}.${parts[2]} (version probe status $status). ' - 'Use the packaged litert-lm-native v0.19.1-1 runtime with supported C API 1.0.x. ' + 'Use the packaged litert-lm-native v0.19.1-2 runtime with supported C API 1.0.x. ' 'See https://github.com/leehack/llamadart/issues/1677 for the admitted ABI contract. ' 'No legacy engine call was attempted.', ); @@ -37,6 +37,19 @@ typedef _GetApiVersionDart = } } +/// Reads litert-lm-native's `litert_lm_native_in_process_litert_abi_version` +/// marker, or returns null when the runtime predates the export. +/// +/// The caller interprets the value: 1 means LiteRT is compiled into the +/// runtime with no separate `libLiteRt` import, 0 or a missing export means +/// that is not established, and later values carry guarantees this package +/// does not know. It never establishes GPU qualification. +int? readLiteRtLmInProcessLiteRtAbiVersion(DynamicLibrary library) { + const symbol = 'litert_lm_native_in_process_litert_abi_version'; + if (!library.providesSymbol(symbol)) return null; + return library.lookupFunction(symbol)(); +} + /// Refuses versioned C APIs before using the pre-1.0 LiteRT-LM bindings. /// /// LiteRT-LM 0.19 introduces `litert_lm_get_api_version` alongside status-return @@ -61,7 +74,7 @@ void requireLiteRtLmLegacyCApi(DynamicLibrary library) { throw LlamaUnsupportedException( 'Native LiteRT-LM C API $version is incompatible with the pre-1.0 bindings. ' 'Use the default LiteRtLmRuntimeClient or LiteRtLmService to select the ' - 'admitted C API 1.0.x route for the packaged litert-lm-native v0.19.1-1 ' + 'admitted C API 1.0.x route for the packaged litert-lm-native v0.19.1-2 ' 'runtime, or select a compatible legacy runtime override for these bindings. ' 'See https://github.com/leehack/llamadart/issues/1677 for the admitted ABI contract. ' 'No legacy engine call was attempted.', diff --git a/lib/src/backends/litert_lm/litert_lm_platform.dart b/lib/src/backends/litert_lm/litert_lm_platform.dart index e2fc462f4..325c14225 100644 --- a/lib/src/backends/litert_lm/litert_lm_platform.dart +++ b/lib/src/backends/litert_lm/litert_lm_platform.dart @@ -122,8 +122,8 @@ void liteRtLmEnsureNativeEmbeddingsQualified() { /// version export, may create native embedding engines on [abi]. /// /// Legacy v0.18.x desktop runtimes crash creating embedding engines (#1367); -/// Linux and Windows embeddings are qualified only on C API 1 runtimes from -/// litert-lm-native v0.19.1-1. +/// Linux and Windows embeddings are qualified only on C API 1 runtimes that +/// report in-process LiteRT, from litert-lm-native v0.19.1-2. bool liteRtLmLegacyNativeEmbeddingsQualifiedForAbi(Abi abi) { return liteRtLmNativeEmbeddingsQualifiedForAbi(abi) && abi != Abi.linuxArm64 && @@ -141,10 +141,42 @@ void liteRtLmEnsureLegacyNativeEmbeddingsQualified() { if (liteRtLmLegacyNativeEmbeddingsQualifiedForAbi(abi)) return; throw LlamaUnsupportedException( 'LiteRT-LM native embeddings on $abi require a C API 1 runtime from ' - 'litert-lm-native v0.19.1-1 or newer. The loaded runtime is a legacy one ' + 'litert-lm-native v0.19.1-2 or newer. The loaded runtime is a legacy one ' 'without litert_lm_get_api_version, such as a v0.18.x custom runtime, ' 'whose desktop embedding engine crashes (#1367). Use the bundled runtime ' - 'or a v0.19.1-1 or newer custom runtime, or the llama.cpp backend.', + 'or a v0.19.1-2 or newer custom runtime, or the llama.cpp backend.', + ); +} + +/// The `litert_lm_native_in_process_litert_abi_version` value that admits +/// Linux and Windows native embeddings. +const int liteRtLmInProcessLiteRtAbiVersion = 1; + +/// Throws a [LlamaUnsupportedException] when a C API 1 runtime on Linux or +/// Windows does not report [liteRtLmInProcessLiteRtAbiVersion]. +/// +/// [abiVersion] is the runtime's in-process LiteRT marker, null when not +/// exported. Custom v0.19.0 and v0.19.1 desktop runtimes report the same C API +/// version but load a separate `libLiteRt` and crash creating embedding +/// engines (#1367); only the marker tells them apart. Unknown values carry +/// guarantees this package does not know, so they are refused too. Apple and +/// Android runtimes are unaffected. Runs before any native embedding call. +void liteRtLmEnsureInProcessLiteRtForNativeEmbeddings(int? abiVersion) { + final abi = liteRtLmGateAbi(); + if (abi != Abi.linuxArm64 && abi != Abi.linuxX64 && abi != Abi.windowsX64) { + return; + } + if (abiVersion == liteRtLmInProcessLiteRtAbiVersion) return; + final reported = abiVersion == null + ? 'does not export litert_lm_native_in_process_litert_abi_version' + : 'reports litert_lm_native_in_process_litert_abi_version $abiVersion'; + throw LlamaUnsupportedException( + 'LiteRT-LM native embeddings on $abi need LiteRT compiled into the ' + 'runtime (in-process LiteRT ABI $liteRtLmInProcessLiteRtAbiVersion), and ' + 'the loaded runtime $reported. Custom v0.19.0 and v0.19.1 desktop ' + 'runtimes load a separate libLiteRt and crash creating embedding engines ' + '(#1367). Use the bundled runtime or a custom runtime from ' + 'litert-lm-native v0.19.1-2 or newer, or the llama.cpp backend.', ); } diff --git a/lib/src/backends/litert_lm/litert_lm_runtime.dart b/lib/src/backends/litert_lm/litert_lm_runtime.dart index 419593a9c..b0dd13a83 100644 --- a/lib/src/backends/litert_lm/litert_lm_runtime.dart +++ b/lib/src/backends/litert_lm/litert_lm_runtime.dart @@ -33,8 +33,8 @@ export 'litert_lm_native_settlement.dart'; part 'litert_lm_embedding_native.dart'; part 'litert_lm_runtime_facade.dart'; -const _litertLmReleaseTag = 'v0.19.1-1'; -const _litertLmVersion = '0.19.1-1'; +const _litertLmReleaseTag = 'v0.19.1-2'; +const _litertLmVersion = '0.19.1-2'; const _litertLmLibDirEnv = 'LLAMADART_LITERT_LM_LIB_DIR'; const _liteRtLmIosNativeAsset = 'package:llamadart/litert_lm_LiteRtLm'; const _processLibraryCandidate = ''; @@ -1377,7 +1377,7 @@ class _LegacyLiteRtLmRuntimeClient extends LiteRtLmRuntimeClient { throw LlamaUnsupportedException( 'Native JSON Schema chat requires the complete LiteRT-LM constraint-provider and thinking API. ' 'Use the default LiteRtLmRuntimeClient or LiteRtLmService with the packaged ' - 'litert-lm-native v0.19.1-1 runtime; legacy overrides must provide this complete API ' + 'litert-lm-native v0.19.1-2 runtime; legacy overrides must provide this complete API ' 'and meet the JSON Schema qualification limits.', ); } diff --git a/lib/src/backends/litert_lm/litert_lm_runtime_facade.dart b/lib/src/backends/litert_lm/litert_lm_runtime_facade.dart index 9a05d5115..729a3fc3f 100644 --- a/lib/src/backends/litert_lm/litert_lm_runtime_facade.dart +++ b/lib/src/backends/litert_lm/litert_lm_runtime_facade.dart @@ -83,7 +83,12 @@ class LiteRtLmRuntimeClient { if (version != null && _allowV1) { final unsupported = liteRtLmUnsupportedAbiException(liteRtLmGateAbi()); if (unsupported != null) throw unsupported; - client = LiteRtLmV1RuntimeClient(selected.library); + client = LiteRtLmV1RuntimeClient( + selected.library, + inProcessLiteRtAbiVersion: readLiteRtLmInProcessLiteRtAbiVersion( + selected.library, + ), + ); } else { requireLiteRtLmLegacyCApi(selected.library); client = LiteRtLmLegacyServiceClient(owner); diff --git a/lib/src/backends/litert_lm/litert_lm_service.dart b/lib/src/backends/litert_lm/litert_lm_service.dart index 795558ad4..074e65ad2 100644 --- a/lib/src/backends/litert_lm/litert_lm_service.dart +++ b/lib/src/backends/litert_lm/litert_lm_service.dart @@ -631,7 +631,7 @@ class LiteRtLmService { if (!client.supportsJsonSchemaConstraints) { throw LlamaUnsupportedException( 'Native JSON Schema chat requires all constraint-provider and thinking-config symbols. ' - 'Use the packaged LiteRT-LM v0.19.1-1 runtime through the default ABI-selecting client; ' + 'Use the packaged LiteRT-LM v0.19.1-2 runtime through the default ABI-selecting client; ' 'model and platform qualification still applies.', ); } diff --git a/lib/src/backends/litert_lm/litert_lm_v1_runtime_client.dart b/lib/src/backends/litert_lm/litert_lm_v1_runtime_client.dart index cf2afe8b8..18ca670c8 100644 --- a/lib/src/backends/litert_lm/litert_lm_v1_runtime_client.dart +++ b/lib/src/backends/litert_lm/litert_lm_v1_runtime_client.dart @@ -4,12 +4,18 @@ part of 'litert_lm_v1_runtime.dart'; /// Runtime selection does not qualify an artifact, model or backend. final class LiteRtLmV1RuntimeClient implements LiteRtLmRuntimeClientContract { /// Admits an explicitly supplied library; never discovers a different runtime. + /// + /// [inProcessLiteRtAbiVersion] is the library's + /// `litert_lm_native_in_process_litert_abi_version`, null when not exported. LiteRtLmV1RuntimeClient( DynamicLibrary library, { LiteRtLmV1CreateRunner? createRunner, - }) : _runtime = LiteRtLmV1Runtime(library, createRunner: createRunner); + int? inProcessLiteRtAbiVersion, + }) : _runtime = LiteRtLmV1Runtime(library, createRunner: createRunner), + _inProcessLiteRtAbiVersion = inProcessLiteRtAbiVersion; final LiteRtLmV1Runtime _runtime; + final int? _inProcessLiteRtAbiVersion; LiteRtLmV1Conversation? _conversation; _V1EmbeddingSession? _embedding; LiteRtLmNativeSettlement _embeddingCreation = @@ -159,6 +165,9 @@ final class LiteRtLmV1RuntimeClient implements LiteRtLmRuntimeClientContract { ); } liteRtLmEnsureNativeEmbeddingsQualified(); + liteRtLmEnsureInProcessLiteRtForNativeEmbeddings( + _inProcessLiteRtAbiVersion, + ); ensureLiteRtLmNativeEmbeddingBackend(backend); if (maxInputLength <= 0 || maxInputLength > 0x7fffffff || diff --git a/lib/src/hook/native_release_pins.dart b/lib/src/hook/native_release_pins.dart index 4084e0380..f0dd4b18a 100644 --- a/lib/src/hook/native_release_pins.dart +++ b/lib/src/hook/native_release_pins.dart @@ -106,10 +106,10 @@ const llamaCppBackendSidecarSpecs = [ ]; /// `leehack/litert-lm-native` release tag downloaded for the LiteRT-LM runtime. -const liteRtLmReleaseTag = 'v0.19.1-1'; +const liteRtLmReleaseTag = 'v0.19.1-2'; /// LiteRT-LM cache directory version derived from [liteRtLmReleaseTag]. -const liteRtLmVersion = '0.19.1-1'; +const liteRtLmVersion = '0.19.1-2'; /// A published LiteRT-LM runtime archive and the libraries it must contain. class LiteRtLmBundleSpec { @@ -134,7 +134,7 @@ class LiteRtLmBundleSpec { const liteRtLmBundleSpecs = [ LiteRtLmBundleSpec( 'android-arm64', - sha256: '0f719f12595963f9c3718b920c85be94c0813089e051e95326351d92356f2d21', + sha256: '1b72d7f6b144b3c7514e7c8a1573abf190e57dfc9808037302c113d1713c1bf5', requiredLibraries: { 'libGemmaModelConstraintProvider.so', 'libLiteRtGpuAccelerator.so', @@ -146,7 +146,7 @@ const liteRtLmBundleSpecs = [ ), LiteRtLmBundleSpec( 'android-x64', - sha256: 'fd288b11543e2f0a7e1115051132536f44923ef0ad18a1170b72c8cfa80f04ab', + sha256: 'd6a1601750a4ebe4d994971673d8fc6d05c31a1baaf1462ca0db2f249b66af16', requiredLibraries: { 'libGemmaModelConstraintProvider.so', 'libLiteRtGpuAccelerator.so', @@ -158,17 +158,17 @@ const liteRtLmBundleSpecs = [ ), LiteRtLmBundleSpec( 'ios-arm64', - sha256: '5d268e38c3061c9e3ec401a8b104aae9c16773b9bcbea884b8b0b09817fa788b', + sha256: '26dc6e031d5a55f98c9a4b7183829e941e69fa4399ecc8fa0c4853acf0fe2743', requiredLibraries: {'CLiteRTLM', 'LiteRtLm', 'LiteRtMetalAccelerator'}, ), LiteRtLmBundleSpec( 'ios-arm64-sim', - sha256: 'd812678f802e0c795d65e5824ccd30b594aff562922c1411fd6bbe5da9fca660', + sha256: '90348dfa05b4e7f5e2a5dc5731a3490cce5794d1b8bb586a9f7d597e888b3474', requiredLibraries: {'CLiteRTLM', 'LiteRtLm', 'LiteRtMetalAccelerator'}, ), LiteRtLmBundleSpec( 'macos-arm64', - sha256: '56e974890ad1261754f8dc2b869297ef4ffbd2cd2736fddf46dbf641abbb8cb3', + sha256: '84bc2e7fc00ac9bc3135f5a7e05da6af0bb2b813cf5d996ba8749b86dde37b23', requiredLibraries: { 'libCLiteRTLM_mac.dylib', 'libGemmaModelConstraintProvider.dylib', @@ -181,7 +181,7 @@ const liteRtLmBundleSpecs = [ ), LiteRtLmBundleSpec( 'linux-arm64', - sha256: '7d7520ba8e6e5a0a3faae1262ab9e027a33a96e3feebdddff7460fbd4c65e98e', + sha256: 'c01d608cc1f332e090f96295c32019dd238b16cc194f29264aec950e92e511b5', requiredLibraries: { 'libGemmaModelConstraintProvider.so', 'libLiteRtLm.so', @@ -191,7 +191,7 @@ const liteRtLmBundleSpecs = [ ), LiteRtLmBundleSpec( 'linux-x64', - sha256: '1c93ead8d8977b0b1e69d0054555881af16e2b6e46a584870ab86cd51c28589c', + sha256: '360171860fac20057e107dbbe6fd1b1376d4011efe1bcf6ad7b8045ff13b4d5d', requiredLibraries: { 'libGemmaModelConstraintProvider.so', 'libLiteRtLm.so', @@ -201,7 +201,7 @@ const liteRtLmBundleSpecs = [ ), LiteRtLmBundleSpec( 'windows-x64', - sha256: '7d22e57490483f7ecd9e05219cbe6c17c90ccf769154b7b2e35f7d4adae84fd3', + sha256: 'dd25067751cb9f42434e4f2b8dcdae725dd72b94f36ca5c359bb9b3616750f83', requiredLibraries: { 'LiteRtLm.dll', 'dxcompiler.dll', diff --git a/packages/llamadart_litert_lm_flutter/CHANGELOG.md b/packages/llamadart_litert_lm_flutter/CHANGELOG.md index a69c59b50..3c41d189b 100644 --- a/packages/llamadart_litert_lm_flutter/CHANGELOG.md +++ b/packages/llamadart_litert_lm_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +- Updated Apple SwiftPM native pin to `leehack/litert-lm-native@v0.19.1-2`. + ## 0.19.0 - Pair with core `>=0.19.0 <0.20.0`; update Apple SwiftPM to diff --git a/packages/llamadart_litert_lm_flutter/README.md b/packages/llamadart_litert_lm_flutter/README.md index a83ee8365..d983b3d50 100644 --- a/packages/llamadart_litert_lm_flutter/README.md +++ b/packages/llamadart_litert_lm_flutter/README.md @@ -34,7 +34,7 @@ dependencies: This package has no runtime Dart API of its own. Import `package:llamadart` normally from the core package and use `LlamaBackend()` / `LlamaEngine` there. -The Apple SwiftPM manifest pins `leehack/litert-lm-native@v0.19.1-1`. +The Apple SwiftPM manifest pins `leehack/litert-lm-native@v0.19.1-2`. That runtime loads dedicated ASR `.litertlm` containers such as Whisper tiny. Use the companion that shares the core's `MAJOR.MINOR`: companion `0.19.x` pairs diff --git a/packages/llamadart_litert_lm_flutter/darwin/llamadart_litert_lm_flutter/Package.swift b/packages/llamadart_litert_lm_flutter/darwin/llamadart_litert_lm_flutter/Package.swift index 7d8c54b3b..fc61b8429 100644 --- a/packages/llamadart_litert_lm_flutter/darwin/llamadart_litert_lm_flutter/Package.swift +++ b/packages/llamadart_litert_lm_flutter/darwin/llamadart_litert_lm_flutter/Package.swift @@ -4,7 +4,7 @@ import PackageDescription let packageRoot = URL(fileURLWithPath: #filePath).deletingLastPathComponent() let artifactsRoot = packageRoot.appendingPathComponent("Artifacts") -let liteRtLmTag = "v0.19.1-1" +let liteRtLmTag = "v0.19.1-2" func localArtifactPath(_ name: String) -> String? { let path = artifactsRoot.appendingPathComponent(name).path @@ -47,49 +47,49 @@ let package = Package( repository: "leehack/litert-lm-native", artifactName: "litert-lm-native-apple-LiteRtLm-xcframework-\(liteRtLmTag).zip", tag: liteRtLmTag, - checksum: "f10dbe2c476df31593dcc67263751f0cb4c3f2cdf5dd076ab3d1b3001c10420e" + checksum: "66ee469310ee7aec7bcc438cf0ab5bed6f8ab376f49516839bb18ed70e4e40e0" ), nativeRepoBinaryTarget( name: "CLiteRTLM", repository: "leehack/litert-lm-native", artifactName: "litert-lm-native-apple-CLiteRTLM-xcframework-\(liteRtLmTag).zip", tag: liteRtLmTag, - checksum: "d63eccfdd3ceb0d012014571dc397f550dc64324355041663fc03986bf057414" + checksum: "ef10e320169b741552b99dad122d0f7c6b8929332e53c86213e9754c3191c9f4" ), nativeRepoBinaryTarget( name: "CLiteRTLMMac", repository: "leehack/litert-lm-native", artifactName: "litert-lm-native-apple-CLiteRTLMMac-xcframework-\(liteRtLmTag).zip", tag: liteRtLmTag, - checksum: "b9c5826ba2c6c6906f2b2bc6391452723630ef48e4c96e1389822e9f4d4b4e9b" + checksum: "94083e21752430320f3ff210712efcfc090719dd6f63968a7e7fdf5ce57042af" ), nativeRepoBinaryTarget( name: "LiteRtMetalAccelerator", repository: "leehack/litert-lm-native", artifactName: "litert-lm-native-apple-LiteRtMetalAccelerator-xcframework-\(liteRtLmTag).zip", tag: liteRtLmTag, - checksum: "1a746a231556f03e9887be8a8582b92f9a6a1c1c69938cec88891cff5f2ff80f" + checksum: "12a5315dd958956724fc7a1fa42e179a69575d6fc9be18c22dc4db4bc3019fff" ), nativeRepoBinaryTarget( name: "LiteRt", repository: "leehack/litert-lm-native", artifactName: "litert-lm-native-apple-LiteRt-xcframework-\(liteRtLmTag).zip", tag: liteRtLmTag, - checksum: "4b70eb4e1f2cbd7ede36ed647c3cfb8c56eebedca9785b7cb0eb417a1ab59601" + checksum: "3a57e1b43a341629dd7934863d2c02d97d17bf935fe8908a24aea757d93a8461" ), nativeRepoBinaryTarget( name: "LiteRtWebGpuAccelerator", repository: "leehack/litert-lm-native", artifactName: "litert-lm-native-apple-LiteRtWebGpuAccelerator-xcframework-\(liteRtLmTag).zip", tag: liteRtLmTag, - checksum: "a602c3e2c6d27a275b0575db0e84a8065999ade6bc4ed42ebdfeaf77b8194374" + checksum: "22c737793e329dd7c05fce3d928572a1679906feceee199c02918960225ca225" ), nativeRepoBinaryTarget( name: "WebgpuDawn", repository: "leehack/litert-lm-native", artifactName: "litert-lm-native-apple-WebgpuDawn-xcframework-\(liteRtLmTag).zip", tag: liteRtLmTag, - checksum: "2b2dd40ed3e0c51fc2807715ce364d4a274a9466fee0c8eea34f5ae29315ce03" + checksum: "9b943bed89b9dd21178d4b0f3f2dab5273c941ce045ba28940e5e494ece75036" ), .target( name: "llamadart_litert_lm_flutter", diff --git a/packages/llamadart_validation/assets/capability_coverage.json b/packages/llamadart_validation/assets/capability_coverage.json index b0169d13b..9a557c046 100644 --- a/packages/llamadart_validation/assets/capability_coverage.json +++ b/packages/llamadart_validation/assets/capability_coverage.json @@ -43,7 +43,7 @@ "profiles": [ "assets/profiles/embedding-gguf-cpu.json" ], - "notes": "LiteRT-LM native CPU embeddings are qualified by the local-only litert-lm-multimodal-embedding scenario, not by this pack's profiles; Linux x64, Linux arm64 and Windows x64 joined macOS, iOS and Android arm64 with litert-lm-native v0.19.1-1 (https://github.com/leehack/llamadart/issues/1367). Model-free recording tests cover the native qwen35 Android Vulkan #948 restriction, which applies only to llama.cpp runtimes older than ggml 0.28.0 (bundled runtimes lift it), and the lift on newer runtimes. Device evidence for the lift is recorded on the issue, not by a pack. https://github.com/leehack/llamadart/issues/948" + "notes": "LiteRT-LM native CPU embeddings are qualified by the local-only litert-lm-multimodal-embedding scenario, not by this pack's profiles; Linux x64, Linux arm64 and Windows x64 joined macOS, iOS and Android arm64 with litert-lm-native v0.19.1-1 and require its in-process LiteRT marker from v0.19.1-2; VM tests cover refusal of runtimes without it (https://github.com/leehack/llamadart/issues/1367). Model-free recording tests cover the native qwen35 Android Vulkan #948 restriction, which applies only to llama.cpp runtimes older than ggml 0.28.0 (bundled runtimes lift it), and the lift on newer runtimes. Device evidence for the lift is recorded on the issue, not by a pack. https://github.com/leehack/llamadart/issues/948" }, { "id": "history", diff --git a/packages/llamadart_validation/lib/android_litert_qualification.dart b/packages/llamadart_validation/lib/android_litert_qualification.dart index b753fee5e..3d441d0ae 100644 --- a/packages/llamadart_validation/lib/android_litert_qualification.dart +++ b/packages/llamadart_validation/lib/android_litert_qualification.dart @@ -26,8 +26,10 @@ const s24LiteRtNativeLibraries = { /// Owner runtime tags the S24 binding admits. `v0.19.1-1` rebuilt only the /// Linux and Windows hosts; its Android binaries are byte-identical to -/// `v0.19.1` (#1808). -const s24LiteRtRuntimeTags = {'v0.19.1', 'v0.19.1-1'}; +/// `v0.19.1` (#1808). `v0.19.1-2` changes only the Android `libLiteRtLm.so` +/// and passed the full S24 graph again (Test Lab `matrix-wmalbq6nz437a`, +/// #1830). +const s24LiteRtRuntimeTags = {'v0.19.1', 'v0.19.1-1', 'v0.19.1-2'}; /// Fixed prospective stage caps sum to 1,050s; FTL still caps the run at 1,200s. const s24LiteRtStageSeconds = { diff --git a/packages/llamadart_validation/native/android_litert/README.md b/packages/llamadart_validation/native/android_litert/README.md index 64cb903aa..cdc1758fa 100644 --- a/packages/llamadart_validation/native/android_litert/README.md +++ b/packages/llamadart_validation/native/android_litert/README.md @@ -220,12 +220,15 @@ needed for this Dart/diagnostic-only change. ## Source and APK admission still required Freeze clean source and independent review before preparing an APK. The final -binding must contain exact source commit/tree/inventory, runtime tag `v0.19.1` -or `v0.19.1-1` (same Android binaries) and its owner commit, runtime archive -and manifest hashes, complete owner archive libraries, complete installed APK -libraries, child executable and canonical Qwen template hashes, both unchanged -profiles, run id and the existing shared budget receipt hash. Owner `7ea10d0` is explicitly rejected as the aborted -candidate. No final owner payload is selected by these source files. +binding must contain exact source commit/tree/inventory, runtime tag `v0.19.1`, +`v0.19.1-1` (same Android binaries) or `v0.19.1-2` (requalified on S24 in +`matrix-wmalbq6nz437a`, see +[the adoption notes](../../../../doc/litert_lm_v1_adoption.md)) and its owner +commit, runtime archive and manifest hashes, complete owner archive libraries, +complete installed APK libraries, child executable and canonical Qwen template +hashes, both unchanged profiles, run id and the existing shared budget receipt +hash. Owner `7ea10d0` is explicitly rejected as the aborted candidate. +No final owner payload is selected by these source files. Future native preparation compiles `main.cpp` as an Android arm64 PIE executable with NDK 28.2.13676358, links `-ldl`, and packages it as diff --git a/packages/llamadart_validation/test/android_litert_qualification_test.dart b/packages/llamadart_validation/test/android_litert_qualification_test.dart index 87c1ea533..ed558cff1 100644 --- a/packages/llamadart_validation/test/android_litert_qualification_test.dart +++ b/packages/llamadart_validation/test/android_litert_qualification_test.dart @@ -137,7 +137,7 @@ void main() { } for (final tag in [ 'v0.19.0', - 'v0.19.1-2', + 'v0.19.1-3', 'v0.19.2', 'v0.20.0', '0.19.1-1', diff --git a/skills/llamadart-embeddings/SKILL.md b/skills/llamadart-embeddings/SKILL.md index 57dce4eeb..0a97668c5 100644 --- a/skills/llamadart-embeddings/SKILL.md +++ b/skills/llamadart-embeddings/SKILL.md @@ -92,7 +92,9 @@ modalities and speculative strategies before offering them. embedding-engine selector. Select `ComputeDevice.cpu` on macOS, iOS or Android arm64, Linux x64 or arm64, or Windows x64. Native GPU, Android x86_64 and all LiteRT-LM Web paths throw typed unsupported errors at load, whatever - runtime library is loaded; use llama.cpp embeddings there. Keep the + runtime library is loaded; use llama.cpp embeddings there. On Linux and + Windows a custom runtime older than litert-lm-native v0.19.1-2 is refused + the same way. Keep the default false for existing users; llama.cpp GGUF loaders reject true and use their existing per-call embedding mode. - Load a dedicated embedding GGUF (for example diff --git a/skills/llamadart-getting-started/SKILL.md b/skills/llamadart-getting-started/SKILL.md index cfe5f6d74..398b25ab3 100644 --- a/skills/llamadart-getting-started/SKILL.md +++ b/skills/llamadart-getting-started/SKILL.md @@ -24,10 +24,10 @@ interface does not establish backend/model support; read `await engine.capabilit ## Guidelines -- Use the pinned native LiteRT-LM v0.19.1-1 runtime. Direct calls, service +- Use the pinned native LiteRT-LM v0.19.1-2 runtime. Direct calls, service probes and speech share ABI-aware discovery. Public selection admits legacy runtimes and C API 1.0.x; unknown/future versions are refused before engine - calls. The pin is published native v0.19.1-1 (owner `82d4ae1c`, upstream + calls. The pin is published native v0.19.1-2 (owner `0b15fb34`, upstream `7a03724c`). The selected loader requires macOS 14+ even for legacy libraries and custom paths. Web uses `@litert-lm/core@0.19.0`. diff --git a/skills/llamadart-speech/SKILL.md b/skills/llamadart-speech/SKILL.md index cc7050866..2095ac7c6 100644 --- a/skills/llamadart-speech/SKILL.md +++ b/skills/llamadart-speech/SKILL.md @@ -15,7 +15,7 @@ description: >- - Native LiteRT-LM speech probes and workers share the text client's ABI-aware discovery. Public selection admits legacy runtimes and C API 1.0.x; the - pinned runtime is published native v0.19.1-1. The selector checks macOS 14+ + pinned runtime is published native v0.19.1-2. The selector checks macOS 14+ before owned loads, including legacy libraries and custom paths. ASR also requires its independent bridge version, layout and complete export group; a text C API version proves none of those capabilities. diff --git a/test/e2e/backends/multimodal_embedding_litert_e2e_test.dart b/test/e2e/backends/multimodal_embedding_litert_e2e_test.dart index 14a910538..6ec13879f 100644 --- a/test/e2e/backends/multimodal_embedding_litert_e2e_test.dart +++ b/test/e2e/backends/multimodal_embedding_litert_e2e_test.dart @@ -12,6 +12,7 @@ import 'dart:math' as math; import 'package:crypto/crypto.dart'; import 'package:llamadart/llamadart.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_backend.dart'; +import 'package:llamadart/src/backends/litert_lm/litert_lm_c_api_version.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_service.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_v1_runtime.dart'; import 'package:llamadart/src/backends/litert_lm/worker.dart'; @@ -49,8 +50,15 @@ void main() { runLiteRtLmWorkerForTesting( port.sendPort, LiteRtLmService( - runtimeClientFactory: () => - LiteRtLmV1RuntimeClient(DynamicLibrary.open(candidate)), + runtimeClientFactory: () { + final library = DynamicLibrary.open(candidate); + return LiteRtLmV1RuntimeClient( + library, + inProcessLiteRtAbiVersion: readLiteRtLmInProcessLiteRtAbiVersion( + library, + ), + ); + }, ), exitOnDispose: false, ); diff --git a/test/fixtures/litert_lm/c_api_v1_embedding.c b/test/fixtures/litert_lm/c_api_v1_embedding.c index 106db0cf2..7baae7bdf 100644 --- a/test/fixtures/litert_lm/c_api_v1_embedding.c +++ b/test/fixtures/litert_lm/c_api_v1_embedding.c @@ -40,6 +40,14 @@ int fixture_embedding_audio(void) { return embedding_audio; } int fixture_embedding_types(void) { return embedding_types; } size_t fixture_embedding_byte_count(void) { return embedding_byte_count; } +#ifndef OMIT_IN_PROCESS_LITERT_MARKER +static int32_t embedding_in_process_litert = 1; +void fixture_embedding_in_process_litert(int value) { embedding_in_process_litert = value; } +int32_t litert_lm_native_in_process_litert_abi_version(void) { + return embedding_in_process_litert; +} +#endif + static int embedding_status(int stage) { ++embedding_calls; if (embedding_fault != stage) return 0; diff --git a/test/fixtures/litert_lm/c_api_version.c b/test/fixtures/litert_lm/c_api_version.c index b1372333f..df782fa95 100644 --- a/test/fixtures/litert_lm/c_api_version.c +++ b/test/fixtures/litert_lm/c_api_version.c @@ -24,6 +24,12 @@ int litert_lm_get_api_version(int *major, int *minor, int *patch) { } #endif +#ifdef IN_PROCESS_LITERT_ABI +int litert_lm_native_in_process_litert_abi_version(void) { + return IN_PROCESS_LITERT_ABI; +} +#endif + // A missing gate must fail the test process before an incompatible call can // accidentally look like a supported engine initialization. void *litert_lm_engine_settings_create(void) { abort(); } diff --git a/test/unit/backends/litert_lm/litert_lm_c_api_version_test.dart b/test/unit/backends/litert_lm/litert_lm_c_api_version_test.dart index 3c52470ae..fd64ce51e 100644 --- a/test/unit/backends/litert_lm/litert_lm_c_api_version_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_c_api_version_test.dart @@ -23,6 +23,9 @@ void main() { 'futureMinor': ['-DAPI_MINOR=1'], 'negativePatch': ['-DAPI_PATCH=-1'], 'incomplete': ['-DOMIT_PATCH_WRITE'], + 'inProcess0': ['-DIN_PROCESS_LITERT_ABI=0'], + 'inProcess1': ['-DIN_PROCESS_LITERT_ABI=1'], + 'inProcess2': ['-DIN_PROCESS_LITERT_ABI=2'], }.entries) { final output = '${directory.path}/${entry.key}.${Platform.isMacOS ? 'dylib' : 'so'}'; @@ -65,6 +68,18 @@ void main() { } }); + test('in-process LiteRT probe reports the export value or null', () { + int? read(String name) => readLiteRtLmInProcessLiteRtAbiVersion( + DynamicLibrary.open(libraries[name]!), + ); + expect(read('v1'), isNull); + expect(read('legacy'), isNull); + expect( + [read('inProcess0'), read('inProcess1'), read('inProcess2')], + [0, 1, 2], + ); + }); + test('legacy runtime continues to existing capability checks', () { expect( () => @@ -104,7 +119,7 @@ void main() { .having( (error) => error.message, 'repair', - contains('litert-lm-native v0.19.1-1'), + contains('litert-lm-native v0.19.1-2'), ) .having( (error) => error.message, diff --git a/test/unit/backends/litert_lm/litert_lm_embedding_native_test.dart b/test/unit/backends/litert_lm/litert_lm_embedding_native_test.dart index 555b52585..f56e08dc2 100644 --- a/test/unit/backends/litert_lm/litert_lm_embedding_native_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_embedding_native_test.dart @@ -674,7 +674,7 @@ void main() { 'capability, legacy runtime condition and required runtime', allOf( contains('LiteRT-LM native embeddings on $abi'), - contains('C API 1 runtime from litert-lm-native v0.19.1-1'), + contains('C API 1 runtime from litert-lm-native v0.19.1-2'), contains('legacy one without litert_lm_get_api_version'), contains('v0.18.x'), ), 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 6cba98cba..bf673bfe6 100644 --- a/test/unit/backends/litert_lm/litert_lm_service_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_service_test.dart @@ -154,7 +154,7 @@ void main() { .having( (error) => error.message, 'current runtime', - contains('packaged LiteRT-LM v0.19.1-1 runtime'), + contains('packaged LiteRT-LM v0.19.1-2 runtime'), ) .having( (error) => error.message, diff --git a/test/unit/backends/litert_lm/litert_lm_v1_embedding_test.dart b/test/unit/backends/litert_lm/litert_lm_v1_embedding_test.dart index 7f6915768..b2ae3bac3 100644 --- a/test/unit/backends/litert_lm/litert_lm_v1_embedding_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_v1_embedding_test.dart @@ -22,9 +22,10 @@ void main() { late DynamicLibrary library; late DynamicLibrary missing; late String libraryPath; + late String unmarkedPath; late String model; - int count(String name) => - library.lookupFunction( + int count(String name, [DynamicLibrary? from]) => + (from ?? library).lookupFunction( 'fixture_embedding_$name', )(); void set(String name, int value) => @@ -72,6 +73,18 @@ void main() { library = DynamicLibrary.open(path); } } + unmarkedPath = + '${suite().path}/unmarked.${Platform.isMacOS ? 'dylib' : 'so'}'; + final unmarked = await Process.run('cc', [ + '-shared', + '-fPIC', + '-pthread', + '-DOMIT_IN_PROCESS_LITERT_MARKER', + 'test/fixtures/litert_lm/c_api_v1_embedding.c', + '-o', + unmarkedPath, + ]); + expect(unmarked.exitCode, 0, reason: '${unmarked.stderr}'); model = '${suite().path}/model.litertlm'; File(model).writeAsBytesSync(fixtures.embeddingBundleHeader()); }); @@ -79,6 +92,7 @@ void main() { debugLiteRtLmAbiOverride = Abi.macosArm64; set('fault', 0); set('delay', 0); + set('in_process_litert', 1); expect(count('count'), 0); addTearDown(() => debugLiteRtLmAbiOverride = null); }); @@ -303,6 +317,87 @@ void main() { expect(count('count'), 0); }); } + Future createSelected(String path) { + final selected = LiteRtLmRuntimeClient(libraryPath: path); + addTearDown(selected.dispose); + return selected.createEmbeddingSession( + modelPath: model, + backend: 'cpu', + cacheDir: '/secret/cache', + maxInputLength: 1024, + numberOfThreads: 2, + ); + } + + for (final abi in [Abi.linuxArm64, Abi.linuxX64, Abi.windowsX64]) { + for (final marker in [null, 0, 2, -1]) { + test('$abi refuses in-process LiteRT marker $marker before any native ' + 'embedding call', () async { + debugLiteRtLmAbiOverride = abi; + if (marker != null) set('in_process_litert', marker); + final runtime = DynamicLibrary.open( + marker == null ? unmarkedPath : libraryPath, + ); + final before = count('call_count', runtime); + await expectLater( + createSelected(marker == null ? unmarkedPath : libraryPath), + throwsA( + isA().having( + (error) => error.message, + 'message', + allOf( + contains('native embeddings on $abi'), + contains('LiteRT compiled into the runtime'), + contains('litert-lm-native v0.19.1-2'), + contains( + marker == null + ? 'does not export' + : 'reports litert_lm_native_in_process_litert_abi_version ' + '$marker', + ), + ), + ), + ), + ); + expect( + [ + count('call_count', runtime), + count('entered', runtime), + count('count', runtime), + ], + [before, 0, 0], + ); + }); + } + test('$abi refuses a directly constructed client without a marker ' + 'value', () async { + debugLiteRtLmAbiOverride = abi; + final before = count('call_count'); + await expectLater( + create(client()), + throwsA(isA()), + ); + expect(count('call_count'), before); + }); + } + for (final abi in [Abi.macosArm64, Abi.iosArm64, Abi.androidArm64]) { + test( + '$abi creates embeddings without the in-process LiteRT marker', + () async { + debugLiteRtLmAbiOverride = abi; + final runtime = DynamicLibrary.open(unmarkedPath); + final unmarked = await createSelected(unmarkedPath); + expect(await unmarked.compute(input(), normalize: false), [3, 4, 0]); + unmarked.dispose(); + expect(count('count', runtime), 0); + set('in_process_litert', 0); + final reportsZero = await createSelected(libraryPath); + expect(await reportsZero.compute(input(), normalize: false), [3, 4, 0]); + reportsZero.dispose(); + expect(count('count'), 0); + }, + ); + } test( 'missing export, unsupported target/backend and invalid bundle allocate nothing', () async { diff --git a/test/unit/platform/io/runtime_setup_report_io_test.dart b/test/unit/platform/io/runtime_setup_report_io_test.dart index abe56893f..4da14b727 100644 --- a/test/unit/platform/io/runtime_setup_report_io_test.dart +++ b/test/unit/platform/io/runtime_setup_report_io_test.dart @@ -57,7 +57,7 @@ void main() { ]); expect(report.runtimes.map((runtime) => runtime.expectedReleaseTag), [ 'v0.9.0', - 'v0.19.1-1', + 'v0.19.1-2', 'v0.3.0-3', ]); expect(report.dartVersion, '3.13.1'); diff --git a/test/unit/tooling/check_webgpu_bridge_tag_test.dart b/test/unit/tooling/check_webgpu_bridge_tag_test.dart index d755048de..819e77ae6 100644 --- a/test/unit/tooling/check_webgpu_bridge_tag_test.dart +++ b/test/unit/tooling/check_webgpu_bridge_tag_test.dart @@ -313,7 +313,7 @@ void main() { ); expect( File(nativeLlamaCppTagPath).readAsStringSync(), - contains("const liteRtLmReleaseTag = 'v0.19.1-1';"), + contains("const liteRtLmReleaseTag = 'v0.19.1-2';"), ); }, ); diff --git a/test/unit/tooling/litert_lm_library_smoke_test.dart b/test/unit/tooling/litert_lm_library_smoke_test.dart index f330723d4..e1d1911ba 100644 --- a/test/unit/tooling/litert_lm_library_smoke_test.dart +++ b/test/unit/tooling/litert_lm_library_smoke_test.dart @@ -102,6 +102,7 @@ void main() { expect(liteRtLmSmokeUsesCApiV1('v0.19.0'), isTrue); expect(liteRtLmSmokeUsesCApiV1('v0.19.1'), isTrue); expect(liteRtLmSmokeUsesCApiV1('v0.19.1-1'), isTrue); + expect(liteRtLmSmokeUsesCApiV1('v0.19.1-2'), isTrue); expect(liteRtLmSmokeUsesCApiV1('v0.18.1-4'), isFalse); for (final tag in ['v0.19.0-1', 'v0.19.2', 'v0.20.0', 'g0123456789ab']) { expect( @@ -118,9 +119,9 @@ void main() { }); for (final (tag, abi) in [ - ('v0.19.1-1', Abi.linuxX64), - ('v0.19.1-1', Abi.macosArm64), - ('v0.19.1-1', Abi.windowsX64), + ('v0.19.1-2', Abi.linuxX64), + ('v0.19.1-2', Abi.macosArm64), + ('v0.19.1-2', Abi.windowsX64), ('v0.18.1-4', Abi.linuxX64), ('v0.18.1-4', Abi.macosArm64), ('v0.18.1-4', Abi.windowsX64), diff --git a/test/unit/tooling/sync_native_release_pins_script_test.dart b/test/unit/tooling/sync_native_release_pins_script_test.dart index 6ee4cba11..843d9b204 100644 --- a/test/unit/tooling/sync_native_release_pins_script_test.dart +++ b/test/unit/tooling/sync_native_release_pins_script_test.dart @@ -1602,7 +1602,7 @@ printf '%s\\n' '{"tag_name":"v0.2.0-1","assets":[]}' test('keeps LiteRT release identity separate from cache version', () { final pins = File(_pinsPath).readAsStringSync(); - expect(pins, contains("const liteRtLmReleaseTag = 'v0.19.1-1';")); + expect(pins, contains("const liteRtLmReleaseTag = 'v0.19.1-2';")); final hook = File('hook/build.dart').readAsStringSync(); expect(hook, contains(r"'$liteRtLmReleaseTag'")); expect(hook, isNot(contains(r"v$liteRtLmVersion"))); diff --git a/tool/litert_lm_library_smoke.dart b/tool/litert_lm_library_smoke.dart index fefef2cf2..2c770ae7b 100644 --- a/tool/litert_lm_library_smoke.dart +++ b/tool/litert_lm_library_smoke.dart @@ -51,7 +51,7 @@ bool _isSupportedHost() { /// Selects only a reviewed release's required smoke inventory. bool liteRtLmSmokeUsesCApiV1(String releaseTag) { return switch (releaseTag) { - 'v0.19.0' || 'v0.19.1' || 'v0.19.1-1' => true, + 'v0.19.0' || 'v0.19.1' || 'v0.19.1-1' || 'v0.19.1-2' => true, 'v0.18.1-4' => false, _ => throw UnsupportedError( 'LiteRT-LM library smoke has no reviewed C API inventory for $releaseTag.', diff --git a/tool/macos_litert_lm_prepare_app.sh b/tool/macos_litert_lm_prepare_app.sh index 78b3b5b88..4b7d0fd42 100755 --- a/tool/macos_litert_lm_prepare_app.sh +++ b/tool/macos_litert_lm_prepare_app.sh @@ -112,8 +112,8 @@ resolve_litert_dir() { fi local candidates=( - "$ROOT_DIR/.dart_tool/llamadart/litert_lm/0.19.1-1/macos_$LITERT_ARCH" - "$ROOT_DIR/.dart_tool/llamadart/litert_lm/0.19.1-1/macos/$LITERT_ARCH" + "$ROOT_DIR/.dart_tool/llamadart/litert_lm/0.19.1-2/macos_$LITERT_ARCH" + "$ROOT_DIR/.dart_tool/llamadart/litert_lm/0.19.1-2/macos/$LITERT_ARCH" ) local candidate for candidate in "${candidates[@]}"; do diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index a8a4d0203..523ce3a7d 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -16,6 +16,8 @@ validate against the exact release tag notes. - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). - Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). +- Refuse LiteRT-LM native embeddings on Linux and Windows with `LlamaUnsupportedException` unless the runtime reports LiteRT linked in process (litert-lm-native `v0.19.1-2` or later), so a custom `v0.19.0` or `v0.19.1` runtime no longer crashes creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). +- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). - Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). diff --git a/website/docs/guides/embeddings.md b/website/docs/guides/embeddings.md index 2084653b3..fbf480f89 100644 --- a/website/docs/guides/embeddings.md +++ b/website/docs/guides/embeddings.md @@ -112,7 +112,9 @@ arm64 (verified on a Galaxy S24 without SME and on arm64 emulators), Linux x64 and arm64, or Windows x64. Native GPU, Android x86_64 and all LiteRT-LM Web paths throw `LlamaUnsupportedException` at load, before native engine creation, whatever runtime library is loaded. On Linux and Windows, a custom runtime -older than litert-lm-native `v0.19.1-1` cannot create the embedding engine +older than litert-lm-native `v0.19.1-2` throws `LlamaUnsupportedException` +before native engine creation, because older desktop runtimes crash creating +the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). This flag is LiteRT-LM-only: llama.cpp GGUF loaders reject true; the default false preserves existing loading. The qualified bundle is EmbeddingGemma-2 740M; probe it rather diff --git a/website/docs/maintainers/native-and-web-sync.md b/website/docs/maintainers/native-and-web-sync.md index 240bbb948..f2b83dfcd 100644 --- a/website/docs/maintainers/native-and-web-sync.md +++ b/website/docs/maintainers/native-and-web-sync.md @@ -393,9 +393,11 @@ parameters. The public lazy facade, service metadata/finish probes and speech worker share discovery and ABI selection. `_liteRtLmV1ProductionSelection` in `litert_lm_runtime_facade.dart` enables public C API 1.0.x dispatch. The native hook and Apple companion source now pin published -[v0.19.1-1](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-1), -owner `82d4ae1c` / upstream `7a03724c`, which keeps C API 1.0.0 and the -`v0.19.0` exports. The `-1` rebuild links LiteRT into the Linux and Windows +[v0.19.1-2](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-2), +owner `0b15fb34` / upstream `7a03724c`, which keeps C API 1.0.0 and the +`v0.19.0` exports and adds the in-process LiteRT marker +`litert_lm_native_in_process_litert_abi_version` (1 on every platform). The +earlier `-1` rebuild links LiteRT into the Linux and Windows `libLiteRtLm` ([litert-lm-native#112](https://github.com/leehack/litert-lm-native/pull/112)); its Apple and Android binaries are identical to `v0.19.1`. Upstream `v0.19.1`'s only runtime change makes the main executor default @@ -434,7 +436,7 @@ blocks unload and dispose. On Linux ext4, releasing a freshly written CPU XNNPACK weight cache flushes it to disk, about 4 s for Qwen3 0.6B's 600 MB cache on CI disks ([#1814](https://github.com/leehack/llamadart/issues/1814)). -Public ABI-aware selection and the v0.19.1-1 source pin are enabled; remaining +Public ABI-aware selection and the v0.19.1-2 source pin are enabled; remaining consumer, feature and platform gates are recorded in `doc/litert_lm_v1_adoption.md`. This transport contract alone does not qualify a model or device. The owner proxy's diff --git a/website/docs/platforms/known-platform-issues.md b/website/docs/platforms/known-platform-issues.md index 0a03f3fd9..8d43a8435 100644 --- a/website/docs/platforms/known-platform-issues.md +++ b/website/docs/platforms/known-platform-issues.md @@ -65,16 +65,20 @@ feature. For which runtime supports which feature, see the ## Linux and Windows - A custom LiteRT-LM runtime (`LLAMADART_LITERT_LM_LIB_DIR`) on Linux or - Windows must be litert-lm-native `v0.19.1-1` or later. Earlier desktop - runtimes link a prebuilt LiteRT built with a different C++ runtime: CPU - embedding engine creation fails on Linux and crashes on Windows x64 + Windows must be litert-lm-native `v0.19.1-1` or later, and `v0.19.1-2` or + later for embeddings. Earlier desktop runtimes link a prebuilt LiteRT built + with a different C++ runtime: CPU embedding engine creation fails on Linux + and crashes on Windows x64 ([#1367](https://github.com/leehack/llamadart/issues/1367)), and `v0.19.0` and `v0.19.1` explicit GPU generation crashes at the first decode on Linux x64 and Windows x64 ([#1795](https://github.com/leehack/llamadart/issues/1795)). - Legacy `v0.18.x` runtimes are refused for embeddings before any native call, - though `checkLoad`, which opens no runtime, reports them as supported; - `v0.19.0` and `v0.19.1` expose the same C API 1.0 as `v0.19.1-1`, so the - load gate cannot tell them apart. + Embeddings need a runtime whose + `litert_lm_native_in_process_litert_abi_version` export reports 1, first + shipped in `v0.19.1-2`; any other runtime, including `v0.18.x`, `v0.19.0`, + `v0.19.1` and `v0.19.1-1`, is refused before any native embedding call, + though `checkLoad`, which opens no runtime, reports it as supported. GPU + generation is not gated: the marker does not establish GPU support, and + `v0.19.0` and `v0.19.1` expose the same C API 1.0 as later runtimes. - Linux x64 LiteRT-LM GPU needs a hardware Vulkan driver. When every Vulkan device is a software rasterizer (Mesa llvmpipe/lavapipe, SwiftShader), an explicit GPU load throws `LlamaUnsupportedException` and a GPU hint under diff --git a/website/docs/platforms/native-build-hooks.md b/website/docs/platforms/native-build-hooks.md index 4cc331772..213444945 100644 --- a/website/docs/platforms/native-build-hooks.md +++ b/website/docs/platforms/native-build-hooks.md @@ -101,7 +101,7 @@ hooks: ABI checks and requires macOS 14+ before loading even an explicit path or legacy library; public selection admits C API 1.0.x while unknown/future versions remain unsupported. The hook and Apple companion pin published - native `v0.19.1-1`. + native `v0.19.1-2`. - An empty or all-unknown selection falls back to `llama_cpp` and `litert_lm`; one that leaves no runtime, such as `none`, fails the build. diff --git a/website/docs/platforms/support-matrix.md b/website/docs/platforms/support-matrix.md index d1bae93e1..b47071224 100644 --- a/website/docs/platforms/support-matrix.md +++ b/website/docs/platforms/support-matrix.md @@ -165,7 +165,7 @@ native and web. Model architecture support depends on the pinned runtime; see | MoE expert placement and cache | `cpuMoeLayers` keeps experts in host memory; `moeCacheBytes` caches them on Metal and CUDA GPUs (qualified on Metal with OLMoE; CUDA has no hardware evidence); only `moeCacheBytes` throws `LlamaUnsupportedException` on Vulkan, other backends and tensor split, while `cpuMoeLayers` alone runs there | No | No | No | | State persistence | Yes | Yes; WASMFS paths, lost on page reload | No | No | | State identity (`stateIdentity`) | `llamadart-native` `v0.7.0-3+` | No: the bridge reports no build identity | No | No | -| Embeddings | Yes; one-pass attention and MEAN/CLS inputs must fit the physical micro-batch | Yes; rejects rerankers and over-long one-pass input as native does | CPU, explicit embedding engine; macOS arm64, iOS arm64, Linux x64 and arm64, and Windows x64 qualified; Android arm64 verified on a Galaxy S24 without SME and on arm64 emulators; Android x86_64 throws `LlamaUnsupportedException` at load | Unsupported (parity gate) | +| Embeddings | Yes; one-pass attention and MEAN/CLS inputs must fit the physical micro-batch | Yes; rejects rerankers and over-long one-pass input as native does | CPU, explicit embedding engine; macOS arm64, iOS arm64, Linux x64 and arm64, and Windows x64 qualified (Linux and Windows need litert-lm-native `v0.19.1-2` or later, older custom runtimes are refused); Android arm64 verified on a Galaxy S24 without SME and on arm64 emulators; Android x86_64 throws `LlamaUnsupportedException` at load | Unsupported (parity gate) | | Reranking | Rank-pooled GGUF only; explicit loaded-context probe, complete-pair limits and independent sequence batching | No | No | No | | Text task helpers and Matryoshka | Opt-in EG2 text profile; CPU BF16 retrieval reference | Same Dart helpers on an available embedding engine; no new Web qualification | Same Dart helpers on an available CPU embedding engine; bundle requires independent retrieval qualification | Unsupported with the underlying embedding engine | | Image/audio embeddings (`embedContent`) | EmbeddingGemma-2 + compatible projector, native v0.7.0-1; one complete micro-batch (BF16 qualified on CPU on macOS arm64, Linux x64, Windows x64, Android and iOS, and on macOS Metal; other GPU backends unqualified) | Explicit API-version-1 modality probe + compatible projector; EmbeddingGemma-2 qualified Chrome CPU wasm memory64 vs native CPU/Metal; repeated media batches qualified only on memory64 (wasm32 unqualified); hardware WebGPU unqualified | CPU; bundle processors on macOS arm64, iOS arm64, Android arm64 (Galaxy S24 and emulators), Linux x64 and arm64, and Windows x64 | Unsupported (parity gate) | @@ -216,20 +216,20 @@ web are on [Known platform issues](./known-platform-issues). | Runtime | Pinned release | | --- | --- | | llama.cpp native | `leehack/llamadart-native@v0.9.0` | -| LiteRT-LM native | `leehack/litert-lm-native@v0.19.1-1` | +| LiteRT-LM native | `leehack/litert-lm-native@v0.19.1-2` | | stable-diffusion.cpp native (opt-in, Preview) | `leehack/stable-diffusion-native@v0.3.0-3`, for [image generation](../guides/image-generation); see [Opt-in stable_diffusion runtime](./native-build-hooks#opt-in-stable_diffusion-runtime-experimental). Flutter iOS/macOS apps link its XCFramework through `llamadart_stable_diffusion_flutter` | | WebGPU bridge assets | `leehack/llama-web-bridge-assets`; see [Pinned bridge assets](./webgpu-bridge#pinned-bridge-assets) | The native-assets hook currently pins `llamadart-native` tag `v0.9.0` and -`litert-lm-native` release `v0.19.1-1` (`lib/src/hook/native_release_pins.dart`). +`litert-lm-native` release `v0.19.1-2` (`lib/src/hook/native_release_pins.dart`). The direct native client, service probes and speech worker share ABI-aware discovery. Public selection admits legacy runtimes and C API 1.0.x; unknown or future versions are refused before engine calls. The pinned runtime is published native -[v0.19.1-1](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-1) -(owner `82d4ae1c`, upstream `7a03724c`). The selected loader requires macOS 14+ +[v0.19.1-2](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-2) +(owner `0b15fb34`, upstream `7a03724c`). The selected loader requires macOS 14+ before loading any core or companion library, including legacy libraries and custom paths. Web uses `@litert-lm/core@0.19.0`. The Flutter companion's iOS 16.4 floor remains separate. From e2d60d9af7f723e5e3a049c65f73e7dfb80aab94 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sun, 8 Nov 2026 23:46:01 -0500 Subject: [PATCH 8/9] Prepare 0.19.1 release --- CHANGELOG.md | 14 ++++++++------ README.md | 10 +++++----- example/chat_app/pubspec.lock | 8 ++++---- packages/llamadart_litert_lm_flutter/CHANGELOG.md | 8 ++++++-- packages/llamadart_litert_lm_flutter/README.md | 4 ++-- packages/llamadart_litert_lm_flutter/pubspec.yaml | 4 ++-- packages/llamadart_llama_cpp_flutter/CHANGELOG.md | 7 +++++++ packages/llamadart_llama_cpp_flutter/README.md | 4 ++-- packages/llamadart_llama_cpp_flutter/pubspec.yaml | 2 +- .../CHANGELOG.md | 7 +++++++ .../llamadart_stable_diffusion_flutter/README.md | 4 ++-- .../pubspec.yaml | 2 +- packages/llamadart_validation/pubspec.lock | 2 +- pubspec.yaml | 2 +- website/docs/changelog/recent-releases.md | 14 ++++++++------ website/docs/getting-started/installation.md | 10 +++++----- website/docs/guides/image-generation.md | 2 +- website/docs/maintainers/native-and-web-sync.md | 10 ++++++++++ website/examples/observability/pubspec.lock | 2 +- 19 files changed, 74 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25cd197db..1f44d3edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,14 @@ -## Unreleased +## 0.19.1 +- Keep the default WebGPU bridge assets at `v0.1.83` (unchanged from 0.19.0). +- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. Linux and Windows native embeddings now require that report and refuse an older runtime, such as a custom `v0.19.0` or `v0.19.1`, with `LlamaUnsupportedException` instead of crashing when creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). +- Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps, whose runtime links LiteRT in; an older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). +- Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load, and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). -- Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). -- Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). -- Refuse LiteRT-LM native embeddings on Linux and Windows with `LlamaUnsupportedException` unless the runtime reports LiteRT linked in process (litert-lm-native `v0.19.1-2` or later), so a custom `v0.19.0` or `v0.19.1` runtime no longer crashes creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). -- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). -- Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). +- Release all three Apple runtime companions at `0.19.1` with a Flutter floor of `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve them ([#1834](https://github.com/leehack/llamadart/issues/1834)). The LiteRT-LM companion pins `v0.19.1-2` and requires core `0.19.1`. + +Runtime baseline: native llama.cpp `v0.9.0` and Web use upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`; native LiteRT-LM uses `v0.19.1-2` and stable-diffusion uses `v0.3.0-3`. Web LiteRT-LM uses `@litert-lm/core@0.19.0`. Manifest SHA-256: `ae6f488408672f9ba28d8f9e664a2b85f4e12048f290e259e18dd0b750c038e5`. ## 0.19.0 diff --git a/README.md b/README.md index 6a07a0fd4..47b0bf9b9 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ LFM2 replies cut off at a reported length limit expose raw `partialToolCalls` di ```yaml dependencies: - llamadart: ^0.19.0 + llamadart: ^0.19.1 ``` ```bash @@ -55,10 +55,10 @@ companion shares its core's `MAJOR.MINOR` and constrains `llamadart` to it. ```yaml dependencies: - llamadart: ^0.19.0 - llamadart_llama_cpp_flutter: ^0.19.0 # GGUF / llama.cpp - llamadart_litert_lm_flutter: ^0.19.0 # Apple .litertlm / LiteRT-LM targets - llamadart_stable_diffusion_flutter: ^0.19.0 # Apple image generation, opt-in + llamadart: ^0.19.1 + llamadart_llama_cpp_flutter: ^0.19.1 # GGUF / llama.cpp + llamadart_litert_lm_flutter: ^0.19.1 # Apple .litertlm / LiteRT-LM targets + llamadart_stable_diffusion_flutter: ^0.19.1 # Apple image generation, opt-in ``` Pairing rules, the SwiftPM bootstrap and the privacy manifest are in diff --git a/example/chat_app/pubspec.lock b/example/chat_app/pubspec.lock index eabf42f1d..98171f04e 100644 --- a/example/chat_app/pubspec.lock +++ b/example/chat_app/pubspec.lock @@ -421,28 +421,28 @@ packages: path: "../.." relative: true source: path - version: "0.19.0" + version: "0.19.1" llamadart_litert_lm_flutter: dependency: "direct main" description: path: "../../packages/llamadart_litert_lm_flutter" relative: true source: path - version: "0.19.0" + version: "0.19.1" llamadart_llama_cpp_flutter: dependency: "direct main" description: path: "../../packages/llamadart_llama_cpp_flutter" relative: true source: path - version: "0.19.0" + version: "0.19.1" llamadart_stable_diffusion_flutter: dependency: "direct main" description: path: "../../packages/llamadart_stable_diffusion_flutter" relative: true source: path - version: "0.19.0" + version: "0.19.1" llamadart_validation: dependency: "direct main" description: diff --git a/packages/llamadart_litert_lm_flutter/CHANGELOG.md b/packages/llamadart_litert_lm_flutter/CHANGELOG.md index 3c41d189b..88c03982f 100644 --- a/packages/llamadart_litert_lm_flutter/CHANGELOG.md +++ b/packages/llamadart_litert_lm_flutter/CHANGELOG.md @@ -1,6 +1,10 @@ -## Unreleased +## 0.19.1 -- Updated Apple SwiftPM native pin to `leehack/litert-lm-native@v0.19.1-2`. +- Pair with core `>=0.19.1 <0.20.0`; update Apple SwiftPM to + `leehack/litert-lm-native@v0.19.1-2`, which reports LiteRT linked in process. +- Raise the Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) + satisfies `sdk: ^3.10.7` + ([#1834](https://github.com/leehack/llamadart/issues/1834)). ## 0.19.0 diff --git a/packages/llamadart_litert_lm_flutter/README.md b/packages/llamadart_litert_lm_flutter/README.md index d983b3d50..7e4886928 100644 --- a/packages/llamadart_litert_lm_flutter/README.md +++ b/packages/llamadart_litert_lm_flutter/README.md @@ -27,8 +27,8 @@ also request an x86_64 Simulator slice must exclude x86_64 for LiteRT-LM builds. ```yaml dependencies: - llamadart: ^0.19.0 - llamadart_litert_lm_flutter: ^0.19.0 + llamadart: ^0.19.1 + llamadart_litert_lm_flutter: ^0.19.1 ``` This package has no runtime Dart API of its own. Import `package:llamadart` diff --git a/packages/llamadart_litert_lm_flutter/pubspec.yaml b/packages/llamadart_litert_lm_flutter/pubspec.yaml index eb21c89d8..30ee0a353 100644 --- a/packages/llamadart_litert_lm_flutter/pubspec.yaml +++ b/packages/llamadart_litert_lm_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: llamadart_litert_lm_flutter description: Flutter Apple SwiftPM runtime companion package for llamadart LiteRT-LM support. -version: 0.19.0 +version: 0.19.1 repository: https://github.com/leehack/llamadart/tree/main/packages/llamadart_litert_lm_flutter homepage: https://github.com/leehack/llamadart issue_tracker: https://github.com/leehack/llamadart/issues @@ -17,7 +17,7 @@ environment: dependencies: flutter: sdk: flutter - llamadart: '>=0.19.0 <0.20.0' + llamadart: '>=0.19.1 <0.20.0' dev_dependencies: flutter_test: diff --git a/packages/llamadart_llama_cpp_flutter/CHANGELOG.md b/packages/llamadart_llama_cpp_flutter/CHANGELOG.md index e4a32c738..514623c69 100644 --- a/packages/llamadart_llama_cpp_flutter/CHANGELOG.md +++ b/packages/llamadart_llama_cpp_flutter/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.19.1 + +- Raise the Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) + satisfies `sdk: ^3.10.7` + ([#1834](https://github.com/leehack/llamadart/issues/1834)); Apple SwiftPM stays + pinned to `leehack/llamadart-native@v0.9.0`. + ## 0.19.0 - Pair with core `>=0.19.0 <0.20.0`; update Apple SwiftPM to diff --git a/packages/llamadart_llama_cpp_flutter/README.md b/packages/llamadart_llama_cpp_flutter/README.md index 1de193967..cab0dec64 100644 --- a/packages/llamadart_llama_cpp_flutter/README.md +++ b/packages/llamadart_llama_cpp_flutter/README.md @@ -13,8 +13,8 @@ with core `0.19.x`. Upgrade both together. Earlier pairings are in the ```yaml dependencies: - llamadart: ^0.19.0 - llamadart_llama_cpp_flutter: ^0.19.0 + llamadart: ^0.19.1 + llamadart_llama_cpp_flutter: ^0.19.1 ``` This package has no runtime Dart API of its own. Import `package:llamadart` diff --git a/packages/llamadart_llama_cpp_flutter/pubspec.yaml b/packages/llamadart_llama_cpp_flutter/pubspec.yaml index 5375a41f5..d8ca1285d 100644 --- a/packages/llamadart_llama_cpp_flutter/pubspec.yaml +++ b/packages/llamadart_llama_cpp_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: llamadart_llama_cpp_flutter description: Flutter Apple SwiftPM runtime companion package for llamadart llama.cpp and GGUF support. -version: 0.19.0 +version: 0.19.1 repository: https://github.com/leehack/llamadart/tree/main/packages/llamadart_llama_cpp_flutter homepage: https://github.com/leehack/llamadart issue_tracker: https://github.com/leehack/llamadart/issues diff --git a/packages/llamadart_stable_diffusion_flutter/CHANGELOG.md b/packages/llamadart_stable_diffusion_flutter/CHANGELOG.md index 17ec76774..3fb628a7f 100644 --- a/packages/llamadart_stable_diffusion_flutter/CHANGELOG.md +++ b/packages/llamadart_stable_diffusion_flutter/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.19.1 + +- Raise the Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) + satisfies `sdk: ^3.10.7` + ([#1834](https://github.com/leehack/llamadart/issues/1834)); Apple SwiftPM stays + pinned to `leehack/stable-diffusion-native@v0.3.0-3`. + ## 0.19.0 - Pair with core `>=0.19.0 <0.20.0`; Apple SwiftPM stays pinned to diff --git a/packages/llamadart_stable_diffusion_flutter/README.md b/packages/llamadart_stable_diffusion_flutter/README.md index 51658278b..71e6f96d1 100644 --- a/packages/llamadart_stable_diffusion_flutter/README.md +++ b/packages/llamadart_stable_diffusion_flutter/README.md @@ -19,8 +19,8 @@ with core `0.19.x`. Upgrade both together. Earlier pairings are in the ```yaml dependencies: - llamadart: ^0.19.0 - llamadart_stable_diffusion_flutter: ^0.19.0 + llamadart: ^0.19.1 + llamadart_stable_diffusion_flutter: ^0.19.1 ``` Adding the package selects the `stable_diffusion` runtime for Flutter iOS and diff --git a/packages/llamadart_stable_diffusion_flutter/pubspec.yaml b/packages/llamadart_stable_diffusion_flutter/pubspec.yaml index 1d6859aa2..085d235a4 100644 --- a/packages/llamadart_stable_diffusion_flutter/pubspec.yaml +++ b/packages/llamadart_stable_diffusion_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: llamadart_stable_diffusion_flutter description: Flutter Apple SwiftPM runtime companion package for llamadart stable-diffusion.cpp image generation. -version: 0.19.0 +version: 0.19.1 repository: https://github.com/leehack/llamadart/tree/main/packages/llamadart_stable_diffusion_flutter homepage: https://github.com/leehack/llamadart issue_tracker: https://github.com/leehack/llamadart/issues diff --git a/packages/llamadart_validation/pubspec.lock b/packages/llamadart_validation/pubspec.lock index d48245699..354610761 100644 --- a/packages/llamadart_validation/pubspec.lock +++ b/packages/llamadart_validation/pubspec.lock @@ -215,7 +215,7 @@ packages: path: "../.." relative: true source: path - version: "0.19.0" + version: "0.19.1" logging: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c32d581c6..405bbac9a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: llamadart description: Cross-platform, on-device LLM inference for Dart and Flutter. Run GGUF (llama.cpp) and LiteRT-LM models locally on Android, iOS, macOS, Windows, Linux and web. -version: 0.19.0 +version: 0.19.1 homepage: https://llamadart.leehack.com repository: https://github.com/leehack/llamadart issue_tracker: https://github.com/leehack/llamadart/issues diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 523ce3a7d..8ec470487 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -11,15 +11,17 @@ For upgrade planning, combine this page with the [Upgrade Checklist](../migration/upgrade-checklist). For breaking changes, validate against the exact release tag notes. -## Unreleased +## 0.19.1 +- Keep default WebGPU bridge assets at `v0.1.83` (unchanged from 0.19.0). +- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. Linux and Windows native embeddings now require that report and refuse an older runtime, such as a custom `v0.19.0` or `v0.19.1`, with `LlamaUnsupportedException` instead of crashing when creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). +- Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps, whose runtime links LiteRT in; an older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). +- Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load, and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). -- Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps; the `v0.19.1-1` runtime links LiteRT in. An older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). -- Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). -- Refuse LiteRT-LM native embeddings on Linux and Windows with `LlamaUnsupportedException` unless the runtime reports LiteRT linked in process (litert-lm-native `v0.19.1-2` or later), so a custom `v0.19.0` or `v0.19.1` runtime no longer crashes creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). -- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. - Fix model cache `clear`, `remove` and `prune` on Windows failing with "Access is denied" when another process or isolate was deleting the same entry at that moment ([#1821](https://github.com/leehack/llamadart/issues/1821)). -- Raise the Apple companion packages' Flutter floor to `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve ([#1834](https://github.com/leehack/llamadart/issues/1834)). +- Release all three Apple runtime companions at `0.19.1` with a Flutter floor of `>=3.38.6`, the first Flutter whose Dart (3.10.7) satisfies their `sdk: ^3.10.7`; Flutter 3.38.0 to 3.38.5 could not resolve them ([#1834](https://github.com/leehack/llamadart/issues/1834)). The LiteRT-LM companion pins `v0.19.1-2` and requires core `0.19.1`. + +Runtime baseline: native llama.cpp `v0.9.0` and Web use upstream `v0.9.0@cd959bae99ff4bed22bef2604f45241c09bbb8c8`; native LiteRT-LM uses `v0.19.1-2` and stable-diffusion uses `v0.3.0-3`. Web LiteRT-LM uses `@litert-lm/core@0.19.0`. Manifest SHA-256: `ae6f488408672f9ba28d8f9e664a2b85f4e12048f290e259e18dd0b750c038e5`. ## 0.19.0 diff --git a/website/docs/getting-started/installation.md b/website/docs/getting-started/installation.md index ee36c15b6..1ef2953ba 100644 --- a/website/docs/getting-started/installation.md +++ b/website/docs/getting-started/installation.md @@ -23,7 +23,7 @@ For Genkit or Flutter Edge AI integration setup, see ```yaml dependencies: - llamadart: ^0.19.0 + llamadart: ^0.19.1 ``` Then resolve packages: @@ -42,10 +42,10 @@ Apple XCFrameworks: ```yaml dependencies: - llamadart: ^0.19.0 - llamadart_llama_cpp_flutter: ^0.19.0 # GGUF / llama.cpp - llamadart_litert_lm_flutter: ^0.19.0 # Apple .litertlm / LiteRT-LM targets - llamadart_stable_diffusion_flutter: ^0.19.0 # Apple image generation, opt-in + llamadart: ^0.19.1 + llamadart_llama_cpp_flutter: ^0.19.1 # GGUF / llama.cpp + llamadart_litert_lm_flutter: ^0.19.1 # Apple .litertlm / LiteRT-LM targets + llamadart_stable_diffusion_flutter: ^0.19.1 # Apple image generation, opt-in ``` Companions use the core's `MAJOR.MINOR`; pub refuses a mismatched pair. diff --git a/website/docs/guides/image-generation.md b/website/docs/guides/image-generation.md index 4379e7fc6..f5683108d 100644 --- a/website/docs/guides/image-generation.md +++ b/website/docs/guides/image-generation.md @@ -111,7 +111,7 @@ Apple SD companion pinning its own runtime, so upgrade the core and ```yaml dependencies: - llamadart_stable_diffusion_flutter: ^0.19.0 + llamadart_stable_diffusion_flutter: ^0.19.1 ``` Without it, `all` leaves the image runtime out of a Flutter iOS or macOS app diff --git a/website/docs/maintainers/native-and-web-sync.md b/website/docs/maintainers/native-and-web-sync.md index f2b83dfcd..75c6abf3d 100644 --- a/website/docs/maintainers/native-and-web-sync.md +++ b/website/docs/maintainers/native-and-web-sync.md @@ -648,6 +648,16 @@ Use this checklist in native sync PRs: ## Companion package release handoff +Core `0.19.1` preparation moves LiteRT-LM to `v0.19.1-2`, which adds the +in-process LiteRT marker, and pairs all three Apple companions at `0.19.1` +with a Flutter floor of `>=3.38.6`. `llamadart_litert_lm_flutter` `0.19.1` +requires `llamadart: '>=0.19.1 <0.20.0'`: core `0.19.0` treats a companion +pinning `v0.19.1-2` as a later build and keeps macOS LiteRT-LM in the hook +cache. Core `0.19.1` accepts the published `0.19.0` companion (pinning +`v0.19.1-1`) with an upgrade warning. The llama.cpp and SD companions keep +`llamadart: '>=0.19.0 <0.20.0'`; their pins are unchanged, so core `0.19.0` +still accepts them. + After core `0.18.0`, the LiteRT-LM pin moved to `v0.19.1-1`. It ships in core `0.19.0`, which re-releases all three Apple companions at `0.19.0` with `llamadart: '>=0.19.0 <0.20.0'`; the LiteRT-LM companion pins `v0.19.1-1`. Pub diff --git a/website/examples/observability/pubspec.lock b/website/examples/observability/pubspec.lock index 597a503d1..e18c87511 100644 --- a/website/examples/observability/pubspec.lock +++ b/website/examples/observability/pubspec.lock @@ -271,7 +271,7 @@ packages: path: "../../.." relative: true source: path - version: "0.19.0" + version: "0.19.1" logging: dependency: transitive description: From fec9bdc4eb47b02159dd59b8fe5d99179e34247d Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Mon, 9 Nov 2026 00:23:42 -0500 Subject: [PATCH 9/9] State the desktop LiteRT-LM embeddings runtime floor for 0.19.1 --- CHANGELOG.md | 2 +- MIGRATION.md | 11 +++++++++++ website/docs/changelog/recent-releases.md | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f44d3edb..97f209fc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.19.1 - Keep the default WebGPU bridge assets at `v0.1.83` (unchanged from 0.19.0). -- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. Linux and Windows native embeddings now require that report and refuse an older runtime, such as a custom `v0.19.0` or `v0.19.1`, with `LlamaUnsupportedException` instead of crashing when creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). +- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. Linux and Windows native embeddings need `v0.19.1-2` or later, the bundled runtime: an explicit older `LLAMADART_LITERT_LM_LIB_DIR` runtime, including `v0.19.1-1`, is refused with `LlamaUnsupportedException`, where custom `v0.19.0` and `v0.19.1` runtimes used to crash ([#1367](https://github.com/leehack/llamadart/issues/1367)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps, whose runtime links LiteRT in; an older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). - Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load, and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)). diff --git a/MIGRATION.md b/MIGRATION.md index 5a8f5b103..2acf2b095 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -2,6 +2,17 @@ This document covers the major breaking upgrade paths. +## `0.19.0` -> `0.19.1`: desktop LiteRT-LM embeddings need native `v0.19.1-2` + +Core `0.19.1` bundles +[LiteRT-LM v0.19.1-2](https://github.com/leehack/litert-lm-native/releases/tag/v0.19.1-2), +so apps on the bundled runtime are unaffected. Linux and Windows native +embeddings now require that runtime's in-process LiteRT marker: a custom +`LLAMADART_LITERT_LM_LIB_DIR` runtime older than `v0.19.1-2`, including +`v0.19.1-1`, throws `LlamaUnsupportedException` before any native embedding +call. Point the override at `v0.19.1-2` or later +([#1367](https://github.com/leehack/llamadart/issues/1367)). + ## `0.18.x` -> `0.19.0`: LiteRT-LM native `v0.19.1-1` and Web `0.19.0` Core `0.19.0` and `llamadart_litert_lm_flutter` `0.19.0` move to published diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 8ec470487..2673fc129 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -14,7 +14,7 @@ validate against the exact release tag notes. ## 0.19.1 - Keep default WebGPU bridge assets at `v0.1.83` (unchanged from 0.19.0). -- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. Linux and Windows native embeddings now require that report and refuse an older runtime, such as a custom `v0.19.0` or `v0.19.1`, with `LlamaUnsupportedException` instead of crashing when creating the embedding engine ([#1367](https://github.com/leehack/llamadart/issues/1367)). +- Adopt native LiteRT-LM `v0.19.1-2`, which reports LiteRT linked in process; the C API is unchanged. Linux and Windows native embeddings need `v0.19.1-2` or later, the bundled runtime: an explicit older `LLAMADART_LITERT_LM_LIB_DIR` runtime, including `v0.19.1-1`, is refused with `LlamaUnsupportedException`, where custom `v0.19.0` and `v0.19.1` runtimes used to crash ([#1367](https://github.com/leehack/llamadart/issues/1367)). - Stop bundling and loading the unused prebuilt `libLiteRt` (about 7 to 9 MB) in Linux and Windows LiteRT-LM apps, whose runtime links LiteRT in; an older `LLAMADART_LITERT_LM_LIB_DIR` runtime still loads the `libLiteRt` it ships with ([#1815](https://github.com/leehack/llamadart/issues/1815)). - Refuse LiteRT-LM GPU on Linux when every Vulkan device is a software rasterizer such as Mesa llvmpipe, where small models could return wrong text: `ComputeDevice.gpu` throws `LlamaUnsupportedException` at load, and a GPU hint under `ComputeDevice.auto` runs on the CPU with a warning ([#572](https://github.com/leehack/llamadart/issues/572)). - Fix native LiteRT-LM `dispose` failing with "worker stopped before native cleanup was confirmed" when cleanup outlasts 5 s, such as releasing a freshly written CPU weight cache on Linux ext4; `freeTimeout` now bounds only the wait for native teardown to start ([#1814](https://github.com/leehack/llamadart/issues/1814)).