TorchLean API

NN.Runtime.Autograd.Torch.Core.Ops.Elementwise

Eager Tensor Operations #

PyTorch-style tensor operations recorded on the session's tape. Each one runs the CPU or the CUDA kernel of the operation, as the session's device selects, and preserves the typed TensorRef surface.

Elementwise operations #

Record elementwise addition a + b. PyTorch: torch.add.

Instances For

    Record elementwise subtraction a - b. PyTorch: torch.sub.

    Instances For

      Record elementwise multiplication a * b. PyTorch: torch.mul.

      Instances For
        def Runtime.Autograd.Torch.Internal.EagerSession.div {α : Type} [TorchLean.Storage α] (s : EagerSession α) [Div α] [Mul α] [Sub α] [Zero α] {sh : Spec.Shape} (a b : TensorRef α sh) :
        IO (TensorRef α sh)

        Record elementwise division without replacing it by multiplication by a reciprocal.

        Instances For

          Record direct scalar negation, preserving signed zero in the forward value.

          Instances For

            Record scaling by a scalar constant. PyTorch: x * c.

            Instances For
              def Runtime.Autograd.Torch.Internal.EagerSession.abs {α : Type} [TorchLean.Storage α] (s : EagerSession α) [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] {sh : Spec.Shape} (x : TensorRef α sh) :
              IO (TensorRef α sh)

              Record elementwise absolute value. PyTorch: torch.abs.

              Instances For
                def Runtime.Autograd.Torch.Internal.EagerSession.sqrt {α : Type} [TorchLean.Storage α] (s : EagerSession α) [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] {sh : Spec.Shape} (x : TensorRef α sh) :
                IO (TensorRef α sh)

                Record elementwise square root. PyTorch: torch.sqrt.

                Instances For
                  def Runtime.Autograd.Torch.Internal.EagerSession.clamp {α : Type} [TorchLean.Storage α] [TensorTransfer α] (s : EagerSession α) [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] {sh : Spec.Shape} (x : TensorRef α sh) (minVal maxVal : α) :
                  IO (TensorRef α sh)

                  Record elementwise clamp to [minVal,maxVal]. PyTorch: torch.clamp.

                  Instances For
                    def Runtime.Autograd.Torch.Internal.EagerSession.max {α : Type} [TorchLean.Storage α] (s : EagerSession α) [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] {sh : Spec.Shape} (a b : TensorRef α sh) :
                    IO (TensorRef α sh)

                    Record elementwise maximum. PyTorch: torch.maximum.

                    Instances For
                      def Runtime.Autograd.Torch.Internal.EagerSession.min {α : Type} [TorchLean.Storage α] (s : EagerSession α) [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] {sh : Spec.Shape} (a b : TensorRef α sh) :
                      IO (TensorRef α sh)

                      Record elementwise minimum. PyTorch: torch.minimum.

                      Instances For

                        Record the top-k mask of x along its last axis (Spec.MoE.topKMaskSpec), a reference that receives no gradient. CUDA computes it with a comparison kernel; the CPU tape evaluates the spec.

                        Instances For
                          def Runtime.Autograd.Torch.Internal.EagerSession.relu {α : Type} [TorchLean.Storage α] (s : EagerSession α) [Mul α] [Zero α] [Max α] [BEq α] [One α] [LT α] [DecidableRel fun (x1 x2 : α) => x1 > x2] {sh : Spec.Shape} (x : TensorRef α sh) :
                          IO (TensorRef α sh)

                          Record elementwise ReLU. PyTorch: torch.relu / torch.nn.functional.relu.

                          Instances For

                            Record elementwise sigmoid. PyTorch: torch.sigmoid.

                            Instances For

                              Record elementwise tanh. PyTorch: torch.tanh.

                              Instances For

                                Record SiLU as one operation; the input is retained for its negative-tail VJP.

                                Instances For

                                  Record tanh-approximate GELU as one tape operation.

                                  Instances For

                                    Record shape-preserving softmax over the last axis.

                                    PyTorch comparison: torch.softmax(x, dim=-1).

                                    Instances For

                                      Record stable log-softmax (shape-preserving, last-axis convention).

                                      PyTorch comparison: torch.nn.functional.log_softmax(x, dim=-1).

                                      Instances For

                                        Record elementwise softplus. PyTorch: torch.nn.functional.softplus.

                                        Instances For

                                          Record elementwise exponential. PyTorch: torch.exp.

                                          Instances For

                                            Record elementwise sine and dispatch its value and VJP through the selected backend.

                                            Instances For

                                              Record elementwise cosine with the selected backend's -sin(x) * dLdy backward rule.

                                              Instances For

                                                Record elementwise log. PyTorch: torch.log.

                                                Instances For

                                                  Record elementwise inverse 1/x. PyTorch: torch.reciprocal.

                                                  Instances For

                                                    Record log(softplus(x) + ε) and its derivative.

                                                    Backward multiplies the incoming gradient by sigmoid(x) / (softplus(x) + ε). CUDA converts ε to the input dtype; choose a value that stays positive after conversion if softplus can round to zero. Neither backend checks positivity here or guarantees finite results for nonfinite inputs.

                                                    Instances For