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.
Trait Implementations§
Source§impl ComputeProvider for DiffusionProvider
impl ComputeProvider for DiffusionProvider
Source§fn provider_id(&self) -> &str
fn provider_id(&self) -> &str
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
Source§fn provider_config(&self) -> Option<&ProviderConfig>
fn provider_config(&self) -> Option<&ProviderConfig>
Source§impl ImageGeneration for DiffusionProvider
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,
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,
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,
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,
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,
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,
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].
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,
fn load<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), BlazenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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,
fn unload<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), BlazenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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,
fn is_loaded<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn device(&self) -> Device
fn device(&self) -> Device
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,
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,
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,
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,
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,
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,
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,
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,
Vec because “no adapters mounted” is a truthful state for any
backend — adapter capability is probed via Self::load_adapter.