TorchLean API

NN.Spec.Generative.Diffusion.Schedule

VP diffusion schedules (spec layer) #

This file defines a discrete-time variance-preserving (VP) schedule for diffusion models.

We follow the common DDPM-style discrete schedule:

Then the forward noising kernel is (informally):

x_t = sqrt(ᾱ_t) x_0 + sqrt(1-ᾱ_t) ε where ε ~ N(0, I).

We keep the schedule scalar-polymorphic (Context α) so the same definitions can be reused under:

References (informal pointers):

structure Generative.Diffusion.VPSchedule (α : Type) (T : ) [Context α] :

Discrete VP schedule with T diffusion steps.

  • betas : Spec.Vec T α

    Per-step variances β_t for t = 0..T-1.

Instances For
    def Generative.Diffusion.VPSchedule.beta {α : Type} [Context α] {T : } (sched : VPSchedule α T) (t : Fin T) :
    α

    Fetch β_t as a scalar.

    Instances For
      def Generative.Diffusion.VPSchedule.alpha {α : Type} [Context α] {T : } (sched : VPSchedule α T) (t : Fin T) :
      α

      α_t := 1 - β_t.

      Instances For
        def Generative.Diffusion.VPSchedule.alphaBar {α : Type} [Context α] {T : } (sched : VPSchedule α T) (t : Fin (T + 1)) :
        α

        Compute ᾱ_t for t : Fin (T+1) with the convention:

        • ᾱ_0 = 1,
        • ᾱ_{t+1} = ᾱ_t * α_t.

        Implementation note: we define an auxiliary recursion on Nat and then package it as a Fin function; this keeps the definition total and easy to evaluate.

        Instances For
          def Generative.Diffusion.VPSchedule.alphaBar.go {α : Type} [Context α] {T : } (sched : VPSchedule α T) (k : ) :
          k < T + 1α
          Instances For
            def Generative.Diffusion.VPSchedule.alphaBarVec {α : Type} [Context α] {T : } (sched : VPSchedule α T) :
            Spec.Vec (T + 1) α

            Vector form of alphaBar (length T+1).

            Instances For
              def Generative.Diffusion.VPSchedule.timeOfIndex {α : Type} [Context α] {T : } (t : Fin (T + 1)) :
              α

              Convert a discrete time index t : Fin (T+1) into a scalar time t/T ∈ [0,1] (when T > 0).

              If T = 0, we define the time as 0 (the only index is t = 0).

              Instances For

                Simple constructors #

                These are convenience constructors for examples and demos. We intentionally keep them small and deterministic; large-scale training pipelines usually want explicit control over schedules.

                def Generative.Diffusion.VPSchedule.linearBetas {α : Type} [Context α] (T : ) (β_start β_end : α) :

                Linear β schedule over T steps: β_t interpolates from β_start to β_end.

                Note: this is a small spec helper. Popular schedules in the diffusion literature often use variants such as cosine schedules or continuous VP schedules; add those as separate named specs when a model or theorem needs them.

                Instances For
                  def Generative.Diffusion.VPSchedule.linear {α : Type} [Context α] (T : ) (β_start β_end : α) :

                  Build a schedule from a linear beta ramp.

                  Instances For