TorchLean API

NN.Runtime.Autograd.Engine.Cuda.Fno1dRfftFused

CUDA FNO1D (real RFFT fused path) #

This file provides a direct CUDA forward and VJP runner for a real-valued FNO1D model. Its spectral convolution uses the same native tape primitive as nn.models.fnoRfft on CUDA. The public constructor also offers a dense reference with identical one-sided weights.

This runner keeps its explicit buffer lifetime and Adam handling for the Burgers example. Comparisons with the public constructor must load identical parameter tensors and use the same ReLU blocks, loss, and update rule. The arbitrary-rank full-DFT model in Model.Fno has a different spectral parameterization and is not an interchangeable checkpoint.

Trainable parameter plus Adam moment buffers.

All three tensors share shape. Values are serialized only when uploaded to CUDA; host Adam updates consume downloaded gradients as tensors.

Instances For

    Output of one fused-FNO tape construction.

    • tape : Tape

      The completed CUDA tape.

    • predId :

      Node id of the prediction tensor.

    • lossId? : Option

      Optional scalar loss node id, present only when a target was supplied.

    • paramIds : Array

      Tape node ids for parameters, in the same order as the parameter array.

    Instances For

      Number of CUDA buffer handles owned by a completed forward tape.

      Instances For

        Release every forward value and saved workspace owned by a completed tape.

        The fused FNO wrapper rebuilds its tape for every sample. Explicit disposal is therefore part of the wrapper's ownership contract; waiting for external-object finalizers makes long training and evaluation runs retain one full tape per sample until a later runtime collection.

        Instances For

          Minimal Adam state carried across fused-FNO training steps.

          • step :

            Step counter (1-based in the Adam bias correction formulas).

          • beta1Pow : Float

            Cached beta1^step for bias correction (starts at 1).

          • beta2Pow : Float

            Cached beta2^step for bias correction (starts at 1).

          Instances For

            Deterministic uniform sample in [lo, hi) for a scalar index.

            Instances For

              Initialize a trainable parameter and zero Adam moments.

              Instances For

                Initialize a bias-like parameter at zero with zero Adam moments.

                Instances For

                  Initialize parameters for the fused FNO1D model:

                  • input lift: W_in : (1,width), b_in : (width)
                  • blocks: (wRe,wIm) : (modes,width,width), wSkip : (width,width), bSkip : (width)
                  • output proj: W_out : (width,1), b_out : (1)
                  Instances For

                    Fetch a parameter with an error message that points to the fused-FNO wrapper.

                    Instances For

                      Validate uploaded parameter buffer i against its declared shape, add it as a gradient-requiring CUDA tape leaf, and record the new node id.

                      Instances For

                        Broadcast a vector of length cols across grid rows.

                        Instances For
                          def Runtime.Autograd.Cuda.Fno1dRfftFused.forwardWithBuffers (grid width modes blocks : ) (ps : Array Param) (target? : Option (TorchLean.Tensor Float [grid])) (xBuffer : Buffer) (paramBuffers : Array Buffer) (targetBuffer? : Option Buffer) :

                          Build a CUDA tape that computes prediction (and optionally MSE loss) for the fused real-RFFT FNO.

                          Inputs:

                          • x : (grid) (interpreted as (grid,1)),
                          • optional target : (grid).

                          Every external CUDA buffer is checked against the corresponding logical shape and element count before an operation can consume it. Input and parameter buffers are checked before their leaf nodes are added; the optional target is checked by the MSE operation on the loss path.

                          Instances For
                            def Runtime.Autograd.Cuda.Fno1dRfftFused.forward (grid width modes blocks : ) (ps : Array Param) (x : TorchLean.Tensor Float [grid]) (target? : Option (TorchLean.Tensor Float [grid])) :

                            Build one fused-FNO tape from fresh CUDA uploads.

                            The uploads are effectful so repeated forwards over identical host arrays cannot share an external buffer handle. This gives each returned Forward exclusive ownership of the buffers it disposes.

                            Instances For

                              Download a scalar CUDA tape value to host Float.

                              Instances For

                                Download a (grid,1) prediction matrix as a length-grid tensor.

                                Instances For

                                  Mean MSE over a nonempty indexed sample stream, releasing each tape after scalar download.

                                  Instances For
                                    def Runtime.Autograd.Cuda.Fno1dRfftFused.adamUpdateBiasCorrected {shape : Spec.Shape} (value m v grad : TorchLean.Tensor Float shape) (lr beta1 beta2 eps biasCorr1 biasCorr2 : Float) :

                                    Tensor Adam update with cached bias corrections and the fused path's scalar evaluation order.

                                    Each multiplication/division retains its original ordering, including (1-beta2)*g*g and lr*(m/biasCorr1)/(sqrt(v/biasCorr2)+eps). Equal shapes replace the former runtime length checks.

                                    Instances For

                                      Run reverse-mode on the fused-FNO tape and update every recorded parameter with Adam.

                                      Gradients are computed on CUDA buffers and downloaded to host arrays before the update. A high-throughput optimizer kernel should live in a separate CUDA optimizer layer, not inside this model helper.

                                      Instances For
                                        def Runtime.Autograd.Cuda.Fno1dRfftFused.updateParamsAdam (ps : Array Param) (fw : Forward) (lr : Float) (st : AdamState) (beta1 : Float := 0.9) (beta2 : Float := 0.999) (eps : Float := 1e-8) :

                                        Run one Adam update and deterministically release the consumed gradient and forward buffers.

                                        Instances For
                                          def Runtime.Autograd.Cuda.Fno1dRfftFused.predict (grid width modes blocks : ) (parameters : Array Param) (input : TorchLean.Tensor Float [grid]) :

                                          Predict through the fused spectral path and release the temporary tape after downloading.

                                          Instances For
                                            def Runtime.Autograd.Cuda.Fno1dRfftFused.trainStep (grid width modes blocks : ) (parameters : Array Param) (input target : TorchLean.Tensor Float [grid]) (learningRate : Float) (state : AdamState) :

                                            Consume one fused training tape, returning updated parameters and cached Adam state.

                                            Instances For