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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
`@litert-lm/core@0.18.0`. An app still chooses the module through
`window.__llamadartLiteRtLmModuleUrl`; the chat app's `web/index.html` and
the docs now name `0.18.0`.
* Aligned the default WebGPU bridge assets to `v0.1.54`, unchanged from 0.11.1:
they embed llama.cpp `v0.5.0`, are qualified against native `v0.5.0`, and keep
Web/native llama.cpp `v0.5.0@7fe450e19305b828c199d602c23a8337aaa1f03b` parity;
Web LiteRT-LM is `@litert-lm/core@0.18.0`. Immutable Web asset manifest:
`8a9f83c15035eeb034a6563e6f753382d7d7f9be81503ef76902138da7841176`.
- Adopt `leehack/stable-diffusion-native@v0.2.0-2` for the opt-in
`stable_diffusion` image runtime.
- Check the memory of Vulkan GPUs before loading an image model
Expand All @@ -61,6 +56,37 @@
at the configured levels, after each load and generation. The runtime no
longer prints ggml's device messages to stderr: at the default level
`none` it logs nothing.
- Update the default llama.cpp runtime to
`leehack/llamadart-native@v0.6.0-1` (llama.cpp `v0.6.0`), and the
`llamadart_llama_cpp_flutter` Apple SwiftPM pin with it.
- **Behavior change:** a llama.cpp state file saved by llamadart 0.11.x or
earlier no longer loads: llama.cpp `v0.6.0` changed the session format.
On native, `stateLoadFile` throws `LlamaStateException` naming the file's
format version and the one the runtime reads; evaluate the prompt again and
save a new file ([Save and restore prompt state](https://llamadart.leehack.com/docs/guides/model-lifecycle#save-and-restore-prompt-state)).
- Fix a C++ exception inside llama.cpp ending the process on native. The
failed call now throws the typed `LlamaException` of its operation with
llama.cpp's message, such as `LlamaInferenceException` from `detokenize`
for a token outside the vocabulary, or from a lazy-grammar trigger pattern
that is not a regular expression. A context the failed call left undefined
then throws `LlamaStateException` until its model is loaded again
([llamadart-native#102](https://github.com/leehack/llamadart-native/issues/102)).
- Android llama.cpp Vulkan: the 8-token text-prompt decode cap now applies
only on a GPU whose subgroup size llama.cpp `v0.6.0` mis-tiles (16, or below
8) or cannot be read. Other GPUs decode a text prompt in full micro-batches
([#948](https://github.com/leehack/llamadart/issues/948)).
- llama.cpp Vulkan needs Vulkan 1.2 from the loader and the GPU driver. When
the Vulkan GPU a load would run on reports less, `ComputeDevice.gpu` now
throws `LlamaUnsupportedException` naming the GPU and both versions, and
`ComputeDevice.auto` loads the model on the CPU with a warning, instead of
starting a driver llama.cpp cannot use; a load with other usable GPUs
leaves that one out
([#782](https://github.com/leehack/llamadart/issues/782)).
* Aligned the default WebGPU bridge assets to `v0.1.59`: they embed llama.cpp
`v0.6.0`, are qualified against native `v0.6.0`, and keep Web/native
llama.cpp `v0.6.0@d81235049384534c167caea52b85a694f6103d14` parity; Web
LiteRT-LM is `@litert-lm/core@0.18.0`. Immutable Web asset manifest:
`f823b10417b212ff1f66aa1c46bf78af7d9c393497dfcf0fa3a4f77adeb260eb`.

## 0.11.1

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ Current default runtime pins:

| Runtime | Pin |
| --- | --- |
| Native llama.cpp / GGUF | `leehack/llamadart-native@v0.5.0-2` |
| Native llama.cpp / GGUF | `leehack/llamadart-native@v0.6.0-1` |
| Native LiteRT-LM / `.litertlm` | `leehack/litert-lm-native@v0.18.0` |
| Web llama.cpp / GGUF | `leehack/llama-web-bridge-assets@v0.1.54` |
| Web llama.cpp / GGUF | `leehack/llama-web-bridge-assets@v0.1.59` |
| Web LiteRT-LM / `.litertlm` | `@litert-lm/core@0.18.0` |

Native overrides accept stable `vMAJOR.MINOR.PATCH` releases and preserve
Expand Down
4 changes: 2 additions & 2 deletions doc/cross_platform_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ still required for every actual run.

### Native video input

The pinned `llamadart-native` `v0.5.0` archive exports upstream video helper
The pinned `llamadart-native` `v0.6.0-1` archive exports upstream video helper
symbols (`mtmd_helper_video_*`), but the release is not qualified for
end-to-end video input. The companion build does not opt into
`LLAMA_SUBPROCESS`/`MTMD_VIDEO` or package FFmpeg/ffprobe, so the public Dart
Expand Down Expand Up @@ -1378,7 +1378,7 @@ any budget is exceeded:
by more than 7 MiB in every one of the seven cycles after the first. A
plateau passes; a steady leak fails. Slower growth passes this check.

With native `v0.4.1-1` (before the current `v0.5.0` pin), the pack has passed
With native `v0.4.1-1` (before the `v0.5.0` pin), the pack has passed
on macOS arm64 with CPU and with Metal, and on Linux x64 with CPU (AMD EPYC
7B12). The Metal runs report the Metal backend; the pack does not verify GPU
execution.
Expand Down
128 changes: 122 additions & 6 deletions doc/llama_cpp_exit_teardown.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ runs at exit. The native contract is `src/llama_dart_wrapper.h` in
warning at its first model load (visible at log level `warn` or lower) and
exits behave as they did before exit teardown.

`lib/src/backends/llama_cpp/native_barrier_api.dart` holds the functions
`v0.6.0-1` adds (`NativeBarrierApi`): the last-error accessors, and wrappers
for the upstream functions the service used to call directly and that throw
(tokenize, token to piece, sampler accept, the lazy-grammar constructor,
memory clear, the three mtmd bitmap constructors, and the ggml device and
backend calls of the decision head). They are calls in flight for teardown
like the others, and are resolved all or nothing in the same way. See
"C++ exceptions".

One service uses one of the two for all of its calls.
`IsolateShutdownReleases` still holds every object and frees it when its
isolate shuts down; with exit teardown the hold's free function is
Expand All @@ -41,10 +50,11 @@ Teardown waits up to two seconds for guarded calls in flight, then for a
250 ms settle after the end of the last guarded call, and frees the tracked
objects. It knows nothing about other native calls:

- An unguarded call on a tracked object (tokenize, detokenize, metadata
reads, sampler construction, media decode) that is in flight when teardown
runs is not protected, however short it is. Teardown frees the object under
it.
- An unguarded call on a tracked object (metadata reads, sampler
construction other than the lazy-grammar one, and on a runtime older than
`v0.6.0-1` also tokenize, detokenize, sampler accept, memory clear and
media decode) that is in flight when teardown runs is not protected,
however short it is. Teardown frees the object under it.
- A guarded call that is still running after two seconds (an image or audio
evaluation, a long batch) makes teardown free nothing, and ggml-metal
aborts as before.
Expand All @@ -61,8 +71,7 @@ aborted when the object still had Metal buffers allocated. The
a direct C `exit()` reached it; the exits that shut the isolates down wait
for the free.

`v0.5.0-2`, which this package pins, fixes it: teardown waits for a free in
flight. An exit that lands during the last free now takes that free plus the
`v0.5.0-2` fixes it: teardown waits for a free in flight. An exit that lands during the last free now takes that free plus the
rest of the 250 ms settle window, about 255 ms in the native measurements,
where it used to return at once.

Expand All @@ -71,6 +80,88 @@ then the projector, then the model, so the last object a service frees is a
model and never a projector. That is also the lifetime order mtmd needs,
since a projector points at its model.

## C++ exceptions

llama.cpp reports some failures by throwing a C++ exception, which ends the
process when it crosses the C ABI into Dart. From `v0.6.0-1` every
`llama_dart_` function that calls llama.cpp catches it, records its message
for the calling thread (`llama_dart_last_error`) and returns a failure value.

- `LlamaCppObjectCalls.tracked` checks for that after a call returned its
failure value (always, for a call that returns nothing) and throws the
typed error of the operation: `LlamaModelException` for a model, LoRA or
projector load, `LlamaContextException` for a context,
`LlamaStateException` for a state call, `LlamaInferenceException`
otherwise. The message names the upstream function and the details are
llama.cpp's message. A failure value without a caught exception is
returned as before.
- The message is per thread and the next call with a barrier clears it, so it
is read in the same synchronous run as the call, before any other
`llama_dart_` call. A call made outside `LlamaCppObjectCalls` (speculative
decoding, the reasoning-budget sampler, TTS, the mtmd calls and the decision
head's ggml calls) reads it with `NativeCallFailures.throwIfCaught` at the
place that sees the failure value.
- The native contract leaves a llama or mtmd context in no defined state
after a call on it caught an exception, and on Windows every object of the
call, a model included. `NativeCallFailures` records those objects by
address, the service refuses them with `LlamaStateException` at each entry
point (`_ensureContextUsable`, `_ensureModelUsable`), and freeing an object
forgets it. A decision head that caught an exception in one of its ggml
calls stops running the same way.
- A runtime older than `v0.6.0-1` exports none of this: `NativeBarrierApi`
does not resolve, the service calls the upstream functions as before and
logs one warning at its first model load, and an exception still ends the
process.

A failed `GGML_ASSERT` still aborts: the barrier catches exceptions only.

## Vulkan device facts

`lib/src/backends/llama_cpp/vulkan_device_probe.dart` binds
`llama_dart_vulkan_get_device_count` and `llama_dart_vulkan_get_device_info`
(`v0.6.0-1`), which list the system's Vulkan devices with their name, type,
API versions and subgroup size. Reading them makes the Vulkan loader load
the system's GPU drivers, so the service reads them once, and only where
ggml-vulkan has registered a device: for a load that selects one, and for an
Android Vulkan context.

The list follows ggml-vulkan's order but is not always its list: the two can
differ for a device below Vulkan 1.2 beside other GPUs and with more than 16
devices, so `VulkanN` is not entry `N`. A registered device is matched to its
facts by what both sides report, the Vulkan device name
(`ggml_backend_dev_props` `description`) and integrated or discrete. A device
with no such entry, or with several that disagree on Vulkan 1.2, has unknown
facts.

- llama.cpp `v0.6.0` needs Vulkan 1.2 (`ggml_vk_instance_init` refuses an
older loader; for an older driver ggml-vulkan reads
`VkPhysicalDeviceVulkan12Features` the driver never filled in and calls
Vulkan 1.2 functions it lacks, once it initializes the device). A device
is initialized only when a model uses it, so a load is judged by the
devices llama.cpp would select for it, which
`lib/src/backends/llama_cpp/load_device_selection.dart` mirrors from
`llama_prepare_model_devices` (`src/llama.cpp`): the devices of an explicit
backend, which llamadart lists; otherwise the discrete GPUs, one per
device id, and integrated GPUs only when there is no discrete one; in
single-device mode the one `mainGpu` indexes. A CUDA device, an unselected
integrated GPU and a GPU of another backend never count. When every
selected device is known to be below 1.2, `ComputeDevice.gpu` throws
`LlamaUnsupportedException` and `ComputeDevice.auto` loads on the CPU with
a warning. When usable devices remain, the load lists those and logs a
warning naming the device it left out. A speculative draft model gets the
same list. The projector and a decision head pick their own device and are
not covered.
- An Android Vulkan context keeps the 8-token text-prompt decode cap unless
the facts list exactly the registered devices and each has a subgroup size
ggml-vulkan tiles correctly (8, or 32 and above). llama.cpp `v0.6.0` gives
a warp of the small matmul tile 8 rows only at a subgroup size of exactly 8
(`s_warptile_wm`), which is wrong at 16 and at every size below 8
(https://github.com/ggml-org/llama.cpp/issues/28637).

A runtime without the functions, a loader that cannot be queried and a device
that cannot be matched all count as unknown: the cap stays, and no load is
refused or narrowed.

## Which exits are covered

| Exit | What happens |
Expand Down Expand Up @@ -128,6 +219,31 @@ new call on an `sd_ctx_t` that can run longer than the 250 ms settle time
allows. Everything created through the API has to be freed through it.
- `test/unit/backends/llama_cpp/mtmd_chunk_eval_test.dart`: `withExitTeardown`
replaces the three evaluating calls and keeps the accessors.
- `test/unit/backends/llama_cpp/native_barrier_api_test.dart`: the lookup
requests all 18 names and resolves nothing when any one is missing or from
a library that has none; each member calls the function exported under its
own name; on the real runtime, a token outside the vocabulary, a trigger
pattern that is not a regular expression and a grammar that rejects an
accepted token are typed errors; `NativeCallFailures` marks and forgets
free-only objects.
- `test/unit/backends/llama_cpp/exit_teardown_api_test.dart` also pins, for
each tracked call, the error a caught exception throws and the objects it
leaves free-only on every platform and under the Windows rule.
- `test/unit/backends/llama_cpp/llama_cpp_service_native_failure_test.dart`:
a service on the real CPU runtime whose exit API and barrier fail the calls
a test names. Each failed call is the typed error of its operation, the
object it leaves undefined is refused afterwards and usable again once
freed and recreated, and nothing created stays unfreed. It also loads a
state file written by llama.cpp `v0.5.0`.
- `test/unit/backends/llama_cpp/vulkan_device_probe_test.dart`,
`load_device_selection_test.dart` and the "Vulkan" groups of
`llama_cpp_service_test.dart`: the device facts, the device selection and
version check of a load, and the cap on each subgroup size, through an
injected registry and injected facts. No default-CI test reads a real
Vulkan device.
- No test forces an exception through speculative decoding, the
reasoning-budget sampler or TTS: those functions are resolved inside the
service and have no stand-in.
- Two cases of the service test do not run in default CI. The restore and
replay of a rejected draft needs a model whose memory cannot drop a tail:
set `LLAMADART_LFM2_MODEL` to an LFM2 GGUF. The decision head's device
Expand Down
27 changes: 15 additions & 12 deletions doc/webgpu_bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ an earlier `<script>`:

## Pinned assets

Default pinned tag in the example is `v0.1.54`.
Default pinned tag in the example is `v0.1.59`.
Vendor the pinned assets into the chat app with:

```bash
WEBGPU_BRIDGE_ASSETS_TAG=v0.1.54 ./scripts/fetch_webgpu_bridge_assets.sh
WEBGPU_BRIDGE_ASSETS_TAG=v0.1.59 ./scripts/fetch_webgpu_bridge_assets.sh
```

`WEBGPU_BRIDGE_OUT_DIR` changes the destination. The script verifies
Expand All @@ -81,19 +81,22 @@ the chat app, set the bootstrap globals before the bootstrap runs:
```html
<script>
window.__llamadartBridgeAssetsRepo = 'leehack/llama-web-bridge-assets';
window.__llamadartBridgeAssetsTag = 'v0.1.54';
window.__llamadartBridgeAssetsTag = 'v0.1.59';
</script>
```

That release embeds llama.cpp `v0.5.0`, matching the `hook/build.dart` native pin
(`v0.5.0-2`, both built from upstream llama.cpp `v0.5.0@7fe450e19305b828c199d602c23a8337aaa1f03b`)
even though the bridge asset tag `v0.1.54` differs from the native runtime tag
`v0.5.0-2`. Provenance for this immutable consumer artifact: release `397350529`,
tag commit `e161182a09ac560d45ad5e65bb499574f913a466`, bridge source
`65622b297b83513db597a760fa067867755010b4`, and manifest SHA-256
`8a9f83c15035eeb034a6563e6f753382d7d7f9be81503ef76902138da7841176`. The bridge
assets were qualified against native `v0.5.0`; `v0.5.0-2` rebuilds it from the
same upstream commit. They add the decision API
That release embeds llama.cpp `v0.6.0`, matching the `hook/build.dart` native pin
(`v0.6.0-1`, both built from upstream llama.cpp `v0.6.0@d81235049384534c167caea52b85a694f6103d14`)
even though the bridge asset tag `v0.1.59` differs from the native runtime tag
`v0.6.0-1`. Provenance for this immutable consumer artifact: release `406130836`,
tag commit `189dde2798cb65a5ebe12d40068623e1873a6cd9`, bridge source
`c1f64536b9a4ea410066b711928c7cba03691fb0`, and manifest SHA-256
`f823b10417b212ff1f66aa1c46bf78af7d9c393497dfcf0fa3a4f77adeb260eb`. The bridge
assets were qualified against native `v0.6.0`; `v0.6.0-1` rebuilds it from the
same upstream commit. Their bridge JavaScript, type declarations and worker
are byte-identical to `v0.1.54`; the WebAssembly core changed, for llama.cpp
`v0.6.0` and for the bridge's own C++ on the batch and speculative-decoding
paths that adapts to it. They add the decision API
(apiVersion 1), next-token scoring (`scoreNextToken`), presence penalty, Min-P,
thinking budgets, runtime LoRA adapters and speculative decoding, keep the
Qwen3-ASR typed speech contract from `v0.1.30`, and
Expand Down
4 changes: 2 additions & 2 deletions example/chat_app/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@
typeof configuredRepo === 'string' && configuredRepo.length > 0
? configuredRepo
: 'leehack/llama-web-bridge-assets';
const defaultBridgeAssetsTag = 'v0.1.54';
const defaultBridgeLlamaCppTag = 'v0.5.0';
const defaultBridgeAssetsTag = 'v0.1.59';
const defaultBridgeLlamaCppTag = 'v0.6.0';
const bridgeAssetsTag =
typeof configuredTag === 'string' && configuredTag.length > 0
? configuredTag
Expand Down
Loading
Loading