blocks
blocks
¶
Individual building blocks for composing action heads.
ActionHeadBlock
¶
Bases: Module, ABC
Abstract base class for action head building blocks.
Action head blocks are modular components that can be composed together to create complex action prediction heads. Each block processes embeddings and outputs tensors with the same shape.
forward
abstractmethod
¶
Process embeddings through this block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_embedding
|
Tensor
|
Input tensor (B, prediction horizon, embedding_dimension) or (B, embedding_dimension) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Processed tensor with same shape as input |
Source code in src/versatil/models/decoding/action_heads/blocks.py
LayerNormBlock
¶
Bases: ActionHeadBlock
Layer-normalization block for action heads.
Initialize the layer-normalization block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dimension
|
int
|
Input and output feature dimension. |
required |
Source code in src/versatil/models/decoding/action_heads/blocks.py
MLPBlock
¶
MLPBlock(input_dimension, hidden_dimensions=None, output_dim=None, activation=value, dropout=0.0, normalization=True)
Bases: ActionHeadBlock
Multi-layer perceptron block for action heads.
This block applies layer normalization followed by an MLP with configurable hidden layers, activation function, and dropout.
Initialize MLP block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dimension
|
int
|
Input dimension |
required |
hidden_dimensions
|
list[int] | None
|
List of hidden dimensions |
None
|
output_dim
|
int | None
|
Output dimension (None to keep same as last hidden) |
None
|
activation
|
str
|
Activation function name |
value
|
dropout
|
float
|
Dropout rate |
0.0
|
normalization
|
bool
|
Whether to apply layer normalization before MLP |
True
|
Source code in src/versatil/models/decoding/action_heads/blocks.py
forward
¶
Forward pass through normalized MLP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_embedding
|
Tensor
|
Input tensor (B, prediction horizon, embedding_dimension) or (B, embedding_dimension) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Output tensor with same shape |
Source code in src/versatil/models/decoding/action_heads/blocks.py
AttentionBlock
¶
Bases: ActionHeadBlock
Self-attention block for action heads with residual connection.
This block applies layer normalization, self-attention, and adds a residual connection. Useful for allowing action tokens to attend to each other across the prediction horizon.
Initialize attention block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dimension
|
int
|
Embedding dimension |
required |
number_of_heads
|
int
|
Number of attention heads |
8
|
dropout
|
float
|
Dropout rate |
0.0
|
normalization
|
bool
|
Whether to apply layer normalization |
True
|
Source code in src/versatil/models/decoding/action_heads/blocks.py
forward
¶
Forward pass with residual connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_embedding
|
Tensor
|
Input (B, prediction horizon, embedding_dimension) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Output with residual (B, prediction horizon, embedding_dimension) |
Source code in src/versatil/models/decoding/action_heads/blocks.py
ResidualBlock
¶
Bases: ActionHeadBlock
Residual block wrapper for any ActionHeadBlock.
Wraps another block and adds a residual connection around it.
Initialize residual block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
ActionHeadBlock
|
Block to wrap with residual connection |
required |
dropout
|
float
|
Dropout rate after block |
0.0
|
Source code in src/versatil/models/decoding/action_heads/blocks.py
forward
¶
Forward with residual connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_embedding
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
action_embedding + dropout(block(action_embedding)) |
Source code in src/versatil/models/decoding/action_heads/blocks.py
ConditionalActionHeadBlock
¶
Bases: Module, ABC
Abstract base class for action-head blocks with a conditioning input.
forward
abstractmethod
¶
Process action embeddings with a conditioning vector.
AdaNormBlock
¶
Bases: ConditionalActionHeadBlock
Adaptive layer-normalization block for conditional action heads.
Initialize adaptive normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dimension
|
int
|
Action embedding feature dimension. |
required |
conditioning_dimension
|
int
|
Conditioning vector dimension. |
required |
activation
|
str
|
Activation used inside the modulation projection. |
value
|
Source code in src/versatil/models/decoding/action_heads/blocks.py
forward
¶
Apply adaptive normalization.