Manuscript Offprint

arXiv:2608.14373

Boosting Data Augmentation with Stochastic Weight Averaging

Longde Huang, Axel Flinth, Jan E. Gerken

Abstract

The symmetries of a learning task have become an important factor in designing modern deep learning solutions. Data augmentation is a straightforward and effective way of incorporating symmetries into a generic neural network. Recent results show that infinitely large deep ensembles show perfect symmetry when trained on augmented data. However, since training ensembles requires repeating the training process many times, this method is costly. In this work, we study stochastic weight averaging (SWA) applied to classification as an alternative ensembling technique that does not require repeated training runs. We analyze SWA by approximating the stochastic training trajectory at the end of training with an Ornstein–Uhlenbeck process. We show that in the infinite-width limit, SWA on augmented data provides an equivariance boost that goes beyond what could be expected from the performance increase due to SWA alone. We verify our results with extensive numerical experiments on numerous models spanning image and graph classification with both discrete and continuous symmetries.

1 Introduction

Many machine-learning tasks, ranging from protein folding [1] to medical image processing [2] feature symmetries that constrain the learning problem and, if taken into account, can be used to improve the performance of the trained models. In deep learning more specifically, there are two major approaches for incorporating symmetries into the learning algorithm.

Firstly, the symmetry can be realized as a constraint on the neural network architecture. In particular, the layers of the network can be chosen such that they are equivariant functions with respect to the symmetry of the task at hand [3, 4]. This approach requires specialized architectures (discussed in a large body of literature) but realizes the symmetry exactly and improves sample efficiency during training.

Secondly, the neural network can be trained on transformed versions of the original training data, a method known as data augmentation. Since this technique does not constrain the network architecture, it can be applied to any highly optimized off-the-shelf architecture as long as the symmetry transformation can be implemented. It is therefore straightforward and flexible. However, it does not lead to an exactly equivariant model, but rather one that is approximately equivariant (or equivariant in distribution).

Theoretical studies of equivariant neural networks are plentiful due to deep connections between equivariant layers and representation theory. In particular, practically relevant special cases such as the symmetry

∗^{*}Equal Contribution

a^{a}Department of Mathematical Sciences, Chalmers University of Technology and the University of Gothenburg, SE-412 96 Gothenburg, Sweden.

Emails: longde@chalmers.se, gerken@chalmers.se

b^{b}Department of Mathematics and Mathematical Statistics, Umeå University, Linnéus väg 49, 901 87 Umeå, Sweden. Email: axel.flinth@umu.se groups SnS_{n} of permutations, SO(n)SO(n) of rotations or SE(n)SE(n) of roto-translations have been studied extensively in the literature, for various different model architectures.

In contrast, most studies of data augmentation are purely empirical, see e.g. [5]. This is because data augmentation modifies the training procedure and therefore one inevitably needs to study the complicated, non-linear training dynamics of neural networks. Despite this obstacle, recent advances in this area show that in expectation over the initialization distribution, neural networks are exactly equivariant when they are trained on augmented data [6, 7]. Approximately, this can be realized by training a deep ensemble.

However, ensemble training is notoriously computationally intensive, since the training needs to be repeated for each ensemble member. For this reason, and motivated by the recent results mentioned above, we study the effects of data augmentation on stochastic weight averaging (SWA). Instead of an ensemble over independent training trajectories, SWA takes an ensemble mean over several models from the same training trajectory [8], thereby reducing the training cost to that of a single model.

Intuitively, the training trajectory of SGD is dominated by noise from batch selection when it is close to a minimum of the loss. Therefore, SWA can be expected to have a similar effect to averaging over random initializations. In this work, we investigate whether this intuition holds up. In particular, we approximate the stochastic training trajectory at the end of training with an Ornstein–Uhlenbeck process and use the ratio of the expected losses with and without SWA to quantify the performance boost due to SWA.

A central obstacle to the theoretical analysis of SWA in this setting is the non-independence resulting from the samples being taken from a single training trajectory. To overcome this problem, we assume a well-trained network and express the performance boost in terms of the trace of the Hessian of the network. In this setting, we then consider the expected equivariance boost which focuses on the non-equivariant contributions to the loss. In the infinite-width limit, we compute a bound on this expected equivariance boost using the theory of neural tangent kernels (NTKs). Our calculations show that combining data augmentation with SWA leads to an equivariance boost which goes beyond the mere performance increase expected from ordinary SWA.

We validate our theoretical analysis with extensive numerical experiments. In particular, we explicitly verify that the bound predicted by our theory holds and has the right dependence on group size and averaging time on a synthetic problem over which we have full control. We furthermore demonstrate the claimed improvement on computer vision and graph classification tasks, as well as both discrete and continuous symmetry groups, for numerous different model classes.

Our main contributions are as follows:

• We formalize SWA at the end of training with an Ornstein–Uhlenbeck process and analyse the equivariance properties of the resulting model in the case of augmented training data. To quantify the performance boost due to SWA, we introduce the loss ratio R in (20). Similarly, to quantify the equivariance boost due to SWA, we define the loss ratio RE⊥R_{\mathcal{E}^{\perp}} in (36). We overcome the central obstacle of dependent ensemble members from one trajectory by assuming a well-trained network and expressing R and RE⊥R_{\mathcal{E}^{\perp}} in terms of the trace of the Hessian of the network, see (61) and (62).

• We then take the infinite-width limit and leverage the theory of NTKs to derive a bound on RE⊥R_{\mathcal{E}^{\perp}} (Theorem 4.12) which shows that SWA with data augmentation leads to a non-trivial improvement in equivariance for a wide range of models. In the process, we derive novel results about the NTK limit for equivariant models.

• We validate our theoretical results numerically by considering a synthetic learning task. We verify for this task that our bound still holds for a finitely-sized network and has the predicted dependence on the group size and averaging time (Section 5.1). We furthermore test the equivariance gain from SWA in more realistic settings (Section 5.2). In particular, we demonstrate the predicted improvement on five vision datasets with seven different models (MLPs, CNNs, vision and graph transformers) for discrete rotations. We also show that the same effect can be observed for a molecular graph classification task invariant with respect to 3D rotations.

References (42)