Vector Fields
This module contains functionality related to vector fields.
VectorField
A wrapper around a function (x, t) -> f(x, t) which provides some extra data, namely the type of vector field the function f represents.
This class encapsulates a vector field function and its type, allowing for consistent handling of different vector field representations in diffusion models.
Attributes:
Name | Type | Description |
---|---|---|
f |
Callable
|
A function that takes tensors x of shape (N, D) and t of shape (N,) and returns a tensor of shape (N, D). |
vector_field_type |
VectorFieldType
|
The type of vector field the function represents. |
Source code in src/diffusionlab/vector_fields.py
16 17 18 19 20 21 22 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 |
|
f = f
instance-attribute
vector_field_type = vector_field_type
instance-attribute
__call__(x, t)
Call the wrapped vector field function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape (N, *D) where N is the batch size and D represents the data dimensions. |
required |
t
|
Tensor
|
Time parameter tensor of shape (N,). |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Output of the vector field function, of shape (N, *D). |
Source code in src/diffusionlab/vector_fields.py
47 48 49 50 51 52 53 54 55 56 57 58 |
|
__init__(f, vector_field_type)
Initialize a vector field wrapper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
Callable[[Tensor, Tensor], Tensor]
|
A function that takes tensors x of shape (N, D) and t of shape (N,) and returns a tensor of shape (N, D). |
required |
vector_field_type
|
VectorFieldType
|
The type of vector field the function represents (SCORE, X0, EPS, or V). |
required |
Source code in src/diffusionlab/vector_fields.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
VectorFieldType
Bases: Enum
Source code in src/diffusionlab/vector_fields.py
9 10 11 12 13 |
|
EPS = enum.auto()
class-attribute
instance-attribute
SCORE = enum.auto()
class-attribute
instance-attribute
V = enum.auto()
class-attribute
instance-attribute
X0 = enum.auto()
class-attribute
instance-attribute
convert_vector_field_type(x, fx, alpha, sigma, alpha_prime, sigma_prime, in_type, out_type)
Converts the output of a vector field from one type to another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
A tensor of shape (N, *D), where N is the batch size and D is the shape of the data (e.g., (C, H, W) for images, (D,) for vectors, or (N, D) for token sequences). |
required |
fx
|
Tensor
|
The output of the vector field f, of shape (N, *D). |
required |
alpha
|
Tensor
|
A tensor of shape (N,) representing the scale parameter. |
required |
sigma
|
Tensor
|
A tensor of shape (N,) representing the noise level parameter. |
required |
alpha_prime
|
Tensor
|
A tensor of shape (N,) representing the scale derivative parameter. |
required |
sigma_prime
|
Tensor
|
A tensor of shape (N,) representing the noise level derivative parameter. |
required |
in_type
|
VectorFieldType
|
The type of the input vector field (e.g. Score, X0, Eps, V). |
required |
out_type
|
VectorFieldType
|
The type of the output vector field. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The converted output of the vector field, of shape (N, *D). |
Source code in src/diffusionlab/vector_fields.py
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 |
|