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.

Trait Implementations§

Source§

impl ComputeProvider for DiffusionProvider

Source§

fn provider_id(&self) -> &str

Provider identifier (e.g., “fal”, “replicate”, “runpod”).
Source§

fn submit<'life0, 'async_trait>( &'life0 self, _request: ComputeRequest, ) -> Pin<Box<dyn Future<Output = Result<JobHandle, BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Submit a compute job and get a handle to track it.
Source§

fn status<'life0, 'life1, 'async_trait>( &'life0 self, _job: &'life1 JobHandle, ) -> Pin<Box<dyn Future<Output = Result<JobStatus, BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Poll the current status of a submitted job.
Source§

fn result<'life0, 'async_trait>( &'life0 self, _job: JobHandle, ) -> Pin<Box<dyn Future<Output = Result<ComputeResult, BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Wait for a job to complete and return the result. Read more
Source§

fn cancel<'life0, 'life1, 'async_trait>( &'life0 self, _job: &'life1 JobHandle, ) -> Pin<Box<dyn Future<Output = Result<(), BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cancel a running or queued job.
Source§

fn run<'life0, 'async_trait>( &'life0 self, request: ComputeRequest, ) -> Pin<Box<dyn Future<Output = Result<ComputeResult, BlazenError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Submit a job and wait for the result (convenience method). Read more
Source§

fn provider_config(&self) -> Option<&ProviderConfig>

Optional configuration metadata for this provider.
Source§

impl ImageGeneration for DiffusionProvider

Source§

fn generate_image<'life0, 'async_trait>( &'life0 self, request: ImageRequest, ) -> Pin<Box<dyn Future<Output = Result<ImageResult, BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate images from a text prompt.
Source§

fn upscale_image<'life0, 'async_trait>( &'life0 self, _request: UpscaleRequest, ) -> Pin<Box<dyn Future<Output = Result<ImageResult, BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Upscale an existing image.
Source§

fn edit_image<'life0, 'async_trait>( &'life0 self, _request: ImageEditRequest, ) -> Pin<Box<dyn Future<Output = Result<ImageResult, BlazenError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: Sync + 'async_trait,

Edit an existing image (img2img, inpaint, outpaint, etc.). Read more
Source§

impl LocalModel for DiffusionProvider

LocalModel bridge: gives ModelManager explicit load/unload control over the underlying diffusion-rs pipeline. The implementation forwards to the inherent methods on DiffusionProvider and wraps DiffusionError into BlazenError::Provider via [map_err].

Source§

fn load<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load the model into memory. Idempotent – if the model is already loaded, this is a no-op that returns Ok(()).
Source§

fn unload<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Drop the loaded model and free its memory. Idempotent – if the model is already unloaded, this is a no-op that returns Ok(()).
Source§

fn is_loaded<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Whether the model is currently loaded in memory.
Source§

fn device(&self) -> Device

Which device the model is configured to run on. Determines which memory pool the ModelManager charges this model against. Defaults to Device::Cpu for backwards compatibility with implementors that have not yet declared a target.
Source§

fn load_adapter<'life0, 'life1, 'async_trait>( &'life0 self, _adapter_dir: &'life1 Path, _options: AdapterOptions, ) -> Pin<Box<dyn Future<Output = Result<AdapterHandle, BlazenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mount a PEFT-format LoRA adapter onto the loaded base model. Read more
Source§

fn memory_bytes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<u64>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Approximate memory footprint in bytes (host RAM if Self::device returns Device::Cpu, GPU VRAM otherwise). Returns None for implementations that can’t measure.
Source§

fn unload_adapter<'life0, 'life1, 'async_trait>( &'life0 self, _handle: &'life1 AdapterHandle, ) -> Pin<Box<dyn Future<Output = Result<(), BlazenError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Remove a previously-mounted adapter. Default impl returns BlazenError::unsupported for the same reason as Self::load_adapter.
Source§

fn list_adapters<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<AdapterStatus>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

List currently-mounted adapters. The default returns an empty Vec because “no adapters mounted” is a truthful state for any backend — adapter capability is probed via Self::load_adapter.

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> ImageModel for T
where T: ImageGeneration,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more