Manipulating SGD with Data Ordering Attacks
Year: 2022

Abstract:
Machine learning is vulnerable to a wide variety of attacks. It is now well understood that by changing the underlying data distribution, an adversary can poison the model trained with it or introduce backdoors. In this paper we present a novel class of training-time attacks that require no changes to the underlying dataset or model architecture, but instead only change the order in which data are supplied to the model. In particular, we find that the attacker can either prevent the model from learning, or poison it to learn behaviours specified by the attacker. Furthermore, we find that even a single adversarially-ordered epoch can be enough to slow down model learning, or even to reset all of the learning progress. Indeed, the attacks presented here are not specific to the model or dataset, but rather target the stochastic nature of modern learning procedures. We extensively evaluate our attacks on computer vision and natural language benchmarks to find that the adversary can disrupt model training and even introduce backdoors.

heading: 1 Introduction
text: The data-driven nature of modern machine learning (ML) training routines puts pressure on data supply pipelines, which become increasingly more complex. It is common to find separate disks or whole content distribution networks dedicated to servicing massive datasets. Training is often distributed across multiple workers. This emergent complexity gives a perfect opportunity for an attacker to disrupt ML training, while remaining covert. In the case of stochastic gradient descent (SGD), it assumes uniform random sampling of items from the training dataset, yet in practice this randomness is rarely tested or enforced. Here, we focus on adversarial data sampling.
It is now well known that malicious actors can poison data and introduce backdoors, forcing ML models to behave differently in the presence of triggers [12]. While such attacks have been shown to pose a real threat, they have so far required the attacker to perturb the dataset used for training.
We now show that by simply changing the order in which batches or data points are supplied to a model during training, an attacker can affect model behaviour. More precisely, we show that it is
35th Conference on Neural Information Processing Systems (NeurIPS 2021).
possible to perform integrity and availability attacks without adding or modifying any data points. For integrity, an attacker can reduce model accuracy or arbitrarily control its predictions in the presence of particular triggers. For availability, an attacker can increase the amount of time it takes for the model to train, or even reset the learning progress, forcing the model parameters into a meaningless state.
We present three different types of attacks that exploit Batch Reordering, Reshuffling and Replacing – naming them BRRR attacks. We show that an attacker can significantly change model performance by (i) changing the order in which batches are supplied to models during training; (ii) changing the order in which individual data points are supplied to models during training; and (iii) replacing datapoints from batches with other points from the dataset to promote specific data biases. Furthermore, we introduce Batch-Order Poison (BOP) and Batch-Order Backdoor (BOB), the first techniques that enable poisoning and backdooring of neural networks using only clean data and clean labels; an attacker can control the parameter update of a model by appropriate choice of benign datapoints. Importantly, BRRR attacks require no underlying model access or knowledge of the dataset. Instead, they focus on the stochasticity of gradient descent, disrupting how well individual batches approximate the true distribution that a model is trying to learn.
To summarise, we make the following contributions in this paper:
• We present a novel class of attacks on ML models that target the data batching procedure used during training, affecting their integrity and availability. We present a theoretical analysis explaining how and why these attacks work, showing that they target fundamental assumptions of stochastic learning, and are therefore model and dataset agnostic1.
• We evaluate these attacks on a set of common computer vision and language benchmarks, using a range of different hyper-parameter configurations, and find that an attacker can slow the progress of training, as well as reset it, with just a single epoch of intervention.
• We show that data order can poison models and introduce backdoors, even in a blackbox setup. For a whitebox setup, we find that the adversary can introduce backdoors almost as well as if they used perturbed data. While a baseline CIFAR10 VGG16 model that uses perturbed data gets 99% trigger accuracy, the whitebox BOB attacker gets 91%± 13 and the blackbox BOB attacker achieves 68%± 19.

heading: 2 Related Work
text: Attacks on integrity: Szegedy et al. [34] and Biggio et al. [6] concurrently discovered the existence of adversarial examples. These samples, containing human imperceptible perturbations, cause models to output incorrect results during inference. The original whitebox attacks require the adversary to access the models and use gradient information to perform conditioned optimisation to maximise the model loss [34, 6, 10, 22]. The attack later generalised to blackbox setups, where the adversary trains a surrogate model and hopes the generated adversarial samples transfer to the target model [24].
The data-poisoning attack aims at using data manipulation to cause DNNs to fail on specific test-time instances [17]. Chen et al. demonstrated that manipulation of the labels of around 50 training samples is enough to trigger failure [8]. Gu et al. showed that attackers can associate adversarial patterns with labelled images and cause DNNs to overfit to this pattern [12]. Shafahi et al. launched a poisoning attack using instances with clean labels [29]. A number of other works have since created more efficient triggers [28]. It was a common belief that poisoning attacks on DNNs have to contain a certain level of malicious manipulation of whether the data or label at train time. However, this paper
1Codebase is available here: https://github.com/iliaishacked/sgd_datareorder
shows how poisoning is possible with clean data and clean labels, with the only manipulation being of the batching process at training time.
Attacks on availability: Shumailov et al. first attacked the availability of computer vision and natural language processing models at inference time with sponge examples [30]. They pessimized over energy utilisation and inference latency to target hardware and internal model optimisations. By contrast, this paper targets availability at training time. We show that the attacker can reset or slow down training progress by reordering or reshuffling natural batches. Finally, we note that unlike Shumailov et al., our attacks do not target specific optimisations in hardware or individual models, but instead break the fundamental stochastic assumption of training.
Note on terminology: As we study attacks on training, we use the terms integrity and availability in a slightly different sense from the rest of the literature. By availability, we mean the availability of a training procedure – the rate at which the model trains, as opposed to model performance on the task. By integrity attacks, we mean attacks that either stop the model from learning its intended task, or force it to learn an additional unrelated task.

heading: 3 Methodology

heading: 3.1 Threat model
text: We assume one of the strongest threat models currently described in the literature. In particular, our blackbox attacker assumes no access to the model and no prior knowledge of the training data, whereas a whitebox attacker has access to the model under attack and can compute its loss directly. The attack specifically focuses on the batching part of the ML pipeline as is depicted in Figure 1. We discuss the related work in Section 2.
This attack is realistic and can be instantiated in several ways. The attack code can be infiltrated into: the operating system handing file system requests; the disk handling individual data accesses; the software that determines the way random data sampling is performed; the distributed storage manager; or the machine learning pipeline itself handling prefetch operations. That is a substantial attack surface, and for large models these components may be controlled by different principals. The attack is also very stealthy. The attacker does not add any noise or perturbation to the data. There are no triggers or backdoors introduced into the dataset. All of the data points are natural. In two of four variants the attacker uses the whole dataset and does not oversample any given point, i.e. the sampling is without replacement. This makes it difficult to deploy simple countermeasures.

heading: 3.2 Primer on stochastic learning and batching
text: We assume that the defender is trying to train a deep neural network model with parameters θ operating over Xi ∼ Xtrain, solving a non-convex optimization problem with respect to parameters θ, corresponding to minimization of a given loss function L(θ). We will denote the training dataset X = {Xi}. We assume a commonly-used loss function defined as the sample average of the loss per training data point Li(θ) = L(Xi, θ) in k-th batch over the training set, where B is the batch size: L̂k+1(θ) = 1B ∑kB+B i=kB+1 Li(θ). If we let N · B be the total number of items for
training, then in a single epoch one aims to optimize: L̂(θ) = 1N ∑N i=1 L̂i(θ). Optimization with stochastic gradient descent (SGD) algorithm of N ·B samples and a learning rate of η leads to the following weight update rule over one epoch: θk+1 = θk + η∆θk; ∆θk = −∇θL̂k(θk). SGD is often implemented with momentum [25, 33], with µ and v representing momentum and velocity respectively: vk+1 = µvk + η∆θk; θk+1 = θk + vk+1.
Given data, SGD’s stochasticity comes from the batch sampling procedure. Mini-batched gradients approximate the true gradients of L̂ and the quality of this approximation can vary greatly. In fact, assuming an unbiased sampling procedure, i.e. when the k’th gradient step corresponds to ik’th batch with P(ik = i) = 1/N , in expectation the batch gradient matches the true gradient:
E[∇L̂ik(θ)] = N∑ i=1 P(ik = i)∇L̂i(θ) = 1 N N∑ i=1 ∇L̂i(θ) = ∇L̂(θ). (1)
Although this happens in expectation, a given batch taken in isolation can be very far from the mean. This variation has been exploited in the literature to aid training: there exists a field responsible for variance reduction techniques for stochastic optimisation [18], active learning [9, 35], (anti-) curriculum learning [5, 20, 13] and core-set construction [2]. Each area looks at identifying and scheduling data subsets that aid training and give a better true gradient approximation. In this paper, we turn things round and investigate how an attacker can exploit data order to break training. The explicit stochastic assumption opens a new attack surface for the attacker to influence the learning process. In particular, let us consider the effect of N SGD steps over one epoch [31]:
θN+1 = θ1 − η∇L̂1(θ1)− η∇L̂2(θ2)− · · · − η∇L̂N (θN )
= θ1 − η N∑ j=1 ∇L̂j(θ1) + η2 data order dependent︷ ︸︸ ︷ N∑ j=1 ∑ k<j ∇∇L̂j(θ1)∇L̂k(θ1) +O(N3η3) . (2)
As we can see, in this case the second order correction term is dependent on the order of the batches provided. The attacker we describe in this paper focuses on manipulating it i.e. finding a sequence of updates such that the first and second derivatives are misaligned with the true gradient step. In Appendix C we prove that under equally-distributed loss gradients, a change in data order can lead to an increase in the expected value of the term which is dependent on data order. We also derive a condition on the gradient distribution given a model for which it is guaranteed. Finally, we derive an attack objective to target the upper bound on the rate of SGD convergence explicitly in Appendix A.
In this paper we assume the blackbox attacker has no access to the underlying model, and thus no way to monitor its errors or the progress of its training. Instead, we co-train a separate surrogate model, using the batches supplied to the target model. We find that in practice the losses produced by the surrogate model approximate the losses of the true model well enough to enable attacks on both integrity and availability. We empirically find that our blackbox reshuffle attacks perform as well as the whitebox one in Appendix D.
Finally, although the attacker can maximise the term dependent on data order directly, in practice it is expensive to do so. Therefore, in the attack we use the loss magnitudes directly rather than their gradient. Intuitively, large prediction errors correspond to large loss gradient norms, while correct predictions produce near-zero gradients. Although this assumption may not hold for all loss landscapes, for the loss landscapes incurred by real machine learning models, local minima often cluster around the global minima as the loss satisfies certain dissipativity properties [26, 36], and consequently loss magnitudes correlate with the gradient of the loss. We emphasize that we use this approximation only for computational advantage.

heading: 3.3 Taxonomy of batching attacks
text: In this section we describe the taxonomy of batching attacks as shown in Figure 2. The overall attack algorithm is shown in Algorithm 2 in the Appendix, and a shortened attack flow is shown in Algorithm 1. We highlight that our attacks are the first to successfully poison the underlying
Algorithm 1: A high level description of the BRRR attack algorithm /* –– Attack preparation: collecting data –– */ do
get a new batch and add it to a list of unseen datapoints; train surrogate model on a batch and pass it on to the model;
while first epoch is not finished /* –– Attack: reorder based on surrogate loss –– */ while training do
rank each data point from epoch one with a surrogate loss; reorder the data points according to the attack strategy; pass batches to model and train the surrogate at the same time.
model without changing the underlying dataset. In this paper we use three attack policies – (1) batch reshuffling or changing the order of datapoints inside batches; (2) batch reordering or changing the order of batches; and (3) batch replacement or replacing both points and batches. We consider four reordering policies, motivated by research in the fields of curriculum learning [5] and core-set selection [2], which discovered that model training can be enhanced by scheduling how and what data is presented to the model. That can help the model to generalize and to avoid overfitting with memorization. This paper does the opposite – we promote memorization and overfitting, forcing the model to forget generalizable features. Anti-curriculum learning (e.g. [13]) is particularly close to our batch reordering setting.
Random order
Figure 3 shows attack policies. Low to high orders sequence items by their loss. High to low is an inverse of Low to high. Oscillations inwards picks elements from both sides in sequence. Oscillations outwards inverts the halves of the sequence and then picks elements from both sides.

heading: 3.4 Batch-order poison and backdoor
text: Machine-learning poisoning and backdooring techniques aim to manipulate the training of a given model to control its behavior during inference. In the classical setting, both involve either appending adversarial datapoints X̂ to natural dataset X or changing natural datapoints X + δ so as to change model behaviour. This makes the attack easier to detect, and to prevent. For example, an adversary may add a red pixel above every tank in the dataset to introduce the red pixel trigger and cause other objects under red pixels to be classified as tanks.
We present batch-order poisoning (BOP) and batch-order backdooring (BOB) – the first poison and backdoor strategies that do not rely on adding adversarial datapoints or perturbations during training, but only on changing the order in which genuine data are presented. BOP and BOB are based on the idea that the stochastic gradient update rule used in DNN training is agnostic of the batch contents and is an aggregation. Indeed, consider a classical poison setting with an adversarial dataset X̂: θk+1 = θk + η∆θk; ∆θk = −(∇θL̂(Xk, θk) +∇θL̂(X̂k, θk)). Order-agnostic aggregation with a sum makes it hard to reconstruct the individual datapoints Xk from just observing ∆θk. Indeed, the stochastic nature of optimisation allows one to find a set of datapoints Xj 6= Xi such that ∇θL̂(Xi, θk) ≈ ∇θL̂(Xj , θk). Given a model and a dataset such that the gradient covariance matrix is non-singular, an attacker can approximate the gradient update from an adversarial dataset X̂ using natural datapoints from the genuine dataset X , enabling poisoning without having to change of underlying dataset in any way:
θk+1 = θk + η∆̂θk, where { ∆̂θk = −∇θL̂(Xi, θk) ∇θL̂(Xi, θk) ≈ ∇θL̂(X̂k, θk).
(3)
This gives rise to a surprisingly powerful adversary, who can introduce arbitrary behaviors into any models learned with stochastic gradient descent without having to add or perturb training data. This attack becomes more effective as training datasets become larger, further improving the attacker’s ability to shape the gradient update. We discuss its fidelity in Appendix B.
We evaluated a number of different setups, and found that the attack works best when the attacker comprises the batch with B − V natural data points and appends V adversarially-chosen data points X̂i to the batch. Aa larger V is better for gradient approximation, but leads to more conflict with natural gradients; in the paper up to 30% of the batch is filled with natural datapoints to find a balance. Finding precise batch reconstruction is an intractable problem that scales with batch size and size of the dataset. However, we find that random sampling works well; even if mistakes are made, the network still learns the poison over the course of a few batches. Overall we try to minimize the following reconstruction error for a given poisoned batch X̂j :
min Xi ∥∥∥∇θL̂(X̂j , θk)−∇θL̂(Xi, θk)∥∥∥p ; s.t. Xi ∈ X. (4) Although more sophisticated approaches could help find better candidates, we discovered that random sampling works well enough for successful clean-data / clean-label poison and backdoor attacks. It also helps us strike a balance between speed of batch construction and impact on model performance. Figure 4 shows an example of natural data (a) that closely resembled the would-be update with batch in (b). Notably, such updates result in a prediction change towards the target class.

heading: 4 Evaluation

heading: 4.1 Experimental setup
text: We evaluate our attacks using two computer vision and one natural language benchmarks: the CIFAR-10, CIFAR-100 [19] and AGNews [37] datasets. We use ResNet-18 and ResNet-50 as source models [14], and LeNet-5 [21] and MobileNet [16] as surrogate models, to train CIFAR-10 and CIFAR-100 respectively. For AGNews we used sparse mean EmbeddingBag followed by three fully connected layer from torchtext as source model and one fully connected layer for surrogate. Note that the surrogate model is significantly less performant than its corresponding source model in all cases, and cannot learn the dataset to the same degree of accuracy, limiting attacker capabilities. Thus our results represent a lower bound on attack performance.

heading: 4.2 Integrity attacks with reshuffling and reordering of natural data
text: Table 2 presents the results (a much more detailed version is shown in Table 4). Batch reordering disrupts normal model training and introduces from zero to 15% performance degradation (refer to extended results and discussion in Appendix E). Note that the attacker does nothing beyond changing the order of the batches; their internal composition is the same. This shows the potency of this attack. Indeed, when we extend the attack to batch reshuffling – where batches get re-arranged internally – for computer vision, performance degrades to that of random guessing. In each, the best-performing models stay at the first epoch, where the attacker still accumulates the dataset used in training. Here, the degradation in performance is maximum – all models with all attack types failed to perform better than random guessing, having reached their top performance only in the first epoch, when the attacker was observing the dataset.
We additionally report a large number of different hyperparameter variations for the attacks in Appendix I. This hyperparameter search suggests that the attacks work well as long as the surrogate models learn, do not converge to a minimum straight away, and have sufficient learning rate.
Overall, we find that:
• An attacker can affect the integrity of model training by changing the order of individual data items and natural batches.
• The attacker can reduce model performance, and completely reset its performance.

heading: 4.3 Availability attacks
text: 0 20 40 60 80 100 Epochs
0.0
0.2
0.4
0.6
0.8
1.0
M od
el a
cc ur
ac y
Attacking only epoch 10
Train
0 20 40 60 80 100 Epochs
0.0
0.2
0.4
0.6
0.8
1.0
M od
el a
cc ur
ac y
Test
Baseline LowHigh HighLow Ordered by class LowHigh Batchwise Oscillating in Oscillating out
Availability attacks
Figure 5: Availability attacks at epoch 10, ResNet-18 attacked with a LeNet-5 surrogate. Error bars show per-batch accuracy standard deviation.
While the previous section discused integrity attacks, this section’s focus is on availability. This refers to the amount of time and effort required to train a model, and an availability attack can involve an adversary using BRRR attacks to slow down training without disrupting the overall learning procedure. It is worth noting that there are other possible definitions of availability; it can also mean a model’s ability to reach original accuracy, but this case is already included in the integrity attacks we discussed in the last section.
Availability attacks follow a similar scenario to Section 4.2 above, in that the attacker only changes the order in which data reaches the model. Here we at the 10th epoch, an arbitrary attack point, and all other training is done with randomly ordered data. We find that by feeding the model with a few BRRR batches, its training progress can be reset significantly – progress that may take a surprisingly large number of epochs to recover. The red line shows the worst scenario, where each batch has only data points of a single class. It can be seen that the attack manages to reset training, degrading performance for more than 90 epochs – low-high batch reordering at epoch ten results in − 3% performance at epoch 100.
In this section we showed that the attacker can perform availability attacks using both batch reordering and reshuffling and leave an impact on a model long after they have been launched; even a single attack epoch can degrade training progress significantly. Overall, we find that:
• An attacker can cause disruption to model training by changing the order of data in just a single epoch of training.
• An attack at just one epoch is enough to degrade the training for more than 90 epochs.

heading: 4.4 Backdoors with batch replacement
text: We find that the attacker can backdoor models by changing the data order. Here, we apply a trigger to images from the training dataset and then supply untriggered data to the model that result in a similar gradient shape. We find that our method enables the attacker to control the decision of a model when it makes a mistake i.e. when the model is making a decision about data far from the training-set distribution. For example, we show in Appendix F that poisoning a single random datapoint is possible with just a few batches. We hypothesise that the limitation comes from the fact that as only natural data are sampled for each BOP and BOB batch, natural gradients are present and learning continues; so forgetting does not happen and generalisation is not disrupted.
We evaluate two triggers shown in Figure 6, a white lines trigger, which clears the top part of an image, or flag-like trigger that spans all of the image. We report results from injecting up to 20 adversarially-
ordered batches every 50000 natural datapoints for 10 epochs. We then inject 80 adversarially-ordered batches. The training procedure here is similar to the one used for BadNets [12]. We find that 80 batches are not necessary, as most models end up converging after 3–5 adversarially-ordered batches. For reconstruction we randomly sample 300 batches, balancing search efficiency and attack cost as is noted in Appendix H, and use p = 2. As we discuss in Appendix L, similar attacks work against language tasks.
Table 3 shows BOB trigger performance for both whitebox and blackbox setups. We present two baselines, one for normal training without any triggers, and one where triggers are added to the underlying data, i.e. training with perturbed data and labels. Trigger accuracy refers to the proportion of test set that ends up getting the target trigger label, whereas error with triggers shows the proportion of misclassifications that trigger introduces, i.e. when the model makes a mistake, but does not predict the trigger target class. As expected, we observe that for normal training, trigger accuracy stays at random guessing, and the trigger does not dominate errors it introduces, whereas adding perturbed data manipulates the model to predict the target class almost perfectly.
We find that in a whitebox setup for a flag-like trigger we are capable of getting a similar order of performance for a batch of size 32 as if the attack was performed with injected adversarial data. In a blackbox setup with a flag-like trigger we lost around 30% of trigger performance, yet the trigger still remains operational. A trigger of nine white lines outperforms the baseline only marginally; in a whitebox setup it gets from 20–40% performance, whereas in a blackbox one it ranges between zero and 20% performance. We show the training progress of each individual trigger in Appendix K.
Overall, we find that:
• An attacker can poison an individual datapoint, change its label and increase its prediction confidence, without ever actually training the model on an adversarially-crafted datapoint.
• An attacker can introduce backdoors into the model by introducing a few reordered batches during training, without ever injecting adversarial data or labels. Here, trigger performance differs, yet an adversary can perform BOB attacks on a par with attacks that inject perturbations into datasets explicitly.

heading: 5 Conclusion
text: We presented a novel class of attacks that manipulate the integrity and availability of training by changing the order of batches, or the order of datapoints within them. Careful reordering of a model’s training data allows it to be poisoned or backdoored without changing the training data at all. The attacks we presented are fully blackbox; they do not rely on knowledge of the target model or on prior knowledge of the data. Most surprisingly, we find that an attacker can introduce backdoors without disruption of generalisation, even though only natural data is used. We are the first to show that the sampling procedure can be manipulated deterministically to control the model’s behavior.
This paper reminds us that stochastic gradient descent, like cryptography, depends on randomness. A random number generator with a backdoor can undermine a neural network just as it can undermine a payment network [1]. Developers who wish to ensure secure, robust, fair optimization during learning must therefore be able to inspect their assumptions and, in case of SGD, show the provenance of randomness used to select batches and datapoints.
Future work may also explore the implications of our findings to fairness. Recent work has highlighted that ML models can suffer from a large taxonomy of different biases, including sampling bias, with outcomes including sexism and racism [3, 23]. This leads directly to questions of inductive bias and the practical contribution of pseudorandom sampling. Hooker has explained that bias in ML is not just a data problem, but depends on algorithms in subtle ways [15]; this paper shows how to exploit that dependency.

heading: Acknowledgements
text: We thank the reviewers for their insightful feedback. This work was supported by DARPA (through the GARD program), CIFAR (through a Canada CIFAR AI Chair), Bosch Forschungsstiftung im Stifterverband, by NSERC (under the Discovery Program, and COHESA strategic research network), and by a gift from Intel. We also thank the Vector Institute’s sponsors.

Review summaries:
This paper proposes hurting a deep neural network's accuracy, or its training time or introducing poisoning/backdoors only by manipulating the random batching in SGD algorithm. In these attacks, the attacker has the ability to observe the training samples during training and then either re-shuffle, re-order or replace the batches that were supposed to be randomly samples. They experiment on image classification and an NLP task to show that these attacks are effective without manipulating the individual samples at all, by just changing the order in which the model sees them during training.