The optimizer that orthogonalizes its update
Row normalization makes every row short, but it does not remove the correlations that let one direction dominate a matrix update.
What’s going wrong
Original LLM Architecture lab. This is a small, standard-library model of the Muon update and a norm cap inspired by MuonClip. It is not a training run, a distributed optimizer or a reproduction of a framework implementation.
Muon treats a weight matrix as a matrix. It accumulates momentum, orthogonalizes the buffer with a Newton-Schulz iteration, and scales the result by the learning rate. The starter normalizes each row independently. That controls row length but leaves the row correlations intact, so the update can still concentrate in one direction. Repair the orthogonalization and the optional cap.
Read one JSON object with gradient, momentum, momentum_beta, learning_rate, ns_steps and max_update_norm. gradient and momentum are m by n arrays with m and n from 1 to 4; values are finite with at most three decimal places. momentum_beta is in [0,1], learning_rate is in [0.001,1], ns_steps is an integer from 0 to 6, and max_update_norm is null or a number greater than 0. Inputs satisfy the stated bounds. Use only the Python standard library and print one JSON object. Round every returned number with round(value, 6) and print 0.0 for any value that rounds to zero. Inputs satisfy this contract.
Build buffer[i][j] = momentum_beta * momentum[i][j] + gradient[i][j]. Let norm = sqrt(sum(buffer[i][j] * buffer[i][j])). If norm is zero, X is the zero matrix; otherwise X[i][j] = buffer[i][j] / norm. Repeat ns_steps times: gram[i][j] = sum(X[i][k] * X[j][k] for k in range(n)); product[i][j] = sum(gram[i][k] * X[k][j] for k in range(m)); then X[i][j] = 1.5 * X[i][j] - 0.5 * product[i][j]. Set update[i][j] = learning_rate * X[i][j]. If max_update_norm is not null, compute the Frobenius norm of update; when it is greater than the cap, multiply every update entry by cap / norm and set clipped to true. Print {"update":[[...]],"next_momentum":[[...]],"clipped":false}. The momentum field is the buffer before orthogonalization, not the orthogonalized X.
Expected behavior
Orthogonalize the momentum buffer with the stated Newton-Schulz iteration, return the scaled update and the carried momentum, and apply the optional norm cap deterministically.
Reproduction
Execution evidence
Simulated system · deterministic replay
Fixed 2x2 and rectangular buffers. No autograd, GPU or distributed optimizer is used.
- 01Buffer
gradient [[1,2],[3,4]] with zero momentum.
- 02Starter
Each row is divided by its own norm, producing rows of length one but a correlated matrix.
- 03Reference
The Frobenius-normalized buffer is orthogonalized by the Newton-Schulz iteration.
- 04Cap
A separate case scales an oversized update to the requested norm.
Explain your repair before submitting
Which observation contradicts the intended behavior? Where does the code break that contract? Explain why your change fixes the cause and which new regression case would detect it.
This evidence describes the starter. Use Run to observe your current code; Submit checks additional regressions. No live model calls are made.
{"gradient":[[1,2],[3,4]],"momentum":[[0,0],[0,0]],"momentum_beta":0.0,"learning_rate":0.1,"ns_steps":3,"max_update_norm":null}{"update":[[0.006653,0.044803],[0.060046,0.069563]],"next_momentum":[[1.0,2.0],[3.0,4.0]],"clipped":false}{"gradient":[[0,0],[0,0]],"momentum":[[0,0],[0,0]],"momentum_beta":0.9,"learning_rate":0.1,"ns_steps":5,"max_update_norm":null}{"update":[[0.0,0.0],[0.0,0.0]],"next_momentum":[[0.0,0.0],[0.0,0.0]],"clipped":false}{"gradient":[[1,2,3],[4,5,6]],"momentum":[[0,0,0],[0,0,0]],"momentum_beta":0.0,"learning_rate":0.1,"ns_steps":2,"max_update_norm":null}{"update":[[0.003105,0.020001,0.036898],[0.045174,0.05302,0.060866]],"next_momentum":[[1.0,2.0,3.0],[4.0,5.0,6.0]],"clipped":false}Before you begin
- Matrix multiplication and the Frobenius norm
- The idea of a singular value and why equalizing directions changes an update
- Python loops, list comprehensions and stable floating-point ordering
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.