autocast.encoders.base#

class GenericEncoder(*args, **kwargs)[source]#

Bases: Module, ABC, Generic[BatchT, BatchTEncoded]

Base encoder interface.

Parameters:
preprocess(batch)[source]#

Optionally transform a batch before encoding.

Subclasses can override to implement pre-encoding steps that still return a fully-populated Batch instance. Default is identity.

Parameters:

batch (BatchT)

Return type:

BatchT

abstract encode(batch)[source]#

Encode the input tensor into the latent space.

Parameters:

batch (BatchT) – Input batch to be encoded.

Returns:

Encoded tensor in the latent space with shape (B, *, C_latent) or a tuple of

(encoded tensor, optional conditioning tensor of shape (B, D)).

Return type:

Float[Tensor, ‘batch *optional_dims channel’] | tuple[Float[Tensor, ‘batch *optional_dims channel’], Tensor | None]

abstract encode_batch(batch, encoded_info=None)[source]#

Encode a full BatchT into a BatchTEncoded.

Parameters:
  • batch (BatchT) – Input batch to be encoded.

  • encoded_info (dict | None) – Optional dictionary of additional encoded information to include.

Returns:

Encoded batch containing encoded inputs and original output fields.

Return type:

BatchTEncoded

forward(batch)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

batch (BatchT)

Return type:

Float[Tensor, ‘batch *optional_dims channel’] | tuple[Float[Tensor, ‘batch *optional_dims channel’], Tensor | None]

class Encoder(*args, **kwargs)[source]#

Bases: _Encoder

Base encoder.

Parameters:
encoder_model: Module#
channel_axis: int#
latent_channels: int#
outputs_time_channel_concat: bool = False#
abstract encode(batch)[source]#

Encode the input tensor into the latent space.

Parameters:

batch (Batch) – Input batch to be encoded.

Returns:

Encoded tensor in the latent space with shape (B, *, C_latent).

Return type:

Float[Tensor, ‘batch *optional_dims channel’]

class EncoderWithCond(*args, **kwargs)[source]#

Bases: Encoder

Encoder that returns encoded tensor and optional conditioning.

Parameters:
encode_cond(batch)[source]#

Encode global conditioning tensor from the batch.

Default implementation flattens constant scalars and boundary conditions.

Parameters:

batch (Batch)

Return type:

Tensor | None

encode_with_cond(batch)[source]#

Encode the input tensor into the latent space.

Parameters:

batch (Batch) – Input batch to be encoded.

Returns:

Encoded tensor in the latent space with shape (B, *, C_latent) with optional

conditioning tensor of shape (B, D).

Return type:

tuple[Float[Tensor, ‘batch *optional_dims channel’], Tensor | None]

encode_batch(batch, encoded_info=None)[source]#

Encode a full Batch into an EncodedBatch with conditioning.

Overrides base implementation to ensure encode_with_cond is used to capture any provided global conditioning variables.

Parameters:
Return type:

EncodedBatch

forward(batch)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

batch (Batch)

Return type:

Float[Tensor, ‘batch *optional_dims channel’] | tuple[Float[Tensor, ‘batch *optional_dims channel’], Tensor | None]