zuko.lazy¶
Lazy distributions and transformations.
Classes¶
Creates a lazy normalizing flow. |
|
Creates a lazy composed transformation. |
|
Abstract lazy distribution. |
|
Abstract lazy transformation. |
|
Creates an unconditional lazy module from a constructor. |
|
Creates an unconditional lazy distribution from a constructor. |
|
Creates an unconditional lazy transformation from a constructor. |
Descriptions¶
- class zuko.lazy.Flow(transform, base)¶
Creates a lazy normalizing flow.
See also
- Parameters:
transform (Union[LazyTransform, Sequence[LazyTransform]]) – A lazy transformation or sequence of lazy transformations.
base (LazyDistribution) – A lazy distribution.
- class zuko.lazy.LazyComposedTransform(*transforms)¶
Creates a lazy composed transformation.
See also
- Parameters:
transforms (LazyTransform) – A sequence of lazy transformations \(f_i\).
- class zuko.lazy.LazyDistribution(*args, **kwargs)¶
Abstract lazy distribution.
A lazy distribution is a module that builds and returns a distribution \(p(X | c)\) within its forward pass, given a context \(c\).
- class zuko.lazy.LazyTransform(*args, **kwargs)¶
Abstract lazy transformation.
A lazy transformation is a module that builds and returns a transformation \(y = f(x | c)\) within its forward pass, given a context \(c\).
- abstract forward(c=None)¶
- property inv: LazyTransform¶
A lazy inverse transformation \(x = f^{-1}(y | c)\).
- class zuko.lazy.Unconditional(meta, *args, buffer=False, **kwargs)¶
Creates an unconditional lazy module from a constructor.
Typically, the constructor returns a distribution or transformation. The positional arguments of the constructor are registered as buffers or parameters.
Warning
Unconditionalis deprecated and will be removed in the future. UseUnconditionalDistributionorUnconditionalTransforminstead.- Parameters:
meta (Callable[..., Any]) – An arbitrary constructor function.
args (Tensor) – The positional tensor arguments passed to
meta.buffer (bool) – Whether tensors are registered as buffers or parameters.
kwargs – The keyword arguments passed to
meta.
- class zuko.lazy.UnconditionalDistribution(f, *args, buffer=False, **kwargs)¶
Creates an unconditional lazy distribution from a constructor.
The arguments of the constructor are registered as buffers or parameters.
- Parameters:
f (Callable[..., Distribution]) – A distribution constructor. If
fis a module, it is registered as a submodule.args (Any) – The positional arguments passed to
f.buffer (bool) – Whether tensor arguments are registered as buffers or parameters.
kwargs (Any) – The keyword arguments passed to
f.
Examples
>>> f = zuko.distributions.DiagNormal >>> mu, sigma = torch.zeros(3), torch.ones(3) >>> base = UnconditionalDistribution(f, mu, sigma, buffer=True) >>> base() DiagNormal(loc: torch.Size([3]), scale: torch.Size([3])) >>> base().sample() tensor([ 1.5410, -0.2934, -2.1788])
- class zuko.lazy.UnconditionalTransform(f, *args, buffer=False, **kwargs)¶
Creates an unconditional lazy transformation from a constructor.
The arguments of the constructor are registered as buffers or parameters.
- Parameters:
f (Callable[..., Transform]) – A transformation constructor. If
fis a module, it is registered as a submodule.args (Any) – The positional arguments passed to
f.buffer (bool) – Whether tensor arguments are registered as buffers or parameters.
kwargs (Any) – The keyword arguments passed to
f.
Examples
>>> f = zuko.transforms.ExpTransform >>> t = UnconditionalTransform(f) >>> t() ExpTransform() >>> x = torch.randn(3) >>> t()(x) tensor([4.6692, 0.7457, 0.1132])