TorchLean API

NN.GraphSpec.DAG.Primitives.Core

Core DAG Primitives #

Constants, elementwise arithmetic, and standard sequential operations exposed as typed DAG nodes.

Basic DAG primitives #

Produce the all-zero tensor of a statically known shape.

Instances For
    @[simp]

    The zero DAG node denotes the all-zero tensor of its declared shape.

    Produce the all-one tensor of a statically known shape.

    Instances For
      def NN.GraphSpec.DAG.PrimOp.linear (inDim outDim : ) :
      PrimOp [[outDim, inDim], [outDim], [inDim]] [outDim]

      Dense linear layer in DAG form.

      Inputs are ordered as [W, b, x]:

      • W : Tensor α [outDim, inDim],
      • b : Tensor α [outDim],
      • x has shape [inDim].

      The output has shape [outDim]. This is the DAG embedding of Primitive.linear, so the DAG and sequential authoring surfaces share the same Spec semantics and TorchLean lowering path.

      Instances For

        Flatten a tensor to a rank-one tensor in DAG form.

        Input: [x : TorchLean.Tensor s]. Output: Tensor α [Spec.Shape.size s].

        This is the DAG embedding of Primitive.flatten, so it has exactly the same row-major view semantics as the sequential primitive.

        Instances For

          Spatial and residual DAG primitives #

          ReLU activation in DAG form.

          Input: [x : s], output: s.

          Semantics: elementwise $\max(x,0)$. This is parameter-free and derived from Primitive.relu.

          Reference: Nair and Hinton (2010), "Rectified Linear Units Improve Restricted Boltzmann Machines".

          Instances For

            Add two tensors of the same shape.

            Input shapes: [s, s], output shape: s.

            This is the primitive used for residual/skip connections: $\mathrm{out}=\operatorname{main}(x)+x$. It is defined directly because the sequential surface is unary, while residual addition is genuinely multi-input.

            Instances For
              @[simp]

              The pure meaning of the DAG addition node is pointwise tensor addition.

              Subtract two tensors of the same shape.

              Instances For
                @[simp]

                The pure meaning of the DAG subtraction node is pointwise tensor subtraction.

                Multiply two tensors coordinatewise.

                Instances For
                  @[simp]

                  The pure meaning of the DAG multiplication node is pointwise tensor multiplication.

                  def NN.GraphSpec.DAG.PrimOp.conv {d : } (inC outC : ) (kernel stride padding spatial : TorchLean.Tensor [d]) :
                  PrimOp [Spec.Shape.ofList (outC :: inC :: kernel.to (List )), [outC], Spec.Shape.ofList (inC :: spatial.to (List ))] (Spec.Shape.ofList (outC :: (Spec.convOutSpatial spatial kernel stride padding).to (List )))

                  Arbitrary-rank convolution in DAG form, with inputs ordered as [kernel, bias, x].

                  Instances For
                    def NN.GraphSpec.DAG.PrimOp.maxPool {d : } (channels : ) (kernel stride padding spatial : TorchLean.Tensor [d]) {hKernel : ∀ (i : Fin d), kernel.getScalar i 0} {hStride : ∀ (i : Fin d), stride.getScalar i 0} :
                    PrimOp [Spec.Shape.ofList (channels :: spatial.to (List ))] (Spec.Shape.ofList (channels :: (Spec.poolOutSpatialPad spatial kernel stride padding).to (List )))

                    Arbitrary-rank max pooling in DAG form.

                    Instances For
                      def NN.GraphSpec.DAG.PrimOp.batchNorm (channels : ) (spatial : Spec.Shape) (hWellFormed : (Spec.Shape.dim channels spatial).wellFormed) :
                      PrimOp [[channels], [channels], Spec.Shape.dim channels spatial] (Spec.Shape.dim channels spatial)

                      Batch normalization over an arbitrary spatial shape in DAG form.

                      Instances For