Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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<C>` with typed capabilities and reentrant-safe final disposal.
- Prepare llama.cpp worker cleanup during native creation for runtimes with owner API v1.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions doc/llama_cpp_exit_teardown.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions doc/webgpu_bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
274 changes: 50 additions & 224 deletions lib/src/backends/llama_cpp/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6543,173 +6543,85 @@ external int llama_dart_mtmd_tokenize(
int n_bitmaps,
);

@ffi.Native<
ffi.Void Function(ffi.Pointer<llama_dart_mtp>, llama_seq_id, ffi.Uint16)
>()
external void llama_dart_mtp_accept(
ffi.Pointer<llama_dart_mtp> mtp,
int seq_id,
int accepted_count,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>()
external void llama_dart_owner_abandon(ffi.Pointer<ffi.Void> owner);

@ffi.Native<
ffi.Bool Function(
ffi.Pointer<llama_dart_mtp>,
llama_seq_id,
ffi.Pointer<llama_token>,
ffi.Int32,
)
>()
external bool llama_dart_mtp_begin(
ffi.Pointer<llama_dart_mtp> mtp,
int seq_id,
ffi.Pointer<llama_token> prompt,
int prompt_count,
);
@ffi.Native<ffi.Bool Function(ffi.Pointer<ffi.Void>)>()
external bool llama_dart_owner_activate(ffi.Pointer<ffi.Void> owner);

@ffi.Native<
ffi.Int32 Function(
ffi.Pointer<llama_dart_mtp>,
llama_seq_id,
llama_pos,
llama_token,
ffi.Pointer<llama_token>,
ffi.Int32,
ffi.Int32,
ffi.Pointer<llama_token>,
ffi.Int32,
)
>()
external int llama_dart_mtp_draft(
ffi.Pointer<llama_dart_mtp> mtp,
int seq_id,
int n_past,
int id_last,
ffi.Pointer<llama_token> prompt,
int prompt_count,
int draft_token_max,
ffi.Pointer<llama_token> out_tokens,
int out_capacity,
);
@ffi.Native<ffi.Uint32 Function()>()
external int llama_dart_owner_api_version();

@ffi.Native<ffi.Void Function(ffi.Pointer<llama_dart_mtp>)>()
external void llama_dart_mtp_free(ffi.Pointer<llama_dart_mtp> mtp);
@ffi.Native<ffi.Int32 Function()>()
external int llama_dart_owner_count();

@ffi.Native<ffi.Pointer<llama_context> Function(ffi.Pointer<llama_dart_mtp>)>()
external ffi.Pointer<llama_context> llama_dart_mtp_get_draft_context(
ffi.Pointer<llama_dart_mtp> mtp,
);
@ffi.Native<ffi.Pointer<ffi.Void> Function()>()
external ffi.Pointer<ffi.Void> llama_dart_owner_create();

@ffi.Native<
ffi.Pointer<llama_dart_mtp> Function(
ffi.Pointer<llama_context> Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<llama_model>,
ffi.Pointer<llama_context>,
llama_context_params,
ffi.Int32,
ffi.Int32,
ffi.Float,
ffi.Bool,
)
>()
external ffi.Pointer<llama_dart_mtp> llama_dart_mtp_init(
external ffi.Pointer<llama_context> llama_dart_owner_init_from_model(
ffi.Pointer<ffi.Void> owner,
ffi.Pointer<llama_model> model,
ffi.Pointer<llama_context> 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<llama_dart_mtp> Function(
ffi.Pointer<llama_model>,
ffi.Pointer<llama_context>,
llama_context_params,
ffi.Int32,
ffi.Int32,
ffi.Float,
ffi.Bool,
ffi.Pointer<llama_model> Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Char>,
llama_model_params,
)
>()
external ffi.Pointer<llama_dart_mtp> llama_dart_mtp_init_with_draft_model(
ffi.Pointer<llama_model> draft_model,
ffi.Pointer<llama_context> ctx_tgt,
llama_context_params ctx_params,
int draft_token_max,
int draft_token_min,
double min_probability,
bool backend_sampling,
);

@ffi.Native<ffi.Bool Function(ffi.Pointer<llama_dart_mtp>, llama_batch)>()
external bool llama_dart_mtp_process_batch(
ffi.Pointer<llama_dart_mtp> mtp,
llama_batch batch,
);

@ffi.Native<
ffi.Void Function(ffi.Pointer<llama_dart_ngram>, llama_seq_id, ffi.Uint16)
>()
external void llama_dart_ngram_accept(
ffi.Pointer<llama_dart_ngram> ngram,
int seq_id,
int accepted_count,
external ffi.Pointer<llama_model> llama_dart_owner_model_load_from_file(
ffi.Pointer<ffi.Void> owner,
ffi.Pointer<ffi.Char> path,
llama_model_params params,
);

@ffi.Native<
ffi.Bool Function(
ffi.Pointer<llama_dart_ngram>,
llama_seq_id,
ffi.Pointer<llama_token>,
ffi.Int32,
ffi.Pointer<mtmd_context> Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Char>,
ffi.Pointer<llama_model>,
ffi.Pointer<mtmd_context_params>,
)
>()
external bool llama_dart_ngram_begin(
ffi.Pointer<llama_dart_ngram> ngram,
int seq_id,
ffi.Pointer<llama_token> prompt,
int prompt_count,
external ffi.Pointer<mtmd_context> llama_dart_owner_mtmd_init_from_file(
ffi.Pointer<ffi.Void> owner,
ffi.Pointer<ffi.Char> path,
ffi.Pointer<llama_model> model,
ffi.Pointer<mtmd_context_params> params,
);

@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>()
external void llama_dart_owner_release(ffi.Pointer<ffi.Void> owner);

@ffi.Native<
ffi.Int32 Function(
ffi.Pointer<llama_dart_ngram>,
llama_seq_id,
llama_pos,
llama_token,
ffi.Pointer<llama_token>,
ffi.Int32,
ffi.Int32,
ffi.Pointer<llama_token>,
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>,
ffi.Int32,
)
>()
external int llama_dart_ngram_draft(
ffi.Pointer<llama_dart_ngram> ngram,
int seq_id,
int n_past,
int id_last,
ffi.Pointer<llama_token> prompt,
int prompt_count,
int draft_token_max,
ffi.Pointer<llama_token> out_tokens,
int out_capacity,
);

@ffi.Native<ffi.Void Function(ffi.Pointer<llama_dart_ngram>)>()
external void llama_dart_ngram_free(ffi.Pointer<llama_dart_ngram> ngram);

@ffi.Native<ffi.Bool Function(ffi.Pointer<llama_dart_ngram>, llama_batch)>()
external bool llama_dart_ngram_process_batch(
ffi.Pointer<llama_dart_ngram> ngram,
llama_batch batch,
external int llama_dart_owner_track(
ffi.Pointer<ffi.Void> owner,
ffi.Pointer<ffi.Void> object,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>
free_fn,
int stage,
);

@ffi.Native<ffi.Pointer<llama_dart_ngram> Function(ffi.Int32, ffi.Int32)>()
external ffi.Pointer<llama_dart_ngram> llama_dart_ngram_simple_init(
int ngram_size,
int draft_token_max,
@ffi.Native<ffi.Bool Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>)>()
external bool llama_dart_owner_untrack(
ffi.Pointer<ffi.Void> owner,
ffi.Pointer<ffi.Void> object,
);

@ffi.Native<
Expand Down Expand Up @@ -9888,90 +9800,8 @@ final class UnnamedUnion extends ffi.Union {
external ffi.Array<ffi.Char> val_str;
}

final class _IO_FILE extends ffi.Struct {
@ffi.Int()
external int _flags;
final class _IO_FILE extends ffi.Opaque {}

external ffi.Pointer<ffi.Char> _IO_read_ptr;

external ffi.Pointer<ffi.Char> _IO_read_end;

external ffi.Pointer<ffi.Char> _IO_read_base;

external ffi.Pointer<ffi.Char> _IO_write_base;

external ffi.Pointer<ffi.Char> _IO_write_ptr;

external ffi.Pointer<ffi.Char> _IO_write_end;

external ffi.Pointer<ffi.Char> _IO_buf_base;

external ffi.Pointer<ffi.Char> _IO_buf_end;

external ffi.Pointer<ffi.Char> _IO_save_base;

external ffi.Pointer<ffi.Char> _IO_backup_base;

external ffi.Pointer<ffi.Char> _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<ffi.Char> _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<ffi.Void> _freeres_buf;

@ffi.Size()
external int __pad5;

@ffi.Int()
external int _mode;

@ffi.Array.multi([20])
external ffi.Array<ffi.Char> _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<ffi.NativeFunction<ggml_abort_callbackFunction>>;
typedef ggml_abort_callbackFunction =
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading