Skip to main content

blazen_image_diffusion/
lib.rs

1//! Local image generation backend for Blazen using [`diffusion-rs`](https://github.com/huggingface/diffusion-rs).
2//!
3//! This crate wraps the `diffusion-rs` pure-Rust Stable Diffusion inference
4//! engine to provide fully local, offline image generation with no API keys
5//! required.
6//!
7//! When used through `blazen-llm` with the `diffusion` feature flag, this
8//! crate's [`DiffusionProvider`] will implement `blazen_llm::ImageGeneration`.
9//!
10//! # Feature flags
11//!
12//! | Feature  | Description                                      |
13//! |----------|--------------------------------------------------|
14//! | `engine` | Links the actual `diffusion-rs` runtime (CPU)    |
15//! | `cuda`   | NVIDIA CUDA GPU acceleration                     |
16//! | `metal`  | Apple Silicon GPU acceleration (Metal)            |
17//!
18//! Without the `engine` feature the crate compiles (options struct + stub
19//! provider) but cannot actually run image generation. This keeps workspace
20//! builds fast when the heavy native dependencies are not needed.
21//!
22//! # Streaming support
23//!
24//! Image generation through this crate is **single-call**: one
25//! [`DiffusionProvider::generate_image`] invocation returns one complete
26//! [`blazen_llm::ImageResult`]. There is no per-step callback or partial
27//! result stream.
28//!
29//! Upstream `diffusion-rs` does expose a
30//! `gen_img_with_progress(&Config, &mut ModelConfig, Sender<Progress>)`
31//! entry point that emits `(step, total_steps, time)` triples over a
32//! [`std::sync::mpsc::Sender`], but the `Progress` fields are private
33//! (only `Debug` is implemented) so they can be logged but not meaningfully
34//! surfaced through Blazen's typed APIs. Wiring richer progress events
35//! would require either upstream exposing public accessors or building a
36//! progress facade in this crate that re-formats the `Debug` output --
37//! both are out of scope for the initial engine wire-up.
38
39#[cfg(feature = "engine")]
40pub mod engine;
41mod options;
42mod provider;
43
44#[cfg(feature = "engine")]
45pub use engine::GeneratedImage;
46pub use options::{DiffusionOptions, DiffusionScheduler};
47pub use provider::{DiffusionError, DiffusionProvider};