A time-dependent score network over one of the three SDEs.
Parameters
configScoreSDEConfigFrozen configuration.
Notes
Reference: Song, Sohl-Dickstein, Kingma, Kumar, Ermon, and Poole, "Score-Based Generative Modeling through Stochastic Differential Equations", ICLR, 2021 (arXiv:2011.13456).
The network predicts the noise that was added; the score follows from the perturbation kernel, since for
Dividing by rather than folding it into the network is what lets one trained model serve every sampler here — the samplers ask for a score and get one at whatever they are at.
Examples
>>> import lucid
>>> from lucid.models import score_sde_ve
>>> model = score_sde_ve(sample_size=8, base_channels=8,
... channel_mult=(1,), num_res_blocks=1, resnet_groups=4,
... attention_resolutions=()).eval()
>>> model.sde.__class__.__name__
'VESDE'Used by 2
Constructors
1Instance methods
3forward(x: Tensor, t: Tensor | None = None)What the network thinks was added — same shape as x.
, the quantity every sampler wants.
Parameters
Returns
TensorThe score, same shape as x.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.models import score_sde_vp
>>> model = score_sde_vp(sample_size=8, base_channels=8,
... channel_mult=(1,), num_res_blocks=1, resnet_groups=4,
... attention_resolutions=()).eval()
>>> # The output layer starts at zero; give it weights so the check bites.
>>> _ = nn.init.normal_(model.unet.conv_out.weight, std=0.05)
>>> x, t = lucid.randn((2, 3, 8, 8)), lucid.tensor([0.05, 0.9])
>>> score = model.score(x, t)
>>> score.shape
(2, 3, 8, 8)
>>> _, std = model.sde.marginal_prob(x, t)
>>> noise = model.predict_noise(x, t)
>>> bool(lucid.allclose(score * std.reshape(2, 1, 1, 1), -noise, atol=1e-5))
True