TorchLean API

NN.API.Init

Tensor Initialization #

Deterministic tensor initialization helpers (Xavier/Kaiming, etc.) that return TorchLean TorchLean.Tensors with shape tracked in the type.

Tensor Initialization Helpers #

This module exposes Runtime.Autograd.Torch.Init through TorchLean TorchLean.Tensors with shapes tracked in the type.

All initializers are deterministic given an explicit seed : Nat, which is convenient for:

PyTorch Mapping #

The names mirror common PyTorch initializers:

See the PyTorch init docs: https://pytorch.org/docs/stable/nn.init.html

def TorchLean.Init.tensor {α : Type} [Storage α] [Runtime.FromFloat α] {shape : Shape} (scheme : Scheme) (seed : := 0) :
Tensor α shape

Initialize a tensor under any executable arithmetic.

The element type and dimensions are normally inferred from the expected tensor type. Initialization is generated once in Float, then converted through the element type's canonical Runtime.FromFloat instance.

Instances For
    def TorchLean.Init.xavierUniform {α : Type} [Storage α] [Runtime.FromFloat α] {outputWidth inputWidth : } (seed : := 0) :
    Tensor α [outputWidth, inputWidth]

    Xavier/Glorot uniform initialization for a linear weight matrix.

    Both widths are inferred from the expected Tensor α [outputWidth, inputWidth] type.

    Instances For
      def TorchLean.Init.kaimingUniform {α : Type} [Storage α] [Runtime.FromFloat α] {outputWidth inputWidth : } (seed : := 0) :
      Tensor α [outputWidth, inputWidth]

      Kaiming/He uniform initialization for a linear weight matrix used before a ReLU.

      Both widths are inferred from the expected Tensor α [outputWidth, inputWidth] type.

      Instances For