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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Releases before 0.10.0 are in the

- Fixed the generic JSON tool fallback replacing your system message with its JSON instruction when tools are passed with `ToolChoice.auto` or `required`; the instruction now follows the system message ([#1973](https://github.com/leehack/llamadart/issues/1973)).
- Native LiteRT-LM strict `responseFormat` now also runs on the Windows x64 GPU (NVIDIA L4 over Direct3D 12, GRID driver 596.86, Qwen3 and Gemma 4); `ComputeDevice.gpu` there no longer needs `ComputeDevice.cpu`. Other drivers are untested and the Linux arm64 GPU stays unqualified ([#174](https://github.com/leehack/llamadart/issues/174)).
- Adopt stable-diffusion `v0.3.0-6` with Apple host-buffer and model-loader scratch release fixes ([#2004](https://github.com/leehack/llamadart/issues/2004)); full-VAE load/dispose checks passed on iOS 18 and 26 with small residual memory.
- Documented that the Android llama.cpp `opencl` module needs the `libOpenCL.so` `<uses-native-library android:required="false"/>` manifest declaration on target API 31+; without it the module cannot load and `ComputeDevice.gpu` with OpenCL throws. ggml-opencl admits only Adreno (and Intel) GPUs. With it, EmbeddingGemma 2 ran fully on OpenCL on a Galaxy S24 ([#1189](https://github.com/leehack/llamadart/issues/1189)).
- Fixed Android llama.cpp loads that ask for another GPU backend (such as `opencl`) and land on an already registered Vulkan device skipping the Android Vulkan context settings and the 8-token prompt cap ([#2016](https://github.com/leehack/llamadart/issues/2016)).

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ creation fails, `ComputeDevice.auto` retries on the CPU with a warning;

Image generation
is not available on the web. On iOS, use
`ImageModelPlacement(vaeOnCpu: true)` to keep diffusion on Metal, or CPU
generation. The pinned `v0.3.0-4` runtime splits Metal graphs, so a full VAE
`ImageModelPlacement(vaeOnCpu: true)` for CPU VAE decoding with Metal
diffusion, or choose CPU generation. The pinned `v0.3.0-6` runtime splits Metal graphs, so a full VAE
is admitted on iOS Metal (qualified: SD-Turbo's embedded VAE at 512x512); a runtime without the split keeps the intrinsic SDXS
tiny-decoder policy and refuses full-VAE Metal decoding.
SD `v0.3.0-6` passed four full-VAE load/dispose cycles and eight decodes per device on iPhone 16 Pro (iOS 18.3.2) and iPhone 17 Pro (iOS 26.5.1), tested at `6b191b28`. Small nonzero residual memory remains; this single session is not proof of zero leaks (#2004).

Per-target support, device limitations and runtime options:

- [Platform and backend support matrix](https://llamadart.leehack.com/docs/platforms/support-matrix), including
Expand Down
55 changes: 52 additions & 3 deletions doc/cross_platform_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2477,10 +2477,59 @@ with the SD-Turbo full-VAE harness:
| C1, split off | iPhone 16 Pro, iOS 18.3 | third decode failed with the GPU command-buffer error (watchdog) |
| C2b soak | iPhone 16 Pro, iPhone 17 Pro | 30 of 30 decodes passed, one image hash, flat footprint |

Known limit ([#2004](https://github.com/leehack/llamadart/issues/2004)): on
the iPhone 17 Pro (iOS 26.5.1) the second engine dispose kept about 2 GB
On the iPhone 17 Pro (iOS 26.5.1) the second engine dispose kept about 2 GB
resident and later loads failed the memory check; the iPhone 16 Pro returned to
its baseline. Whether it is a leak or delayed reclaim is undecided.
its baseline ([#2004](https://github.com/leehack/llamadart/issues/2004)).
Runtime `v0.3.0-5` carries the ggml `vm_allocate` host-buffer fix for it.

The current `v0.3.0-6` pin adds Apple model-loader scratch release; its
qualification is recorded below, separately from these historical v5 measurements.

Repin soak of runtime `v0.3.0-5` (source `f7dcae3bb`): DDP session
`session-790c4db5-300b-4c86-aeb0-2e74585a34a2`, record `R1047`, SD-Turbo q8_0 with its embedded full VAE,
4 load/dispose cycles per device. The preserved harness calls
`profile.buildModel(modelPath: modelFile)` without `taesdPath`; the original
v5 soak and the v4/v5 A/B therefore both used full VAE. Both jobs passed with no `load_failed`
and stable decode hashes.

| Device | Peak per load | After dispose |
| --- | --- | --- |
| iPhone 17 Pro, iOS 26.5.1 | about 2.4 GB | 163 to 190 MB (148 MB baseline); the old runtime kept about 2 GB |
| iPhone 16 Pro, iOS 18.3.2 | about 2.4 GB | about 370 MB, flat across cycles (125 MB first-cycle baseline; earlier v3/v4 measured about 150 MB on this device/model) |

#### v0.3.0-6 full-VAE disposal qualification (2026-11-15)

Tested source: `6b191b28b0f39eae1368fc76ea37f8051c5d2cb8`, session
`session-5511bf15-6626-4b14-b920-70836728c503`, test ZIP SHA-256
`a7af0af3d97606d2e93d0eacb84f4307d521ca6120a6ae50bbbb601f255881a8`.
Both devices completed four loads/disposals and eight successful decodes with
no failures on Metal (`MTL0`). The preserved harness used the same SD-Turbo
q8_0 model with its embedded full VAE, no `taesdPath`, at 512x512, one step,
guidance 1 and seed 42. Per-device PNG hashes were unchanged across v4/v5/v6.

| Device / OS | v4 end residual (MiB) | v5 end residual (MiB) | v6 end residual (MiB) |
| --- | --- | --- | --- |
| iPhone 16 Pro / iOS 18.3.2 | 21.38–25.56 | 239.66–240.56 | 37.91–40.05 |
| iPhone 17 Pro / iOS 26.5.1 | about 1.9 GiB retained after the first cycle | 28.23–43.63 | 32.36–43.95 |

Residuals are relative to each run's first baseline, before epilogue heap
churn. V6 substantially reduces the v5 iOS 18 residual and keeps iOS 26 near
v5; small nonzero residuals remain. These are single-session observations,
not proof of zero leaks. The historical v4 iOS 26 provider result was PASS,
but its raw log has one `load_failed` and five disposal records; it was not a
clean functional pass.

Raw configs report `runtime_version: unknown`. Independent binary provenance
verified the published v6 XCFramework SHA-256
`7e5a79218d731ce7fb6b54020190a79630bd843d9a1dbafb24e5f0442ab95cb8`,
matching UUID `7C8D9AC4-524A-309E-A24B-FF6FF5A7B673` and byte equality after
signature removal and normalization of `__LINKEDIT.vmsize`. The evidence bundle
retains `results/ab-v6/evidence-report.md`, `comparison.json`,
`bundles/ab-v6/state.json` and `artifact-verification.json` under
`llamadart-evidence/issue-2004`. Original logs remain unchanged. This follow-up
changes documentation only; tested source and v6 native binary are unchanged.

#### v0.3.0-4 public API qualification

Final qualification of the public API at PR head `6109c8d1e` with the published
`v0.3.0-4` pin: DDP session `session-954952c8-39c6-4878-9f17-ca2c6efed56b`,
Expand Down
4 changes: 3 additions & 1 deletion example/chat_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ layouts) opens a separate screen for the experimental `ImageGenerationEngine`
runtime…** meanwhile. With an empty Metal shader cache the first check
compiles ggml's Metal library, about 16 s on an M4 Max; with the cache warm
it takes under 0.5 s.
- On iOS, the pinned SD runtime (`v0.3.0-4`) splits Metal graphs, so full-VAE recipes decode on the GPU; the app has no iOS-specific gating. A runtime without the split refuses them and needs CPU VAE placement or CPU generation. On iOS 26 the second engine dispose can leave about 2 GB resident ([#2004](https://github.com/leehack/llamadart/issues/2004)).
- On iOS, the pinned SD runtime (`v0.3.0-6`) splits Metal graphs, so full-VAE recipes decode on the GPU; the app has no iOS-specific gating. A runtime without the split refuses them and needs CPU VAE placement or CPU generation. On iOS 26 the runtime returns an image model's memory on dispose; earlier runtimes could leave about 2 GB resident ([#2004](https://github.com/leehack/llamadart/issues/2004)).
- Models: **SDXS-512** (683 MB, recommended, fits most phones) and
**SD-Turbo + TAESD** (2.0 GB). Both download into the app's model cache
from pinned Hugging Face revisions with exact sizes and SHA-256 checks; an
Expand Down Expand Up @@ -350,6 +350,8 @@ layouts) opens a separate screen for the experimental `ImageGenerationEngine`
scratch test using the seed entry this test now uses generated with seed 42
there, but this test itself has not been re-run on a physical iPhone.

SD `v0.3.0-6` passed four full-VAE load/dispose cycles and eight decodes per device on iPhone 16 Pro (iOS 18.3.2) and iPhone 17 Pro (iOS 26.5.1), tested at `6b191b28`. Small nonzero residual memory remains; this single session is not proof of zero leaks (#2004).

### 3. Advanced Configuration (Optional)
1. Tap the settings control in the top bar.
2. Adjust **GPU Layers**, **Context Size**, and **Preferred Backend**. Expand
Expand Down
43 changes: 24 additions & 19 deletions lib/src/hook/native_release_pins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ const liteRtLmBundleSpecs = <LiteRtLmBundleSpec>[

/// `leehack/stable-diffusion-native` release tag downloaded for the opt-in
/// stable-diffusion.cpp runtime.
const stableDiffusionReleaseTag = 'v0.3.0-4';
const stableDiffusionReleaseTag = 'v0.3.0-6';

/// First Apple companion release containing [stableDiffusionReleaseTag].
const stableDiffusionAppleCompanionVersion = '0.19.10';
const stableDiffusionAppleCompanionVersion = '0.19.11';

/// Explicitly qualified older Apple SD pins that preserve existing app locks.
///
Expand All @@ -229,11 +229,14 @@ const stableDiffusionAppleCompanionVersion = '0.19.10';
/// native generation returns images; the newer native guard remains preferred.
/// Clear and requalify this map whenever [stableDiffusionReleaseTag] changes.
///
/// `v0.3.0-3` has the same upstream as `v0.3.0-4` and lacks only the
/// `sd_dart_graph_split_*` exports, which the bindings load as an optional
/// group, so an older framework keeps the iOS full-VAE refusal.
/// `v0.3.0-3` and `v0.3.0-4` share the pinned upstream and its C headers.
/// `v0.3.0-3` lacks the `sd_dart_graph_split_*` exports, which the bindings
/// load as an optional group, so it keeps the iOS full-VAE refusal; `v0.3.0-4`
/// lacks the Apple host-buffer and model-loader scratch release fixes.
const stableDiffusionCompatibleAppleCompanionTags = <String, String>{
'v0.3.0-3': 'the sd_dart_graph_split_* exports (iOS full-VAE decoding)',
'v0.3.0-3':
'the sd_dart_graph_split_* exports (iOS full-VAE decoding) and Apple host-buffer and model-loader scratch release fixes',
'v0.3.0-4': 'the Apple host-buffer and model-loader scratch release fixes',
};

/// Checksums of the exact published XCFrameworks accepted by the SD hook.
Expand All @@ -242,11 +245,13 @@ const stableDiffusionAppleCompanionChecksums = <String, String>{
'8f35c67f72d1d4bf86d31f20f3437d04baaf3b6ac7389908000fd166e387783f',
'v0.3.0-4':
'0d022638f54be80aa75fd8e73a94d139ad8887f4f3c73084501369ca5e7ac354',
'v0.3.0-6':
'7e5a79218d731ce7fb6b54020190a79630bd843d9a1dbafb24e5f0442ab95cb8',
};

/// stable_diffusion cache directory version derived from
/// [stableDiffusionReleaseTag].
const stableDiffusionVersion = '0.3.0-4';
const stableDiffusionVersion = '0.3.0-6';

/// A published stable-diffusion-native runtime archive and the library it must
/// contain under `lib/`.
Expand All @@ -273,62 +278,62 @@ class StableDiffusionBundleSpec {
const stableDiffusionBundleSpecs = <StableDiffusionBundleSpec>[
StableDiffusionBundleSpec(
'android-arm64',
sha256: 'fdc1a614bc7b50d838dfee4416a8ffea04eb01a0042f2d65821e80225e4000cd',
sha256: '56ab35a9e1b941fab1169b6308c0e2a1fceaea0e97499e19f849242ee2d076f8',
requiredLibraries: {'libstable-diffusion.so'},
),
StableDiffusionBundleSpec(
'ios-arm64',
sha256: 'c24c7df0a7c21370d026668cd12a98baf646d7951829088e6957f25ad13cdce9',
sha256: '87e5a91bf2b68fac21722aac7bc22ec265ba4946cb54a83e75e7ff3b69aaa801',
requiredLibraries: {'libstable-diffusion.dylib'},
),
StableDiffusionBundleSpec(
'ios-arm64-sim',
sha256: 'be5ab833a7a902ba75bce16c3020565372bef672106e5b91a2d9bcb7e85d0fb2',
sha256: '30f65bcebf4044b87085b8c130322398d3212530ad0948e6166a11e838966731',
requiredLibraries: {'libstable-diffusion.dylib'},
),
StableDiffusionBundleSpec(
'ios-x64-sim',
sha256: 'eae74517da056d3cd44964a5ada097b4ec58158be4978721efdb9801d90e7540',
sha256: 'ff135eca41f75798dd3edc16da31af515b10f5793d35e8d70c340f02479fdfcd',
requiredLibraries: {'libstable-diffusion.dylib'},
),
StableDiffusionBundleSpec(
'macos-arm64',
sha256: 'd34dbaf3c9ecfbbaa97e1c89687e27cefdae824ed27a1a8cf694a9c9489d3eae',
sha256: '2a2468ecd8aa284a093179ecf28f17e93b31d4359ab553a4010353063cb410dc',
requiredLibraries: {'libstable-diffusion.dylib'},
),
StableDiffusionBundleSpec(
'macos-x64',
sha256: '7f5954264d0e904a5049822e320eb6b06696c38a59428868537915b439eec478',
sha256: 'e2f49a8ecbc898cfafa9feefaca1b4703f23af19e74b3b2a6bd407f8730eb8ff',
requiredLibraries: {'libstable-diffusion.dylib'},
),
StableDiffusionBundleSpec(
'linux-arm64',
sha256: '71277d3a6f2c3a500b69fae829318c19ef00ed035a86cef09215865167b354a4',
sha256: 'd394acffe3a9de8cc86abb4f1176f1bb1b5af5ed83efc013384e2b6e220d831f',
requiredLibraries: {'libstable-diffusion.so'},
),
StableDiffusionBundleSpec(
'linux-arm64-vulkan',
sha256: '58b362b189473334d3ca92f40eb998228ef723b740efc1f1d9b885c7ad711be6',
sha256: 'd2412bc1ee28dd87a353d37181c060e1e0287d37ffc6c231dae5b3b399071dab',
requiredLibraries: {'libstable-diffusion.so'},
),
StableDiffusionBundleSpec(
'linux-x64',
sha256: '4b5405c319f500d1190e2e363386d561484ebcc88fe41cdfb6fa67fe863e68f4',
sha256: '6dd33ff5cede6b9468006dcd08b6b60d5d3ac32c65863df1475942b7c6d9baac',
requiredLibraries: {'libstable-diffusion.so'},
),
StableDiffusionBundleSpec(
'linux-x64-vulkan',
sha256: '43c3331afc6c72dd5ac16eef6625abdbc8fbed29544b442d3299e11c36d1caba',
sha256: 'dda3969e18974ddd2dc110ca2576927548bcc0e9355932cd25249803ff1f816c',
requiredLibraries: {'libstable-diffusion.so'},
),
StableDiffusionBundleSpec(
'windows-x64',
sha256: '5eff9c03d5a8b13412df02816d451b9f5e53aba689d8b65118cc2e4862dd1848',
sha256: '8da3d2d03634bcd9a76e52d84d92995a02b956ed697cc23e4303f45b3d1fdc5e',
requiredLibraries: {'stable-diffusion.dll'},
),
StableDiffusionBundleSpec(
'windows-x64-vulkan',
sha256: '19351af58dc09ee6d66b2b09b3206518a4920e28377c86a5f1ebf2fb8dfac8c4',
sha256: 'eb15f8673c87cfbfd0a8a9f133dc96af1316bc1b58009e33f9f851e43b8d3d39',
requiredLibraries: {'stable-diffusion.dll'},
),
];
4 changes: 4 additions & 0 deletions packages/llamadart_stable_diffusion_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

- Updated Apple SwiftPM native pin to `leehack/stable-diffusion-native@v0.3.0-6`.

## 0.19.10

- Updated Apple SwiftPM native pin to `leehack/stable-diffusion-native@v0.3.0-4`.
Expand Down
2 changes: 1 addition & 1 deletion packages/llamadart_stable_diffusion_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Flutter iOS and macOS it does so only with this package.
This package has no runtime Dart API of its own. Import `package:llamadart`
normally from the core package and use `ImageGenerationEngine` there.

The Apple SwiftPM manifest pins `leehack/stable-diffusion-native@v0.3.0-4`.
The Apple SwiftPM manifest pins `leehack/stable-diffusion-native@v0.3.0-6`.

Apps bound for the App Store should use this package: the Apple privacy
manifest for the stable-diffusion.cpp runtime ships inside this XCFramework,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription

let packageRoot = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
let artifactsRoot = packageRoot.appendingPathComponent("Artifacts")
let stableDiffusionTag = "v0.3.0-4"
let stableDiffusionTag = "v0.3.0-6"

func localArtifactPath(_ name: String) -> String? {
let path = artifactsRoot.appendingPathComponent(name).path
Expand Down Expand Up @@ -47,7 +47,7 @@ let package = Package(
repository: "leehack/stable-diffusion-native",
artifactName: "stable-diffusion-native-apple-xcframework-\(stableDiffusionTag).zip",
tag: stableDiffusionTag,
checksum: "0d022638f54be80aa75fd8e73a94d139ad8887f4f3c73084501369ca5e7ac354"
checksum: "7e5a79218d731ce7fb6b54020190a79630bd843d9a1dbafb24e5f0442ab95cb8"
),
.target(
name: "llamadart_stable_diffusion_flutter",
Expand Down
9 changes: 4 additions & 5 deletions skills/llamadart-image-generation/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ description: >-
`xcodebuild` show both. Use the companion with the core's `MAJOR.MINOR`. Adding it
opts the app into the runtime (about 37 MB per Apple target).
The core accepts only an Apple SD companion pinning its own runtime
(`v0.3.0-4`): runtimes before `v0.3.0-1` abort on FP8 weights on Metal, and those before
(`v0.3.0-6`, or `v0.3.0-4`/`v0.3.0-3` with an upgrade warning): runtimes before `v0.3.0-1` abort on FP8 weights on Metal, and those before
`v0.3.0` have a smaller `sd_ctx_params_t`. Upgrade the
core and `llamadart_stable_diffusion_flutter` together.

core and `llamadart_stable_diffusion_flutter` together. SD `v0.3.0-6` passed four full-VAE load/dispose cycles and eight decodes per device on iPhone 16 Pro (iOS 18.3.2) and iPhone 17 Pro (iOS 26.5.1), tested at `6b191b28`. Small nonzero residual memory remains; this single session is not proof of zero leaks (#2004).
- Platforms: Android arm64 (CPU only; Armv8.2 dot-product and fp16), iOS 16.4+
and macOS 13.3+ (Metal), Linux arm64/x64 and Windows x64 (CPU or Vulkan; x64
CPUs need AVX2, FMA, F16C and BMI2). Web, Android x64 and Windows arm64
Expand Down Expand Up @@ -283,10 +282,10 @@ core and `llamadart_stable_diffusion_flutter` together.
true` on iOS Metal throws `LlamaUnsupportedException` at load: every decode
tripped the GPU watchdog and returned a corrupt image
([#1044](https://github.com/leehack/llamadart/issues/1044)). Full-VAE Metal
decoding on iOS is refused only without the graph split (pinned `v0.3.0-4`
decoding on iOS is refused only without the graph split (pinned `v0.3.0-6`
has it, #1047); only SD-Turbo's embedded VAE at 512x512 is qualified, and a
Metal command-buffer failure is an error. An older runtime needs an SDXS
intrinsic decoder, `vaeOnCpu: true` or CPU. iOS 26: 2 GB may stay resident (#2004).
intrinsic decoder, `vaeOnCpu: true` or CPU. iOS 26: fixed in runtime `v0.3.0-5` (measured on iPhone 17 Pro; iPhone 16 Pro retained memory above baseline, #2004).
- `ImageConditioningCacheParams(capacity: ...)`: ordinary `ImageModelParams`
preserve the native default of 4 prompt-conditioning entries. `0` disables
reuse; positive values set an LRU entry limit up to `2147483647` (the signed 32-bit ABI
Expand Down
Loading
Loading