← All writing

Optimizers · Reverse engineering

Reverse engineering DiMuon through a training API

A hidden optimizer, a programmable LoRA adapter, and a symmetry trick that made the update rule fall out.

On this page

Thinking Machines released DiMuon, a LoRA optimizer available through Tinker, without publishing its update equations. I tried to recover them using only the API.

I ended up with a local reconstruction that replayed four batches of SST2 gradients with every recovered FP16 polar-output value matching. That experiment used rank-one LoRA on Qwen3-8B's output projection, with gradients measured at Tinker's weights.

The rule: scale, polar, scale again#

Muon takes a momentum matrix and approximately makes its nonzero singular values equal. This stops the largest singular direction from dominating the update.

The interesting addition in DiMuon is a row-and-column sandwich. The previous momentum determines which rows and columns to scale. Apply that scaling before Muon's polar transform, then apply it again afterward.

The geometryScale. Balance. Scale again.
01ScaleStretch the two axes differently.
02PolarBring their lengths back together.
03Scale againThe same preference reappears.
Old momentum chooses the row and column multipliers. Apply them on both sides of polar, then normalize the update length.

A diagonal example with ideal polar. Each ellipse shows how the matrix stretches a circle.

Rows and columns with stronger old momentum get smaller multipliers. The two LoRA matrices—the wide A and tall B—get the same final update norm.

The scaling statistics are cheap to compute from the momentum the optimizer already keeps.

The trick: turn the model into a linear system#

LoRA learns a weight change BA: A compresses an input into a few coordinates, and B expands it back out. The original model weight stays frozen.

At initialization, B = 0. Put that adapter on the output projection, and the transformer supplies a fixed feature h. The trainable addition to the logits is just sBAh. From B's perspective, an eight-billion-parameter language model has become a linear system.

The loss simplifies too. Cross-entropy contains a shared log-sum-exp term; signed token weights that sum to zero cancel it. What's left is a linear combination of logits.

Now I could construct useful gradient patterns instead of hoping ordinary text would produce them. To read those gradients back, I borrowed Martin Marek's large-epsilon Adam trick: choose an invertible optimizer step, download the weights, and undo the step mathematically. Adam became my gradient meter.

Making the unknown cancel#

I wanted to know whether DiMuon scaled the matrix after the polar transform. But I hadn't reproduced that transform precisely yet.

So I chose a gradient that made two axes equal at its input. Symmetry forces the polar computation to treat them equally. Their common response cancels when you take the output ratio—leaving the post-scaling exposed.

The experiment at a glanceEqual inputs to polar. Unequal outputs after it.
  1. Match the two axesChoose the gradient so pre-scaling makes them equal.
  2. Let polar actSymmetry gives both axes the same response.
  3. Read the ratioCommon gains cancel. Post-scaling is what remains.
Predicted 1.99970010Measured 1.99970013

The shared polar response cancels out of the ratio. Only the post-scaling remains.

The predicted ratio agreed with the API to about eight significant figures.

A second simple experiment explained where the scaling came from: build history with learning rate zero, then set beta to zero for the measured step. The current momentum forgets the past, yet the update still changes. The old momentum is doing a second job: choosing the row and column scaling.

Same math, different program#

The numerics turned into a second puzzle: which way of computing the same equation matched the API? Three details stood out.

Rearrange the polynomial#

Each polar stage applies a polynomial to the working matrix X. Here R = XᵀX, I is the identity, and a, b, c are that stage's coefficients. I initially evaluated it in expanded form. Switching to Horner form made the difference:

Same polynomial · different roundingMove the work into the small matrix.
Expanded
aX+X(bR+cR2)aX + X(bR + cR^2)
Horner
X[aI+R(bI+cR)]X\bigl[aI + R(bI + cR)\bigr]

Everything inside the brackets is rank × rank. Only the final multiplication touches the large X matrix again.

The coefficients stayed the same. The rearranged version matched all eleven of my retained numerical fingerprints.

This is a natural optimization for LoRA: X is tall and skinny, while R is only rank × rank. Folding the aX term into the small matrix avoids a separate multiply-and-add over the entire large matrix. It also changes where rounding happens. The algebra alone doesn't tell you which program ran.

Catch an intermediate being rounded#

Inside the Horner calculation, cR gets rounded to FP16 before adding bI. Keeping that intermediate in higher precision gives a different answer.

I made two inputs specifically to distinguish those implementations. Skipping the FP16 store missed their tiny output ratios by about 20% and 4.6%; including it matched both to roughly 4 × 10⁻⁸ relative error.

That's a surprisingly specific thing to learn through an API. A low-precision tensor operation naturally leaves this kind of trace: the result gets stored before the next operation reads it. “More accurate” arithmetic erased the trace I was trying to reproduce.

Let the GPU split up the work#

One CPU replay still differed by 0.79%. Native FP16 matrix products on an H100 brought that case to roughly 8 × 10⁻⁸. The first Gram matrix differed by just one FP16 rounding step; the polynomial amplified it.

Profiling my GPU replay exposed a useful reason: split-K. The GPU divides a long dot product into chunks, computes them in parallel, then combines the partial sums. That helps keep it busy when the output matrix is tiny—exactly the shape LoRA produces. cuBLAS allows those partial sums to be stored in FP16, adding another rounding boundary.

Inside the GPUOne long sum. Several parallel workers.
A long dot product
Worker A
Σ · · ·
FP16 store
Worker B
Σ · · ·
FP16 store
Worker C
Σ · · ·
FP16 store
Σ Combine the rounded partial sums
Parallel work keeps the GPU busy. Storing each partial sum adds a rounding boundary before the final sum.

Split-K illustrated with three workers. The split count depends on the execution backend.

I could reproduce two of my GPU execution paths by changing only the split count and partial-sum precision. That parallelization choice left a visible signature in the optimizer's output.

Run the four-step replay on GitHub · Update equations and experiment details → · Replay data →