Diffusion core (spec layer) #
This module defines the common vocabulary used by TorchLean's diffusion / flow specs:
EpsModel: an $\varepsilon_\theta(x,t)$ denoiser interface (noise prediction), and- scalar helpers (
sqrtNonneg,safeDiv) with explicit clamping and epsilon-shift formulas. Total scalar operations can still return nonfinite values on floating-point 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 clamped 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. $\bar\alpha(t)$ and $1-\bar\alpha(t)$), but numeric backends can still produce small negative values.
Instances For
Epsilon-shifted scalar division: $x/(y+\varepsilon)$.
The shift regularizes small denominators in schedules and samplers. Context imposes no
nonzero-denominator law, so the shifted denominator can still be zero.
Instances For
Noise-prediction model interface: $\varepsilon_\theta(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 : TorchLean.Tensor α s → α → TorchLean.Tensor α s
Predict $\varepsilon$ from a noisy sample $x$ at scalar time $t$.