pub struct DiffusionProvider { /* private fields */ }Expand description
A local image generation provider backed by diffusion-rs.
Constructed via DiffusionProvider::from_options. With the engine
feature on, [DiffusionProvider::generate_image] lazily initialises the
underlying pipeline on first call and runs the synchronous
stable-diffusion.cpp generation inside tokio::task::spawn_blocking.
Implementations§
Source§impl DiffusionProvider
impl DiffusionProvider
Sourcepub fn from_options(opts: DiffusionOptions) -> Result<Self, DiffusionError>
pub fn from_options(opts: DiffusionOptions) -> Result<Self, DiffusionError>
Create a new provider from the given options.
This currently validates the options and stores them. The actual diffusion-rs pipeline will be initialised in Phase 5.3.
§Errors
Returns DiffusionError::InvalidOptions if any option is present but
invalid (e.g. an empty device string, zero dimensions, or zero steps).
Sourcepub fn device_str(&self) -> &str
pub fn device_str(&self) -> &str
The resolved device string ("cpu" when unset).
Sourcepub fn num_inference_steps(&self) -> u32
pub fn num_inference_steps(&self) -> u32
The resolved number of inference steps (user-specified or default 20).
Sourcepub fn guidance_scale(&self) -> f32
pub fn guidance_scale(&self) -> f32
The resolved guidance scale (user-specified or default 7.5).
Sourcepub const fn scheduler(&self) -> DiffusionScheduler
pub const fn scheduler(&self) -> DiffusionScheduler
The scheduler configured for this provider.
Sourcepub async fn load(&self) -> Result<(), DiffusionError>
pub async fn load(&self) -> Result<(), DiffusionError>
Eagerly warm the underlying diffusion-rs pipeline.
Without the engine feature this returns
DiffusionError::EngineNotAvailable. With it, this is idempotent
and safe to call from multiple tasks concurrently.
§Errors
Returns DiffusionError::ModelLoad if pipeline construction or the
output-directory bootstrap fails.
Sourcepub async fn unload(&self) -> Result<(), DiffusionError>
pub async fn unload(&self) -> Result<(), DiffusionError>
Best-effort unload. Always succeeds.
diffusion-rs does not expose a “drop weights” entry point and the
cached pipeline lives behind a tokio::sync::OnceCell shared via
&self, so we cannot evict it from interior mutability alone.
Callers that require strict resource release should drop the
entire DiffusionProvider and construct a fresh one.
§Errors
Never errors today; the Result is kept to match the
[blazen_llm::LocalModel::unload] trait signature so the
bridge can forward without contortions.
Sourcepub async fn is_loaded(&self) -> bool
pub async fn is_loaded(&self) -> bool
true if a pipeline has been warmed via Self::load or the first
generate call.