Optimizer Selection for Loop Depth Models: A Practical Guide

    This article examines how optimizer choice affects training behavior in Loop Transformers, where shared parameters are reused across multiple computation rounds. It explains why identical learning rates can still produce different update magnitudes, contrasts element-wise adaptive methods such as AdamW with matrix-level approximately orthogonalized methods such as Muon, and presents a practical hybrid configuration. Readers will find guidance on parameter grouping, learning rate tuning, weight decay, gradient clipping, and a two-track evaluation approach that balances fitting speed against retention of previously learned samples.

    1. Starting Point: From Writing Out the Derivation to Running More Internal Rounds

    In supervised fine-tuning, training data often preserves not only the final answer but also the full reasoning process. Training on such data essentially teaches a model to break a problem into intermediate steps and advance through them one by one. This naturally leads to a further idea: if a model can write out a derivation on “paper” as a sequence of tokens, can it run several additional iterations inside a single forward pass before emitting the next token, reusing the intermediate results left by the previous round to make the next prediction more accurate?

    This is the core idea behind the Loop Transformer: trading parameter sharing for “compute depth,” increasing the effective number of computation rounds without a significant increase in parameter count.

    A straightforward setup that is easy to reproduce looks like this:

    • Use a language model backbone of roughly 300 million parameters;
    • Use 4 shared Transformer blocks, each participating in 4 computation rounds;
    • A single forward pass involves 16 block calls in total, but only the weights of these 4 blocks need to be trained.
    1. # Illustration: multi-round loop calls over shared blocks
    2. h = embed(tokens)
    3. for step in range(num_loops): # 4 rounds
    4. for block in shared_blocks: # 4 shared blocks
    5. h = block(h, step=step)
    6. logits = lm_head(h)

    This structure has an easily overlooked consequence: the same set of weights is used repeatedly within a single forward pass, and the gradients produced by each round accumulate onto the same projection matrices. In other words, the projection matrices receive a “superposition of signals from four rounds,” and their gradient statistics differ markedly from those of a conventional stacked network.

    2. The Anomaly: Why the Same Learning Rate Leads to Divergent Behavior

    The experiments surfaced a phenomenon worth digging into. Presenting the same batch of 128 samples repeatedly to the same model, two training schemes behaved in opposite ways on “the problem in front of it” versus “old problems”:

    • Scheme A fit the current 128 samples faster;
    • Scheme B, after training, showed a smaller loss increase on another 32 samples that the model had seen before but did not review in this round.

    Both runs started from the same initial weights and used the same data order, and the learning rate for the projection matrices was set to 5e-5 in both. The difference lay neither in the data nor in the learning rate value itself, but in how the optimizer converted gradients into the actual increments written back to the weights.

    The investigation therefore shifted from model architecture to the optimizer: one scheme used element-wise adaptive optimization (AdamW-style) throughout, while the other handed only the 28 projection matrices to matrix-level optimization (a Muon-style method) and kept the remaining trainable parameters on AdamW. After 200 steps, the all-AdamW scheme achieved lower loss on the 128 samples, while the hybrid scheme showed less loss drift on the held-out review samples.

    3. Mechanism Breakdown: The Fundamental Difference in “Update Magnitude”

    The chain of a training step is fixed: read the prompt and the existing answer prefix, predict the next token; the lower the probability assigned to the reference token, the higher the loss; backpropagation produces a gradient for each weight; when optimizer.step() runs, the optimizer combines the gradient with historical state to write the increment back into the weights. The difference occurs at this last step.

    Element-wise adaptive methods (AdamW-style) maintain two statistics per weight element: a moving average of the gradient, reflecting the recent direction, and a moving average of the squared gradient, used to estimate the typical gradient magnitude for that element and to scale the step size for each element individually. The update is “coordinate-wise” and completely ignores coupling between directions within the weight matrix.

    Matrix-level approximately orthogonalized methods (Muon-style) treat the entire projection matrix as a whole: they first accumulate momentum, then apply approximate orthogonalization to the momentum matrix, suppressing the dominance of a few strong singular directions over the update so that the update is distributed more evenly across the directions of the matrix. The update is “whole-matrix.”

    Key takeaway: the same learning rate does not mean the same update magnitude before multiplying by the learning rate. The single-step displacement produced by matrix-level methods on projection matrices is often larger and more spread across directions than that of element-wise methods. This explains the experimental results: a larger displacement fits the current samples faster but is more likely to overwrite old knowledge, while a more even displacement causes less damage to old knowledge.

    1. # Illustration: configuring optimizers by parameter type
    2. decay, no_decay = [], []
    3. for n, p in model.named_parameters():
    4. (no_decay if p.ndim < 2 else decay).append(p)
    5. optimizer = HybridOptimizer(
    6. [
    7. {"params": projection_matrices, "use_matrix_method": True, "lr": 5e-5},
    8. {"params": other_trainable, "use_matrix_method": False, "lr": 1e-4},
    9. ],
    10. betas=(0.9, 0.95),
    11. weight_decay=0.01,
    12. )

    4. A Practical Hybrid Configuration Approach

    1. Group parameters by semantics rather than hard-coding by layer name. Put 2D projection matrices in their own group, and keep the rest (biases, normalization parameters, embedding-related parameters) on element-wise adaptive optimization.
    2. The learning rate for the matrix group needs to be calibrated independently. Because the single-step update scale differs, reusing the same value directly is prone to imbalance; run a small-scale sweep over the initial learning rate, combined with warmup and cosine decay.
    3. Keep decoupled weight decay, but consider lowering it for the matrix group to avoid excessive shrinkage from stacking it on top of the directional evenness introduced by approximate orthogonalization.
    4. Monitoring metrics should be “dual-track”: look at both training loss and the loss drift on held-out old samples. Looking only at the former leads to the misjudgment that “faster learning is better.”
    5. Pay attention to interactions with the gradient clipping threshold. The gradient of shared weights is accumulated over multiple rounds, so the clipping threshold needs to be rechecked in sync with the optimizer switch.

    5. Common Pitfalls and a Troubleshooting Checklist

    • Pitfall 1: treating the same learning rate as the same update magnitude. Quantify the single-step displacement first (for example, the ratio of the update to the weight norm) before comparing.
    • Pitfall 2: drawing conclusions at only one data scale. Repeated training on a small sample amplifies the forgetting effect, so conclusions need to be re-verified at a larger scale.
    • Pitfall 3: switching all parameters uniformly. The value of a hybrid strategy lies precisely in “changing only the part that should be changed.”
    • Suggested troubleshooting order: confirm the parameter grouping is correct → recheck the learning rate and decay for each group → check gradient accumulation and clipping → align the random seeds and data order of the two schemes → only then look at metric differences.

    6. Summary

    The loop depth structure makes weights reused across multiple rounds, producing gradient statistics unlike those of conventional networks and turning optimizer selection from a “default configuration” into a step that requires explicit design. The practical lesson is that matrix-level approximate orthogonalization and element-wise adaptive optimization each have their own applicable scope; a hybrid configuration by parameter type, evaluated with the dual metrics of “fitting speed + old knowledge retention,” is usually more stable than a one-size-fits-all choice. In related training and inference practice at Baidu AI Cloud, this kind of coordinated tuning of “structure–optimizer–evaluation metrics” applies as well, and can be combined with general capabilities such as container platforms, object storage, and monitoring and alerting to standardize and make the experimental process reproducible.