TorchLean API

NN.Runtime.Autograd.Torch.Initialization

Deterministic parameter initialization #

Pure, reproducible initializers for TorchLean.Tensor Float. These definitions are used when building model parameters before they enter a runtime session. Large runtime backends may provide more specialized allocation paths, but they should implement the same initialization scheme.

The formulas follow the corresponding PyTorch initializers:

References:

A deterministic scheme for initializing a tensor of Float values.

Instances For

    Check the parameter domains of a declared initialization scheme.

    Instances For

      Preserve the ordinary bound unless converting the fan count erased a nonzero root.

      The denominator retains each scheme's original casting and addition order. On range loss, FloatLib rounds the square root of the exact rational ratio without casting the count first.

      Instances For

        Xavier/Glorot uniform bound.

        The zero-fan case has no meaningful random interval. Returning zero keeps direct scheme use finite and agrees with the empty-tensor behavior expected when a weight has no elements. A count that overflows binary64 is handled before rounding the root, which may still be representable.

        Instances For

          Kaiming/He uniform bound.

          A zero fan-in uses the degenerate interval [0, 0], avoiding infinities and NaN in host and runtime initialization paths. Overflowing counts use the same exact-root recovery as Xavier.

          Instances For

            Return sample idx from sch, using the counter-based stream determined by seed.

            Uniform sampling keeps the ordinary affine formula unless the span of two finite bounds overflows. Interpolating the endpoints separately then avoids materializing that span.

            Instances For

              Initialize the row-major buffer directly, avoiding recursive subtensor construction. Flat index i still receives sampleAt sch seed i, preserving the seed and sample order.

              Instances For
                def Runtime.Autograd.Torch.Init.xavierUniform (outDim inDim : ℕ) (seed : ℕ := 0) :

                Initialize a matrix with the Xavier/Glorot uniform distribution and gain 1.

                Instances For