TorchLean API

NN.Backend.Reference

Reference and Portable Backend Capsules #

Portable capsules for paths that do not require CUDA or LibTorch.

These are not meant to win benchmarks. They keep TorchLean runnable on CPU-only machines and give the planner a clear fallback vocabulary for reference/spec-aligned execution.

def NN.Backend.Reference.Internal.capsule (name : String) (op : BackendOp) (valueSummary vjpSummary : String) (vjpMode : VJPMode := VJPMode.torchLeanTape) :

Build a checked portable CPU capsule with explicit value, VJP, shape, and layout contracts.

Instances For

    Build the standard portable capsule for a pointwise operation.

    Instances For

      Build a portable reduction capsule with deterministic left-to-right accumulation.

      Instances For

        Reference kernel whose scalar result contains an explicit left-to-right accumulation.

        Matrix products, affine layers, convolutions, and averaging operations all reduce several products or samples into one output entry. Keeping this constructor separate from pointwise kernels prevents the numerical audit from incorrectly reporting that reduction order is irrelevant.

        Instances For

          Build the standard portable capsule for a shape or layout transformation.

          Instances For

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

            Instances For

              Reference ReLU activation.

              Instances For

                Reference GELU activation.

                Instances For

                  Reference pointwise addition.

                  Instances For

                    Reference pointwise subtraction.

                    Instances For

                      Reference pointwise multiplication.

                      Instances For

                        Reference scalar multiplication.

                        Instances For

                          Reference pointwise absolute value.

                          Instances For

                            Reference pointwise square root.

                            Instances For

                              Reference pointwise interval clamp.

                              Instances For

                                Reference pointwise maximum.

                                Instances For

                                  Reference pointwise minimum.

                                  Instances For

                                    Reference pointwise sigmoid.

                                    Instances For

                                      SiLU calls the canonical value and VJP directly, without an intermediate sigmoid tensor.

                                      Instances For

                                        Reference pointwise hyperbolic tangent.

                                        Instances For

                                          Reference pointwise softplus.

                                          Instances For

                                            Reference pointwise exponential.

                                            Instances For

                                              Reference pointwise natural logarithm.

                                              Instances For

                                                Reference pointwise sine.

                                                Instances For

                                                  Reference pointwise cosine.

                                                  Instances For

                                                    Reference pointwise reciprocal.

                                                    Instances For

                                                      Reference quotient arithmetic with the recorded quotient-rule VJP.

                                                      Instances For

                                                        Reference scalar negation with the sign-reversing VJP.

                                                        Instances For

                                                          Reference smooth logarithm surrogate log (softplus x + epsilon).

                                                          Instances For

                                                            Reference log-softmax reduction and normalization.

                                                            Instances For

                                                              Reference softmax path.

                                                              Instances For

                                                                Reference hard-masked softmax with exact zero weight at blocked coordinates.

                                                                Instances For

                                                                  Reference sum reduction.

                                                                  Instances For

                                                                    Reference arithmetic-mean reduction.

                                                                    Instances For

                                                                      Reference shape-preserving reshape view.

                                                                      Instances For

                                                                        Reference axis permutation.

                                                                        Instances For

                                                                          Reference tensor broadcasting.

                                                                          Instances For

                                                                            Reference tensor concatenation.

                                                                            Instances For

                                                                              Reference contiguous tensor slice.

                                                                              Instances For

                                                                                Reference indexed gather.

                                                                                Instances For

                                                                                  Reference indexed scatter-add.

                                                                                  Instances For

                                                                                    Reference seeded uniform-random tensor generation.

                                                                                    Instances For

                                                                                      Reference seeded Bernoulli-mask generation.

                                                                                      Instances For

                                                                                        Reference top-k routing mask.

                                                                                        Instances For

                                                                                          Reference matmul path.

                                                                                          Instances For

                                                                                            Reference scaled contraction, distinguished from fixed-left ordinary matrix multiplication.

                                                                                            Instances For

                                                                                              A compound pullback keeps original cotangents through row normalization.

                                                                                              Instances For

                                                                                                Reference linear layer.

                                                                                                Instances For

                                                                                                  Reference mean-squared-error loss.

                                                                                                  Instances For

                                                                                                    Weighted logits cross-entropy with both pullbacks supplied by the shared specification.

                                                                                                    Instances For

                                                                                                      Fixed-teacher cross-entropy using the shared loss and cancellation-resistant gradient.

                                                                                                      Instances For

                                                                                                        Reference layer normalization.

                                                                                                        Instances For

                                                                                                          Reference batch normalization.

                                                                                                          Instances For

                                                                                                            Reference generic channel-first convolution.

                                                                                                            Instances For

                                                                                                              Reference generic channel-first transpose convolution.

                                                                                                              Instances For

                                                                                                                Reference max pooling.

                                                                                                                Instances For

                                                                                                                  Reference smooth max pooling.

                                                                                                                  Instances For

                                                                                                                    Reference average pooling.

                                                                                                                    Instances For

                                                                                                                      Reference attention with fixed-order arithmetic and finite-coefficient range repair.

                                                                                                                      Instances For

                                                                                                                        Cross-platform reference capsules.

                                                                                                                        Instances For