Score network over a geometric schedule.
Implements the noise-conditional score network of Song and Ermon, 2019
(and the NCSNv2 / NCSN++ refinements of Song 2020, Song et al. 2021).
Reuses _DDPMUNet as the score backbone — modern NCSN variants
converged on the same U-Net architecture as diffusion — but feeds the
integer noise-level index rather than a raw
value through the timestep embedding. Divergence,
deliberate: this matches none of the three published recipes exactly.
NCSN v1 also conditions on the index, but through
CondInstanceNorm++ per- gain/bias rather than an
additive MLP; NCSNv2's Technique 3 drops noise conditioning entirely
and divides the output by ; NCSN++ conditions on
continuous via Fourier features of
. Feeding the index through the timestep MLP
keeps _DDPMUNet reusable unchanged, which is what makes one
backbone serve both families here. The geometric table itself is
held as a non-persistent buffer so it travels with .to(device=...).
Parameters
configNCSNConfigbase_channels, channel_mult, num_res_blocks,
attention_resolutions, num_heads, dropout,
resnet_groups) and the score-based extras
(num_noise_levels, sigma_max, sigma_min).Attributes
unet_DDPMUNetDDPMConfig.sigmasTensor(num_noise_levels,) holding the geometric
schedule.Notes
Reference: Song and Ermon, "Generative Modeling by Estimating Gradients of the Data Distribution", NeurIPS, 2019 (arXiv:1907.05600); NCSNv2 refinements in Song and Ermon, 2020 (arXiv:2006.09011).
The trained score satisfies
where is the data distribution convolved with a Gaussian of standard deviation .
Examples
>>> import lucid
>>> from lucid.models.generative.ncsn import NCSNConfig, NCSNModel
>>> cfg = NCSNConfig(sample_size=32, base_channels=32,
... channel_mult=(1, 2), num_res_blocks=1,
... resnet_groups=16, num_noise_levels=10)
>>> model = NCSNModel(cfg).eval()
>>> x_tilde = lucid.randn((1, 3, 32, 32))
>>> sigma_idx = lucid.tensor([3]).long()
>>> out = model(x_tilde, sigma_idx)
>>> out.sample.shape # (1, 3, 32, 32) — raw score
(1, 3, 32, 32)Used by 2
Constructors
1Properties
1Instance methods
1forward(sample: Tensor, sigma_idx: Tensor)Predict the score at sample for the given noise-level indices.
Parameters
Returns
DiffusionModelOutputclass:DiffusionModelOutput whose sample field is the raw