Long-Context LLM Training: A Practical Guide to the Muon Optimizer
This article explains why memory, not compute, is usually the first bottleneck when scaling large language models to million-token contexts, and how matrix-based orthogonalized optimizers such as Muon reduce that pressure. It contrasts element-wise adaptive updates with matrix-level updates, outlines the engineering work required to make the approach usable at billion- to trillion-parameter scale, and shows how to quantify memory, throughput, convergence, and stability gains. Practical rollout advice and common pitfalls are included for teams preparing long-context training runs.
1. Where the Problem Starts: Memory Bottlenecks Long-Context Training First
When large language models scale toward million-token contexts, the first constraint to surface is usually memory rather than compute. The reason is straightforward: intermediate activations from the attention mechanism grow rapidly with sequence length, while optimizer state is a fixed, resident memory cost. Together they leave very little room for batch size and context length.
Take mainstream adaptive optimization methods as an example. To maintain a per-element adaptive step size, they store two extra states per parameter: a first moment and a second moment. Under mixed-precision training, parameters, gradients, both moment variables, and the required precision copies all exist at the same time. Once parameter count reaches the trillions, optimizer state alone can consume tens of gigabytes. This is not an implementation detail; it is a precondition for whether a training plan is viable at all.
So the industry has begun to revisit a long-overlooked question: can optimizer state be made cheaper?
2. Two Optimization Paradigms and Their Essential Difference
2.1 Element-Wise Updates: Precise but Expensive
Traditional adaptive methods treat a weight matrix as a large collection of independent scalars. They estimate first- and second-order gradient statistics for each element separately, then determine the update magnitude element by element. The advantage is strong anisotropic adaptation, which is friendly to sparse gradients or gradients whose scales differ widely. The cost is that state size scales linearly with parameter count, and the numerical stability of second-order statistics requires extra epsilon terms and bias correction.
2.2 Matrix-Level Updates: Treating Weights as a Whole Geometric Object
Matrix-based optimization (often referred to in the industry as orthogonalization-based methods) treats a layer’s weights as a single, indivisible high-dimensional linear operator. It maintains only one momentum matrix, fuses momentum with the current gradient, orthogonalizes the result into an approximately orthogonal update matrix, and applies that update to the weights as a whole.
The intuition behind orthogonalization is to equalize update magnitudes across singular directions, so that a few directions do not dominate the step. Because state drops from two copies to one, memory overhead is nearly halved, and the space saved can be converted directly into a larger batch size or a longer context window.
A useful analogy: element-wise methods are like letting every soldier choose their own stride, which is flexible but demands heavy coordination overhead; matrix-level methods are like a formation marching at one shared pace, with low scheduling cost and strong directional consistency.
Illustrative code (structure only, not a specific implementation):
# Pseudocode: core structure of a matrix-based orthogonalized updatedef muon_step(W, G, momentum, beta, lr):# 1) Momentum accumulation (single state only)momentum = beta * momentum + (1 - beta) * G# 2) Orthogonalize the 2D weight matrix (e.g., iterative approximate orthogonalization)U = orthogonalize(momentum)# 3) Apply the update to the whole matrixW = W - lr * Ureturn W, momentum
3. The Key Leap: From Workable on Small Models to Usable at Scale
These methods were initially validated only on small models in the hundreds of millions of parameters, and the skepticism was concentrated in one place: faster convergence at small scale does not guarantee the same stability in real training runs with billions or trillions of parameters and very long sequences. Crossing that threshold requires solving at least four engineering problems.
- Parameter grouping. Apply matrix-level updates only to the 2D weight matrices in hidden layers, while keeping the original adaptive method for embeddings, the output head, normalization parameters, and biases. This balances stability against gains.
- Mixed precision and numerical stability. Orthogonalization involves matrix norm estimation and iterative solving, which is prone to numerical instability at low precision. Higher precision must be preserved in critical accumulation steps, and update magnitudes need normalization constraints.
- Communication efficiency under distributed sharding. Tensor parallelism splits weight matrices, and orthogonalization requires coordination across shards, which introduces extra communication if implemented poorly. In practice, the sharding direction is aligned with the direction of the update computation to reduce synchronization rounds.
- Matching learning rate to spectral norm. The step-size scale of matrix-level updates differs from element-wise methods, so reusing the original learning rate often overshoots. Learning rates need to be calibrated per layer type, together with gradient clipping and warmup.
4. Quantifying the Gains: A Reproducible Accounting Method
Do not stop at conclusions like “half the optimizer state is saved.” A quantitative evaluation is better done in this order:
- Memory accounting: measure parameters, gradients, optimizer state, activations, and temporary buffers separately, and state clearly how much the optimizer-state share drops.
- Throughput metrics: under identical hardware and identical context length, compare per-step time and the achievable batch size.
- Convergence efficiency: use “training steps or total compute required to reach a target loss” as the measure, not a single-step loss curve.
- Stability metrics: record gradient norms, quantiles of update norms, and the frequency of loss spikes.
Illustrative accounting logic:
# Rough memory estimate (in bytes), for comparing approachesdef optimizer_state_bytes(n_params, bytes_per_param, n_state):return n_params * bytes_per_param * n_state# Adaptive methods typically use n_state=2; matrix-based methods typically use n_state=1print(optimizer_state_bytes(1.6e12, 2, 2)) # element-wise adaptiveprint(optimizer_state_bytes(1.6e12, 2, 1)) # matrix-based
5. Adoption Advice and Common Pitfalls
- Pitfall 1: replacing the optimizer everywhere at once. A safer approach is a layered, gradual rollout: enable it on some hidden layers first, watch stability, then widen the scope.
- Pitfall 2: ignoring non-matrix parameters. Normalization and biases are few in number but have a clear effect on training stability, so they should not be converted along with everything else.
- Pitfall 3: looking at memory but not communication. In distributed environments, the synchronization overhead introduced by orthogonalization can offset part of the gains, so end-to-end throughput must be measured.
- Engineering support: complete logging services and monitoring with alerts, with thresholds set for loss spikes and abnormal gradient norms; training data and checkpoints are best placed on object storage for consistent recovery of large-scale parallel jobs; the orchestration layer can rely on a container platform for elastic scaling and failure rescheduling.
6. Conclusion
The value of matrix-based orthogonalized optimizers is not to replace every adaptive method, but to compress optimizer state, a permanent cost, into a more controllable amount, so the memory budget can be reallocated to context length and batch size. For teams preparing long-context training, the recommendation is to start from memory accounting, proceed through a small-scope gradual rollout, and use end-to-end throughput and convergence efficiency as the final criteria. Running on an environment with a container platform, object storage, and monitoring and alerting capabilities, such as Baidu AI Cloud, can further reduce the engineering complexity of distributed training.
