Diffusion core (spec layer) #
This module defines the common vocabulary used by TorchLean's diffusion / flow specs:
EpsModel: anε_θ(x,t)denoiser interface (noise prediction), and- a couple of total scalar helpers (
sqrtNonneg,safeDiv) that keep specs robust across scalar backends.
Design notes:
EpsModelis deliberately backbone-independent: it is a pure function of the current statexand a scalar time parametert(typically normalized into[0,1]).- Schedules and samplers remain separate modules so we can reuse the same denoiser with:
- discrete DDPM / DDIM-style samplers, and
- continuous-time probability-flow ODE samplers.
References (informal pointers):
- Ho, Jain, Abbeel (2020), "Denoising Diffusion Probabilistic Models" (DDPM).
- Song et al. (2021), "Score-Based Generative Modeling through Stochastic Differential Equations" (continuous-time VP SDE and probability-flow ODE).
A safe square root used by diffusion schedules and samplers: sqrt(max x 0).
Why this helper exists:
- Some backends (intervals, IEEE models, etc.) prefer total semantics.
- In diffusion schedules, the quantities under a square root are mathematically nonnegative
(e.g.
ᾱ(t)and1-ᾱ(t)), but numeric backends can still produce small negative values.
Instances For
Safe scalar division with epsilon protection: x / (y + ε).
This is primarily used to avoid 1/0 in edge cases like t = 0 or degenerate schedules.
Instances For
Noise-prediction model interface: ε_θ(x,t).
The intended interpretation is "predict the noise used to construct the noisy sample x at time
t".
Notes:
tis a scalar, not a discrete index. Discrete samplers can providet := (k/T)or any other conventional embedding; continuous samplers can pass true continuous time.- This interface does not bake in class-conditioning or text-conditioning; those can be handled by
closing over extra context in the
epsfunction, or by defining a richer model record in user code.
- eps : Spec.Tensor α s → α → Spec.Tensor α s
Predict
εfrom a noisy samplexat scalar timet.