Initializers#
The mlx.nn.init
package contains commonly used initializers for neural
network parameters. Initializers return a function which can be applied to any
input mlx.core.array
to produce an initialized output.
For example:
import mlx.core as mx
import mlx.nn as nn
init_fn = nn.init.uniform()
# Produces a [2, 2] uniform matrix
param = init_fn(mx.zeros((2, 2)))
To re-initialize all the parameter in an mlx.nn.Module
from say a uniform
distribution, you can do:
import mlx.nn as nn
model = nn.Sequential(nn.Linear(5, 10), nn.ReLU(), nn.Linear(10, 5))
init_fn = nn.init.uniform(low=-0.1, high=0.1)
model.apply(init_fn)
|
An initializer that returns an array filled with |
|
An initializer that returns samples from a normal distribution. |
|
An initializer that returns samples from a uniform distribution. |
|
An initializer that returns an identity matrix. |
|
A Glorot normal initializer. |
|
A Glorot uniform initializer. |
|
Build a He normal initializer. |
|
A He uniform (Kaiming uniform) initializer. |