SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Georg Bokman Fredrik Kahl
Chalmers University of Technology
{bokman, fredrik.kahl}@chalmers.se
Many data symmetries can be described in terms of group equivariance and the most common way of encoding group equivariances in neural networks is by building linear layers that are group equivariant. In this work we investigate whether equivariance of a network implies that all layers are equivariant. On the theoretical side we find cases where equivariance implies layerwise equivariance, but also demonstrate that this is not the case generally. Nevertheless, we conjecture that CNNs that are trained to be equivariant will exhibit layerwise equivariance and explain how this conjecture is a weaker version of the recent permutation conjecture by Entezari et al. [2022]. We perform quantitative experiments with VGG-nets on CIFAR10 and qualitative experiments with ResNets on ImageNet to illustrate and support our theoretical findings. These experiments are not only of interest for understanding how group equivariance is encoded in ReLU-networks, but they also give a new perspective on Entezari et al.'s permutation conjecture as we find that it is typically easier to merge a network with a group-transformed version of itself than merging two different networks.
Understanding the inner workings of deep neural networks is a key problem in machine learning and it has been investigated from many different perspectives, ranging from studying the loss landscape and its connection to generalization properties to understanding the learned representations of the networks. Such an understanding may lead to improved optimization techniques, better inductive biases of the network architecture and to more explainable and predictable results. In this paper, we focus on ReLU-networks—networks with activation function  $\operatorname{ReLU}(x) := \max(0, x)$ —and how they encode and learn data symmetries via equivariance.
Equivariances can be built into a neural network by design. The most classical example is of course the CNN where translational symmetry is obtained via convolutional layers. Stacking such equivariant layers in combination with pointwise ReLU activations results in an equivariant network. We will pursue a different research path and instead start with a neural network which has been trained to be equivariant and ask how the equivariance is encoded in the network. This approach in itself is not new and has been, for instance, experimentally explored in [24] where computational methods for quantifying layerwise equivariance are developed. We will shed new light on the problem by deriving new theoretical results when network equivariance implies layerwise equivariance. We will also give counterexamples for when this is not the case. Another insight is obtained via the recent conjecture by Entezari et al. [13] which states that networks with the same architecture trained on the same data are often close to each other in weight space modulo permutation symmetries of the network weights. Our new conjecture 3.2 which we derive from the conjecture of Entezari et al. states that most SGD CNN solutions will be close to group equivariant CNNs (GCNNs).
Figure 1: Illustration of how a VGG11 encodes the horizontal flipping symmetry. The 64 filters in the first convolutional layer of two VGG11-nets trained on CIFAR10 are shown, where each filter is next to a filter in the same net which after horizontally flipping the filter results in a similar convolution output. The order of the filters in the right columns is a permutation of the original order in the left columns. This permutation is obtained with the method in Figure 2, i.e., the columns here correspond to 1. and 4. there. Net A is trained with an invariance loss to output the same logits for horizontally flipped images. It has learnt very close to a GCNN structure where each filter in the first layer is either horizontally symmetric or has a mirrored twin. Net B is trained with horizontal flipping data augmentation. This net is quite close to a GCNN structure, but the mirrored filters are less close to each other than in Net A. More details are given in Section 4.
Figure 2: Permutation aligning horizontally flipped filters.
1. The three original filters in a convolutional layer.
2. The three filters flipped horizontally.
3. Permutation of the flipped filters to align them with the originals.
This permutation is found using activation matching following [25].
4. Flipping the filters back to their original form for illustration.
Our theoretical results and new conjecture are also validated with experiments. We focus exclusively on the horizontal flipping symmetry in image classification, for the following three reasons: 1. Horizontal flipping is ubiquitously assumed to not change the class of an image and horizontal flipping data augmentation is in practice always used. 2. The group of horizontal flips  $(S_2)$  is small and has simple representation theory. 3. As we study ReLU as activation function, if a network is layerwise equivariant, then the representations acting on the feature spaces must be permutation representations as we shall prove later (cf. Section 2.1).
The experiments show that networks trained on CIFAR10 and ImageNet with horizontal flipping data augmentation are close to GCNNs and in particular when we train networks with an invariance loss, they become very close to GCNNs. This is illustrated in Figure 1 and also discussed in Section 4. As further support of our main conjecture, we find that the interpolation barrier is lower for merging a ResNet50 with a flipped version of itself than the barrier for merging two separately trained ResNet50's. In summary, our main contribution is a new conjecture on how ReLU-networks encode symmetries which is supported by both theory and experiments.
Group equivariant neural networks. The most common approach to encoding group symmetries into neural networks is by designing the network so that each layer is group equivariant [41, 14]. This has been done for many groups, e.g., the permutation group [43, 27] and the 2D or 3D rotation group [39, 34, 16, 4, 37]. Another possibility is to use symmetry regularization during training [32]. Group
equivariant nets have many possible applications, for instance estimating molecular properties [31] or image feature matching [3]. For this paper, the most relevant group equivariant nets are so-called GCNNs acting on images, which are equivariant to Euclidean transformations [10, 42, 2, 40, 38]. In the experiments in Section 4 we will investigate how close to GCNNs ordinary CNNs are when they are trained to be equivariant—either by using an invariance loss or by using data augmentation.
Measuring layerwise equivariance. [24] measure layerwise equivariance by fitting linear group representations in intermediate feature spaces of networks. Our approach is similar but we restrict ourselves to permutation representations and consider fitting group representations in all layers simultaneously rather than looking at a single layer at a time. We explain in Section 2.1 why it is enough to search for permutation representations, given that we have a network with ReLU activation functions. [5] measure layerwise equivariance by counting how many filters in each layer have group-transformed copies of themselves in the same layer. They find that often more layerwise equivariance means better performance. Our approach explicitly looks for permutations of the filters in each layer that align the filters with group-transformed versions of themselves. We are thus able to capture how close the whole net is to being a GCNN. [29] find evidence for layerwise equivariance using a qualitative approach of visualizing filters in each layer and finding which look like group-transformed versions of each other. [20] measure local layerwise equivariance, i.e., layerwise robustness to small group transformations, by computing derivatives of the output of a network w.r.t. group transformations of the input. They interestingly find that transformers can be more translation equivariant than CNNs, due to aliasing effects in CNN downsampling layers.
Networks modulo permutation symmetries. [25] demonstrated that two CNNs with the same architecture trained on the same data often learn similar features. They did this by permuting the filters in one network to align with the filters in another network. [13] conjectured that it should be possible to permute the weights of one network to put it in the same loss-basin as the other network and that the networks after permutation should be linearly mode connected. I.e., it should be possible to average ("merge") the weights of the two networks to obtain a new network with close to the same performance. This conjecture has recently gained empirical support in particular through [1], where several good methods for finding permutations were proposed and [22] where the performance of a merged network was improved by resetting batch norm statistics and batch statistics of individual neurons to alleviate what the authors call variance collapse. In Section 3 we give a new version of [13]'s conjecture by conjecturing that CNNs trained on group invariant data should be close to GCNNs.
1.2 Limitations
While we are able to show several relevant theoretical results, we have not been able to give a conclusive answer in terms of necessary and sufficient conditions to when equivariance of a network implies layerwise equivariance or that the network can be rewritten to be layerwise equivariant. An answer to this question would be valuable from a theoretical point of view.
In the experiments, we limit ourselves to looking at a single symmetry of images - horizontal flipping. As in most prior work on finding weight space symmetries in trained nets, we only search for permutations and not scaled permutations which would also be compatible with the ReLU-nonlinearity. Our experimental results depend on a method of finding permutations between networks that is not perfect [25]. Future improvements to permutation finding methods may increase the level of certainty which we can have about Conjectures 3.1 and 3.2.
2 Layerwise equivariance
We will assume that the reader has some familiarity with group theory and here only briefly review a couple of important concepts. Given a group  $G$ , a representation of  $G$  is a group homomorphism  $\rho : G \to \mathrm{GL}(V)$  from  $G$  to the general linear group of some vector space  $V$ . E.g., if  $V = \mathbb{R}^m$ , then  $\operatorname{GL}(V)$  consists of all invertible  $m \times m$ -matrices and  $\rho$  assigns a matrix to each group element, so that the group multiplication of  $G$  is encoded as matrix multiplication in  $\rho(G) \subset \operatorname{GL}(V)$ .
A function  $f: V_0 \to V_1$  is called equivariant with respect to a group  $G$  with representations  $\rho_0$  on  $V_0$  and  $\rho_1$  on  $V_1$  if  $f(\rho_0(g)x) = \rho_1(g)f(x)$  for all  $g \in G$  and  $x \in V_0$ . An important representation that exists for any group on any vector space is the trivial representation where  $\rho(g) = I$  for all  $g$ . If
a function  $f$  is equivariant w.r.t.  $\rho_0$  and  $\rho_1$  as above, and  $\rho_1$  is the trivial representation, we call  $f$  invariant. A permutation representation is a representation  $\rho$  for which  $\rho(g)$  is a permutation matrix for all  $g \in G$ . We will also have use for the concept of a group invariant data distribution. We say that a distribution  $\mu$  on a vector space  $V$  is  $G$ -invariant w.r.t. a representation  $\rho$  on  $V$ , if whenever  $X$  is a random variable distributed according to  $\mu$ , then  $\rho(g)X$  is also distributed according to  $\mu$ .
Let's for now consider a neural network  $f: \mathbb{R}^{m_0} \to \mathbb{R}^{m_L}$  as a composition of linear layers  $W_{j}: \mathbb{R}^{m_{j-1}} \to \mathbb{R}^{m_j}$  and activation functions  $\sigma$ :
$$
f (x) = W _ {L} \sigma \left(W _ {L - 1} \sigma \left(\dots W _ {2} \sigma \left(W _ {1} x\right) \dots\right)\right). \tag {1}
$$
Assume that  $f$  is equivariant with respect to a group  $G$  with representations  $\rho_0: G \to \mathrm{GL}(\mathbb{R}^{m_0})$  on the input and  $\rho_L: G \to \mathrm{GL}(\mathbb{R}^{m_L})$  on the output, i.e.,
$$
f \left(\rho_ {0} (g) x\right) = \rho_ {L} (g) f (x), \quad \text {f o r a l l} x \in \mathbb {R} ^ {m _ {0}}, g \in G. \tag {2}
$$
A natural question to ask is what the equivariance of  $f$  means for the layers it is composed of. Do they all have to be equivariant? For a layer  $W_{j}$  to be  $G$ -equivariant we require that there is a representation  $\rho_{j-1}$  on the input and a representation  $\rho_{j}$  on the output of  $W_{j}$  such that  $\rho_{j}(g)W_{j} = W_{j}\rho_{j-1}(g)$  for all  $g \in G$ . Note again that the only representations that are specified for  $f$  to be equivariant are  $\rho_{0}$  and  $\rho_{L}$ , so that all the other  $\rho_{j}: G \to \mathrm{GL}(\mathbb{R}^{m_{j}})$  can be arbitrarily chosen. If there exists a choice of  $\rho_{j}$ 's that makes each layer in  $f$  equivariant (including the nonlinearities  $\sigma$ ), we call  $f$  layerwise equivariant. In general we could have that different representations act on the input and output of the nonlinearities  $\sigma$ , but as we explain in Section 2.1, this cannot be the case for the ReLU-nonlinearity, which will be our main focus. Hence we assume that the same group representation acts on the input and output of  $\sigma$  as above.
The following simple example shows that equivariance of  $f$  does not imply layerwise equivariance. Example 2.1. Let  $G = S_{2} = \{i, h\}$  be the permutation group on two indices, where  $i$  is the identity permutation and  $h$  the transposition of two indices. Consider a two-layer network  $f: \mathbb{R}^2 \to \mathbb{R}$ ,
$$
f (x) = W _ {2} \operatorname {R e L U} \left(W _ {1} x\right),
$$
where  $W_{1} = (10)$  and  $W_{2} = 0$ .  $f$  is invariant to permutation of the two coordinates of  $x$  (indeed,  $f$  is constant 0). Thus, if we select  $\rho_0(h) = \left( \begin{array}{cc}0 & 1\\ 1 & 0 \end{array} \right)$  and  $\rho_{2}(h) = 1$ , then  $f$  is equivariant (note that a representation of  $S_{2}$  is specified by giving an involutory  $\rho (h)$  as we always have  $\rho (i) = I$ ). However, there is no choice of a representation  $\rho_{1}$  that makes  $W_{1}$  equivariant since that would require  $\rho_{1}(h)W_{1} = W_{1}\rho_{0}(h) = (0 - 1)$ , which is impossible (note that  $\rho_{1}(h)$  is a scalar). The reader will however notice that we can define a network  $\tilde{f}$ , with  $\tilde{W}_1 = (0\quad 0)$ ,  $\tilde{W}_{2} = 0$  for which we have  $f(x) = \tilde{f} (x)$  and then  $\tilde{f}$  is layerwise equivariant when choosing  $\rho_{1}(h) = 1$ .
In the example just given it was easy to, given an equivariant  $f$ , find an equivalent net  $\bar{f}$  which is layerwise equivariant. For very small 2-layer networks we can prove that this will always be the case, see Proposition D.1.
Example 2.1 might seem somewhat unnatural, but we note that the existence of "dead neurons" (also known as "dying RLUs") with constant zero output is well known [26]. Hence, such degeneracies could come into play and make the search for linear representations in trained nets more difficult. We will however ignore this complication in the experiments in the present work.
From an intuitive point of view, equivariance of a neural network should mean that some sort of group action is present on the intermediate feature spaces as the network should not be able to "forget" about the equivariance in the middle of the net only to recover it at the end. In order to make this intuition more precise we switch to a more abstract formulation in Appendix D.1. The main takeaway will be that it is indeed possible to define group actions on modified forms of the intermediate feature spaces whenever the network is equivariant, but this will not be very practically useful as it changes the feature spaces from vector spaces to arbitrary sets, making it impossible to define linear layers to/from these feature spaces.
An interesting question that was posed by Elesedy and Zaidi [12], is whether non-layerwise equivariant nets can ever perform better at equivariant tasks than layerwise equivariant nets. In Appendix C, we give a positive answer by demonstrating that when the size of the net is low, equivariance can hurt
<sup>1</sup>The main results in this section are generalized to networks with affine layers in Appendix E.
performance. In particular we give the example of cooccurrence of equivariant features in C.1. This is a scenario in image classification, where important features always occur in multiple orientations in every image. It is intuitive that in such a case, it suffices for the network to recognize a feature in a single orientation for it to be invariant on the given data, but a network recognizing features in only one orientation will not be layerwise equivariant.
2.1 From general representations to permutation representations
We will now first sidestep the issue of an equivariant network perhaps not being layerwise equivariant, by simply assuming that the network is layerwise equivariant with a group representation acting on every feature space (this will to some degree be empirically justified in Section 4). Then we will present results on 2-layer networks, where we can in fact show that layerwise equivariance is implied by equivariance.
The choice of activation function determines which representations are at all possible. In this section we lay out the details for the ReLU-nonlinearity. We will have use for the following lemma, which is essentially the well known property of ReLU being "positive homogeneous".
Lemma 2.2. [Godfrey et al. [18, Lemma 3.1, Table 1]] Let  $A$  and  $B$  be invertible matrices such that  $\operatorname{ReLU}(Ax) = B\operatorname{ReLU}(x)$  for all  $x$ . Then  $A = B = PD$  where  $P$  is a permutation matrix and  $D$  is a diagonal matrix with positive entries on the diagonal.
We provide an elementary proof in Appendix B.1. It immediately follows from Lemma 2.2 that if ReLU is  $G$ -equivariant with respect to representations  $\rho_0$  and  $\rho_{1}$  on the input and output respectively, then  $\rho_0(g) = \rho_1(g) = P(g)D(g)$  for all  $g\in G$ . I.e., the representations acting on the intermediate feature spaces in a layerwise equivariant ReLU-network are scaled permutation representations. This holds also if we add bias terms to the layers in (1).
We note that Godfrey et al. [18] consider more nonlinearities than ReLU, and that their results on other nonlinearities could similarly be used to infer what input and output group representations are admissible for these other nonlinearities. Also, Wood and Shawe-Taylor [41] derive in large generality what nonlinearities commute with which finite group representations, which is very related to our discussion. However, to apply the results from [41] we would have to first prove that the representations acting on the inputs and outputs of the nonlinearity are the same.
For two-layer networks with invertible weight matrices we can show that equivariance implies layerwise equivariance with a scaled permutation representation acting on the feature space on which ReLU is applied. The reader should note that the invertibility assumption is strong and rules out cases such as Example 2.1.
Proposition 2.3. Consider the case of a two-layer network  $f: \mathbb{R}^m \to \mathbb{R}^m$ ,
where  $\operatorname{ReLU}$  is applied point-wise. Assume that the matrices  $W_{1} \in \mathbb{R}^{m \times m}$ ,  $W_{2} \in \mathbb{R}^{m \times m}$  are non-singular. Then  $f$  is  $G$ -equivariant with  $\rho_{j}: G \to \mathrm{GL}(\mathbb{R}^{m})$  for  $j = 0, 2$  on the input and the output respectively if and only if
$$
\rho_ {0} (g) = W _ {1} ^ {- 1} P (g) D (g) W _ {1} \quad a n d \quad \rho_ {2} (g) = W _ {2} P (g) D (g) W _ {2} ^ {- 1},
$$
where  $P(g)$  is a permutation and  $D(g)$  a diagonal matrix with positive entries. Furthermore, the network  $f$  is layerwise equivariant with  $\rho_1(g) = P(g)D(g)$ .
Proof. Invertibility of  $W_{1}$  and  $W_{2}$  means that  $f$  being equivariant w.r.t.  $\rho_0, \rho_2$  is equivalent to ReLU being equivariant w.r.t.  $\rho_{1}(g) = W_{1}\rho_{0}(g)W_{1}^{-1}$  and  $\tilde{\rho}_{1}(g) = W_{2}^{-1}\rho_{2}(g)W_{2}$ . The discussion after Lemma 2.2 now shows that  $\rho_{1}(g) = \tilde{\rho}_{1}(g) = P(g)D(g)$  and the proposition follows.
The set of group representations for which a two-layer ReLU-network can be  $G$ -equivariant is hence quite restricted. It is only representations that are similar (or conjugate) to scaled permutations that are feasible. In the appendix, we also discuss the case of two-layer networks that are  $G$ -invariant and show that they have to be layerwise equivariant with permutation representations in Proposition B.1.
2.2 Permutation representations in CNNs—group convolutional neural networks
As explained in Section 2.1, for a ReLU-network to be layerwise equivariant, the representations must be scaled permutation representations. We will now review how such representations can be used to encode the horizontal flipping symmetry in CNNs. This is a special case of group equivariant convolutional networks—GCNNs—which were introduced by [10]. An extensive reference is [38]. The reader familiar with [10, 38] can skip this section, here we will try to lay out in a condensed manner what the theory of horizontal flipping equivariant GCNNs looks like.
Note first that horizontally flipping an image corresponds to a certain permutation of the pixels. Let's denote the action of horizontally flipping by  $\tau$ . This is a permutation representation of the abstract group  $S_{2}$ . If a convolutional layer  $\Psi$  only contains horizontally symmetric filters, then it is immediate that  $\Psi(\tau(x)) = \tau(\Psi(x))$ . It is however possible to construct more general equivariant layers.
Let's assume that the representations acting on the input and output of  $\Psi$  split into the spatial permutation  $\tau$  and a permutation  $P$  of the channels.  $P_0$  on the input and  $P_{1}$  on the output.  $P_0$  and  $P_{1}$  need to have order maximum 2 to define representations of  $S_{2}$ . One can show, using the so-called kernel constraint [39, 38], what form the convolution kernel  $\psi$  of  $\Psi$  needs to have to be equivariant. The kernel constraint says that the convolution kernel  $\psi \in \mathbb{R}^{c_1\times c_0\times k\times k}$  needs to satisfy
$$
\tau (\psi) = P _ {1} \psi P _ {0} ^ {T} (= P _ {1} \psi P _ {0}), \tag {3}
$$
where  $\tau$  acts on the spatial  $k\times k$  part of  $\psi$ ,  $P_{1}$  on the  $c_{1}$  output channels and  $P_{0}$  on the  $c_{0}$  input channels. The last equality holds since  $P_{0}$  is of order 2. In short, permuting the channels of  $\psi$  with  $P_{0}$  and  $P_{1}$  should be the same as horizontally flipping all filters. We see this in action in Figure 1, even for layers that are not explicitly constrained to satisfy (3). An intuitive explanation of why (3) should hold for equivariant layers is that it guarantees that the same information will be captured by  $\psi$  on input  $x$  and flipped input  $\tau(x)$ , since all horizontally flipped filters in  $\tau(\psi)$  do exist in  $\psi$ .
Channels that are fixed under a channel permutation are called invariant and channels that are permuted are called regular, as they are part of the regular representation of  $S_{2}$ . We point out three special cases—if  $P_{0} = P_{1} = I$ , then  $\psi$  has to be horizontally symmetric. If  $P_{0} = I$  and  $P_{1}$  has no diagonal entries, then we get a lifting convolution and if  $P_{0}$  and  $P_{1}$  both have no diagonal entries then we get a regular group convolution [10]. In the following when referring to a regular GCNN, we mean the "most generally equivariant" case where  $P$  has no diagonal entries.
3 The permutation conjecture by Entezari et al. and its connection to GCNNs