TorchLean API

NN.Spec.Generative.Diffusion.Core

Diffusion core (spec layer) #

This module defines the common vocabulary used by TorchLean's diffusion / flow specs:

Design notes:

References (informal pointers):

def Generative.Diffusion.sqrtNonneg {α : Type} [Context α] (x : α) :
α

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) and 1-ᾱ(t)), but numeric backends can still produce small negative values.
Instances For
    def Generative.Diffusion.safeDiv {α : Type} [Context α] (x y : α) :
    α

    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:

      • t is a scalar, not a discrete index. Discrete samplers can provide t := (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 eps function, or by defining a richer model record in user code.
      Instances For