torchebm.core.base_interpolant ¶
Base class for interpolant schedules.
BaseInterpolant ¶
Bases: ABC
Abstract base class for stochastic interpolants.
An interpolant defines a conditional probability path between a source distribution (typically Gaussian noise) and a target distribution (data).
The interpolation is parameterized as:
where \(x_0 \sim \mathcal{N}(0, I)\) and \(x_1 \sim p_{\text{data}}\).
Subclasses must implement compute_alpha_t and compute_sigma_t.
Source code in torchebm/core/base_interpolant.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 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 | |
compute_alpha_t(t) abstractmethod ¶
Compute the data coefficient \(\alpha(t)\) and its time derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t | Tensor | Time tensor of shape (batch_size, ...). | required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor] | Tuple of (\(\alpha(t)\), \(\dot{\alpha}(t)\)). |
Source code in torchebm/core/base_interpolant.py
compute_d_alpha_alpha_ratio_t(t) ¶
Compute the ratio \(\dot{\alpha}(t) / \alpha(t)\) for numerical stability.
This method can be overridden for better numerical precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t | Tensor | Time tensor. | required |
Returns:
| Type | Description |
|---|---|
Tensor | The ratio tensor. |
Source code in torchebm/core/base_interpolant.py
compute_diffusion(x, t, form='SBDM', norm=1.0) ¶
Compute diffusion coefficient for SDE sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | Current state of shape (batch_size, ...). | required |
t | Tensor | Time values of shape (batch_size,). | required |
form | str | Diffusion form. Choices: - 'constant': Constant diffusion - 'SBDM': Score-based diffusion matching - 'sigma': Proportional to noise schedule - 'linear': Linear decay - 'decreasing': Faster decay towards t=1 - 'increasing-decreasing': Peak at midpoint | 'SBDM' |
norm | float | Scaling factor for diffusion. | 1.0 |
Returns:
| Type | Description |
|---|---|
Tensor | Diffusion coefficient tensor. |
Source code in torchebm/core/base_interpolant.py
compute_drift(x, t) ¶
Compute drift coefficients for score-based parameterization.
For the probability flow ODE in score parameterization: dx = [-drift_mean + drift_var * score] dt
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | Current state of shape (batch_size, ...). | required |
t | Tensor | Time values of shape (batch_size,). | required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor] | Tuple of (drift_mean, drift_var) for score parameterization. |
Source code in torchebm/core/base_interpolant.py
compute_sigma_t(t) abstractmethod ¶
Compute the noise coefficient \(\sigma(t)\) and its time derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t | Tensor | Time tensor of shape (batch_size, ...). | required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor] | Tuple of (\(\sigma(t)\), \(\dot{\sigma}(t)\)). |
Source code in torchebm/core/base_interpolant.py
interpolate(x0, x1, t) ¶
Compute the interpolated sample \(x_t\) and conditional velocity \(u_t\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0 | Tensor | Noise samples of shape (batch_size, ...). | required |
x1 | Tensor | Data samples of shape (batch_size, ...). | required |
t | Tensor | Time values of shape (batch_size,). | required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor] | Tuple of (x_t, u_t) where: - x_t = α(t) x₁ + σ(t) x₀ - u_t = α̇(t) x₁ + σ̇(t) x₀ |
Source code in torchebm/core/base_interpolant.py
score_to_velocity(score, x, t) ¶
Convert score prediction to velocity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score | Tensor | Predicted score of shape (batch_size, ...). | required |
x | Tensor | Current state of shape (batch_size, ...). | required |
t | Tensor | Time values of shape (batch_size,). | required |
Returns:
| Type | Description |
|---|---|
Tensor | Velocity tensor of shape (batch_size, ...). |
Source code in torchebm/core/base_interpolant.py
velocity_to_noise(velocity, x, t) ¶
Convert velocity prediction to noise prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity | Tensor | Predicted velocity of shape (batch_size, ...). | required |
x | Tensor | Current state of shape (batch_size, ...). | required |
t | Tensor | Time values of shape (batch_size,). | required |
Returns:
| Type | Description |
|---|---|
Tensor | Noise tensor of shape (batch_size, ...). |
Source code in torchebm/core/base_interpolant.py
velocity_to_score(velocity, x, t) ¶
Convert velocity prediction to score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity | Tensor | Predicted velocity of shape (batch_size, ...). | required |
x | Tensor | Current state of shape (batch_size, ...). | required |
t | Tensor | Time values of shape (batch_size,). | required |
Returns:
| Type | Description |
|---|---|
Tensor | Score tensor of shape (batch_size, ...). |
Source code in torchebm/core/base_interpolant.py
expand_t_like_x(t, x) ¶
Expand time tensor to match spatial dimensions of x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t | Tensor | Time tensor of shape (batch_size,). | required |
x | Tensor | Reference tensor of shape (batch_size, ...). | required |
Returns:
| Type | Description |
|---|---|
Tensor | Time tensor expanded to shape (batch_size, 1, 1, ...). |