dit_prior
dit_prior
¶
Denoising Score-Matching based Transformer Prior for variational models.
Implements a DiT-style transformer prior that learns p(z|s) through Denoising Score-Matching with either diffusion or flow matching, where z is the latent variable and s is the conditioning (observations).
DiTPrior
¶
DiTPrior(latent_dimension, embedding_dimension, number_of_heads, number_of_layers, feedforward_dimension, device, observation_horizon=1, algorithm_type=value, sigma=0.0, ode_solver=value, timestep_sampler=BETA.value, logit_mean=0.0, logit_std=1.0, beta_alpha=1.5, beta_beta=1.0, max_timestep=0.999, num_train_timesteps=100, num_inference_steps=10, beta_start=0.0001, beta_end=0.02, beta_schedule=value, scheduler_type=value, prediction_type=value, clip_sample=False, variance_type=None, dropout=0.1, normalization_type=value, attention_type=value, number_of_key_value_heads=None, activation=value, use_gating=True, exclude_keys=None, prior_target_key=value, latent_standardization_enabled=True, latent_standardization_eps=1e-06, latent_standardization_max_batches=None, require_fitted_latent_standardization=False)
Bases: PriorLatentEncoder
DiT prior supporting diffusion and flow matching.
Uses a DiT transformer network where the noisy latent z is treated as a CLS token appended to observation tokens. The transformer attends bidirectionally across all tokens, is gated by the timestep embedding (Adaptive LayerNorm Zero), and the final CLS representation is projected to predict noise (diffusion) or velocity (flow matching).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent_dimension
|
int
|
Dimension of latent variable z. |
required |
embedding_dimension
|
int
|
Hidden dimension of the transformer. |
required |
number_of_heads
|
int
|
Number of attention heads. |
required |
number_of_layers
|
int
|
Number of DiT decoder layers. |
required |
feedforward_dimension
|
int
|
Dimension of the feedforward network. |
required |
device
|
str
|
Device to place prior on. |
required |
observation_horizon
|
int
|
Observation history size. |
1
|
algorithm_type
|
str
|
Algorithm type ("diffusion" or "flow_matching"). |
value
|
sigma
|
float
|
Noise level for flow matching (0 = deterministic OT). |
0.0
|
ode_solver
|
str
|
ODE solver for flow matching ("euler", "heun", or "rk4"). |
value
|
num_train_timesteps
|
int
|
Number of diffusion timesteps during training. |
100
|
num_inference_steps
|
int
|
Number of denoising/integration steps. |
10
|
beta_start
|
float
|
Starting beta for noise schedule (diffusion). |
0.0001
|
beta_end
|
float
|
Ending beta for noise schedule (diffusion). |
0.02
|
beta_schedule
|
str
|
Type of noise schedule (diffusion). |
value
|
scheduler_type
|
str
|
Diffusion scheduler type. |
value
|
prediction_type
|
str
|
What diffusion model predicts (epsilon, sample, velocity). |
value
|
clip_sample
|
bool
|
Whether to clip samples during diffusion. |
False
|
variance_type
|
str | None
|
Variance type for DDPM scheduler. |
None
|
dropout
|
float
|
Dropout rate. |
0.1
|
normalization_type
|
str
|
Type of adaptive normalization layer |
value
|
activation
|
str
|
Activation function name. |
value
|
use_gating
|
bool
|
Whether to use AdaLN-Zero gating in DiT layers. |
True
|
exclude_keys
|
list[str] | None
|
Keys to exclude from observations. |
None
|
prior_target_key
|
str
|
Posterior output key used as denoising target. |
value
|
latent_standardization_enabled
|
bool
|
Whether to standardize DiT target latents. |
True
|
latent_standardization_eps
|
float
|
Numerical epsilon used in latent standardization. |
1e-06
|
latent_standardization_max_batches
|
int | None
|
Maximum train batches to scan when
fitting latent standardization stats. |
None
|
require_fitted_latent_standardization
|
bool
|
Whether missing latent stats should raise. |
False
|
Source code in src/versatil/models/decoding/latent/prior/dit_prior.py
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
get_auxiliary_output_keys
¶
DiT prior outputs denoising predictions and targets.
Source code in src/versatil/models/decoding/latent/prior/dit_prior.py
get_callbacks
¶
Provide DiT prior training callbacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_config
|
ExperimentConfig
|
Experiment-level callback configuration. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Prior target standardization callback when enabled, otherwise no callbacks. |
Source code in src/versatil/models/decoding/latent/prior/dit_prior.py
build_training_target
¶
Select and detach the configured posterior target for DiT training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posterior_output
|
dict[str, Tensor]
|
Posterior encoder output dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Detached latent target selected by |
Source code in src/versatil/models/decoding/latent/prior/dit_prior.py
forward
¶
Compute denoising predictions for training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_latents
|
Tensor | None
|
Clean latent samples from posterior (B, latent_dim). |
required |
observations
|
dict[str, Tensor]
|
Dictionary of conditioning features. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dictionary with LatentKey.PRIOR_PREDICTION.value and LatentKey.PRIOR_TARGET.value. |
Source code in src/versatil/models/decoding/latent/prior/dit_prior.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
sample_prior
¶
Sample latent variable from learned prior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of samples to generate. |
required |
observations
|
dict[str, Tensor] | None
|
Dictionary of conditioning features. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Sampled latent embeddings (batch_size, latent_dim). |