pub struct DiagonalGaussianDistribution<T: Float> {
pub mean: Tensor<T>,
pub logvar: Tensor<T>,
}Expand description
Diagonal Gaussian over latent space — the same parameterization
diffusers.models.autoencoders.vae.DiagonalGaussianDistribution
uses. Holds mean and logvar tensors (both [B, L, h, w]) split
from the encoder’s concatenated parameters output.
logvar is clamped to [-30, 20] on construction, matching the
diffusers reference exactly.
Fields§
§mean: Tensor<T>Mean of the diagonal Gaussian, [B, L, h, w].
logvar: Tensor<T>Log-variance of the diagonal Gaussian (clamped), [B, L, h, w].
Implementations§
Source§impl<T: Float> DiagonalGaussianDistribution<T>
impl<T: Float> DiagonalGaussianDistribution<T>
Sourcepub fn from_parameters(
params: &Tensor<T>,
latent_channels: usize,
) -> FerrotorchResult<Self>
pub fn from_parameters( params: &Tensor<T>, latent_channels: usize, ) -> FerrotorchResult<Self>
Split the encoder’s [B, 2*L, h, w] parameters tensor into
mean / logvar halves along the channel axis.
§Errors
Returns FerrotorchError::ShapeMismatch when the channel
dimension is not 2 * latent_channels. Propagates downstream
errors from the chunk / clamp ops.
Sourcepub fn mode(&self) -> &Tensor<T>
pub fn mode(&self) -> &Tensor<T>
Return the distribution mode — the deterministic latent if the
caller does not want to sample. Matches
DiagonalGaussianDistribution.mode() in diffusers.
Sourcepub fn sample_with_seed(&self, seed: u64) -> FerrotorchResult<Tensor<T>>
pub fn sample_with_seed(&self, seed: u64) -> FerrotorchResult<Tensor<T>>
Sample from the distribution with a deterministic seed.
Computes mean + std * eps where std = exp(0.5 * logvar)
and eps is a fresh N(0, 1) tensor produced by Box-Muller
over a seeded xorshift64 PRNG (mirroring the CPU branch of
ferrotorch_core::randn but using seed as the state).
This is fully deterministic for a given seed on a given host
— but the bitwise output will NOT match a CUDA PyTorch reference
run, because PyTorch’s CUDA RNG uses Philox, not xorshift +
Box-Muller. Tests should compare statistical properties (mean,
std) or use .mode() for bit-exact reference matches.
§Errors
Returns the underlying FerrotorchError for shape or
arithmetic failures.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DiagonalGaussianDistribution<T>
impl<T> !RefUnwindSafe for DiagonalGaussianDistribution<T>
impl<T> Send for DiagonalGaussianDistribution<T>
impl<T> Sync for DiagonalGaussianDistribution<T>
impl<T> Unpin for DiagonalGaussianDistribution<T>
impl<T> UnsafeUnpin for DiagonalGaussianDistribution<T>
impl<T> !UnwindSafe for DiagonalGaussianDistribution<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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