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
18 changes: 14 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,20 @@ analyze and the relevant tests before the final commit.
- Use the closest affected-family model or artifact; if its weights are
unavailable, name each unavailable family and use primary upstream emissions
plus durable fixtures. An unrelated model is pipeline-only evidence.
- Post-merge QA is still required but is never the first adversarial pass. If
it finds a PR-caused P1, stop lower-priority merge work, file a causally
accurate issue, and prepare one cohesive recovery before resuming feature
work.
- Several PRs may land as one batch integration PR. High-risk constituents are
audited at their own exact head as above and standard-risk ones pinned at the
head whose CI passed; they are then combined on a new branch cut from current
`main`, one commit per PR, and landed with a rebase merge, never squash. A
constituent audit lets its diff land through a batch
only together with a passing integration audit of the integration head.
Dropping or replacing a constituent, or `main` moving, means
a new integration branch and PR.
Procedure: `doc/high_risk_pre_merge_readiness.md`, "Batch integration PR".
- Post-merge QA is still required but is never the first adversarial pass. When
the merged tree equals an audited head, it need not repeat checks the
independent audit already ran on that head. If it finds a PR-caused P1, stop
lower-priority merge work, file a causally accurate issue, and prepare one
cohesive recovery before resuming feature work.

## This file

Expand Down
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,54 @@
`LlamaStructuredOutput.parse` still decode it); trim replies you compare
exactly. `ChatSession` and its tool loop store assistant turns in `history`
without that whitespace, so the next prompt is unchanged.
- Fix a process abort on an image with more tokens than the context's
micro-batch when the projector's images are decoded with non-causal
attention (Gemma 3 and Gemma 4 other than E2B and E4B, among others): the
prompt now throws `LlamaInferenceException` naming the
`ModelParams.microBatchSize` it needs. With default batch sizes that is an
image above 512 tokens. A context whose batch equals its micro-batch still
decodes such an image in several batches, and now logs a warning that this
can reduce accuracy
([#958](https://github.com/leehack/llamadart/issues/958)).
- **Behavior change:** `all` in `llamadart_native_runtimes` now includes the
opt-in `stable_diffusion` image runtime, so `llamadart_native_runtimes: all`
ships GGUF, `.litertlm` and image generation together. An app that already
sets `all`, or a list containing it, downloads 14.7 to 15.6 MB more per
target, or 25.8 to 27.8 MB for the Vulkan build Linux and Windows use by
default, and grows by about 37 MB as measured on macOS arm64 and Android
arm64. android-x64 and Windows arm64 publish no image runtime and skip it
with a warning. A Flutter iOS or macOS app skips it with a build warning
unless `llamadart_stable_diffusion_flutter` is a dependency; a pub
workspace member, whose user-defines live in the workspace root pubspec, is
not recognised as one and bundles it. Leaving the key unset, or setting
`both`, still bundles only `llama_cpp` and `litert_lm`
([#856](https://github.com/leehack/llamadart/issues/856)).
- **Behavior change:** an image or audio part of a chat request to a GGUF
model takes the place it has in its message, as llama.cpp's `llama-server`
renders it ([#964](https://github.com/leehack/llamadart/issues/964)). For
Qwen3.5 and Qwen2.5-Omni it was attached before the whole prompt, and for
GLM-OCR it was wrapped in the image start and end tokens twice, so prompts
for media turns of these models change. A chat template no longer writes
its own text for a media part: Qwen's `Picture N: ` under `add_vision_id`,
the Kimi-K2 wrapper, Reka's run of image tokens and Cohere's
`<|IMG_PATCH|>` are gone, as on `llama-server`. A placeholder string that
a chat message quotes (`<img>`, `<image>`, `[IMG]`, `<__media__>`) is text
instead of a part. Where the runtime would still read such a string as a
part, it reaches the model with a zero-width space (U+200B) after its
first character, which the model may repeat in its answer: a quoted
`<__media__>` in `create` on native; every placeholder the bridge
rewrites in `create` on Web; and every placeholder `generate` reads in the
prompt `chatTemplate` returns for messages with media and in `create` on
a custom backend without `BackendChatPromptGeneration`, which
`package:llamadart/backend.dart` now exports. A prompt written for
`generate` keeps its placeholders, and `chatTemplate` output for messages
without media is unchanged.
- On native llama.cpp, image or audio input that the loaded projector has no
encoder for throws `LlamaUnsupportedException` naming the encoder, where
`create` and `generate` threw `LlamaInferenceException`. A chat template
that raises or has invalid syntax throws `LlamaInferenceException` with the
template's message instead of a raw `Exception`
([#963](https://github.com/leehack/llamadart/issues/963)).

## 0.11.1

Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,25 @@ experimental and may change, and the runtime is opt-in.
hooks:
user_defines:
llamadart:
llamadart_native_runtimes: [llama_cpp, stable_diffusion]
llamadart_native_runtimes: all
```

Keep `litert_lm` in the list if the app also loads `.litertlm` models.
Unset, the key bundles `llama_cpp` and `litert_lm`. A list replaces those
defaults, so it names everything the app loads:
- `all`: every runtime published for the target, `llama_cpp`, `litert_lm`
and `stable_diffusion`.
- `[llama_cpp, stable_diffusion]`: GGUF chat and images, no LiteRT-LM.
- `[stable_diffusion]`: images only.

- **Flutter iOS/macOS apps** should add the
`llamadart_stable_diffusion_flutter` companion (see [Install](#install)),
which links the runtime through Swift Package Manager and selects it without
the entry above. Pair companion `0.0.2` with core `0.11.1` and `0.11.0`.
Without it the hook bundles the runtime, App Store Connect rejects that iOS
framework's `MinimumOSVersion`, and only Xcode and `xcodebuild` show the
build warning about it.
Without it, `all` leaves the image runtime out of a Flutter iOS/macOS app
with a build warning. A list naming `stable_diffusion` bundles it through
the hook instead, and App Store Connect rejects that iOS framework's
`MinimumOSVersion`. `flutter build ios` output shows neither warning; Xcode
and `xcodebuild` show both.

- **Platforms:** Android arm64 (CPU), iOS and macOS (Metal), Linux arm64/x64
and Windows x64 (CPU or Vulkan). Not available on the web yet
Expand Down
133 changes: 133 additions & 0 deletions doc/high_risk_pre_merge_readiness.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,139 @@ add a focused rendering regression in that case. No unrelated compiled-grammar
edit is required. This policy example is not a claim that historical #529 had
already supplied v2 causal evidence or an authenticated audit.

## Batch integration PR

Whenever a PR head moves, earlier CI runs, approvals, audits and matrix
evidence no longer count. Landing N high-risk PRs one at a time therefore
costs N rounds of merging `main` in, re-audit, CI and post-merge QA. A batch
integration PR is the allowed alternative. It changes nothing for a PR that
lands on its own.

A release-prep PR is never a constituent, and the integration PR never carries
the `release-prep` label or a `release/prep-*` branch name.

1. **Constituent gates.** Each constituent PR first passes its own pre-merge
gate at its own exact head, exactly as if it were landing alone.
- A high-risk constituent has its [independent audit](#independent-audit)
at that head: blocking-only, by an auditor who took no part in the
implementation, with decision `accepted`, zero known PR-caused P1
regressions and zero unresolved review threads.
- A standard-risk constituent is pinned at the exact head whose CI passed.

A constituent whose head moves afterwards passes its gate again at the new
head before it joins a batch.
2. **Integration branch.** Cut a new branch from current `main` and add the
constituents as one commit each, so each stays individually revertable.
Each commit subject ends with `(#<constituent PR number>)`. Resolve
conflicts once, inside the commit of the constituent being applied. Publish
the branch through `tool/git/safe_pr_head_update.dart`.
3. **Conflict resolutions.** A resolution only reconciles hunks that two sides
both changed: a real merge conflict, or the mechanical union of changelog
or doc lines. Anything else, including a fix for a defect found in a
constituent, goes back to that constituent's PR and is re-audited there.
4. **Integration PR body.** Besides the normal template, it lists:
- for every constituent, its PR number, risk class, pinned head SHA and
audit result (or the passing CI run for a standard-risk one);
- every conflict resolution, listed per hunk, not per file;
- the closing keywords (`Closes #N`) of every constituent, because a PR
that is closed without merging does not close its issues.
5. **Integration audit.** One independent auditor reviews the integration PR's
exact head against current `main`, blocking-only. The auditor took no part
in implementing any constituent or in the integration; having audited a
constituent does not disqualify. The audit checks only what is new:
- the tree is a clean combination of the pinned heads plus the listed
resolutions and nothing else: each commit's diff matches
`git diff main...<pinned-head>` of its constituent, for audited and
standard-risk constituents alike, and every difference is a listed hunk;
- each listed resolution, reviewed as a change in its own right;
- the full default suites and the relevant real-model smokes pass on the
combined tree;
- the readiness evidence is valid for the integration head (below).

A constituent audit lets its diff land through a batch
only together with a passing integration audit of the integration head. It
stays valid for landing that PR alone at its audited head against the base
it was audited on, under the normal single-PR rules.
6. **CI** runs once, on the integration head.
7. **Review threads.** Before the merge, every review thread on the
integration PR and on every constituent PR is replied to and resolved. The
live unresolved count per constituent, which must be 0, is recorded in the
integration PR body at merge time.
8. **Merge** with a rebase merge, never squash, so `main` stays linear and
keeps one commit per constituent. Only then close each constituent PR with
a link to the integration PR.
9. **Post-merge QA** runs once for the batch. See
[Post-merge QA scope](#post-merge-qa-scope).

### When the batch has to change

`tool/git/safe_pr_head_update.dart` is fast-forward only, so the integration
branch can only gain commits. Appending a constituent moves the integration
head, so its audit, CI and evidence are redone. Each of these needs a
new integration branch and PR cut from current `main`, and the old integration
PR is closed:

- dropping a constituent;
- replacing a constituent's commit after that constituent was fixed and
re-audited in its own PR;
- `main` moving after the branch was cut.

The integration branch never takes a history rewrite, a revert commit or a
merge-from-`main` commit. If the integration audit finds a problem caused by
one constituent, that constituent is either fixed in its own PR or dropped;
both lead to a new integration branch. Its audit, CI and evidence are done
against the new integration head; the gates of the untouched constituents
still stand. A PR-caused P1 found in post-merge QA is handled as for any other
merge.

### Evidence for the integration head

The integration PR is an ordinary PR to the evaluator. Its evidence document
binds the integration PR number, author, exact head and current base; its
`independent_audit` is the integration audit; and its surfaces, matrix rows,
impacts and `test_evidence` cover the whole combined diff, which the evaluator
derives from Git as usual. That includes `test_evidence` controls for the
changed `lib/`, `tool/` and `hook/` paths of standard-risk constituents, which
had none of their own. Each high-risk constituent keeps its own evidence
document for its own audited head.

A `test_evidence` control (`control_result`) observed on a constituent's
audited head may be carried over only when every `production_refs` path and
the cited test file are identical on the integration head:

```bash
git diff --exit-code <audited-head> <integration-head> -- <paths>
```

Take the paths from the evidence and check that each exists at both commits; a
mistyped path prints nothing. Re-observe the control on the integration head
when the files differ, or when another constituent, or `main` since the
constituent's audited base, changed anything the test runs through. A cited
`local-only` test is always re-run on the integration head.

The schema has no field for constituent PR numbers, pinned heads, audit
results or conflict resolutions. Those live in the integration PR body, and the
integration audit's `summary` names the constituents it verified. The
readiness tool therefore cannot check the clean-combination claim; it rests on
the integration auditor.

## Post-merge QA scope

Post-merge QA is still required and is never the first adversarial pass. When
the merged tree equals an audited head, it need not repeat checks the
independent audit already ran on that head. Compare the tree of the commit
`main` points to once the merge lands (after a rebase merge, the last rebased
commit) with the audited head's tree:

```bash
git rev-parse <main-after-merge>^{tree} <audited-head>^{tree}
```

QA is then limited to what cannot be checked before merge: workflow runs on
`main`, deployed demos and anything else environment-specific. Local suites
are not repeated. When the trees differ, the checks run on the audited head do
not carry over.

## CLI

```bash
Expand Down
6 changes: 3 additions & 3 deletions doc/litert_lm_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ Templates are committed as jinja under `tool/litert_lm_templates/` and embedded
into `lib/src/backends/litert_lm/litert_lm_chat_templates.dart` by a generator.
Start from the canonical template llama.cpp uses. Keep any runtime
content-shape adapter in this source and cover it with prompt-parity tests.
An adapter that reads content part lists either renders image and audio parts
or rejects both: the Dart renderer gives a template that reads part lists
media as typed parts unless it rejects both kinds. Pin the result in
The Dart renderer gives an adapter the media marker in the message text and
never an image or audio part. It still reports an adapter that reads content
part lists but rejects both kinds as reading strings only. Pin the result in
`test/unit/core/template/template_caps_cache_fixtures_test.dart`.

1. Copy the canonical jinja into `tool/litert_lm_templates/<id>.jinja`
Expand Down
6 changes: 4 additions & 2 deletions doc/llama_cpp_exit_teardown.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ new call on an `sd_ctx_t` that can run longer than the 250 ms settle time
sequence is compared for creation and frees, plain generation (one decode
and one sample per token), one-text and batch embedding on a decoder and on
an encoder, state files, LoRA init, a decision head, a decision head that
fails after its context was created, and a fake projector. N-gram and
fails after its context was created, a fake projector, and an image the
service rejects after the tokenize without an evaluating call. N-gram and
draft-model speculation are matched against the sequences their loop
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.
replaces the three evaluating calls and keeps the accessors, which are all
the check of a media chunk against the micro-batch calls.
- `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
Expand Down
24 changes: 24 additions & 0 deletions doc/testing_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Pick targeted rows based on the touched surface:
| LiteRT-LM web / Gemma 4 web bundle | `gemma4-litert-web` |
| Chat app model cache/download/projector | `chat-app-device-cache` |
| LiteRT-LM engine reload memory on a device | `chat-app-litert-reload-memory` |
| Android Vulkan prompt cap, Vulkan device facts or the Vulkan 1.2 load refusal on a device | `chat-app-micro-batch-sweep` |
| Isolate shutdown releases, exit teardown, a Flutter pin bump, or app-exit guidance | `chat-app-macos-quit` |
| Speech-to-text API or adapter | `speech-to-text-smoke`, `web-speech-to-text-smoke`, plus `litert-lm-asr-smoke` for the dedicated LiteRT-LM streaming engine |
| Text-to-speech API or adapter | `text-to-speech-smoke`, plus `web-text-to-speech-smoke` for browser synthesis/playback/export |
Expand Down Expand Up @@ -546,6 +547,29 @@ after reload or replacement. Pair them with
pre-output stops, buffered tool calls, running handlers, projector creation
and teardown races, and speech parameter validation before file resolution.

### Image above the context micro-batch

```bash
MULTIMODAL_MICRO_BATCH_MODEL=/path/to/gemma-4-12B-it.gguf \
MULTIMODAL_MICRO_BATCH_MMPROJ=/path/to/mmproj.gguf \
MULTIMODAL_MICRO_BATCH_BACKEND=cpu \
dart test -p vm -j 1 --run-skipped \
test/e2e/backends/multimodal_micro_batch_e2e_test.dart
```

These local-only tests need a model whose projector decodes an image with
non-causal attention: Gemma 3, or Gemma 4 other than E2B and E4B. They answer
a small image at the default batch sizes; require a typed error and a working
engine for an image above a micro-batch that is below the batch, explicit or
default, and answer the large image with the micro-batch the error names; and
require an answer and one warning per request where the batch equals the
micro-batch (32/32, batch 32 alone, 256/256, 512/512, and a text turn after
an image turn). Repeat with `MULTIMODAL_MICRO_BATCH_BACKEND=metal` on macOS.
Without the check the first group aborts the process on llama.cpp's
`non-causal attention requires n_ubatch >= n_tokens` assertion. `test/unit/backends/llama_cpp/llama_cpp_service_media_micro_batch_test.dart`
covers the same paths in default CI with a stand-in projector on the real
runtime.

### Native exit teardown

```bash
Expand Down
11 changes: 11 additions & 0 deletions doc/webgpu_bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ gates against real assets and models; its header lists the setup.
exported from `package:llamadart`.
- Large model URL loads can use a worker-thread fetch-backed path to reduce
contiguous `ArrayBuffer` pressure, but only after an explicit opt-in.
- With media parts the bridge reads its marker `<__media__>` and the
placeholders it rewrites to it (`<image>`, `[IMG]`, `<|image|>`, `<img>`,
`<|img|>`, `<|vision_start|><|image_pad|><|vision_end|>` and its
`video_pad` form, `<audio>`, `<|audio|>`, `<|image_N|>`, `<|audio_N|>`) as
a part wherever they are in the prompt, and the pinned assets have no
option that turns this off. For a prompt that `LlamaEngine.create` rendered,
`WebGpuLlamaBackend` writes `<__media__>` where each part was and puts a
zero-width space after the first character of any such string in the rest,
so a message that quotes one is not read as media. A prompt passed to
`generate` goes to the bridge as written. A bridge option that takes the
marker with the request would make the zero-width space unnecessary.
- Bridge runtimes can provide `llama_webgpu_core_mem64.js/.wasm`. When the
page sets `__llamadartBridgeCoreModuleUrlMem64` and memory64 is preferred,
the bridge tries the wasm64 core first and falls back to wasm32.
Expand Down
Loading
Loading