diffusion
diffusion
¶
Diffusion algorithm for action generation via iterative denoising.
This module implements diffusion-based action generation using shared diffusion process components from diffusion_process.py. The algorithm trains a network to denoise actions at various noise levels and uses iterative denoising for action prediction during inference.
See diffusion_process.py for detailed documentation of these components.
Diffusion
¶
Diffusion(scheduler_type=value, num_train_timesteps=100, num_inference_steps=10, beta_start=0.0001, beta_end=0.02, beta_schedule=value, prediction_type=value, scheduler_variance_type=value, clip_sample=True, set_alpha_to_one=True, steps_offset=0)
Bases: DecodingAlgorithm
Diffusion algorithm for action prediction.
Trains a model to denoise actions by predicting noise (or clean actions) at various noise levels. During inference, starts from random noise and iteratively denoises to generate actions.
The diffusion process follows: - Training: x_t = sqrt(alpha_t) * x_0 + sqrt(1 - alpha_t) * epsilon - Inference: Iteratively denoise from x_T to x_0 using learned denoising model
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheduler_type
|
str
|
Type of diffusion scheduler ("ddpm" or "ddim") |
value
|
num_train_timesteps
|
int
|
Number of diffusion steps during training |
100
|
num_inference_steps
|
int
|
Number of denoising steps during inference |
10
|
beta_start
|
float
|
Starting value of noise schedule |
0.0001
|
beta_end
|
float
|
Ending value of noise schedule |
0.02
|
beta_schedule
|
str
|
Noise schedule type ("linear", "squaredcos_cap_v2", etc.) |
value
|
prediction_type
|
str
|
What the network predicts ("epsilon" for noise, "sample" for clean actions) |
value
|
scheduler_variance_type
|
str
|
Variance type for DDPM scheduler |
value
|
clip_sample
|
bool
|
Whether to clip samples to [-1, 1] during inference |
True
|
set_alpha_to_one
|
bool
|
Whether to set final alpha to 1 |
True
|
steps_offset
|
int
|
Offset for timestep calculation |
0
|
Initialize Diffusion algorithm.
Source code in src/versatil/models/decoding/algorithm/diffusion.py
predicts_in_action_space
property
¶
Only 'sample' prediction type outputs actions directly; 'epsilon' and 'velocity' do not.
injected_feature_keys
¶
forward
¶
Forward pass during training.
Adds noise to ground-truth actions and trains the network to denoise them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
ActionDecoder
|
The action decoder network module (should support timestep conditioning) |
required |
features
|
dict[str, Tensor]
|
Dictionary of encoded features from the encoding pipeline. |
required |
actions
|
dict[str, Tensor] | None
|
Dictionary of ground truth actions. Required for diffusion training. Expected keys depend on action space (e.g., 'position_action', 'gripper_action') |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Decoder output dictionary containing: - Predicted noise or actions (depending on prediction_type) - 'target': The training target (noise or clean actions) - 'noise': The noise added to the clean actions - 'timestep': The random timesteps sampled for each action in the batch - 'is_pad_action': Padding mask if present |
Raises:
| Type | Description |
|---|---|
ValueError
|
If actions are not provided (required for diffusion training) |
Source code in src/versatil/models/decoding/algorithm/diffusion.py
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
get_targets
¶
Return the diffusion target (noise, sample, or velocity).
Source code in src/versatil/models/decoding/algorithm/diffusion.py
predict
¶
Inference/prediction pass.
Generates actions by starting from random noise and iteratively denoising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
ActionDecoder
|
The action decoder network module |
required |
features
|
dict[str, Tensor]
|
Dict of encoded features from encoding pipeline |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Decoder output dictionary containing denoised action predictions. |