r/MachineLearning • • 6d ago

Discussion Why don't optimizes like Shampoo, SOAP, and Adam measure the actual per sample second moments like the Fischer Information Matrix does? [d]

It always felt unintuitive to me that Muon matched the performance of Shampoo despite dropping the actual second moments L and R.

But I then I realized, Shampoo itself isn't actually measuring the true second moments.

For each sample i in the batch, we have a gradient G_i.

And the gradient we use during SGD is:

G = E(G_i)

The factors of Shampoo are:

L = EMA GG^T

R = EMA G^TG

Whereas, the true second moments are:

L = EMA E(G_i G_i^T)

R = EMA E(G_i^T G_i)

We can also write them as:

D_i = G_i - G

L = EMA (GG^T + E(D_i D_i^T))

R = EMA (G^TG + E(D_i^T D_i))

What shampoo is doing is dropping the covariance terms like E(D_i D_i^T) from the factors.

It's an approximation.

And, Muon does the same thing. It takes things one step further:

M = EMA G

L = MM^T

R = M^TM

Shampoo's factors are

L_C = EMA (G - M) (G - M)^T
R_C = EMA (G - M)^T (G - M)

L = MM^T + L_C

R = M^TM - R_C

Shampoo drops the covariance across the samples in the batch.

Muon drops the covariance across the batches in the optimization path.

Adam does the same thing except it's doing it to the diagonal of the Fischer. It drops the per sample variance terms from its second moment.

These approximations are sufficient when the covariance terms are small enough.

But the strange thing is, when I tried using the actual second factors for Shampoo and Adam, they underperformed compared to their approximate versions...

I don't understand this at all.

37 Upvotes

13 comments sorted by

26

u/trolls_toll 6d ago

because second moment is more expensive than the first one

4

u/Future_Pace_5290 5d ago

And why does the expensive one get outperformed by its approximations? I'm talking about step efficiency not WCT.

2

u/sockb0y 5d ago

Could it be that it is noisier? If the extra moment approximation adds more noise than signal it could lead to worse performance maybe?

Probably everything is dependent on how well-behaved the search space is, so its very likely case dependent.

4

u/Future_Pace_5290 5d ago

Also interesting that Muon only works when you approximate the Fischer matrix by treating each row as a variable and treating each column as a variable, giving you row second moment L and column second moment R, which you approximate as MM^T and M^TM.

If you try to do that with the full Fischer matrix E(gg^T) where g is your gradient flattened, E(g)E(g)^T, you'd just get normalized SGD+Momentum.

1

u/Future_Pace_5290 5d ago

That might be...

I think the EMA GG^T is approximating something very different from the empirical Fischer information matrix E(GG^T).

If we have only 1 batch, it completely stops measuring the sample to sample variance. So you'd expect their performance to downgrade. But in my tests, they still work very well, and methods like SOAP start working even better when you increase the batch size.

2

u/sockb0y 5d ago

I agree they are probably a bit different.

My thinking is that the EMA or any other momentum like behaviours let information cross the batch boundary. Otherwise you are restricted to batch information only. In cases where each batch is truly representative of the global distribution its probably ok, but with very small batches theres a lot of noise introduced because the batch metrics are not representative of the global metrics.

There's a tradeoff between using the slow updating EMA or fitting to the noisy batch stats. Both are 'wrong' in different ways.

1

u/DrXaos 5d ago

Then, it must be that the actual effects are not guided by usual intuition of convex optimization in low dimensions where using a good second moment helps.

If these work on high dimensional all saddle point problems like big nets better than a non approximation then they are working by accident for reasons we don’t know.

At some point, if it hasn’t happened already in frontier labs, is that every possible inexpensive computation based on easily accessible gradients and weights gets explored empirically.

Then someone invents a rationalization post hoc for a paper publication but the reason might be bullshit.

15

u/sqweeeeeeeeeeeeeeeps 5d ago

wow a real post on r/MachineLearning

4

u/DataDiplomat 5d ago

And all you contribute is this

1

u/Technical_Estate_529 5d ago

And all you contribute is this

1

u/DigThatData Researcher 5d ago

the second thing I contributed was this!

1

u/ButterscotchSalty905 Student 5d ago

Username checks out /j

2

u/DigThatData Researcher 5d ago

I think you might be confusing inter-sample covariances with inter-parameter covariances.