TorchLean API

NN.Runtime.Autograd.Torch.LinkedSession.GraphOps

Proof-Linked Session: Basic Graph Operations #

Graph-node ops (implemented by reusing Compiled.GraphM) #

Run a Compiled.GraphM computation against the current (ss, g) pair.

Compiled.GraphM is the builder monad used by the proof-friendly compiled pipeline; reusing it here ensures this eager-style API records the same typed IR that the compiler expects.

Instances For

    Atomically apply a graph-building update to the session snapshot.

    This is the central adapter used by each op wrapper below: it reads s.st, runs a builder that returns an updated SessionIRState, stores it back into s.st, and returns the op result.

    Instances For

      Record a constant tensor.

      Subtlety: if no op nodes have been created yet (ss = []), we record const as a leaf to match the eager session's leaf-collection behavior. Once op nodes exist, we emit an explicit constant node so users can introduce literal constants mid-graph. PyTorch comparison: like torch.tensor(...) (a leaf) vs inserting a literal constant into the graph; constants are treated as non-requires-grad.

      Instances For

        Record elementwise addition a + b.

        PyTorch comparison: torch.add(a, b) / the + operator.

        Instances For

          Record elementwise subtraction a - b.

          PyTorch comparison: torch.sub(a, b) / the - operator.

          Instances For

            Record elementwise multiplication a * b.

            PyTorch comparison: torch.mul(a, b) / the * operator.

            Instances For
              def Runtime.Autograd.Torch.Internal.SessionIR.scale {α : Type} (s : SessionIR α) [Mul α] [Add α] [Zero α] [DecidableEq Spec.Shape] {sh : Spec.Shape} (x : TensorRef α sh) (c : α) :
              IO (TensorRef α sh)

              Record scaling by a scalar constant: x * c.

              PyTorch comparison: like x * c (where c is a Python scalar).

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

                Record elementwise absolute value.

                PyTorch comparison: torch.abs(x).

                Instances For

                  Stop-gradient boundary.

                  Forward semantics: identity. Backward semantics: no gradient flows to the input. PyTorch comparison: x.detach().

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

                    Record elementwise square root.

                    PyTorch comparison: torch.sqrt(x).

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

                      Record elementwise clamp to the interval [minVal, maxVal].

                      PyTorch comparison: torch.clamp(x, min=minVal, max=maxVal).

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

                        Record elementwise maximum of a and b.

                        PyTorch comparison: torch.maximum(a, b).

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

                          Record elementwise minimum of a and b.

                          PyTorch comparison: torch.minimum(a, b).

                          Instances For

                            Record 2D matrix multiplication.

                            PyTorch comparison: torch.matmul(a, b) for 2D tensors.

                            Instances For

                              Record batched matrix multiplication.

                              PyTorch comparison: torch.bmm(a, b) for 3D tensors of shape (batch, m, n) and (batch, n, p).

                              Instances For

                                Concatenate two 1D vectors along dimension 0.

                                PyTorch comparison: torch.cat([a, b], dim=0) for 1D tensors.

                                Instances For

                                  Concatenate two tensors along dimension 0.

                                  PyTorch comparison: torch.cat([a, b], dim=0).

                                  Instances For
                                    def Runtime.Autograd.Torch.Internal.SessionIR.sliceRange0 {α : Type} (s : SessionIR α) [Zero α] [DecidableEq Spec.Shape] {n : } {sh : Spec.Shape} (x : TensorRef α (Spec.Shape.dim n sh)) (start len : ) (h : len + start n) :

                                    Slice a tensor along dimension 0.

                                    This returns x[start : start+len]. The proof argument h enforces bounds. PyTorch comparison: x[start:start+len] for tensors with a leading dimension.

                                    Instances For