diff --git a/CHANGELOG.md b/CHANGELOG.md index f065b8795..b64ec0419 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased +- Update the llama.cpp native runtime to `v0.8.0-2` for speculative-decoding rollback and model-creation ownership fixes, with matching Apple binaries. + - Constrain native LFM2 automatic Python tool calls with lazy schema grammar, preserving copied string data and non-executable foreign-closing diagnostics; reject unsupported Web runtimes. - Preserve prompt penalties for supported Web LFM2 automatic tool grammars, with explicit loaded-core capability checks and unchanged ordinary grammar defaults. @@ -22,7 +24,7 @@ - Fail early with an actionable error when a Windows native runtime lacks speculative decoding helpers. - Aligned the default WebGPU bridge assets to `v0.1.82` with bounded preallocation for large wasm32 model writes. -Runtime baseline: native llama.cpp `v0.8.0-1` and Web use upstream `v0.8.0@8642541b255bfb5dc39cd351a178be09013a55d6`; Web LiteRT-LM stays `@litert-lm/core@0.18.0`. Manifest SHA-256: `fda19e047aba5a511020854437cc89e2f53e2f67f5f6cf5fec336faef3a6c362`. +Runtime baseline: native llama.cpp `v0.8.0-2` and Web use upstream `v0.8.0@8642541b255bfb5dc39cd351a178be09013a55d6`; Web LiteRT-LM stays `@litert-lm/core@0.18.0`. Manifest SHA-256: `fda19e047aba5a511020854437cc89e2f53e2f67f5f6cf5fec336faef3a6c362`. - Manage text, decision, image and speech engine lifecycles through `LlamadartEngine` with typed capabilities and reentrant-safe final disposal. - Prepare llama.cpp worker cleanup during native creation for runtimes with owner API v1. diff --git a/README.md b/README.md index 214fd9ec9..484b5f223 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ Current default runtime pins: | Runtime | Pin | | --- | --- | -| Native llama.cpp / GGUF | `leehack/llamadart-native@v0.8.0-1` | +| Native llama.cpp / GGUF | `leehack/llamadart-native@v0.8.0-2` | | Native LiteRT-LM / `.litertlm` | `leehack/litert-lm-native@v0.18.1-4` | | Web llama.cpp / GGUF | `leehack/llama-web-bridge-assets@v0.1.82` | | Web LiteRT-LM / `.litertlm` | `@litert-lm/core@0.18.0` | @@ -169,8 +169,8 @@ overrides select backend modules; use `llamadart_native_path` to replace the complete runtime. The full override rules are in [Native runtime configuration](https://llamadart.leehack.com/docs/platforms/native-build-hooks#override-the-llamacpp-release). Await engine disposal before host shutdown. Forced worker cleanup during -native creation requires a runtime with owner API v1; the current pinned -`v0.8.0-1` runtime retains that gap. See the +native creation uses owner API v1 in the pinned `v0.8.0-2` runtime. Raw +allocation-to-registration gaps remain; see the [shutdown contract](doc/llama_cpp_exit_teardown.md#creation-time-owner-preparation). ## Guides diff --git a/doc/llama_cpp_exit_teardown.md b/doc/llama_cpp_exit_teardown.md index 2f0519d70..3965995eb 100644 --- a/doc/llama_cpp_exit_teardown.md +++ b/doc/llama_cpp_exit_teardown.md @@ -251,11 +251,10 @@ control record until process termination. No guarantee covers arbitrary simultaneous parent/worker death. Token registration is separate from payload ownership. -This core preparation does not change the native pin. The current published -`v0.8.0-1` runtime has no owner API and retains the creation-time gap described -below. Capability resolution is all-or-nothing, so absent/partial/unsupported -owner APIs use the existing path rather than mixing ownership protocols. -Native publication, repinning and exact-artifact qualification remain separate. +The pinned `v0.8.0-2` runtime supplies owner API v1 for this creation-time +cleanup path. Capability resolution remains all-or-nothing: custom runtimes +with absent, partial or unsupported owner APIs use the existing path and +retain its creation-time gap rather than mixing ownership protocols. Raw allocation-to-registration gaps remain under [#629](https://github.com/leehack/llamadart/issues/629): token buffers, sampler diff --git a/doc/webgpu_bridge.md b/doc/webgpu_bridge.md index 2d5c60787..41db9f9f7 100644 --- a/doc/webgpu_bridge.md +++ b/doc/webgpu_bridge.md @@ -95,9 +95,9 @@ the chat app, set the bootstrap globals before the bootstrap runs: ``` That release embeds llama.cpp `v0.8.0`, matching the `hook/build.dart` native pin -(`v0.8.0-1`, both built from upstream llama.cpp `v0.8.0@8642541b255bfb5dc39cd351a178be09013a55d6`) +(`v0.8.0-2`, both built from upstream llama.cpp `v0.8.0@8642541b255bfb5dc39cd351a178be09013a55d6`) even though the bridge asset tag `v0.1.82` differs from the native runtime tag -`v0.8.0-1`. Provenance for this immutable consumer artifact: release `432258348`, +`v0.8.0-2`. Provenance for this immutable consumer artifact: release `432258348`, tag commit `33c782f2acdae78860ad1197344240f60290cecb`, bridge source `e57b9f68fb38d1471af7b94443229993f777df97`, and manifest SHA-256 `fda19e047aba5a511020854437cc89e2f53e2f67f5f6cf5fec336faef3a6c362`. diff --git a/lib/src/backends/llama_cpp/bindings.dart b/lib/src/backends/llama_cpp/bindings.dart index fa9728f4f..6cf692bd1 100644 --- a/lib/src/backends/llama_cpp/bindings.dart +++ b/lib/src/backends/llama_cpp/bindings.dart @@ -6543,173 +6543,85 @@ external int llama_dart_mtmd_tokenize( int n_bitmaps, ); -@ffi.Native< - ffi.Void Function(ffi.Pointer, llama_seq_id, ffi.Uint16) ->() -external void llama_dart_mtp_accept( - ffi.Pointer mtp, - int seq_id, - int accepted_count, -); +@ffi.Native)>() +external void llama_dart_owner_abandon(ffi.Pointer owner); -@ffi.Native< - ffi.Bool Function( - ffi.Pointer, - llama_seq_id, - ffi.Pointer, - ffi.Int32, - ) ->() -external bool llama_dart_mtp_begin( - ffi.Pointer mtp, - int seq_id, - ffi.Pointer prompt, - int prompt_count, -); +@ffi.Native)>() +external bool llama_dart_owner_activate(ffi.Pointer owner); -@ffi.Native< - ffi.Int32 Function( - ffi.Pointer, - llama_seq_id, - llama_pos, - llama_token, - ffi.Pointer, - ffi.Int32, - ffi.Int32, - ffi.Pointer, - ffi.Int32, - ) ->() -external int llama_dart_mtp_draft( - ffi.Pointer mtp, - int seq_id, - int n_past, - int id_last, - ffi.Pointer prompt, - int prompt_count, - int draft_token_max, - ffi.Pointer out_tokens, - int out_capacity, -); +@ffi.Native() +external int llama_dart_owner_api_version(); -@ffi.Native)>() -external void llama_dart_mtp_free(ffi.Pointer mtp); +@ffi.Native() +external int llama_dart_owner_count(); -@ffi.Native Function(ffi.Pointer)>() -external ffi.Pointer llama_dart_mtp_get_draft_context( - ffi.Pointer mtp, -); +@ffi.Native Function()>() +external ffi.Pointer llama_dart_owner_create(); @ffi.Native< - ffi.Pointer Function( + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer, - ffi.Pointer, llama_context_params, - ffi.Int32, - ffi.Int32, - ffi.Float, - ffi.Bool, ) >() -external ffi.Pointer llama_dart_mtp_init( +external ffi.Pointer llama_dart_owner_init_from_model( + ffi.Pointer owner, ffi.Pointer model, - ffi.Pointer ctx_tgt, - llama_context_params ctx_params, - int draft_token_max, - int draft_token_min, - double min_probability, - bool backend_sampling, + llama_context_params params, ); @ffi.Native< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - llama_context_params, - ffi.Int32, - ffi.Int32, - ffi.Float, - ffi.Bool, + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + llama_model_params, ) >() -external ffi.Pointer llama_dart_mtp_init_with_draft_model( - ffi.Pointer draft_model, - ffi.Pointer ctx_tgt, - llama_context_params ctx_params, - int draft_token_max, - int draft_token_min, - double min_probability, - bool backend_sampling, -); - -@ffi.Native, llama_batch)>() -external bool llama_dart_mtp_process_batch( - ffi.Pointer mtp, - llama_batch batch, -); - -@ffi.Native< - ffi.Void Function(ffi.Pointer, llama_seq_id, ffi.Uint16) ->() -external void llama_dart_ngram_accept( - ffi.Pointer ngram, - int seq_id, - int accepted_count, +external ffi.Pointer llama_dart_owner_model_load_from_file( + ffi.Pointer owner, + ffi.Pointer path, + llama_model_params params, ); @ffi.Native< - ffi.Bool Function( - ffi.Pointer, - llama_seq_id, - ffi.Pointer, - ffi.Int32, + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, ) >() -external bool llama_dart_ngram_begin( - ffi.Pointer ngram, - int seq_id, - ffi.Pointer prompt, - int prompt_count, +external ffi.Pointer llama_dart_owner_mtmd_init_from_file( + ffi.Pointer owner, + ffi.Pointer path, + ffi.Pointer model, + ffi.Pointer params, ); +@ffi.Native)>() +external void llama_dart_owner_release(ffi.Pointer owner); + @ffi.Native< ffi.Int32 Function( - ffi.Pointer, - llama_seq_id, - llama_pos, - llama_token, - ffi.Pointer, - ffi.Int32, - ffi.Int32, - ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>, ffi.Int32, ) >() -external int llama_dart_ngram_draft( - ffi.Pointer ngram, - int seq_id, - int n_past, - int id_last, - ffi.Pointer prompt, - int prompt_count, - int draft_token_max, - ffi.Pointer out_tokens, - int out_capacity, -); - -@ffi.Native)>() -external void llama_dart_ngram_free(ffi.Pointer ngram); - -@ffi.Native, llama_batch)>() -external bool llama_dart_ngram_process_batch( - ffi.Pointer ngram, - llama_batch batch, +external int llama_dart_owner_track( + ffi.Pointer owner, + ffi.Pointer object, + ffi.Pointer)>> + free_fn, + int stage, ); -@ffi.Native Function(ffi.Int32, ffi.Int32)>() -external ffi.Pointer llama_dart_ngram_simple_init( - int ngram_size, - int draft_token_max, +@ffi.Native, ffi.Pointer)>() +external bool llama_dart_owner_untrack( + ffi.Pointer owner, + ffi.Pointer object, ); @ffi.Native< @@ -9888,90 +9800,8 @@ final class UnnamedUnion extends ffi.Union { external ffi.Array val_str; } -final class _IO_FILE extends ffi.Struct { - @ffi.Int() - external int _flags; +final class _IO_FILE extends ffi.Opaque {} - external ffi.Pointer _IO_read_ptr; - - external ffi.Pointer _IO_read_end; - - external ffi.Pointer _IO_read_base; - - external ffi.Pointer _IO_write_base; - - external ffi.Pointer _IO_write_ptr; - - external ffi.Pointer _IO_write_end; - - external ffi.Pointer _IO_buf_base; - - external ffi.Pointer _IO_buf_end; - - external ffi.Pointer _IO_save_base; - - external ffi.Pointer _IO_backup_base; - - external ffi.Pointer _IO_save_end; - - external ffi.Pointer<_IO_marker> _markers; - - external ffi.Pointer<_IO_FILE> _chain; - - @ffi.Int() - external int _fileno; - - @ffi.Int() - external int _flags2; - - @__off_t() - external int _old_offset; - - @ffi.UnsignedShort() - external int _cur_column; - - @ffi.SignedChar() - external int _vtable_offset; - - @ffi.Array.multi([1]) - external ffi.Array _shortbuf; - - external ffi.Pointer<_IO_lock_t> _lock; - - @__off64_t() - external int _offset; - - external ffi.Pointer<_IO_codecvt> _codecvt; - - external ffi.Pointer<_IO_wide_data> _wide_data; - - external ffi.Pointer<_IO_FILE> _freeres_list; - - external ffi.Pointer _freeres_buf; - - @ffi.Size() - external int __pad5; - - @ffi.Int() - external int _mode; - - @ffi.Array.multi([20]) - external ffi.Array _unused2; -} - -final class _IO_codecvt extends ffi.Opaque {} - -typedef _IO_lock_t = ffi.Void; -typedef Dart_IO_lock_t = void; - -final class _IO_marker extends ffi.Opaque {} - -final class _IO_wide_data extends ffi.Opaque {} - -typedef __off64_t = ffi.Long; -typedef Dart__off64_t = int; -typedef __off_t = ffi.Long; -typedef Dart__off_t = int; typedef ggml_abort_callback = ffi.Pointer>; typedef ggml_abort_callbackFunction = @@ -11696,10 +11526,6 @@ enum llama_dart_mtmd_encode_status { }; } -final class llama_dart_mtp extends ffi.Opaque {} - -final class llama_dart_ngram extends ffi.Opaque {} - enum llama_dart_process_status { LLAMA_DART_PROCESS_STATUS_UNSUPPORTED_TYPE(-1), LLAMA_DART_PROCESS_STATUS_UNSUPPORTED(-4); diff --git a/lib/src/hook/native_release_pins.dart b/lib/src/hook/native_release_pins.dart index ea4ea4ca8..1be4192bf 100644 --- a/lib/src/hook/native_release_pins.dart +++ b/lib/src/hook/native_release_pins.dart @@ -5,7 +5,7 @@ library; /// `leehack/llamadart-native` release tag downloaded for the llama.cpp runtime. -const llamaCppTag = 'v0.8.0-1'; +const llamaCppTag = 'v0.8.0-2'; /// The first `llamadart_llama_cpp_flutter` release whose `Package.swift` pins /// [llamaCppTag]. @@ -16,25 +16,17 @@ const llamaCppTag = 'v0.8.0-1'; /// `MAJOR.MINOR`, and its own minor's first release otherwise. The native pin /// sync sets it to the companion's next release whenever it moves the /// companion pin. -const llamaCppAppleCompanionVersion = '0.17.1'; +const llamaCppAppleCompanionVersion = '0.17.4'; /// Earlier `leehack/llamadart-native` tags that a published Apple llama.cpp /// companion pins and the build still accepts, each mapped to what its /// frameworks lack compared with [llamaCppTag]. /// -/// An entry may come from an earlier upstream release. Its frameworks stand in -/// for [llamaCppTag] only because the core calls no symbol they lack and passes -/// them no struct they would read or write out of bounds, as -/// `test/fixtures/native/llama_cpp_apple_compatibility.json` records for the -/// exact XCFramework checksums in -/// [llamaCppCompatibleAppleCompanionChecksums]. A test keeps the core off the -/// symbols and layouts only [llamaCppTag] has, so calling one needs a runtime -/// probe. The build accepts such a companion with a warning. The native pin -/// sync clears this map whenever it moves [llamaCppTag], because each entry is -/// verified against one pin. -const llamaCppCompatibleAppleCompanionTags = { - 'v0.7.0-3': 'the llama.cpp v0.8.0 fixes and model families', -}; +/// No older Apple runtime is admitted for v0.8.0-2: consumers need its +/// speculative rollback and model-creation ownership fixes. Native pin sync +/// clears this map whenever the pin moves; additions require exact artifact +/// compatibility evidence and matching checksums below. +const llamaCppCompatibleAppleCompanionTags = {}; /// The exact XCFramework checksum a companion pinning each /// [llamaCppCompatibleAppleCompanionTags] entry must declare. @@ -42,10 +34,7 @@ const llamaCppCompatibleAppleCompanionTags = { /// A tag alone establishes no ABI compatibility, so the build rejects a /// compatible tag whose checksum is missing here or differs. The native pin /// sync clears it together with [llamaCppCompatibleAppleCompanionTags]. -const llamaCppCompatibleAppleCompanionChecksums = { - 'v0.7.0-3': - '749c9bc9fa846fb2386b3cf20ac1e6754182cd145aaf21affa2634c1f1177192', -}; +const llamaCppCompatibleAppleCompanionChecksums = {}; /// SHA-256 of each published `llamadart-native--.tar.gz` /// archive, keyed by bundle. @@ -54,27 +43,27 @@ const llamaCppCompatibleAppleCompanionChecksums = { /// against this map before extracting it. const llamaCppBundleSha256 = { 'android-arm64': - '3e4242c2f3559742dd17790ebe8c413555a5f6a746bdc849b498264859e216e1', + 'a40669ffb3ab20a62028fbe65c0d217e5a36f71e4beef36447a6a630d5953a76', 'android-x64': - 'dc9ac4530c898a9071cab6dff76b014764a06ff090e6a4f0183a9fbdbe09cc93', + 'a6044487a3ba51d18f8c3544187959bf30f857447bd35b35b2f0a6d3005c90ba', 'ios-arm64': - 'b0e3521426bc34a75112844f5516d4edcced92118217671c5e0da009e3b8fbb4', + 'f678bea09764dcc689e29388404fc00244565097fbc948f447527c5c2c9608f1', 'ios-arm64-sim': - '19e0da6097101e2d63c8a4df4ab239da5f6a5d80e31d72d6cfcce58be4a249fc', + 'ebb9de05c816984f746a8b1a390a216f7a8b3a2c6156991356cc2a28458bc13f', 'ios-x86_64-sim': - 'f04b5b77050b420f5f6aaf08fcf77b2608a285c45536f6407c4be6223b59c108', + '7c94a70cf8cd426c88e2af378226fc2229e877d8ea55d9a390f320b846508662', 'linux-arm64': - 'af98f40c1f1d0da1dede74521b8fd219a3c244608f19aab80d7cea834b318820', + '8681a9b0e9ab93faff3d5f9c87aa8c078cc7cffbfa75a090e4bc94895ed45816', 'linux-x64': - 'd8de604f0ee0374bdbc13c34f27efbb3dd7f3f00f92eb694299b82c5c5a45aac', + 'b9d04424898f21a0c162211031523be4ee54acffe4f69fd72955ba2f6c66a595', 'macos-arm64': - '02acb586823d2fac9313dff438d67dabd1bdf18bdacc1658042eb1619298c1ed', + '03ce83c196380d04a77b78530b3596294d218a3d260a7c00a958ed1318aa7732', 'macos-x86_64': - 'b664b6141aa96dbb08b826bf92a28437b9fa50638511253b7766201d189bfbd3', + '6230e3fc532b33895bd0960f5d302255f8716d4626f7cdb3a300349fe85b2859', 'windows-arm64': - 'c9b77db32938bd1157f9943c9d243d2eeea901fce3712ed7e3444d6c20d8fa22', + '429a492f3c4a991f72fe8e2c9490278217c9d0d763e55253c5152351383f043e', 'windows-x64': - 'e7bbc544cfc65780569b62823157f91e1bff45b79332b61fa1da87ff8fd62121', + '130f8ba56439b3b7ad13ea820b812432b7ff9c67c8e0bbd007856e2d712c75d6', }; /// The `hook_contract_version` of the [llamaCppTag] release's `assets.json`. @@ -111,7 +100,7 @@ const llamaCppBackendSidecarSpecs = [ bundle: 'windows-x64', backend: 'cuda', archive: 'windows-x64-cuda12', - sha256: '04a7aa2fce3df4766f97da12b9a4834e2229152620b6706365a92268e8f967f6', + sha256: '0ed33465d8713482c023b0e8706d8f968ca75358edd90d0a5bb0a26b4b9d7819', ), ]; diff --git a/packages/llamadart_llama_cpp_flutter/CHANGELOG.md b/packages/llamadart_llama_cpp_flutter/CHANGELOG.md index 67da51e3c..1d13f2594 100644 --- a/packages/llamadart_llama_cpp_flutter/CHANGELOG.md +++ b/packages/llamadart_llama_cpp_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +* Updated Apple SwiftPM native pin to `leehack/llamadart-native@v0.8.0-2`. + ## 0.17.3 * Refresh README installation guidance for core `0.17.5`; Apple SwiftPM stays pinned to `leehack/llamadart-native@v0.8.0-1`. diff --git a/packages/llamadart_llama_cpp_flutter/README.md b/packages/llamadart_llama_cpp_flutter/README.md index c4e51ff39..5189aaa59 100644 --- a/packages/llamadart_llama_cpp_flutter/README.md +++ b/packages/llamadart_llama_cpp_flutter/README.md @@ -20,7 +20,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/llamadart-native@v0.8.0-1`. +The Apple SwiftPM manifest pins `leehack/llamadart-native@v0.8.0-2`. Apps bound for the App Store should use this package: the Apple privacy manifest for the llama.cpp runtime ships inside this XCFramework, never in the diff --git a/packages/llamadart_llama_cpp_flutter/darwin/llamadart_llama_cpp_flutter/Package.swift b/packages/llamadart_llama_cpp_flutter/darwin/llamadart_llama_cpp_flutter/Package.swift index cb7f89e4b..aafa31e2b 100644 --- a/packages/llamadart_llama_cpp_flutter/darwin/llamadart_llama_cpp_flutter/Package.swift +++ b/packages/llamadart_llama_cpp_flutter/darwin/llamadart_llama_cpp_flutter/Package.swift @@ -4,7 +4,7 @@ import PackageDescription let packageRoot = URL(fileURLWithPath: #filePath).deletingLastPathComponent() let artifactsRoot = packageRoot.appendingPathComponent("Artifacts") -let llamaCppTag = "v0.8.0-1" +let llamaCppTag = "v0.8.0-2" func localArtifactPath(_ name: String) -> String? { let path = artifactsRoot.appendingPathComponent(name).path @@ -47,7 +47,7 @@ let package = Package( repository: "leehack/llamadart-native", artifactName: "llamadart-native-apple-xcframework-\(llamaCppTag).zip", tag: llamaCppTag, - checksum: "b959e9782f402c8ba72f7cbb68bea24c937ea48fa544e920fdcfc68db198ebf0" + checksum: "026dba77a76858553e329e4bd317550d8c619a5e3b3e9498a52b72b0712b4d3e" ), .target( name: "llamadart_llama_cpp_flutter", diff --git a/skills/llamadart-getting-started/SKILL.md b/skills/llamadart-getting-started/SKILL.md index 484f50c70..313920bab 100644 --- a/skills/llamadart-getting-started/SKILL.md +++ b/skills/llamadart-getting-started/SKILL.md @@ -75,8 +75,8 @@ interface does not establish backend/model support; read `await engine.capabilit token they receive, even though disposal no longer waits for their work. - Await `dispose()` before host shutdown. Killing a worker is not cooperative cancellation. Reclaiming models/contexts created during a forced kill needs - a native runtime with owner API v1; the current pinned `v0.8.0-1` runtime - retains that creation-time gap. Other raw allocations have separate limits. + owner API v1, supplied by the pinned `v0.8.0-2` runtime. Custom runtimes + without it retain that gap. Other raw allocations have separate limits. - `LlamaBackend()` routes by model format: LiteRT-LM bundles run on LiteRT-LM and GGUF on llama.cpp. Native targets read the file header, so extensionless files load; a header contradicting the extension throws diff --git a/test/integration/backends/llama_cpp/native_symbol_integration_test.dart b/test/integration/backends/llama_cpp/native_symbol_integration_test.dart index a38a8b9f1..958496c94 100644 --- a/test/integration/backends/llama_cpp/native_symbol_integration_test.dart +++ b/test/integration/backends/llama_cpp/native_symbol_integration_test.dart @@ -17,27 +17,6 @@ import 'package:test/test.dart'; const _llamadartWrapperAssetId = 'package:llamadart/llamadart_wrapper'; const _llamadartPrimaryAssetId = 'package:llamadart/llamadart'; -const _mtpSymbols = [ - 'llama_dart_mtp_init', - 'llama_dart_mtp_init_with_draft_model', - 'llama_dart_mtp_free', - 'llama_dart_mtp_get_draft_context', - 'llama_dart_mtp_begin', - 'llama_dart_mtp_process_batch', - 'llama_dart_mtp_draft', - 'llama_dart_mtp_accept', - 'llama_dart_sampler_sample_and_accept_n', -]; - -const _ngramSymbols = [ - 'llama_dart_ngram_simple_init', - 'llama_dart_ngram_free', - 'llama_dart_ngram_begin', - 'llama_dart_ngram_process_batch', - 'llama_dart_ngram_draft', - 'llama_dart_ngram_accept', -]; - const _genericSpeculativeSymbols = [ 'llama_dart_speculative_init', 'llama_dart_speculative_free', @@ -48,6 +27,7 @@ const _genericSpeculativeSymbols = [ 'llama_dart_speculative_process_batch', 'llama_dart_speculative_draft', 'llama_dart_speculative_accept', + 'llama_dart_sampler_sample_and_accept_n', ]; const _b10514BindingSymbols = [ @@ -233,12 +213,6 @@ typedef _MtmdHelperBitmapInitFromBufDart = typedef _MtmdBitmapFreeNative = ffi.Void Function(ffi.Pointer); typedef _MtmdBitmapFreeDart = void Function(ffi.Pointer); -@ffi.Native)>( - assetId: _llamadartWrapperAssetId, - symbol: 'llama_dart_mtp_free', -) -external void _windowsMtpFree(ffi.Pointer mtp); - File? _llamadartWrapperLibraryFileOrNull() { if (Platform.isWindows) { try { @@ -723,11 +697,7 @@ void main() { 'lib/src/backends/llama_cpp/bindings.dart', ).readAsStringSync(); - for (final symbol in [ - ..._mtpSymbols, - ..._ngramSymbols, - ..._genericSpeculativeSymbols, - ]) { + for (final symbol in [..._genericSpeculativeSymbols]) { expect( _declaresExternalFunction(bindingsSource, symbol), isTrue, @@ -900,167 +870,6 @@ void main() { expect(printTimingsIndex, greaterThan(deviceIndex)); }); - test('Verify MTP wrapper symbols are resolvable', () { - if (Platform.isWindows) { - expect(() => llama_context_default_params(), returnsNormally); - expect( - () => _windowsMtpFree(ffi.nullptr.cast()), - returnsNormally, - ); - final wrapper = _windowsMtpWrapperLibraryFile(); - for (final symbol in _mtpSymbols) { - expect(_fileContainsAscii(wrapper, symbol), isTrue, reason: symbol); - } - return; - } - - final nullMtp = ffi.nullptr.cast(); - final nullModel = ffi.nullptr.cast(); - final nullContext = ffi.nullptr.cast(); - final nullSampler = ffi.nullptr.cast(); - final nullTokenArray = ffi.nullptr.cast(); - final ctxParams = llama_context_default_params(); - - expect( - llama_dart_mtp_init( - nullModel, - nullContext, - ctxParams, - 1, - 0, - 0.0, - true, - ).address, - 0, - ); - expect( - llama_dart_mtp_init_with_draft_model( - nullModel, - nullContext, - ctxParams, - 1, - 0, - 0.0, - true, - ).address, - 0, - ); - expect(() => llama_dart_mtp_free(nullMtp), returnsNormally); - expect(llama_dart_mtp_get_draft_context(nullMtp).address, 0); - expect(llama_dart_mtp_begin(nullMtp, 0, nullTokenArray, 0), isFalse); - expect( - llama_dart_mtp_draft( - nullMtp, - 0, - 0, - 0, - nullTokenArray, - 0, - 1, - nullTokenArray, - 0, - ), - -1, - ); - expect(() => llama_dart_mtp_accept(nullMtp, 0, 0), returnsNormally); - expect( - llama_dart_sampler_sample_and_accept_n( - nullSampler, - nullContext, - nullTokenArray, - 0, - nullTokenArray, - 0, - nullTokenArray, - 0, - ), - -1, - ); - - final batch = llama_batch_init(1, 0, 1); - try { - expect(llama_dart_mtp_process_batch(nullMtp, batch), isFalse); - } finally { - llama_batch_free(batch); - } - }); - - test('Verify ngram wrapper symbols are resolvable when exported', () { - final wrapper = _llamadartWrapperLibraryFileOrNull(); - if (wrapper == null) { - markTestSkipped('Unable to locate the llama.cpp wrapper library.'); - return; - } - - final missing = _ngramSymbols - .where((symbol) => !_fileContainsAscii(wrapper, symbol)) - .toList(growable: false); - if (missing.isNotEmpty) { - markTestSkipped( - 'Current native bundle does not export ngram wrapper symbols: ' - '${missing.join(', ')}.', - ); - return; - } - if (Platform.isWindows) { - _expectDynamicLibraryExports(wrapper, _ngramSymbols); - return; - } - - final nullNgram = ffi.nullptr.cast(); - final nullTokenArray = ffi.nullptr.cast(); - final session = llama_dart_ngram_simple_init(1, 1); - expect(session.address, isNot(0)); - - try { - expect(() => llama_dart_ngram_free(nullNgram), returnsNormally); - expect( - llama_dart_ngram_begin(nullNgram, 0, nullTokenArray, 0), - isFalse, - ); - expect(llama_dart_ngram_begin(session, 1, nullTokenArray, 0), isFalse); - expect( - llama_dart_ngram_draft( - nullNgram, - 0, - 0, - 0, - nullTokenArray, - 0, - 1, - nullTokenArray, - 0, - ), - -1, - ); - expect( - llama_dart_ngram_draft( - session, - 1, - 0, - 0, - nullTokenArray, - 0, - 1, - nullTokenArray, - 0, - ), - -1, - ); - expect(() => llama_dart_ngram_accept(nullNgram, 0, 0), returnsNormally); - expect(() => llama_dart_ngram_accept(session, 0, 0), returnsNormally); - - final batch = llama_batch_init(1, 0, 1); - try { - expect(llama_dart_ngram_process_batch(nullNgram, batch), isFalse); - } finally { - llama_batch_free(batch); - } - } finally { - llama_dart_ngram_free(session); - } - }); - test('Verify generic speculative symbols are resolvable when exported', () { final wrapper = _llamadartWrapperLibraryFileOrNull(); if (wrapper == null) { @@ -1088,8 +897,22 @@ void main() { final nullContext = ffi.nullptr.cast(); final nullTokenArray = ffi.nullptr.cast(); final nullParams = ffi.nullptr.cast(); + final nullSampler = ffi.nullptr.cast(); final ctxParams = llama_context_default_params(); + expect( + llama_dart_sampler_sample_and_accept_n( + nullSampler, + nullContext, + nullTokenArray, + 0, + nullTokenArray, + 0, + nullTokenArray, + 0, + ), + -1, + ); expect( llama_dart_speculative_init( nullModel, diff --git a/test/unit/hook/native_release_pins_test.dart b/test/unit/hook/native_release_pins_test.dart index d2cb406fe..8c1534032 100644 --- a/test/unit/hook/native_release_pins_test.dart +++ b/test/unit/hook/native_release_pins_test.dart @@ -7,7 +7,6 @@ import 'dart:io'; import 'package:code_assets/code_assets.dart'; import 'package:llamadart/src/backends/litert_lm/litert_lm_runtime.dart'; -import 'package:llamadart/src/backends/llama_cpp/bindings.dart'; import 'package:llamadart/src/hook/native_bundle_config.dart'; import 'package:llamadart/src/hook/native_release_manifest.dart'; import 'package:llamadart/src/hook/native_release_pins.dart'; @@ -16,136 +15,30 @@ import 'package:test/test.dart'; void main() { final sha256Pattern = RegExp(r'^[0-9a-f]{64}$'); - test('llama.cpp pins the approved v0.8.0-1 release', () { - expect(llamaCppTag, 'v0.8.0-1'); + test('llama.cpp pins the approved v0.8.0-2 release', () { + expect(llamaCppTag, 'v0.8.0-2'); }); test('llama.cpp tag follows the native release tag grammar', () { expect(isValidNativeReleaseTag(llamaCppTag), isTrue, reason: llamaCppTag); }); - group('Apple llama.cpp compatibility', () { - final proof = - jsonDecode( - File( - 'test/fixtures/native/llama_cpp_apple_compatibility.json', - ).readAsStringSync(), - ) - as Map; - - test('is bound to the verified artifact pair', () { - final checksums = proof['xcframework_checksums'] as Map; - final previous = proof['previous_tag'] as String; - expect(proof['current_tag'], llamaCppTag); - expect(llamaCppCompatibleAppleCompanionTags.keys, [previous]); - expect( - llamaCppCompatibleAppleCompanionTags[previous]!.trim(), - isNotEmpty, - ); - expect(llamaCppCompatibleAppleCompanionChecksums, { - previous: checksums[previous], - }); - expect( - File( - 'packages/llamadart_llama_cpp_flutter/darwin/' - 'llamadart_llama_cpp_flutter/Package.swift', - ).readAsStringSync(), - contains('checksum: "${checksums[llamaCppTag]}"'), - ); - }); - - test('checked every framework slice', () { - final slices = proof['slices'] as List; - expect(slices, hasLength(5)); - for (final slice in slices.cast>()) { - expect(slice['core_symbols_missing_from_previous'], isEmpty); - expect(slice['core_symbols_missing_from_current'], isEmpty); - } - }); - - test('names the checksum the published companions declare', () { - final previous = proof['previous_tag'] as String; - final published = - proof['published_companion_checksums'] as Map; - expect(published, isNotEmpty); - for (final MapEntry(key: tag, value: checksum) in published.entries) { - expect(checksum, llamaCppCompatibleAppleCompanionChecksums[previous]); - // Release tags are absent from shallow CI checkouts; the recorded - // value is checked against the tag wherever it is present. - final shown = Process.runSync('git', [ - 'show', - '$tag:packages/llamadart_llama_cpp_flutter/darwin/' - 'llamadart_llama_cpp_flutter/Package.swift', - ]); - if (shown.exitCode != 0) continue; - final manifest = shown.stdout as String; - expect( - manifest, - contains('let llamaCppTag = "$previous"'), - reason: tag, - ); - expect(manifest, contains('checksum: "$checksum"'), reason: tag); - } - }); - - test('matches the regenerated struct growth', () { - final growth = proof['by_value_struct_growth'] as Map; - final initOpt = growth['mtmd_helper_init_opt'] as Map; - expect(sizeOf(), initOpt['current_size']); - }); - - test('core stays off what only the pinned runtime has', () { - final changedTypes = - (proof['types_changed_and_unused_by_core'] as List) - .cast(); - final bindings = RegExp(r'(^|/)(stable_diffusion_)?bindings\.dart$'); - final word = RegExp(r'[A-Za-z_][A-Za-z_0-9]*'); - final llamaBindings = File( - 'lib/src/backends/llama_cpp/bindings.dart', - ).readAsStringSync(); - final dependingOnChangedTypes = { - for (final match in RegExp( - r'^(?:external\s+[^;]*?|[\w.<>]+\s+)\b(\w+)\([^;{]*?\)\s*[;{]', - multiLine: true, - ).allMatches(llamaBindings)) - if (word - .allMatches(match[0]!) - .any((w) => changedTypes.contains(w[0]))) - match[1]!, - }; - expect( - dependingOnChangedTypes, - containsAll(['mtmd_get_cap_from_file', 'mtmd_gen_audio_process']), - reason: 'A binding taking or returning a changed type is derived', - ); - final forbidden = { - ...(proof['current_only_symbols'] as List).cast(), - ...changedTypes, - ...dependingOnChangedTypes, - }; - final uses = []; - for (final entity in Directory('lib').listSync(recursive: true)) { - if (entity is! File || - !entity.path.endsWith('.dart') || - bindings.hasMatch(entity.path.replaceAll(r'\', '/'))) { - continue; - } - final source = entity.readAsStringSync(); - for (final match in word.allMatches(source)) { - if (forbidden.contains(match[0])) { - uses.add('${entity.path}: ${match[0]}'); - } - } - } - expect( - uses, - isEmpty, - reason: - 'A published companion links ${proof['previous_tag']}, which ' - 'lacks these or lays them out differently. Probe the runtime ' - 'first, then move the name out of the fixture.', - ); - }); + test('Apple llama.cpp requires the matching repaired runtime', () { + // Older artifacts do not include this release's speculative rollback and + // model-creation ownership fixes, even when their exported ABI is usable. + expect(llamaCppCompatibleAppleCompanionTags, isEmpty); + expect(llamaCppCompatibleAppleCompanionChecksums, isEmpty); + final manifest = File( + 'packages/llamadart_llama_cpp_flutter/darwin/' + 'llamadart_llama_cpp_flutter/Package.swift', + ).readAsStringSync(); + expect(manifest, contains('let llamaCppTag = "$llamaCppTag"')); + expect( + manifest, + contains( + 'checksum: "026dba77a76858553e329e4bd317550d8c619a5e3b3e9498a52b72b0712b4d3e"', + ), + ); }); test('Apple companion version is the first release pinning llamaCppTag', () { 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 261f7ae01..ca5ff1ead 100644 --- a/test/unit/platform/io/runtime_setup_report_io_test.dart +++ b/test/unit/platform/io/runtime_setup_report_io_test.dart @@ -56,7 +56,7 @@ void main() { 'stable_diffusion', ]); expect(report.runtimes.map((runtime) => runtime.expectedReleaseTag), [ - 'v0.8.0-1', + 'v0.8.0-2', 'v0.18.1-4', 'v0.3.0-2', ]); diff --git a/test/unit/tooling/check_webgpu_bridge_tag_test.dart b/test/unit/tooling/check_webgpu_bridge_tag_test.dart index 4544f877a..df451fd2a 100644 --- a/test/unit/tooling/check_webgpu_bridge_tag_test.dart +++ b/test/unit/tooling/check_webgpu_bridge_tag_test.dart @@ -225,7 +225,7 @@ void main() { test('default assets include the qualified media embedding API', () { expect(readPinnedBridgeTag(Directory.current), 'v0.1.82'); expect(bridgeNativeReleaseTag, 'v0.8.0-1'); - expect(bridgeApprovedNativePin, 'v0.8.0-1'); + expect(bridgeApprovedNativePin, 'v0.8.0-2'); expect( normalizeNativeLlamaCppTag(bridgeApprovedNativePin), bridgeLlamaCppTag, @@ -291,7 +291,7 @@ void main() { contains('$bridgeLlamaCppTag@$bridgeLlamaCppCommit'), reason: path, ); - expect(current, contains(bridgeNativeReleaseTag), reason: path); + expect(current, contains(bridgeApprovedNativePin), reason: path); expect(current, contains('@litert-lm/core@0.18.0'), reason: path); } diff --git a/tool/testing/check_webgpu_bridge_tag.dart b/tool/testing/check_webgpu_bridge_tag.dart index 29218778b..5acc4861c 100644 --- a/tool/testing/check_webgpu_bridge_tag.dart +++ b/tool/testing/check_webgpu_bridge_tag.dart @@ -386,7 +386,7 @@ const String bridgeNativeReleaseTag = 'v0.8.0-1'; /// The native pin approved beside the pinned bridge assets: either /// [bridgeNativeReleaseTag] or a native wrapper rebuild of it from the same /// upstream llama.cpp commit. -const String bridgeApprovedNativePin = 'v0.8.0-1'; +const String bridgeApprovedNativePin = 'v0.8.0-2'; /// The asset repository release that published the pinned bridge assets. const String bridgeAssetsReleaseId = '432258348'; diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 2c67f7f32..c4d5779ec 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -13,6 +13,7 @@ validate against the exact release tag notes. ## Unreleased +- Update the llama.cpp native runtime to `v0.8.0-2` for speculative-decoding rollback and model-creation ownership fixes, with matching Apple binaries. - Constrain native LFM2 automatic Python tool calls with lazy schema grammar, preserving copied string data and non-executable foreign-closing diagnostics; reject unsupported Web runtimes. - Preserve prompt penalties for supported Web LFM2 automatic tool grammars, with explicit loaded-core capability checks and unchanged ordinary grammar defaults. @@ -35,7 +36,7 @@ validate against the exact release tag notes. - Fail early with an actionable error when a Windows native runtime lacks speculative decoding helpers. - Aligned default WebGPU bridge assets to `v0.1.82` with bounded preallocation for large wasm32 model writes. -Runtime baseline: native llama.cpp `v0.8.0-1` and Web use upstream `v0.8.0@8642541b255bfb5dc39cd351a178be09013a55d6`; Web LiteRT-LM stays `@litert-lm/core@0.18.0`. Manifest SHA-256: `fda19e047aba5a511020854437cc89e2f53e2f67f5f6cf5fec336faef3a6c362`. +Runtime baseline: native llama.cpp `v0.8.0-2` and Web use upstream `v0.8.0@8642541b255bfb5dc39cd351a178be09013a55d6`; Web LiteRT-LM stays `@litert-lm/core@0.18.0`. Manifest SHA-256: `fda19e047aba5a511020854437cc89e2f53e2f67f5f6cf5fec336faef3a6c362`. - Manage text, decision, image and speech engine lifecycles through `LlamadartEngine` with typed capabilities and reentrant-safe final disposal. - Prepare llama.cpp worker cleanup during native creation for runtimes with owner API v1. diff --git a/website/docs/getting-started/installation.md b/website/docs/getting-started/installation.md index 3a26b4a1f..22ad1b2a7 100644 --- a/website/docs/getting-started/installation.md +++ b/website/docs/getting-started/installation.md @@ -114,14 +114,14 @@ hooks: llamadart: llamadart_native_runtimes: [llama_cpp] # or [litert_lm] # Compatibility testing only; omit to use the tested pin. - # llamadart_native_tag: v0.8.0-1 + # llamadart_native_tag: v0.8.0-2 ``` An override tag names a `leehack/llamadart-native` release and must be explicit; the accepted forms are in [Override the llama.cpp release](../platforms/native-build-hooks#override-the-llamacpp-release). An override does not regenerate the Dart bindings, so its binary must stay -ABI-compatible with the default `leehack/llamadart-native@v0.8.0-1` runtime. +ABI-compatible with the default `leehack/llamadart-native@v0.8.0-2` runtime. Do not point a core before `0.17.1` at native `v0.8.0` or later: its bindings give `mtmd_helper_init_opt` 24 bytes, and `v0.8.0` writes past them. diff --git a/website/docs/guides/api-levels.md b/website/docs/guides/api-levels.md index ad8876907..f0c30e024 100644 --- a/website/docs/guides/api-levels.md +++ b/website/docs/guides/api-levels.md @@ -133,8 +133,7 @@ Future main() async { Always await `backend.dispose()` before shutting down its host. A forced worker kill cannot interrupt synchronous native creation. Creation-time -reclamation needs a runtime with owner API v1; the current pinned `v0.8.0-1` -bundle retains that gap. See the maintainer +reclamation uses owner API v1 in the pinned `v0.8.0-2` runtime. See the maintainer [shutdown contract](https://github.com/leehack/llamadart/blob/main/doc/llama_cpp_exit_teardown.md#creation-time-owner-preparation) for the bounded guarantee and remaining raw-allocation limits. diff --git a/website/docs/guides/performance-tuning.md b/website/docs/guides/performance-tuning.md index bfbb28cb8..59fd0e715 100644 --- a/website/docs/guides/performance-tuning.md +++ b/website/docs/guides/performance-tuning.md @@ -265,7 +265,7 @@ local checks; short natural-language and code prompts were slower. DSpark (`SpeculativeDecodingConfig.draftDspark(draftModel: ...)`) is an experimental, opt-in llama.cpp external-draft strategy mapped to upstream -`draft-dspark`. The default `v0.8.0-1` runtime supports it, including +`draft-dspark`. The default `v0.8.0-2` runtime supports it, including speculators-format checkpoints. Native recurrent/hybrid target pairs such as LFM2 remain subject to the rollback restriction above. It is never selected automatically, and support still depends on the target, draft and diff --git a/website/docs/maintainers/native-and-web-sync.md b/website/docs/maintainers/native-and-web-sync.md index 43f5f610a..14df49605 100644 --- a/website/docs/maintainers/native-and-web-sync.md +++ b/website/docs/maintainers/native-and-web-sync.md @@ -454,10 +454,15 @@ Core `0.17.1` moves the llama.cpp pin to `v0.8.0-1`, built from upstream `v0.8.0 the `0.17` minor. It keeps companion `0.17.0` (`v0.7.0-3`) through `llamaCppCompatibleAppleCompanionTags` because the core calls no symbol that framework lacks; `test/fixtures/native/llama_cpp_apple_compatibility.json` records -the per-slice check and a test keeps the core off the listed v0.8.0-only names. The +the historical per-slice check. The reverse pair is unsafe (`mtmd_helper_init_opt` grows to 32 bytes), so companion `0.17.1` needs `llamadart: '>=0.17.1 <0.18.0'`. +The 0.18.0 preparation moves to `v0.8.0-2` and requires its matching Apple +companion. Older runtimes are no longer admitted: they lack the speculative +rollback and model-creation ownership fixes. All Apple companions will be +versioned with the core minor during release preparation. + Native sync PRs can leave the repository in a state where the companion package source under `packages/` is ready, but the corresponding pub.dev package version does not exist yet. That is expected before merge, but it must be resolved by diff --git a/website/docs/platforms/support-matrix.md b/website/docs/platforms/support-matrix.md index 013eedd3a..756658b5b 100644 --- a/website/docs/platforms/support-matrix.md +++ b/website/docs/platforms/support-matrix.md @@ -198,13 +198,13 @@ web are on [Known platform issues](./known-platform-issues). | Runtime | Pinned release | | --- | --- | -| llama.cpp native | `leehack/llamadart-native@v0.8.0-1` | +| llama.cpp native | `leehack/llamadart-native@v0.8.0-2` | | LiteRT-LM native | `leehack/litert-lm-native@v0.18.1-4` | | stable-diffusion.cpp native (opt-in, Preview) | `leehack/stable-diffusion-native@v0.3.0-2`, 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.8.0-1` and +`v0.8.0-2` and `litert-lm-native` release `v0.18.1-4` (`lib/src/hook/native_release_pins.dart`). Native overrides exporting LiteRT-LM's versioned C API are rejected before