nemo_automodel.components.optim.muown
nemo_automodel.components.optim.muown
Muown: Muon directions and Adam neuron magnitudes, using Dion’s FSDP2 all-to-all ownership scheme.
Algorithm reference: https://arxiv.org/abs/2605.10797. Numerical conventions follow the reference implementation’s ordinary Muown / newtonschulz5_torch backend.
Module Contents
Classes
Functions
Data
API
Bases: _MuonBase
Learn per-output-neuron magnitudes with Adam and matrix directions with Muon.
Uses the existing optional Dion dependency. Leading dimensions of 3D+ weights are independent matrices (experts). Groups with matrix_transposed=True store matrices as […, input, output]; the default is […, output, input]. Embeddings, biases and heads should be placed in algorithm=“adamw” or “lion” groups by MuownConfig.
FSDP communication follows each parameter’s DTensor mesh, so dense and expert parameters can share an optimizer despite different DP/EP meshes. Only one evenly sharded matrix axis is supported. EP-only and replicated matrices are orthogonalized locally. FP32 parameter storage is recommended.
Parameters:
Parameters or parameter-group dictionaries. Matrix weights have global shape […, output, input], or […, input, output] for matrix_transposed groups; leading axes are independent experts. AdamW/Lion groups accept arbitrary parameter shapes. DTensor matrix sharding follows _matrix_sharding. Gradients must use matching placements. Parameters and optimizer state are updated in-place; caller-owned gradients are preserved.
Compatibility argument for Dion; matrix collectives use each parameter’s actual DTensor mesh.
Base magnitude LR; direction LR is scaled by matrix dimensions.
Direction momentum coefficient.
Adam coefficients for learned magnitudes and scalar fallback.
Decoupled decay applied to the original weight.
Adam denominator and zero-norm stabilizer.
Enable Nesterov direction momentum.
Newton-Schulz iteration count.
Newton-Schulz normalization stabilizer.
Nonnegative multiplier for direction updates only. Magnitude Adam and auxiliary AdamW/Lion updates are unchanged. This run-level setting is read from config, including on resume.
Fuse local FP32 row updates on CUDA. Unsupported layouts, wide rows and input-feature shards retain the Torch implementation.
Schedule PyTorch AdamW for the non-matrix parameter groups.
Parameters:
Dion groups of arbitrary-shaped floating-point parameters. DTensors and their gradients/states share the same placements; each local shard is updated independently.
Dion’s scalar-algorithm name.
Schedule groups with matrix layouts and ownership documented by Muown.
Parameters:
Dion group dictionaries containing matrix parameters of global shape […, rows, columns] and Muown hyperparameters.
Dion’s matrix-algorithm name.
Apply AdamW to local shards using PyTorch’s reference arithmetic.
Parameters:
AdamW group with arbitrary-shaped parameters; DTensor parameters, gradients and moments have matching placements. Parameters, moments and per-parameter steps are mutated in place.
Update a batch while keeping temporary direction buffers batch-local.
Parameters:
Parameters sharing global shape […, rows, columns], placements, dtype, device, and mesh. Last-two-axis ordering is given by group[“matrix_transposed”]. Gradients are preserved.
Dion hyperparameters and the Muown matrix layout.
Evenly sharded matrix axis, or None for complete matrices.
Group owning the matrix shards, or None.
Size of process_group, or 1 for local matrices.
Resolve the communication group for the last two matrix axes.
Parameters:
Parameter of global shape […, rows, columns]. Leading axes are matrix batches; DTensors may shard those axes and at most one matrix axis. Matrix shards must be even and Partial is unsupported.
Returns: int | None
Matrix tensor axis and its process group, or (None, None) when each
Orthogonalize complete local matrices with the reference quintic polynomial.
Parameters:
Local tensor of shape […, output, input], or […, input, output] when matrix_transposed is true. Leading axes are independent matrices; this function does not accept matrix-sharded DTensors.
Stabilizer for the matrix Frobenius norm. Dion supplies a zero-dimensional CPU tensor; Python scalars are also accepted.
Whether the last axis contains output neurons.
Number of polynomial iterations.
Returns: Tensor
Independent contiguous BF16 tensor matching update’s shape and axis
Preserve signed neuron magnitudes while guarding division by zero.
Parameters:
Magnitude tensor of shape […, output, 1] or […, 1, output], with arbitrary leading batch axes; DTensor placements are preserved.
Minimum absolute magnitude.
Returns: Tensor
Independent tensor with the same shape, dtype, device and placements.
Reconstruct a direction and apply the weight-normalization Jacobian.
Parameters:
Effective weights […, output, input], or […, input, output] when axis is -2. DTensor shapes are global.
Signed neuron magnitudes with axis reduced to size 1.
Direction norms with the same shape and placements as magnitude.
Weight gradients matching weight’s shape and placements.
Physical input-feature axis; partial row sums are resolved.
Returns: Tensor
Tuple (direction, magnitude_gradient, direction_gradient). Direction
Compose effective weights with reference-compatible fused arithmetic.
Parameters:
Destination weights […, output, input], or […, input, output] for axis -2. Mutated in place; DTensor shapes are global.
Signed magnitudes with the input-feature axis reduced to 1.
Updated directions matching weight’s shape and placements.
Physical input-feature axis.
Returns: Tensor
Independent row norms with magnitude’s shape and placements. The caller
Compute per-output-neuron norms without gathering the weight matrix.
Parameters:
Tensor of shape […, output, input] or […, input, output], including globally shaped DTensors as described by _row_sum.
Physical input-feature axis, -1 or -2.
Minimum returned norm.
Returns: Tensor
Norm tensor in value’s dtype, with the input-feature axis of size 1
Reduce an input-feature axis and resolve DTensor partial sums.
Parameters:
Tensor of shape […, output, input] or […, input, output], with arbitrary leading matrix-batch dimensions. DTensors may shard batch or matrix axes; shapes are global.
Physical input-feature axis, -1 or -2.
Returns: Tensor
Tensor with the input-feature axis reduced to size 1. Partial sums are