TorchLean API

NN.Spec.Generative.Diffusion.PFODE

Probability-flow ODE (spec layer) #

This file defines a small continuous-time VP schedule (linear β(t)) and the corresponding probability-flow ODE drift field, using an ε_θ(x,t) model.

Why include this in the spec layer:

We keep the implementation scalar-polymorphic (Context α) so it can be:

References (informal pointers):

Continuous-time linear VP schedule on t ∈ [0,1]: β(t) = β0 + t(β1-β0).

  • beta0 : α

    β(0).

  • beta1 : α

    β(1).

Instances For

    Linear interpolation β(t) on t ∈ [0,1].

    Instances For

      Closed-form ᾱ(t) for the VP SDE with linear β(t):

      ᾱ(t) = exp(-∫₀ᵗ β(s) ds) = exp(-(β0 t + 0.5 (β1-β0) t^2)).

      Instances For

        σ(t) = sqrt(1-ᾱ(t)) (clamped to stay total).

        Instances For
          def Generative.Diffusion.pfOdeRhs {α : Type} [Context α] {s : Spec.Shape} (sch : VPLinearSchedule α) (model : EpsModel α s) (x : Spec.Tensor α s) (t : α) :

          Probability-flow ODE drift for a VP schedule, expressed via an ε_θ(x,t) model.

          For VP SDE:

          dx = -0.5 β(t) x dt + sqrt(β(t)) dW

          The probability-flow ODE is:

          dx = (-0.5 β(t) x - β(t) score(x,t)) dt.

          Using the ε-parameterization, an approximate score is score ≈ -(1/σ(t)) ε̂, so:

          dx = (-0.5 β(t) x + (β(t)/σ(t)) ε̂(x,t)) dt.

          Instances For
            def Generative.Diffusion.eulerStep {α : Type} [Context α] {s : Spec.Shape} (f : Spec.Tensor α sαSpec.Tensor α s) (x : Spec.Tensor α s) (t dt : α) :

            One explicit Euler step for an ODE x' = f(x,t):

            xNext = x + dt * f(x,t).

            To integrate the probability-flow ODE backwards from t=1 to t=0, use a negative dt.

            Instances For
              def Generative.Diffusion.pfOdeSampleEuler {α : Type} [Context α] {s : Spec.Shape} (sch : VPLinearSchedule α) (model : EpsModel α s) (steps : ) (x1 : Spec.Tensor α s) :

              Deterministic probability-flow sampler using Euler integration on a uniform grid.

              Inputs:

              • steps: number of Euler steps (typically large, e.g. 1000),
              • x1: initial state at t = 1 (typically standard normal noise).

              We integrate backwards in time on the grid: t_i = 1 - i/steps, with dt = -1/steps.

              Instances For
                def Generative.Diffusion.pfOdeSampleEuler.loop {α : Type} [Context α] {s : Spec.Shape} (sch : VPLinearSchedule α) (model : EpsModel α s) (n : ) (dt : α) :
                Spec.Tensor α sSpec.Tensor α s
                Instances For

                  Real-valued probability-flow Euler step as a DynamicalSystem.

                  This is the formal hook used by trajectory/fixed-point/contraction lemmas in NN.Spec.Dynamics.System: at a fixed time and step size, Euler integration is an autonomous discrete update on the current sample.

                  Instances For