# How to Better Report Sparse Autoencoder Performance

TL;DR
-----

When presenting data from SAEs, try plotting $1/L0$ against $1-\mathrm{Recovered Loss}$ and fitting a Hill curve.

![undefined](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Hill-Langmuir_equation.svg/1920px-Hill-Langmuir_equation.svg.png)

From Wikipedia

Long
====

Sparse autoencoders are hot, people are experimenting. The typical graph for SAE experimentation looks something like this. I'm using borrowed data here to better illustrate my point, but I have also noticed this pattern in my own data:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/2b2cd0c29d88c45d4e69a6728ddaff725b6815845a33707a.png)

*Data taken with permission from DeepMind's Gated AutoEncoder paper* [*https://arxiv.org/pdf/2404.16014,*](https://arxiv.org/pdf/2404.16014,) *Tables 3 and 4,  Standard SAE and Gated SAE performance, Gemma-7B Residual Layer 20, 1024 tokens,  pareto-optimal SAEs only*

Which shows quantitative performance adequately in this case. However it gets a bit messy when there are 5-6 plots very close to each other (e.g. in an ablation study), and doesn't give an easily-interpreted (heh) value to quantify pareto improvements.

I've found it much more helpful to to plot $\mathrm{Sparsity} = 1/\mathrm{L0}$ on the $x$-axis, and "performance hit" (i.e. $1 - \mathrm{Loss Recovered}$ i.e. $(\mathcal L_{\mathrm{SAE}} - \mathcal L_\mathrm{base}) / (\mathcal L_\mathrm{mean} - \mathcal L_\mathrm{base})$ where "mean" is mean-ablation and "base" is the base model loss.

I think some people instead calculate the loss when all features are set to zero, instead of strictly doing the mean ablation loss, but these are conceptually extremely similar.

If we re-plot the data from above we get this:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/752b187f2cd052f92fb02faf2fc039c5a3fdce932c41882f.png)

While I've used linear fits here, I don't think these are optimal for two reasons, one is that they obviously go through (0,0) so it seems silly to let the intercept vary. The other is described later.

This lets us say something like "In this case, gated SAEs outperform baseline SAEs by a factor of around 2.7 as measured by Performance Hit/Sparsity".

One might want to use a dimensionless sparsity measure, relative to the dimension of the stream from the base model that we are encoding. I don't know whether this would actually enable comparisons between wildly different model sizes.

Of course as $\mathrm{Sparsity} \to \infty$, Performance Hit won't approach infinity, instead we would expect it to approach 1 (and if you run an autoencoder with $\lambda_{L1} = 100$ you will in fact see this). This could be modelled with a the following equation:

$y = \frac {x}{x + x_{1/2}}$

Where $x_{1/2}$ is the value of $x$ at which $y = 1/2$. Near $x = 0$ it looks like $y = \frac 1{x_{1/2}} x$, but it flattens off as $x$ gets larger. In biology this is a Hill curve with Hill coefficient $1$. It has just one free parameter, so even for small datasets (such as a pareto-frontier of four SAEs) it's possible to get a valid fit.

What about MLP/Attention?
-------------------------

In these cases, we get a better fit with letting the Hill coefficient vary:

$y = \frac {x^k}{x^k + x^k_{1/2}}$

Attention:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/fe70d8f0ab067acd7f81b3a6d17e3f33b8612cc5cd178909.png)MLP:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/6006ad4779c08fa509d8b7613e126fe1025c4f66290bf98c.png)

These *kind of* look like a good fit for the Hill equation with variable Hill coefficients, but they also *kind of* just look like linear fits with non-zero intercept in some cases. It's difficult to tell (also they *kind of* look like regular power fits of the form $y = a x^k$) I'll plot the first graph with a Hill curve for completion:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/1a0b270badfe39a1ae4cf7e8d56c885c41c014e19712dedb.png)

If we consider the relative values of $x_{1/2}$ and $k$ for gated vs baseline SAEs, we can start to see a pattern:

|     | Baseline $x_{1/2}$ | Baseline $k$ | Gated $x_{1/2}$ | Gated $k$ | $x_{1/2}$ ratio | $k$ ratio |
| --- | --- | --- | --- | --- | --- | --- |
| Residual | 1.04 | 1.01 | 6.28 | 0.816 | 6.0 | 1.2 |
| MLP | 1.16 | 0.461 | 7.29 | 0.383 | 6.3 | 1.2 |
| Attention | 0.256 | 0.826 | 1.28 | 0.6 | 5.0 | 1.4 |

So in this case we might want to say "Gated SAEs increase $x_{1/2}$ by a factor of around 5-6 and decrease $k$ by a factor of around 1.3 across the board, as compared to baseline SAEs".

What about $k>1$?
-----------------

In some of my own data, I've noticed that it sometimes looks like we have $k > 1$. These are some results I have from some quick and dirty $\mathrm{Residual}\to\mathrm{Residual}$ transcoders.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/19f5578d6c83ff3192ab09139a388d70dd00ebf2362b7014.png)

Ignore the specifics, like how some have <0 performance hit.

Some of these look more like quadratics, and trying to interpret them as linear plots with non-zero fit seems wrong here!

Conclusions
===========

So we have three options for fitting Performance/Sparsity graphs

1.  $y = mx+c$: This has two fitted parameters except when $c \approx 0$. This is the "simplest" plot in the sense that it's an obvious first choice. Fails to capture our expectation that the plot passes through the origin, and also fails to capture our expectation that the plot levels off at high sparsity.
2.  $$$y = ax^k$: Two fitted parameters except when $k \approx 1$. This is more unusual than the first plot. Always passes through the origin but doesn't level off at high sparsity.
3.  $y = \frac {x^k}{x_{1/2}^k + x^k}$: Two fitted parameters except when $k \approx 1$. This both passes through the origin and levels off, but is a slightly weird function.

I plan to use option 3 (the Hill equation) to report my own data where I can, since the added weirdness seems worth the theoretical considerations, especially since I often get very high-sparsity SAEs when scanning various L1 coefficients, which would break an automated fitting system.

I also think that a value of $x_{1/2}$ in the Hill equation is slightly easier to interpret than a value of $a$ from option 2, though I admit neither is as easy to interpret as $m,c$ from a linear plot.