nami.components.transformer#

Classes

TransformerBackbone(dim, *, depth, num_heads)

A stack of transformer blocks operating on sequences/sets.

TransformerBlock(dim, *, num_heads[, ...])

Transformer block for token sequences, with optional cross-attention.

class nami.components.transformer.TransformerBackbone(dim, *, depth, num_heads, mlp_ratio=4.0, dropout=0.0, activation='gelu', cross_attention=False)[source]#

Bases: Module

A stack of transformer blocks operating on sequences/sets.

Parameters:
forward(x, context=None)[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.

Return type:

Tensor

Parameters:
class nami.components.transformer.TransformerBlock(dim, *, num_heads, mlp_ratio=4.0, dropout=0.0, activation='gelu', cross_attention=False)[source]#

Bases: Module

Transformer block for token sequences, with optional cross-attention.

Parameters:
forward(x, context=None)[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.

Return type:

Tensor

Parameters: