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.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
        def NN.Backend.Reference.accumulationCapsule (name : String) (op : BackendOp) (valueSummary vjpSummary : String) :

        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

              Build a portable capsule for channel-first convolution or pooling.

              Instances For

                Reference window selection with deterministic traversal and tie handling.

                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

                                          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 guarded logarithm used by numerically defensive programs.

                                                        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 matmul path.

                                                                                      Instances For

                                                                                        Reference linear layer.

                                                                                        Instances For

                                                                                          Reference mean-squared-error loss.

                                                                                          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 path using the composed TorchLean expression.

                                                                                                          Instances For

                                                                                                            Cross-platform reference capsules.

                                                                                                            Instances For