TorchLean API

NN.Backend.LibTorch

LibTorch Backend Capsules #

Maintained CUDA primitives implemented with LibTorch ATen tensor operations.

TorchLean owns tape traversal and selects each local VJP. Native forward and backward routines execute without recording a LibTorch autograd graph. The wrappers remain a foreign implementation boundary: shape/layout guards and named regression suites are engineering evidence, not Lean proofs of ATen, its dependencies, or compiled execution. Numerical reductions retain implementation-defined ordering. The CPU/reference capsules and their mathematical contracts are separate.

Local VJP ownership follows Engine.LibTorch.Ops: .torchLeanTape means Lean composes the derivative from numerical primitives; .backendVJP means it calls a native backward primitive. Both retain the LibTorch provider and TorchLean's global tape.

Retained CUDA comparisons, by operation. An absent entry leaves an explicit trust boundary.

Instances For

    Record the available comparison, or the untested native agreement being assumed.

    Instances For

      checked when the forward pass, and the VJP if there is one, have a retained CUDA comparison; otherwise an explicit trusted boundary.

      Instances For
        def NN.Backend.LibTorch.Internal.capsule (name : String) (op : BackendOp) (valueSummary vjpSummary : String) (vjpMode : VJPMode) :

        Describe a maintained LibTorch primitive and the evidence required by its runtime contract.

        Instances For

          Build the standard LibTorch CUDA capsule for a pointwise operation.

          Instances For

            Build a LibTorch CUDA reduction capsule with implementation-defined reduction order.

            Instances For
              def NN.Backend.LibTorch.Internal.accumulationCapsule (name : String) (op : BackendOp) (valueSummary vjpSummary : String) (vjpMode : VJPMode) :

              LibTorch CUDA kernel with an accumulation whose tree/order is selected by the implementation.

              This covers matrix products, affine layers, convolutions, losses, and average pooling. ATen selects the accumulation implementation; the capsule does not promise the reference left fold. Deterministic execution settings do not strengthen this to a particular numerical schedule.

              Instances For

                Build the standard LibTorch CUDA capsule for a shape or layout transformation.

                Instances For

                  Build a LibTorch CUDA forward-only capsule with no registered reverse derivative.

                  Instances For

                    LibTorch CUDA batched/matrix multiplication.

                    Instances For

                      Scaled CUDA contractions with conservative range recovery from the original operands.

                      The recovery path synchronizes a flag and may run reference coefficient arithmetic on CPU. Neither this mixed execution path nor its VJP promises a fixed-left accumulation schedule.

                      Instances For

                        Lean-recorded normalized matrix product with conservative host range recovery.

                        Instances For

                          LibTorch CUDA ReLU activation.

                          Instances For

                            LibTorch CUDA GELU activation.

                            Instances For

                              LibTorch CUDA pointwise addition.

                              Instances For

                                LibTorch CUDA pointwise subtraction.

                                Instances For

                                  LibTorch CUDA pointwise multiplication.

                                  Instances For

                                    LibTorch CUDA scalar multiplication.

                                    Instances For

                                      LibTorch CUDA pointwise absolute value.

                                      Instances For

                                        LibTorch CUDA pointwise square root.

                                        Instances For

                                          LibTorch CUDA pointwise interval clamp.

                                          Instances For

                                            LibTorch CUDA pointwise maximum.

                                            Instances For

                                              LibTorch CUDA pointwise minimum.

                                              Instances For

                                                LibTorch CUDA pointwise sigmoid.

                                                Instances For

                                                  SiLU value and local gradient use the shared ATen adapter; TorchLean owns traversal.

                                                  Instances For

                                                    LibTorch CUDA pointwise hyperbolic tangent.

                                                    Instances For

                                                      LibTorch CUDA pointwise softplus.

                                                      Instances For

                                                        LibTorch CUDA pointwise exponential.

                                                        Instances For

                                                          LibTorch CUDA sine, with angles measured in radians.

                                                          Instances For

                                                            LibTorch CUDA cosine, with angles measured in radians.

                                                            Instances For

                                                              LibTorch CUDA pointwise natural logarithm.

                                                              Instances For

                                                                LibTorch CUDA pointwise reciprocal.

                                                                Instances For

                                                                  Native quotient arithmetic with TorchLean's quotient-rule VJP.

                                                                  Instances For

                                                                    Native scalar negation with TorchLean's sign-reversing VJP.

                                                                    Instances For

                                                                      LibTorch CUDA smooth logarithm surrogate log (softplus x + epsilon).

                                                                      Instances For

                                                                        LibTorch CUDA log-softmax reduction and normalization.

                                                                        Instances For

                                                                          LibTorch CUDA row/axis softmax kernels.

                                                                          Instances For

                                                                            LibTorch CUDA hard-masked row softmax.

                                                                            Instances For

                                                                              LibTorch CUDA top-k routing mask.

                                                                              Instances For

                                                                                LibTorch CUDA sum reduction.

                                                                                Instances For

                                                                                  LibTorch CUDA arithmetic-mean reduction.

                                                                                  Instances For

                                                                                    LibTorch CUDA shape-preserving reshape view.

                                                                                    Instances For

                                                                                      LibTorch CUDA axis permutation.

                                                                                      Instances For

                                                                                        LibTorch CUDA tensor broadcasting.

                                                                                        Instances For

                                                                                          LibTorch CUDA tensor concatenation.

                                                                                          Instances For

                                                                                            LibTorch CUDA contiguous tensor slice.

                                                                                            Instances For

                                                                                              LibTorch CUDA indexed gather.

                                                                                              Instances For

                                                                                                LibTorch CUDA indexed scatter-add.

                                                                                                Instances For

                                                                                                  LibTorch CUDA seeded uniform-random tensor generation.

                                                                                                  Instances For

                                                                                                    LibTorch CUDA seeded Bernoulli-mask generation.

                                                                                                    Instances For

                                                                                                      LibTorch CUDA layer normalization.

                                                                                                      Instances For

                                                                                                        LibTorch CUDA batch normalization.

                                                                                                        Instances For

                                                                                                          LibTorch CUDA generic channel-first convolution.

                                                                                                          Instances For

                                                                                                            LibTorch CUDA generic channel-first transpose convolution.

                                                                                                            Instances For

                                                                                                              LibTorch CUDA max pooling, skipping padded cells and retaining the first row-major winner.

                                                                                                              Instances For

                                                                                                                LibTorch CUDA smooth max pooling.

                                                                                                                Instances For

                                                                                                                  LibTorch CUDA average pooling.

                                                                                                                  Instances For

                                                                                                                    LibTorch CUDA linear layer.

                                                                                                                    Instances For

                                                                                                                      LibTorch CUDA mean-squared-error loss.

                                                                                                                      Instances For

                                                                                                                        Weighted logits cross-entropy and both local VJPs, evaluated without LibTorch autograd.

                                                                                                                        Instances For

                                                                                                                          Teacher-logit cross-entropy and its student VJP, evaluated with ATen operations under TorchLean's tape. No LibTorch autograd graph is recorded.

                                                                                                                          Instances For

                                                                                                                            LibTorch numerical FFTs with Lean adjoints and spectral-layer composition.

                                                                                                                            Instances For

                                                                                                                              LibTorch CUDA selective scan kernels.

                                                                                                                              Instances For

                                                                                                                                Lean-composed attention over LibTorch numerical primitives.

                                                                                                                                TorchLean composes forward and the local VJP and owns the saved Q/K/V and probability buffers. The existing capsule identity is retained for routing and audits. No native attention context or fused-provider selection is involved; full score matrices require quadratic sequence memory. Numerical primitives execute without a LibTorch autograd graph or a fixed reduction schedule.

                                                                                                                                Instances For

                                                                                                                                  LibTorch CUDA primitive contracts.

                                                                                                                                  Instances For