Skip to content
class

DriftingModel

extendsPretrainedModel
DriftingModel(config: DriftingConfig)

The one-step generator fθ(ϵ,c,α)f_\theta(\epsilon, c, \alpha).

Parameters

The variant to build.

Attributes

Class table, (num_classes, cond_dim).
noise_coords style codebooks, each (noise_classes, cond_dim).
cfg_embedder_CFGEmbedder
Embedding of the guidance scale α\alpha.
patch_embedlucid.nn.Linear
Patch projection; its input is a (p, p, C)-ordered patch.
(1, num_patches, hidden_size) — trainable, initialised to the 2-D sine-cosine table.
(1, n_cls_tokens, hidden_size) learnable in-context offsets.
The transformer blocks.
final_FinalLayer
Modulated norm and projection back to patches.

Notes

Reference: Deng, Li, Li, Du, and He, "Generative Modeling via Drifting", arXiv:2602.04770, 2026, Appendix A.2 and Table 8.

The conditioning vector is the release's c_cfg_noise_to_cond:

c=Ecls[y]+∑i=132Ei[si]+0.02 RMSNorm(MLP(sin(α))),c = E_\mathrm{cls}[y] + \sum_{i=1}^{32} E_i[s_i] + 0.02\,\mathrm{RMSNorm}\bigl(\mathrm{MLP}(\mathrm{sin}(\alpha))\bigr),

and it drives both adaLN and the 16 in-context tokens, which are Linear(c) + cls_embed prepended before the first block. RoPE runs over the flattened sequence, in-context tokens included, as in the release.

Examples

>>> import lucid
>>> from lucid.models.generative.drifting import DriftingConfig, DriftingModel
>>> config = DriftingConfig(sample_size=8, hidden_size=32, cond_dim=32, depth=1,
...                         num_heads=4, num_classes=10, noise_classes=4,
...                         noise_coords=2, n_cls_tokens=2)
>>> model = DriftingModel(config).eval()
>>> model(lucid.randn(2, 4, 8, 8), lucid.tensor([0, 1])).sample.shape
(2, 4, 8, 8)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: DriftingConfig)

Initialise the generator. See the class docstring for parameters.

Instance methods

3
fn

conditioning

→Tensor
conditioning(labels: Tensor, guidance_scale: Tensor, style_indices: Tensor, dtype: lucid.dtype)

Class, styles and guidance scale summed into (B, cond_dim).

Parameters

labelsTensor
(B,) class indices.
guidance_scaleTensor
(B,) guidance scales α\alpha.
style_indicesTensor
(B, noise_coords) style indices, unread when noise_classes=0.
dtypelucid.dtype
The dtype of the result.

Returns

Tensor

The (B, cond_dim) conditioning vector.

Raises

ValueError
If style_indices does not hold one column per style codebook.
fn

draw_style_indices

→Tensor
draw_style_indices(batch: int, device: str)

The discrete half of the noise: (batch, noise_coords) codebook indices.

Drawn uniformly, as the release does (max(1, ·) keeps the shape valid when styles are disabled; the indices are then unused).

Parameters

batchint
Number of samples to draw indices for.
devicestr
Device the indices are created on.

Returns

Tensor

int64 indices of shape (batch, max(1, noise_coords)), each in [0, max(1, noise_classes)).

forward(x: Tensor, labels: Tensor, guidance_scale: float | Tensor = 1.0, style_indices: Tensor | None = None)

Map noise to a sample in one evaluation.

Parameters

(B, in_channels, H, W) Gaussian noise (already scaled by the sampling temperature, if any).
labelsTensor
(B,) class indices.
guidance_scalefloat or Tensor= 1.0
Guidance scale α\alpha, a scalar or (B,). 1 is no guidance.
style_indicesTensor or None= None
(B, noise_coords) style indices. Drawn uniformly when None, as the release always does.

Returns

DiffusionModelOutput

sample of shape (B, out_channels, H, W).