Skip to main content

VaeDecoderConfig

Struct VaeDecoderConfig 

Source
pub struct VaeDecoderConfig {
    pub out_channels: usize,
    pub latent_channels: usize,
    pub block_out_channels: Vec<usize>,
    pub layers_per_block: usize,
    pub norm_num_groups: usize,
    pub sample_size: usize,
    pub scaling_factor: f64,
}
Expand description

Frozen config for the Stable-Diffusion VAE decoder.

Mirrors the decoder-relevant subset of AutoencoderKL.config for runwayml/stable-diffusion-v1-5. The defaults match SD 1.5 exactly.

Fields§

§out_channels: usize

Number of input channels of the image the encoder consumes (and therefore of the image the decoder produces). For SD 1.5: 3.

§latent_channels: usize

Number of latent channels. For SD 1.5: 4.

§block_out_channels: Vec<usize>

Per-block-level output channel counts (in encoder order: from the highest-resolution block out). For SD 1.5: [128, 256, 512, 512]. The decoder walks these in reverse, so the first block after conv_in has block_out_channels[-1] channels (= 512).

§layers_per_block: usize

Number of resnet layers in each Encoder / Decoder up- or down-block. The decoder’s UpDecoderBlock2D uses layers_per_block + 1 resnets (the diffusers convention). For SD 1.5: 2 (so each up-block has 3 resnets).

§norm_num_groups: usize

Number of GroupNorm groups (decoder-internal norm1 / norm2 / conv_norm_out). For SD 1.5: 32.

§sample_size: usize

Spatial size the encoder accepts (and the decoder produces). For SD 1.5: 512.

§scaling_factor: f64

VAE latent scaling factor. The decoder pre-divides the latent by this value (matching AutoencoderKL.decode). For SD 1.5: 0.18215.

Implementations§

Source§

impl VaeDecoderConfig

Source

pub fn sd_v1_5() -> Self

SD 1.5 VAE decoder config (alias for Default::default()).

Source

pub fn validate(&self) -> FerrotorchResult<()>

Validate field bounds (positive sizes, channels divisible by norm_num_groups, at least one resolution).

§Errors

Returns FerrotorchError::InvalidArgument for any out-of-bounds or arithmetic-incompatible field.

Source

pub fn resnets_per_up_block(&self) -> usize

Number of resnets in each UpDecoderBlock2D (the diffusers convention is layers_per_block + 1).

Source

pub fn num_up_blocks(&self) -> usize

Number of up-blocks (== number of down-blocks the encoder used, == block_out_channels.len()).

Source

pub fn from_json_str(s: &str) -> FerrotorchResult<Self>

Parse a vae/config.json document into a VaeDecoderConfig.

Recognised keys (all optional — anything missing falls back to the SD-1.5 defaults):

  • out_channels, latent_channels, block_out_channels, layers_per_block, norm_num_groups, sample_size, scaling_factor.
§Errors

Returns FerrotorchError::InvalidArgument on malformed JSON or a wrong-type field (e.g. block_out_channels not an array of integers).

Source

pub fn from_file(path: &Path) -> FerrotorchResult<Self>

Parse a vae/config.json file from disk.

§Errors

Returns FerrotorchError::InvalidArgument for I/O or parse failures (file missing, malformed JSON, wrong-type field).

Trait Implementations§

Source§

impl Clone for VaeDecoderConfig

Source§

fn clone(&self) -> VaeDecoderConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VaeDecoderConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VaeDecoderConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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