mode_act
mode_act
¶
Mixture of Densities Action Transformer (MODE-ACT) for multi-modal action prediction.
This module implements a Mixture Density Network style transformer decoder that predicts multiple mixture components for each action, enabling multi-modal action distributions.
MixtureOfDensitiesActionTransformer
¶
MixtureOfDensitiesActionTransformer(input_keys, action_space, action_heads, observation_space, observation_horizon, prediction_horizon, device, embedding_dimension=256, number_of_heads=8, number_of_key_value_heads=None, feedforward_dimension=None, number_of_layers=6, activation=value, normalization_type=value, attention_type=value, dropout_rate=0.1, attention_dropout=0.0, positional_encoding_type=value, num_mixture_components=8, gating_hidden_dims=None, gating_activation=value, gating_dropout=0.1, gating_normalization=True, temperature=1.0, learnable_temperature=False, gating_feature_key=None, gmm_init_strategy=value, inference_sampling_mode=value)
Bases: BaseParallelTransformerDecoder
Mixture Density Network Transformer for multi-modal action prediction.
Note
This architecture combines a transformer decoder with K expert action heads to predict mixture density parameters. For the mixture weight computation, either a mode learnable query token or an external feature token are used.
Initialize MODE-ACT decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_keys
|
list[str]
|
Feature keys from encoding pipeline. |
required |
action_space
|
ActionSpace
|
Action space configuration. |
required |
action_heads
|
dict[str, ActionHead]
|
Base action heads to clone K times. |
required |
observation_space
|
ObservationSpace
|
Observation space configuration. |
required |
observation_horizon
|
int
|
Number of observation timesteps. |
required |
prediction_horizon
|
int
|
Number of action timesteps to predict. |
required |
device
|
str
|
Device to place model on. |
required |
embedding_dimension
|
int
|
Transformer embedding dimension. |
256
|
number_of_heads
|
int
|
Number of attention heads. |
8
|
number_of_key_value_heads
|
int | None
|
Number of key-value heads for GQA. |
None
|
feedforward_dimension
|
int | None
|
FFN hidden dimension. |
None
|
number_of_layers
|
int
|
Number of decoder layers. |
6
|
activation
|
str
|
Activation function. |
value
|
normalization_type
|
str
|
Normalization type. |
value
|
attention_type
|
str
|
Attention type. |
value
|
dropout_rate
|
float
|
Dropout rate. |
0.1
|
attention_dropout
|
float
|
Attention dropout rate. |
0.0
|
positional_encoding_type
|
str | None
|
Positional encoding type. |
value
|
num_mixture_components
|
int
|
Number of mixture components (K). |
8
|
gating_hidden_dims
|
list[int] | None
|
Hidden dimensions for gating MLP. |
None
|
gating_activation
|
str
|
Activation for gating MLP. |
value
|
gating_dropout
|
float
|
Dropout rate in gating MLP. |
0.1
|
gating_normalization
|
bool
|
Whether to normalize gating input. |
True
|
temperature
|
float
|
Temperature for softmax scaling. |
1.0
|
learnable_temperature
|
bool
|
Whether temperature is learnable. |
False
|
gating_feature_key
|
str | None
|
If set, use this feature for gating instead of mode embedding. |
None
|
gmm_init_strategy
|
str
|
Strategy for initializing GMM component means. |
value
|
inference_sampling_mode
|
str
|
How to sample from the mixture at inference. DETERMINISTIC: argmax component, return mean. STOCHASTIC_MEAN: multinomial component, return mean (no noise). STOCHASTIC_SAMPLE: multinomial component, add Gaussian noise. |
value
|
Source code in src/versatil/models/decoding/decoders/factory/mode_act.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
get_auxiliary_output_keys
¶
MoDEACT produces routing weights for mixture density prediction.
Source code in src/versatil/models/decoding/decoders/factory/mode_act.py
set_normalizer
¶
Set normalizer and initialize GMM components from output statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalizer
|
LinearNormalizer
|
Normalizer with fitted statistics. |
required |
Source code in src/versatil/models/decoding/decoders/factory/mode_act.py
forward
¶
Forward pass dispatching based on training vs inference mode.
During training (actions provided): returns raw mixture outputs for loss computation. During inference (actions=None): returns sampled actions from mixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
dict[str, Tensor]
|
Dictionary of encoded features. |
required |
actions
|
dict[str, Tensor] | None
|
Ground truth actions (used only to distinguish training from inference). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
During training: Dict with mixture outputs (mean, logvar, routing_weights). |
dict[str, Tensor]
|
During inference: Dict with sampled actions (B, T, D) for each action key. |