Skip to main content

DiffusionProvider

Struct DiffusionProvider 

Source
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

Source

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).

Source

pub fn device_str(&self) -> &str

The resolved device string ("cpu" when unset).

Source

pub fn model_id(&self) -> &str

The configured model identifier (or "sd-1.5" when unset).

Source

pub fn width(&self) -> u32

The resolved width (user-specified or default 512).

Source

pub fn height(&self) -> u32

The resolved height (user-specified or default 512).

Source

pub fn num_inference_steps(&self) -> u32

The resolved number of inference steps (user-specified or default 20).

Source

pub fn guidance_scale(&self) -> f32

The resolved guidance scale (user-specified or default 7.5).

Source

pub const fn scheduler(&self) -> DiffusionScheduler

The scheduler configured for this provider.

Source

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.

Source

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.

Source

pub async fn is_loaded(&self) -> bool

true if a pipeline has been warmed via Self::load or the first generate call.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.