TorchLean API

NN.Runtime.Autograd.Torch.Core.Functional

Backend-Generic Functional API #

The Ops interface and curried helper syntax used to write one model once and run it on either the eager runtime or the compiled graph backend.

def Runtime.Autograd.Torch.Proofs.Autograd.Algebra.TList.append {α : Type} {ss₁ ss₂ : List Spec.Shape} :
TList α ss₁TList α ss₂TList α (ss₁ ++ ss₂)

Append two TLists.

This is a small utility for bridging between curried APIs and list-of-shapes APIs.

Instances For
    def Runtime.Autograd.Torch.Proofs.Autograd.Algebra.TList.splitAppend {α : Type} {ss₁ ss₂ : List Spec.Shape} :
    TList α (ss₁ ++ ss₂)TList α ss₁ × TList α ss₂

    Split a TList α (ss₁ ++ ss₂) into its left and right parts.

    This is the inverse of TList.append.

    Instances For

      Type of a curried function accepting one tensor argument per shape in ss.

      For example, Fn α [s₁, s₂] β is Tensor α s₁ → Tensor α s₂ → β.

      Instances For
        def Runtime.Autograd.Torch.Curried.curry {α β : Type} {ss : List Spec.Shape} :
        (TList α ssβ)Fn α ss β

        Convert a function on TList inputs into its curried form.

        Instances For
          def Runtime.Autograd.Torch.Curried.uncurry {α β : Type} {ss : List Spec.Shape} :
          Fn α ss βTList α ssβ

          Convert a curried function into a function on TList inputs.

          Instances For

            RefList is the reference-analogue of TList: a heterogeneous list of Ref s values indexed by a shape list.

            This is used to write backend-generic code over references (e.g. TensorRefs in eager mode, or GraphM.Vars in compiled mode).

            Reference-analogue of TList: a heterogeneous list of Ref s values indexed by shapes.

            Instances For
              def Runtime.Autograd.Torch.RefList.append {Ref : Spec.ShapeType} {ss₁ ss₂ : List Spec.Shape} :
              RefList Ref ss₁RefList Ref ss₂RefList Ref (ss₁ ++ ss₂)

              Append two RefLists.

              Instances For
                def Runtime.Autograd.Torch.RefList.split {Ref : Spec.ShapeType} {ss₁ ss₂ : List Spec.Shape} :
                RefList Ref (ss₁ ++ ss₂)RefList Ref ss₁ × RefList Ref ss₂

                Split a RefList Ref (ss₁ ++ ss₂) into its left and right parts.

                Instances For
                  def Runtime.Autograd.Torch.RefList.splitAppend1 {Ref : Spec.ShapeType} {ss : List Spec.Shape} {τ : Spec.Shape} :
                  RefList Ref (ss ++ [τ])RefList Ref ss × Ref τ

                  Split a RefList Ref (ss ++ [τ]) into its prefix and last element.

                  Instances For

                    Type of a curried function over references, one Ref s argument per shape in ss.

                    This mirrors Curried.Fn, but for Ref-valued arguments (e.g. TensorRefs in eager mode or GraphM.Vars in compiled mode).

                    Instances For
                      def Runtime.Autograd.Torch.CurriedRef.uncurry {Ref : Spec.ShapeType} {β : Type} {ss : List Spec.Shape} :
                      CurriedRef Ref ss βRefList Ref ssβ

                      Uncurry a curried reference function to accept a RefList.

                      Instances For
                        def Runtime.Autograd.Torch.CurriedRef.curry {Ref : Spec.ShapeType} {β : Type} {ss : List Spec.Shape} :
                        (RefList Ref ssβ)CurriedRef Ref ss β

                        Curry a reference function that consumes a RefList.

                        Instances For

                          Apply a curried reference function to a GraphM.VarList.

                          This is a convenience for the compiled backend, where leaves/inputs are represented as Vars.

                          Instances For

                            Backend-generic interface for building and executing tensor programs.

                            This typeclass lets you write a single model/loss once (polymorphic over Ops m α) and then choose:

                            • an eager backend that executes immediately on a runtime tape, or
                            • a compiled backend that records proved IR (GraphM) for later compilation/proofs.

                            Each method corresponds to a Tensor op; implementations are expected to match the semantics of the corresponding Runtime.Autograd.Tape.* / Compiled.GraphM.* operator.

                            Instances
                              @[reducible, inline]

                              Reference type for the current Ops instance.

                              In eager mode this will typically be TensorRef; in compiled mode it will typically be GraphM.Var.

                              Instances For
                                def Runtime.Autograd.Torch.const {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (t : Spec.Tensor α s) :
                                m (Ref s)

                                Re-export of Ops.const. PyTorch: torch.tensor(...) / literal constants.

                                Instances For
                                  def Runtime.Autograd.Torch.add {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (a b : Ref s) :
                                  m (Ref s)

                                  Re-export of Ops.add. PyTorch: torch.add / +.

                                  Instances For
                                    def Runtime.Autograd.Torch.sub {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (a b : Ref s) :
                                    m (Ref s)

                                    Re-export of Ops.sub. PyTorch: torch.sub / -.

                                    Instances For
                                      def Runtime.Autograd.Torch.mul {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (a b : Ref s) :
                                      m (Ref s)

                                      Re-export of Ops.mul. PyTorch: torch.mul / *.

                                      Instances For
                                        def Runtime.Autograd.Torch.scale {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) (c : α) :
                                        m (Ref s)

                                        Re-export of Ops.scale. PyTorch: x * c for a scalar c.

                                        Instances For
                                          def Runtime.Autograd.Torch.abs {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                          m (Ref s)

                                          Re-export of Ops.abs. PyTorch: torch.abs.

                                          Instances For
                                            def Runtime.Autograd.Torch.sqrt {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                            m (Ref s)

                                            Re-export of Ops.sqrt. PyTorch: torch.sqrt.

                                            Instances For
                                              def Runtime.Autograd.Torch.clamp {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) (minVal maxVal : α) :
                                              m (Ref s)

                                              Re-export of Ops.clamp. PyTorch: torch.clamp.

                                              Instances For
                                                def Runtime.Autograd.Torch.max {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (a b : Ref s) :
                                                m (Ref s)

                                                Re-export of Ops.max. PyTorch: torch.maximum.

                                                Instances For
                                                  def Runtime.Autograd.Torch.min {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (a b : Ref s) :
                                                  m (Ref s)

                                                  Re-export of Ops.min. PyTorch: torch.minimum.

                                                  Instances For
                                                    def Runtime.Autograd.Torch.broadcastTo {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s₁ s₂ : Spec.Shape} (cb : s₁.CanBroadcastTo s₂) (x : Ref s₁) :
                                                    m (Ref s₂)

                                                    Re-export of Ops.broadcastTo. PyTorch: broadcasting / expand.

                                                    Instances For
                                                      def Runtime.Autograd.Torch.reshape {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s₁ s₂ : Spec.Shape} (x : Ref s₁) (h : s₁.size = s₂.size) :
                                                      m (Ref s₂)

                                                      Re-export of Ops.reshape. PyTorch: reshape / view.

                                                      Instances For

                                                        Re-export of Ops.transpose2d. PyTorch: x.t() / transpose.

                                                        Instances For

                                                          Re-export of Ops.transpose3d_first_to_last. PyTorch: permute(1,2,0).

                                                          Instances For

                                                            Re-export of Ops.transpose3d_last_to_first. PyTorch: permute(2,0,1).

                                                            Instances For

                                                              Re-export of Ops.transpose3d_last_two. PyTorch: transpose(1,2).

                                                              Instances For
                                                                def Runtime.Autograd.Torch.swapAdjacentAtDepth {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (depth : ) (x : Ref s) :
                                                                m (Ref (s.swapAdjacentAtDepth depth))

                                                                Re-export of Ops.swapAdjacentAtDepth (general adjacent-axis swap).

                                                                Instances For

                                                                  Re-export of Ops.reduce_sum. PyTorch: torch.sum(..., dim=axis).

                                                                  Instances For

                                                                    Re-export of Ops.reduce_mean. PyTorch: torch.mean(..., dim=axis).

                                                                    Instances For

                                                                      Re-export of Ops.gather_scalar. PyTorch: x[i] (1D).

                                                                      Instances For

                                                                        Re-export of Ops.gather_row. PyTorch: x[i] (2D row).

                                                                        Instances For

                                                                          Re-export of Ops.gather_scalar_nat (index is a raw Nat).

                                                                          Instances For

                                                                            Re-export of Ops.gather_vec_nat (index tensor).

                                                                            Instances For

                                                                              Re-export of Ops.gather_rows_nat (index tensor).

                                                                              Instances For

                                                                                Re-export of Ops.scatter_add_vec.

                                                                                Instances For

                                                                                  Re-export of Ops.scatter_add_row.

                                                                                  Instances For

                                                                                    Re-export of Ops.matmul. PyTorch: torch.matmul for 2D tensors.

                                                                                    Instances For

                                                                                      Re-export of Ops.bmm. PyTorch: torch.bmm.

                                                                                      Instances For

                                                                                        Re-export of Ops.concat_vectors. PyTorch: torch.cat([a,b], dim=0) for vectors.

                                                                                        Instances For
                                                                                          def Runtime.Autograd.Torch.concatDim0 {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {nDim mDim : } {s : Spec.Shape} (a : Ref (Spec.Shape.dim nDim s)) (b : Ref (Spec.Shape.dim mDim s)) :
                                                                                          m (Ref (Spec.Shape.dim (nDim + mDim) s))

                                                                                          Re-export of Ops.concat_dim0. PyTorch: torch.cat(..., dim=0).

                                                                                          Instances For
                                                                                            def Runtime.Autograd.Torch.sliceRange0 {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {nDim : } {s : Spec.Shape} (start len : ) (h : len + start nDim) (x : Ref (Spec.Shape.dim nDim s)) :
                                                                                            m (Ref (Spec.Shape.dim len s))

                                                                                            Re-export of Ops.slice_range0. PyTorch: x[start:start+len] on the leading dimension.

                                                                                            Instances For
                                                                                              def Runtime.Autograd.Torch.maxPool {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {d C : } {inSpatial kernel stride padding : Vector d} {hKernel : ∀ (i : Fin d), kernel.get i 0} (x : Ref (Spec.Shape.ofList (C :: inSpatial.toList))) :
                                                                                              m (Ref (Spec.Shape.ofList (C :: (Spec.poolOutSpatialPad inSpatial kernel stride padding).toList)))

                                                                                              Re-export of Ops.max_pool (generic N-D max pooling, channels-first; no batch axis).

                                                                                              PyTorch comparison: torch.nn.functional.max_pool1d / max_pool2d / max_pool3d depending on the spatial rank d.

                                                                                              Instances For
                                                                                                def Runtime.Autograd.Torch.avgPool {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {d C : } {inSpatial kernel stride padding : Vector d} (hKernel : ∀ (i : Fin d), kernel.get i 0) (x : Ref (Spec.Shape.ofList (C :: inSpatial.toList))) :
                                                                                                m (Ref (Spec.Shape.ofList (C :: (Spec.poolOutSpatialPad inSpatial kernel stride padding).toList)))

                                                                                                Re-export of Ops.avg_pool (generic N-D average pooling, channels-first; no batch axis).

                                                                                                PyTorch comparison: torch.nn.functional.avg_pool1d / avg_pool2d / avg_pool3d depending on the spatial rank d.

                                                                                                Instances For
                                                                                                  def Runtime.Autograd.Torch.smoothMaxPool {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {d C : } {inSpatial kernel stride padding : Vector d} {hKernel : ∀ (i : Fin d), kernel.get i 0} (x : Ref (Spec.Shape.ofList (C :: inSpatial.toList))) (beta : α) :
                                                                                                  m (Ref (Spec.Shape.ofList (C :: (Spec.poolOutSpatialPad inSpatial kernel stride padding).toList)))

                                                                                                  Re-export of Ops.smooth_max_pool (generic N-D smooth max pooling, channels-first; no batch axis).

                                                                                                  This is a differentiable approximation to max pooling; PyTorch does not expose it as a single primitive.

                                                                                                  Instances For
                                                                                                    def Runtime.Autograd.Torch.maxPool2d {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {kH kW inH inW inC stride : } {h1 : kH 0} {h2 : kW 0} (x : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                    m (Ref (Spec.Shape.dim inC (Spec.Shape.dim ((inH - kH) / stride + 1) (Spec.Shape.dim ((inW - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                    Re-export of Ops.max_pool2d. PyTorch: torch.nn.functional.max_pool2d.

                                                                                                    Instances For
                                                                                                      def Runtime.Autograd.Torch.maxPool2dPad {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {kH kW inH inW inC stride padding : } {h1 : kH 0} {h2 : kW 0} (x : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                      m (Ref (Spec.Shape.dim inC (Spec.Shape.dim ((inH + 2 * padding - kH) / stride + 1) (Spec.Shape.dim ((inW + 2 * padding - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                      Re-export of Ops.max_pool2d_pad. PyTorch: max_pool2d(..., padding=...).

                                                                                                      Instances For
                                                                                                        @[reducible, inline]
                                                                                                        abbrev Runtime.Autograd.Torch.maxPoolPad {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {kH kW inH inW inC stride padding : } {h1 : kH 0} {h2 : kW 0} (x : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                        m (Ref (Spec.Shape.dim inC (Spec.Shape.dim ((inH + 2 * padding - kH) / stride + 1) (Spec.Shape.dim ((inW + 2 * padding - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                        Alias for max_pool2d_pad (PyTorch-style shorthand).

                                                                                                        Instances For
                                                                                                          def Runtime.Autograd.Torch.smoothMaxPool2d {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {kH kW inH inW inC stride : } {h1 : kH 0} {h2 : kW 0} (x : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) (beta : α) :
                                                                                                          m (Ref (Spec.Shape.dim inC (Spec.Shape.dim ((inH - kH) / stride + 1) (Spec.Shape.dim ((inW - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                          Re-export of Ops.smooth_max_pool2d (softmax pooling).

                                                                                                          Instances For
                                                                                                            def Runtime.Autograd.Torch.avgPool2d {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {kH kW inH inW inC stride : } (h1 : kH 0) (h2 : kW 0) (x : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                            m (Ref (Spec.Shape.dim inC (Spec.Shape.dim ((inH - kH) / stride + 1) (Spec.Shape.dim ((inW - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                            Re-export of Ops.avg_pool2d. PyTorch: torch.nn.functional.avg_pool2d.

                                                                                                            Instances For
                                                                                                              def Runtime.Autograd.Torch.avgPool2dPad {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {kH kW inH inW inC stride padding : } (h1 : kH 0) (h2 : kW 0) (x : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                              m (Ref (Spec.Shape.dim inC (Spec.Shape.dim ((inH + 2 * padding - kH) / stride + 1) (Spec.Shape.dim ((inW + 2 * padding - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                              Re-export of Ops.avg_pool2d_pad. PyTorch: avg_pool2d(..., padding=...).

                                                                                                              Instances For
                                                                                                                @[reducible, inline]
                                                                                                                abbrev Runtime.Autograd.Torch.avgPoolPad {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {kH kW inH inW inC stride padding : } (h1 : kH 0) (h2 : kW 0) (x : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                                m (Ref (Spec.Shape.dim inC (Spec.Shape.dim ((inH + 2 * padding - kH) / stride + 1) (Spec.Shape.dim ((inW + 2 * padding - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                                Alias for avg_pool2d_pad (PyTorch-style shorthand).

                                                                                                                Instances For
                                                                                                                  def Runtime.Autograd.Torch.relu {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                  m (Ref s)

                                                                                                                  Re-export of Ops.relu.

                                                                                                                  Instances For
                                                                                                                    def Runtime.Autograd.Torch.sigmoid {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                    m (Ref s)

                                                                                                                    Re-export of Ops.sigmoid.

                                                                                                                    Instances For
                                                                                                                      def Runtime.Autograd.Torch.tanh {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                      m (Ref s)

                                                                                                                      Re-export of Ops.tanh.

                                                                                                                      Instances For
                                                                                                                        def Runtime.Autograd.Torch.softmax {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                        m (Ref s)

                                                                                                                        Re-export of Ops.softmax.

                                                                                                                        Instances For
                                                                                                                          def Runtime.Autograd.Torch.softplus {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                          m (Ref s)

                                                                                                                          Re-export of Ops.softplus.

                                                                                                                          Instances For
                                                                                                                            def Runtime.Autograd.Torch.exp {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                            m (Ref s)

                                                                                                                            Re-export of Ops.exp.

                                                                                                                            Instances For
                                                                                                                              def Runtime.Autograd.Torch.log {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                              m (Ref s)

                                                                                                                              Re-export of Ops.log.

                                                                                                                              Instances For
                                                                                                                                def Runtime.Autograd.Torch.inv {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                                m (Ref s)

                                                                                                                                Re-export of Ops.inv (reciprocal).

                                                                                                                                Instances For
                                                                                                                                  def Runtime.Autograd.Torch.detach {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                                  m (Ref s)

                                                                                                                                  Re-export of Ops.detach. PyTorch: x.detach().

                                                                                                                                  Instances For
                                                                                                                                    def Runtime.Autograd.Torch.safeLog {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) (ε : α := Numbers.epsilon) :
                                                                                                                                    m (Ref s)

                                                                                                                                    Re-export of Ops.safe_log.

                                                                                                                                    Instances For
                                                                                                                                      def Runtime.Autograd.Torch.randUniform {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (seed : ) :
                                                                                                                                      m (Ref s)

                                                                                                                                      Re-export of Ops.rand_uniform (deterministic seeded RNG).

                                                                                                                                      Instances For
                                                                                                                                        def Runtime.Autograd.Torch.bernoulliMask {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (keepProb : Ref Spec.Shape.scalar) (seed : ) :
                                                                                                                                        m (Ref s)

                                                                                                                                        Re-export of Ops.bernoulli_mask (deterministic dropout-style mask).

                                                                                                                                        Instances For
                                                                                                                                          def Runtime.Autograd.Torch.logSoftmax {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (x : Ref s) (ε : α := Numbers.epsilon) :
                                                                                                                                          m (Ref s)

                                                                                                                                          Stable log_softmax(x) along the last axis.

                                                                                                                                          This is a backend primitive with the standard max-shifted formulation x - max(x) - log(sum(exp(x - max(x)))), matching PyTorch's numerical intent. The optional ε parameter is accepted to keep existing call sites stable and is ignored by this primitive; callers that need an epsilon-smoothed logarithm should use safeLog explicitly.

                                                                                                                                          Instances For
                                                                                                                                            def Runtime.Autograd.Torch.silu {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Monad m] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                                            m (Ref s)

                                                                                                                                            SiLU / swish: x * sigmoid(x).

                                                                                                                                            Instances For
                                                                                                                                              def Runtime.Autograd.Torch.gelu {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Monad m] [Ops m α] {s : Spec.Shape} (x : Ref s) :
                                                                                                                                              m (Ref s)

                                                                                                                                              GELU (approximation used by many ML frameworks):

                                                                                                                                              0.5 * x * (1 + tanh(√(2/π) * (x + 0.044715 * x^3))).

                                                                                                                                              This is defined using existing primitives (tanh, mul, add, scale), so it works in eager, compiled, and verifier-IR backends without introducing a new opcode.

                                                                                                                                              Instances For
                                                                                                                                                def Runtime.Autograd.Torch.globalAvgPool2dChw {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Monad m] [Ops m α] {c h w : } (h_c_pos : c > 0) (h_h_pos : h > 0) (h_w_pos : w > 0) (x : Ref (Spec.Shape.dim c (Spec.Shape.dim h (Spec.Shape.dim w Spec.Shape.scalar)))) :

                                                                                                                                                Global average pooling over the last two axes of a C×H×W tensor (channel-first).

                                                                                                                                                Returns a vector C, averaging each channel over H×W.

                                                                                                                                                Instances For
                                                                                                                                                  def Runtime.Autograd.Torch.globalAvgPool2dNchw {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Monad m] [Ops m α] {n c h w : } (h_n_pos : n > 0) (h_c_pos : c > 0) (h_h_pos : h > 0) (h_w_pos : w > 0) (x : Ref (Spec.Shape.dim n (Spec.Shape.dim c (Spec.Shape.dim h (Spec.Shape.dim w Spec.Shape.scalar))))) :

                                                                                                                                                  Global average pooling over the last two axes of an N×C×H×W tensor (PyTorch default layout).

                                                                                                                                                  Returns N×C, averaging each channel over H×W for each batch element.

                                                                                                                                                  Instances For

                                                                                                                                                    Re-export of Ops.sum. PyTorch: x.sum().

                                                                                                                                                    Instances For

                                                                                                                                                      Re-export of Ops.flatten. PyTorch: torch.flatten.

                                                                                                                                                      Instances For

                                                                                                                                                        Re-export of Ops.linear. PyTorch: torch.nn.functional.linear.

                                                                                                                                                        Instances For
                                                                                                                                                          def Runtime.Autograd.Torch.mseLoss {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {s : Spec.Shape} (yhat target : Ref s) :

                                                                                                                                                          Re-export of Ops.mse_loss. PyTorch: torch.nn.functional.mse_loss.

                                                                                                                                                          Instances For
                                                                                                                                                            def Runtime.Autograd.Torch.layerNorm {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {seqLen embedDim : } (h_seq_pos : seqLen > 0) (h_embed_pos : embedDim > 0) (x : Ref (Spec.Shape.dim seqLen (Spec.Shape.dim embedDim Spec.Shape.scalar))) (gamma beta : Ref (Spec.Shape.dim embedDim Spec.Shape.scalar)) :

                                                                                                                                                            Re-export of Ops.layer_norm. PyTorch: nn.LayerNorm / functional.layer_norm.

                                                                                                                                                            Instances For
                                                                                                                                                              def Runtime.Autograd.Torch.batchnormChannelFirst {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {channels height width : } (h_c : channels > 0) (h_h : height > 0) (h_w : width > 0) (x : Ref (Spec.Shape.dim channels (Spec.Shape.dim height (Spec.Shape.dim width Spec.Shape.scalar)))) (gamma beta : Ref (Spec.Shape.dim channels Spec.Shape.scalar)) :

                                                                                                                                                              Re-export of Ops.batchnorm_channel_first. PyTorch: nn.BatchNorm2d (conceptually).

                                                                                                                                                              Instances For
                                                                                                                                                                def Runtime.Autograd.Torch.multiHeadAttention {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {n numHeads dModel headDim : } (h1 : n 0) (wq wk wv : Ref (Spec.Shape.dim dModel (Spec.Shape.dim (numHeads * headDim) Spec.Shape.scalar))) (wo : Ref (Spec.Shape.dim (numHeads * headDim) (Spec.Shape.dim dModel Spec.Shape.scalar))) (x : Ref (Spec.Shape.dim n (Spec.Shape.dim dModel Spec.Shape.scalar))) (mask : Option (Spec.Tensor Bool (Spec.Shape.dim n (Spec.Shape.dim n Spec.Shape.scalar))) := none) :

                                                                                                                                                                Re-export of Ops.multi_head_attention.

                                                                                                                                                                Instances For
                                                                                                                                                                  def Runtime.Autograd.Torch.conv {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {d inC outC : } {kernel stride padding inSpatial : Vector d} {hInC : inC 0} {hKernel : ∀ (i : Fin d), kernel.get i 0} (weight : Ref (Spec.Shape.ofList (outC :: inC :: kernel.toList))) (bias : Ref (Spec.Shape.dim outC Spec.Shape.scalar)) (input : Ref (Spec.Shape.ofList (inC :: inSpatial.toList))) :
                                                                                                                                                                  m (Ref (Spec.Shape.ofList (outC :: (Spec.convOutSpatial inSpatial kernel stride padding).toList)))

                                                                                                                                                                  Re-export of Ops.conv (generic N-D convolution, channels-first).

                                                                                                                                                                  PyTorch comparison: torch.nn.functional.conv{d}d specialized to a single sample (no batch axis).

                                                                                                                                                                  Instances For
                                                                                                                                                                    def Runtime.Autograd.Torch.convTranspose {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {d inC outC : } {kernel stride padding inSpatial : Vector d} {hInC : inC 0} {hKernel : ∀ (i : Fin d), kernel.get i 0} (weight : Ref (Spec.Shape.ofList (inC :: outC :: kernel.toList))) (bias : Ref (Spec.Shape.dim outC Spec.Shape.scalar)) (input : Ref (Spec.Shape.ofList (inC :: inSpatial.toList))) :
                                                                                                                                                                    m (Ref (Spec.Shape.ofList (outC :: (Spec.convTransposeOutSpatial inSpatial kernel stride padding).toList)))

                                                                                                                                                                    Re-export of Ops.conv_transpose (generic N-D transpose convolution, channels-first).

                                                                                                                                                                    PyTorch comparison: torch.nn.functional.conv_transpose{d}d specialized to a single sample.

                                                                                                                                                                    Instances For
                                                                                                                                                                      def Runtime.Autograd.Torch.conv2d {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {inC outC kH kW stride padding inH inW : } {h1 : inC 0} {h2 : kH 0} {h3 : kW 0} (kernel : Ref (Spec.Shape.dim outC (Spec.Shape.dim inC (Spec.Shape.dim kH (Spec.Shape.dim kW Spec.Shape.scalar))))) (bias : Ref (Spec.Shape.dim outC Spec.Shape.scalar)) (input : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                                                                                      m (Ref (Spec.Shape.dim outC (Spec.Shape.dim ((inH + 2 * padding - kH) / stride + 1) (Spec.Shape.dim ((inW + 2 * padding - kW) / stride + 1) Spec.Shape.scalar))))

                                                                                                                                                                      Re-export of Ops.conv2d. PyTorch: torch.nn.functional.conv2d (conceptually, no batch axis).

                                                                                                                                                                      Instances For
                                                                                                                                                                        def Runtime.Autograd.Torch.convTranspose2d {m : TypeType} {α : Type} [Context α] [DecidableEq Spec.Shape] [Ops m α] {inC outC kH kW stride padding inH inW : } {h1 : inC 0} {h2 : kH 0} {h3 : kW 0} (kernel : Ref (Spec.Shape.dim inC (Spec.Shape.dim outC (Spec.Shape.dim kH (Spec.Shape.dim kW Spec.Shape.scalar))))) (bias : Ref (Spec.Shape.dim outC Spec.Shape.scalar)) (input : Ref (Spec.Shape.dim inC (Spec.Shape.dim inH (Spec.Shape.dim inW Spec.Shape.scalar)))) :
                                                                                                                                                                        m (Ref (Spec.Shape.dim outC (Spec.Shape.dim ((inH - 1) * stride - 2 * padding + kH) (Spec.Shape.dim ((inW - 1) * stride - 2 * padding + kW) Spec.Shape.scalar))))

                                                                                                                                                                        Re-export of Ops.conv_transpose2d. PyTorch: torch.nn.functional.conv_transpose2d.

                                                                                                                                                                        Instances For