Skip to content

Experimental ImageGenerationEngine public API #778

Closed

Description

@leehack

Part of #776. Depends on #777.

Public experimental API, starting from the prototype's ImageGenerationEngine (reference branch llamadart-media-generation-1efede) and the sketch in #776.

Fix what the prototype exposed:

  • Global callbacks. stable-diffusion.cpp's progress and log callbacks are process-wide: allow one active generation per process (LlamaStateException) and label progress by phase (loading, encodingPrompt, sampling, decoding), since the callback fires for all of them.
  • Logs. Route runtime logs through LlamaLogger. The log text is only valid during the callback, so the native side must copy it (tracked in stable-diffusion-native).
  • Early cancel. stable-diffusion.cpp resets its cancel flag when generation starts; keep a pending cancel on the Dart side and re-apply it.
  • GPU aborts. Map an iOS Metal command-buffer abort to LlamaInferenceException and keep the engine usable.
  • Memory preflight. Refuse a model that cannot fit the device with LlamaModelException instead of letting Android kill the process (SD-Turbo on the 6 GB Galaxy A53).
  • Warm-up. Document the ~19 s first Metal load, or offer warmUp().
  • Model presets. ImageGenerationModel.sdxs(...) and .sdTurbo(..., taesdPath:) carry required defaults (SDXS needs 1 step, guidance 1); .custom(...) for other checkpoints.
  • Downloads. Reuse the existing download and cache path, with resume.

Same PR, per AGENTS.md: export from lib/llamadart.dart with Dartdoc, README, website guide and support matrix, CHANGELOG.md and recent-releases.md under Unreleased, the affected SKILL.md, and an example.

Activity

  1. added
    enhancement
    priority:P2
    on Sep 29, 2026
  2. leehack commented on Sep 29, 2026

    @leehack
    OwnerAuthor

    Carry-over from the #784 audits (non-blocking there because nothing reached the probe yet; this PR makes it reachable):

    • Point the Vulkan-loader failure advice in lib/src/backends/stable_diffusion/stable_diffusion_runtime_io.dart to llamadart_stable_diffusion_backends instead of llamadart_native_backends.
    • Gate x64 CPU builds on AVX2, FMA and F16C (the linux-x64/windows-x64 runtimes use them); an older CPU would crash with SIGILL.
    • Test that vulkan wins over cpu in a mixed llamadart_stable_diffusion_backends list and that an empty value neither warns nor overrides.
    • List llamadart_stable_diffusion_backends in the build-hooks key table and document the warn-and-fall-back for unsupported values.
    • State the minimum OS versions (iOS 16.4, macOS 13.3).
    • Windows: confirm whether a missing vulkan-1.dll reaches the Vulkan hint (LoadLibrary error 126 may not name it).
  3. leehack commented on Sep 29, 2026

    @leehack
    OwnerAuthor

    Delivery plan (stacked PRs):

    1. feat: add opt-in stable_diffusion native runtime #784 — opt-in stable_diffusion runtime, hook, pins, probe (base: main).
    2. PR for this issue — public experimental ImageGenerationEngine API, the audit carry-overs above, docs/skills/changelog, and a command-line example (llamadart_cli image subcommand or basic_app) that writes a PNG with progress and cancellation (base: feat: add opt-in stable_diffusion native runtime #784's branch).
    3. Follow-up PR — chat app image screen with SDXS / SD-Turbo + TAESD model entries and size warnings; becomes the device QA path for Image validation: Firebase harness, Android coexistence and remaining device checks #779 (base: this issue's branch).

    The repo squash-merges, so each child PR is rebased onto main and retargeted after its parent merges.

  4. added a commit that references this issue on Oct 16, 2026
    420b7b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:P2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions