Expand description
Layers, as in MLX’s mlx.nn (and mlx-lm’s LoRA layer). Initialisation draws from this
thread’s key sequence in MLX’s order, so the same seed gives MLX’s values.
Constructors take no bool and return no Result: they build lazy arrays, and an
invalid size gives failed parameters whose error surfaces at the first boundary. Every
forward returns an Array and is #[track_caller]: an invalid input gives a failed
array whose error (check(), eval(), …) reports the line that called forward.
Structs§
- Dropout
- Randomly zeroes elements with probability
pduring training and scales the rest by1/(1 − p); the identity in evaluation mode (MLX’snn.Dropout). The mask isbernoulli(1 − p), drawn from the thread’s key sequence (bit for bit MLX’s for a seed) or from an explicit key (Dropout::forward_with_key). - Embedding
- A lookup table of
dims-dimensional vectors for integer ids (MLX’snn.Embedding). - Layer
Norm - Layer normalisation over the last axis, optionally with a learned scale and bias
(MLX’s
nn.LayerNorm, the fusedfast::layer_norm). - Linear
- An affine layer
y = x Wᵀ + b, withWof shape[output, input]andbof shape[output](MLX’snn.Linear). - Lora
Linear - A frozen linear layer plus a trainable low-rank update (mlx-lm’s
LoRALinear):y = base(x) + scale · (dropout(x) A) B, withAof shape[input, r]andBof shape[r, output](zeros at first, so the layer starts as its base). Names follow mlx-lm:linear.weight,lora_a,lora_b. - Quantized
Embedding - An
Embeddingwith its table quantized (MLX’snn.QuantizedEmbedding): rows are gathered packed and dequantized; the packed table, scales and biases are buffers. In the floating-point modes the rows come out in bfloat16, as MLX’s. - Quantized
Linear - A
Linearlayer with its weight quantized (MLX’snn.QuantizedLinear):x Wᵀ + bcomputed byquantized_matmulfrom the packed weight and its scales (and, for affine, biases), in anyQuantMode. - RmsNorm
- Root-mean-square normalisation over the last axis with a learned scale (MLX’s
nn.RMSNorm, the fusedfast::rms_norm). - Rope
- Rotary position embedding of the first
dimsfeatures (MLX’snn.RoPE, the fusedfast::rope), optionally with a frequency scaling (Rope::scaled: mlx-lm’sLlama3RoPE,YarnRoPE,SuScaledRoPE,ProportionalRoPE). No parameters: the frequencies are computed from the settings, never loaded or saved.
Enums§
- Lora
Base - The layer a
LoraLinearadapts.