Log-mean-exp in attention mysteriously works

My better idea mysteriously doesn't work


The weighted mean is done in exp space.

Attention is o=∑jwjvjo = \sum_j w_j v_j, with softmax weights wjw_j and values vjv_j. log-mean-exp works better:

o=log⁡∑jwjevjo = \log \sum_j w_j e^{v_j}

On a small pixel image model, it matches a model with 3% ± 0.3% more parameters: it has 0.06% ± 0.006% lower loss, 0.8% ± 0.07% slower steps.

On modded-nanoGPT track 3, it achieves 0.0062 lower loss and is a bit slower.

Wider models will slow down less.

Theory

Values in attention have redundant symmetry: transforming WVW_V and counter-transforming WOW_O produces an equivalent network. To fix this inefficiency, my idea was:

o=f(∑jwjg(vj))o = f \Bigl(\sum_j w_j g(v_j)\Bigr)

for nonlinear functions ff and gg. I did not have a good guess for the optimal ff and gg, so I made them learnable.

This is a much better idea than log-mean-exp values, which are the special case f=log⁡f = \log and g=exp⁡g = \exp.

I asked Opus 5.5 to come up with flexible channelwise nonlinearities and look through the literature. It produced many terrible ideas which I allowed to run (I have a lot of compute). It failed to include learnable polynomial and Padé activations; I had to request them. The only improvement was log-mean-exp values, one of the terrible ideas, which Claude found in the LASER paper.

A recurring failure

If log-mean-exp works, why can’t learnable polynomials find it? They’re universal approximators. Isn’t that what gradient descent is all about?

Maybe my experiment sucks, since it was driven by Claude. I vouch for the baseline, but I haven’t checked Claude’s experiment code.

I briefly tuned the LR with no success. Forcing f=g−1f=g^{-1} with Padé doesn’t help. Maybe I need a higher-order polynomial approximation; I used order 5 out of stability fears. (Log-mean-exp is special since the exp is stabilized by the corresponding log.) If the learnable nonlinearity is started halfway to log-mean-exp, it slowly approaches log-mean-exp but never reaches it, and the loss is also worse.

But learnable MLP activations are also not used in practice. One expects to be able to learn some optimal MLP activation, which could be reused. Nobody has publicly solved this in a convincing way. I hope it’s not required to brute-force every imaginable activation combination.

Technical details

exp’s range causes numerical problems, but your Claude can handle it, so no need to discuss it here.

You want a fused kernel.

Credit assignment

Credit is intended to figure out someone’s potential for future ideas, or to incentivize coming up with such ideas.

My idea was the flexible nonlinearities; none of them worked.

Claude struggles to do original ML research—it only found log-mean-exp because I told it where to search the literature.

The LASER paper is indistinguishable from all the other architecture papers that don’t work. Their theory of gradient magnitude doesn’t make sense, and their Figure 6 shows their baseline is broken. Maybe a genius could have seen that log-mean-exp would work, but Claude tried it out of ignorance rather than insight.

All three—me, Claude, LASER—were necessary to discover this result. But we are just monkeys on typewriters; you wouldn’t expect further results from us.

Credit for this result goes to my large blob of compute. It allows me to say yes to all of my AI’s dumb ideas, so we monkeys can type really fast.

Future work

It’s only worth 3% more parameters. There are nearby ideas for nonlinearities which are likely better. For example, swish-gated attention breaks symmetry, although it likely underperforms. Note that redundant symmetry isn’t the right explanation for log-mean-exp, since it removes 0.23% redundant dimensions, which is less than 3%. The right explanation is just improved expressivity. Maybe it helps on linear attention variants.

These small improvements are only honestly discoverable on a good baseline; otherwise you get [current sea of architecture papers].

To discuss this article: EleutherAI discord, or email me at kevin+lme@anlatan.ai.