# Behaviour Manifolds and the Hessian of the Total Loss - Notes and Criticism

In this note I will discuss some computations and observations that I have seen in other posts about "basin broadness/flatness". I am mostly working off the content of the posts [Information Loss --> Basin flatness](https://www.lesswrong.com/posts/wPudaEemohdYPmsye/information-loss-greater-than-basin-flatness) and [Basin broadness depends on the size and number of orthogonal features](https://www.lesswrong.com/posts/EkSvsJkZE8GCeCj7u/basin-broadness-depends-on-the-size-and-number-of-orthogonal-1). I will attempt to give one rigorous and unified narrative for core mathematical parts of these posts and I will also attempt to explain my reservations about some aspects of these approaches. This post started out as a series of comments that I had already made on the posts, but I felt it may be worthwhile for me to spell out my position and give my own explanations. 

  
*Work completed while author was a SERI MATS scholar under the mentorship of Evan Hubinger.*

Basic Notation and Terminology
------------------------------

$$We will imagine fixing some model architecture and thinking about the loss landscape from a purely mathematical perspective. We will not concern ourselves with the realities of training.

Let $\Theta$ denote the *parameter space* of a deep neural network model $f$. This means that each element $\theta \in \Theta$ is a complete set of weights and biases for the model. And suppose that when a set of parameters $\theta \in \Theta$ is fixed, the network maps from an input space $\mathbb{R}^n$ to an output space $\mathcal{O}$. When it matters below, we will take $\mathcal{O} = \mathbb{R}^k$, but for now let us leave it abstract. So we have a function

$$
f : \Theta \times \mathbb{R}^n \to \mathcal{O},
$$

such that for any $\theta \in \Theta$, the function $f(\cdot,\theta) : \mathbb{R}^n \to \mathcal{O}$ is a fixed input-output function implemented by the network.

Let $\mathcal{D} = \bigl\{(x^d,y^d)\bigr\}_{d=1}^D \subset \mathbb{R}^n \times \mathcal{O}$ be a dataset of $D$ training examples.  We can then define a function $F : \Theta \to \mathcal{O}^D$, by $$

$$
F(\theta) = \bigl(f(x^1,\theta),\dots,f(x^D,\theta)\bigr).
$$

This takes as input a set of parameters $\theta$ and returns the *behaviour* of $f(\cdot,\theta)$ on the training data.$$

We will think of the *loss function* as $l : \mathcal{O}^D \to \mathbb{R}$*. *

**Example.**  We could have $\mathcal{D} = \bigl\{ (x^d,y^d) \bigr\}_{d=1}^D$ , $\mathcal{O} = \mathbb{R}^k$ , and

$$
l\bigl(o^1,\dots,o^D\bigr) = \frac{1}{2}\sum_{d=1}^D \bigl\|o^d - y^d\bigr\|^2. \tag{*}
$$

We also then define what we will call the *total* *loss*

$$
\mathcal{L} : \Theta \to \mathbb{R}
$$

by 

$$
\mathcal{L}(\theta) = l\bigl(F(\theta)\bigr) = l\bigl( f(x^1,\theta),\dots,f(x^D,\theta)\bigr).
$$

This is just the usual thing: The total loss over the training data set for a given set of weights and biases. So the graph of $\mathcal{L}$ is what one might call the 'loss landscape'.  
 

Behaviour Manifolds
-------------------

By a *behaviour manifold* (see [\[Hebbar\]](https://www.lesswrong.com/posts/wPudaEemohdYPmsye/#Behavior_manifolds)), we mean a set $\Sigma \subset \Theta$ of the form 

$$
\Sigma = F^{-1}\bigl((o_1,\dots,o_D)\bigr) = \bigl\{ \theta \in \Theta : F(\theta) = (o_1,\dots,o_D)\bigr\}
$$

where $(o_1,\dots,o_D) \in \mathcal{O}^D$ is a tuple of possible outputs. The idea here is that for a fixed behaviour manifold $\Sigma$, all of the models given by parameter sets $\theta \in \Sigma$ have identical behaviour on the training data. 

Assume that $\Theta$ is an appropriately smooth $N$-dimensional space and let us now assume that $\mathcal{O} = \mathbb{R}^k$.

Suppose that $N > kD$. In this case, at a point $\theta \in \Theta$ at which the Jacobian matrix $JF(\theta)$ has full rank, the map $F$ is a submersion. The [*submersion theorem*](https://en.wikipedia.org/wiki/Submersion_(mathematics)#Submersion_theorem) *(*which - in this context - is little more than the implicit function theorem*)* tells us that given $o \in \mathcal{O}^D$, if $F$ is a submersion in a neighbourhood of a point $\theta \in F^{-1}(o)$, then $F^{-1}(o)$ is a smooth $(N-kD)$-dimensional submanifold in a neighbourhood of $\theta$ . So we conclude that in a neighbourhood of a point in parameter space at which the Jacobian of $F$ has full rank, the behaviour manifold is an $(N-kD)$-dimensional smooth submanifold. 

### Reservations

Firstly, I want to emphasize that when the Jacobian of $F$ does not have full rank, it is generally difficult to make conclusions about the geometry of the level set, i.e. about the set that is called the behaviour manifold in this setting.  

**Examples.** The following simple examples are to emphasize that there is ***not** a* straightforward intuitive relationship that says "when the Jacobian has less than full rank, there are fewer directions in parameter space along which the behaviour changes and therefore the behaviour manifold is bigger than $(N-kD)$-dimensional":

1.  Consider $g : \mathbb{R}^2 \to \mathbb{R}$ given by $g(x,y) = x^2 + y^2$. We have $\nabla g = (2x,2y)$. This has rank 1 everywhere except the origin: At the point $(0,0)$ it has less than full rank. And at that point, the level set is just a single point, i.e. it is 0-dimensional.
2.  Consider $h : \mathbb{R}^2 \to \mathbb{R}$ given by $h(x,y) = x^2.$ We have $\nabla h = (2x,0)$. Again, this has less than full rank at the point $(0,0).$ And at that point, the level set is the entire $y$-axis, i.e. it is 1-dimensional.
3.  Consider $j : \mathbb{R}^2 \to \mathbb{R}$ given by $j(x,y) = 1.$ We of course have $\nabla j = (0,0)$. This has less than full rank everywhere, and the only non-empty level set is the entire of $\mathbb{R}^2$, i.e. 2-dimensional.

**Remark.** We note further, just for the sake of intuition about these kinds of issues, that the geometry of the level set of a smooth function can in general be very bad: *Every* closed subset is the zero set of some smooth function, i.e. given *any* closed set $C \subset \mathbb{R}^n$ , there exists a smooth function $g : \mathbb{R}^n \to \mathbb{R}$ with $C = \{x \in \mathbb{R}^n : g(x) = 0\}.$ Knowing that a level set is closed is an extremely basic fact and yet without using specific information about the function you are looking at, you cannot conclude *anything* else. 

Secondly, the use of the submersion theorem here only makes sense when $N > kD$. But this is not even commonly the case. It is common to have many more data points (the $D$) than parameters (the $N$), ultimately meaning that the dimension of $\mathcal{O}^D$ is much, much larger than the dimension of the domain of $F$. This suggests a slightly different perspective, which I briefly outline next.

### Behavioural Space

When the codomain is a higher-dimensional space than the domain, we more commonly picture the *image* of a function, as opposed to the graph, e.g. if I say to consider a smooth function $g : \mathbb{R} \to \mathbb{R}^2$, one more naturally pictures the curve $g(\mathbb{R})$ in the plane, as a kind-of 'copy' of the line $\mathbb{R}$, as opposed to the graph of $g$. So if one were to try to continue along these lines, one might instead imagine the *image* $F(\Theta)$ of parameter space *in* the *behaviour space* $\mathcal{O}^D.$ We think of each point of $\mathcal{O}^D$ as a complete specification of possible outputs on the dataset. Then the image $F(\Theta) \subset \mathcal{O}^D$ is (loosely speaking) an $N-$dimensional submanifold of this space which we should think of as having large codimension. And each point $F(\theta)$ on this submanifold is the outputs of an actual model with parameters $\theta$. In this setting, the points $\theta \in \Theta$ at which the Jacobian $JF(\theta)$ has full rank map to points $F(\theta) \in F(\Theta)$ which have neighbourhoods in which $F(\Theta)$ is smooth and embedded.  
 

The Hessian of the Total Loss
-----------------------------

A computation of the Hessian of $\mathcal{L}$ appears in both [Information Loss --> Basin flatness](https://www.lesswrong.com/posts/wPudaEemohdYPmsye/information-loss-greater-than-basin-flatness) and  [Basin broadness depends on the size and number of orthogonal features](https://www.lesswrong.com/posts/EkSvsJkZE8GCeCj7u/basin-broadness-depends-on-the-size-and-number-of-orthogonal-1), under slightly different assumptions. Let us carefully go over that computation here, in a slightly greater level of generality. We continue with $\mathcal{O} = \mathbb{R}^k$, in which case $\mathcal{O}^D = \mathbb{R}^{k\times D}$.  The function we are going to differentiate is:

$$
\mathcal{L}(\theta) = l\bigl(F(\theta)\bigr) = l\bigl(f(x^1,\theta),\dots,f(x^D,\theta)\bigr).
$$

And since each $f(x^d,\theta) \in \mathbb{R}^k$ for $d = 1,\dots,D$, we should think of $F(\theta)$ as a $k\times D$ matrix, the general $(p,d)^{th}$entry of which is $f^p(x^d,\theta)$.

We want to differentiate twice with respect to $\theta$. Firstly, we have 

$$
\frac{\partial}{\partial \theta_i} \mathcal{L}(\theta) = \sum_{p=1}^k\sum_{d=1}^D \nabla^{(p,d)} l\bigl(F(\theta)\bigr)\cdot \frac{\partial f^p(x^d,\theta)}{\partial \theta_i}
$$

for $i=1,\dots,N$. 

Then for $j = 1,\dots,N$ we differentiate again:

$$
\frac{\partial^2}{\partial \theta_j\partial\theta_i} \mathcal{L}(\theta) = \sum_{p,q=1}^{k} \sum_{d,d'=1}^{D}\nabla^{(q,d')}\nabla^{(p,d)} l\bigl(F(\theta)\bigr)\frac{\partial f^q(x^{d'},\theta)}{\partial \theta_j}\, \frac{\partial f^p(x^d,\theta)}{\partial \theta_i}
$$

$$
+ \sum_{p=1}^{k}\sum_{d=1}^D\nabla^{(p,d)}l\bigl(F(\theta)\bigr)\, \frac{\partial^2 f^p(x^d,\theta)}{\partial\theta_j\partial \theta_i}. \tag{1}
$$

This is now an equation of $(N \times N)$ matrices.

### At A Local Minimum of The Loss Function

If $\theta$ is such that $F(\theta)$ is a local minimum for $l$ (which means that the parameters are such that the output of the network on the training data is a local minimum for the loss function), then the second term on the right-hand side of (1) vanishes (because the term includes the first derivatives of $l$, which are zero at a minimum). Therefore: If $F(\theta^*)$ is a local minimum for $l$ we have: 

$$
\frac{\partial^2}{\partial \theta_j\partial\theta_i} \mathcal{L}(\theta^*) = \sum_{p,q=1}^{k} \sum_{d,d'=1}^{D}\nabla^{(q,d')}\nabla^{(p,d)} l\bigl(F(\theta^*)\bigr)\frac{\partial f^q(x^{d'},\theta^*)}{\partial \theta_j}\, \frac{\partial f^p(x^d,\theta^*)}{\partial \theta_i}.
$$

If, in addition, the Hessian of $l$ is equal to the identity matrix (by which we mean $\nabla^{(q,d')}\nabla^{(p,d)}l = \delta_{pq}\delta_{dd'}$ \- as is the case for the example loss function given above in (*)), then we would have:

$$
\frac{\partial^2}{\partial \theta_j\partial\theta_i} \mathcal{L}(\theta^*) = \sum_{p=1}^{k} \sum_{d=1}^{D}\frac{\partial f^p(x^{d},\theta^*)}{\partial \theta_j}\, \frac{\partial f^p(x^d,\theta^*)}{\partial \theta_i}
$$

$$
\qquad \qquad  = \sum_{d=1}^{D}\frac{\partial f(x^{d},\theta^*)}{\partial \theta_i}\,\cdot \frac{\partial f(x^d,\theta^*)}{\partial \theta_j}. \tag{2}
$$

### Reservations

In [Basin broadness depends on the size and number of orthogonal features](https://www.lesswrong.com/posts/EkSvsJkZE8GCeCj7u/basin-broadness-depends-on-the-size-and-number-of-orthogonal-1), the expression on the right-hand side of equation (2) above is referred to as an inner product of "the features over the training data set". I do not understand the use of the word 'features' here and in the remainder of their post. The phrase seems to imply that a function of the form

$$
x^d \longmapsto \frac{\partial f(x^d,\theta^*)}{\partial \theta_j},
$$

defined on the inputs of the training dataset, is what constitutes a feature. No further explanation is really given. It's completely plausible that I have missed something (and perhaps other readers do not or will not share my confusion) but I would like to see an attempt at a clear and detailed explanation of exactly how this notion is supposed to be the same notion of feature that (say) Anthropic use in their interpretability work (as was claimed to me).

  
Criticism
------------

I'd like to tentatively try to give some higher-level criticism of these kinds of approaches. This is a tricky thing to do, I admit; it's generally very hard to say that a certain approach is unlikely to yield results, but I will at least try to explain where my skepticism is coming from. 

The perspective and the computations that are presented here (which in my opinion are representative of the mathematical parts of the linked posts and of various other unnamed posts) do not use any significant facts about neural networks or their architecture. In particular, in the mathematical framework that is set up, the function $f$ is more or less just any smooth function. And the methods used are just a few lines of calculus and linear algebra applied to abstract smooth functions. If these are the principal ingredients, then I am naturally led to expect that the conclusions will be relatively straightforward facts that will hold for more or less any smooth function $f$.

Such facts may be useful as part of bigger arguments - of course many arguments in mathematics do yield truly significant results using only 'low-level' methods - but in my experience one is extremely unlikely to end up with significant results in this way without it ultimately being clear after the fact where the hard work has happened or what the significant original insight was. 

So, naively, my expectation at the moment is that in order to arrive at better results about this sort of thing, arguments that start like these ones do must quickly bring to bear substantial mathematical facts *about* the network, e.g. random initialization, gradient descent, the structure of the network's layers, activations etc. One has to actually *use* *something.* I feel (again, speaking naively) that after achieving more success with a mathematical argument along these lines, one's hands would look dirtier. In particular, for what it's worth, I do not expect my suggestion to look at the image of the parameter space in 'behaviour space' to lead (by itself) to any further non-trivial progress. (And I say 'naively' in the preceding sentences here because I do not claim myself to have produced any significant results of the form I am discussing).  
  
  
$$