SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Truong Thao Nguyen<sup>1</sup> Balazs Gerofi<sup>2,4</sup> Edgar Josafat Martinez-Noriega<sup>1</sup> François Trahay<sup>3</sup> Mohamed Wahib<sup>4</sup>
$^{1}$  National Institute of Advanced Industrial Science and Technology (AIST), Japan  
 $^{2}$  Intel Corporation, USA
3 Télecom SudParis, Institut Polytechnique de Paris, France
$^{4}$  RIKEN Center for Computational Science, Japan
{nguyen.truong, edgar.martineznoriega}@aist.go.jp
balazs.gerofi@intel.com
francois.trahay@telecom-sudparis.eu
mohamed.ATTIA@RIKEN.jp
This paper proposes a method for hiding the least-important samples during the training of deep neural networks to increase efficiency, i.e., to reduce the cost of training. Using information about the loss and prediction confidence during training, we adaptively find samples to exclude in a given epoch based on their contribution to the overall learning process, without significantly degrading accuracy. We explore the converge properties when accounting for the reduction in the number of SGD updates. Empirical results on various large-scale datasets and models used directly in image classification and segmentation show that while the with-replacement importance sampling algorithm performs poorly on large datasets, our method can reduce total training time by up to  $22\%$  impacting accuracy only by  $0.4\%$  compared to the baseline. Code available at https://github.com/
TruongThaoNguyen/kakurenbo
Empirical evidence shows the performance benefits of using larger datasets when training deep neural networks (DNN) for computer vision, as well as in other domains such as language models or graphs [1]. More so, attention-based models are increasingly employed as pre-trained models using unprecedented dataset sizes, e.g. the JFT-3B dataset consists of nearly three billion images, annotated with a class-hierarchy of around 30K labels [2], LIAON-5B provides 5,85 billion CLIP-filtered image-text pairs that constitute over 240TB [3]. A similar trend is also observed in scientific computing, e.g., DeepCAM, a climate simulation dataset, is over 8.8TB in size [4]. Furthermore, the trend of larger datasets prompted efforts that create synthetic datasets using GANS [5] or fractals [6]. The downside of using large datasets is, however, the ballooning cost of training. For example, it has been reported that training models such as T5 and AlphaGo cost $1.3M [7] and $35M [8], respectively. Additionally, large datasets can also stress non-compute parts of supercomputers and clusters used for DNN training (e.g., stressing the storage system due to excessive I/O requirements [9, 10]).
In this paper, we are focusing on accelerating DNN training over large datasets and models. We build our hypothesis on the following observations on the effect of sample quality on training: a) biased with-replacement sampling postulates that not all samples are of the same importance and a biased, with-replacement sampling method can lead to faster convergence [11, 12], b) data pruning methods show that when select samples are pruned away from a dataset, the predication accuracy
Table 1: Summary of related works. Complexity on the number of samples  $N$ , number of Epochs  $M$  and ensemble size  $E$ .
Approach	Method	Merits (+)Demerits (-)	Online/Offline	Practical Overhead(Bottleneck)	Complexity(Cost)
Biased w/ReplacementSampling	ImportanceSampling [11]	+ Theoretically faster convergence- No demonstrated speedup on large datasets (Section 4)- Nondeterministic	Online	Sorting samples	O(N.log(N))
RHO-LOSS [12]	+ Theoretically faster convergence- No demonstrated speedup- Nondeterministic	Hold-out approx.	O(N2)
DataPruning(prune datasetoffline to save cost infuture training)	ForgivenessScores [13]	+ Robust- Full training needed to identify samples to prune	Offline	Tracking change in prediction	O(N·M2)
EL2N [15]	+ Demonstrated speedup- Full training needed to identify samples to prune- Limited scalability	Sorting samples	O(N2)
Memorization [14]	+ Demonstrated speedup- Full training needed to identify samples to prune- Limited scalability	Tracking cross-sample prediction	O(N2)
Ensemble ActiveLearning [16]	+ Demonstrated speedup- Full training needed to identify samples to prune- Limited scalability	Model uncertaintyapproximation	O(N2)
Diverse Ensembles(DDD) [20]	+ Demonstrated speedup- Full training needed to identify samples to prune- Limited scalability	Tracking cross-ensemble prediction	O(N2·E)
Hiding Samples	SelectiveBackprop [17]	- Arbitrary hiding samples- No convergence guarantee- No demonstrated speedup while maintaining accuracy	Online	Sorting samples	O(N · log(N))
GRAD-MATCH[21]	+ Adpative- Limited to single GPU (distributed training impractical)- No convergence guarantee for skipping selection	Matching samples to gradients	O(N.M)
This Work	+ Scalable+ Efficiently hiding samples+ Theoretically convergence guarantee+ Demonstrated speedup while maintaining accuracy	Sorting samples	O(N · log(N))
that can be achieved by training from scratch using the pruned dataset is similar to that of the original dataset [13, 14, 15, 16]. Our hypothesis is that if samples have a varying impact on the learning process and their impact decreases as the training progresses, then we can in real-time, adaptively, exclude samples with the least impact from the dataset during neural network training.
In this paper, we dynamically hide samples in a dataset to reduce the total amount of computing and the training time, while maintaining the accuracy level. Our proposal, named KAKURENBO, is built upon two pillars. First, using combined information about the loss and online estimation of the historical prediction confidence (see Section 3.1) of input samples, we adaptively exclude samples that contribute the least to the overall learning process on a per-epoch basis. Second, in compensation for the decrease in the number of SGD steps, we derive a method to dynamically adjust the learning rate and the upper limit on the number of samples to hide in order to recover convergence rate and accuracy.
We evaluate performance both in terms of reduction in wall-clock time and degradation in accuracy. Our main results are twofold: first, we show that decaying datasets by eliminating the samples with the least contribution to learning has no notable negative impact on the accuracy and convergence and that the overhead of identifying and eliminating the least important samples is negligible. Second, we show that decaying the dataset can significantly reduce the total amount of computation needed for DNN training. We also find that state-of-the-art methods such as importance sampling algorithm [11], pruning [13], or sample hiding techniques [17, 18] performs poorly on large-scale datasets. To the contrary, our method can reduce training time by  $10.4\%$  and  $22.4\%$  on ImageNet-1K [19] and DeepCAM [4], respectively, impacting Top-1 accuracy only by  $0.4\%$ .
As the size of training datasets and the complexity of deep-learning models increase, the cost of training neural networks becomes prohibitive. Several approaches have been proposed to reduce this training cost without degrading accuracy significantly. Table 1 summarizes related work against this proposal. This section presents the main state-of-the-art techniques. Related works are detailed in the Appendix-E.
Biased with-Replacement Sampling has been proposed as a method to improve the convergence rate in SGD training [11, 12]. Importance sampling is based on the observation that not all samples are of equal importance for training, and accordingly replaces the regular uniform sampling used to draw samples from datasets with a biased sampling function that assigns a likelihood to a sample being
Figure 1: Overview of KAKURENBO. At each epoch, samples are filtered into two different subsets, the training list and the hidden list, based on their loss, prediction accuracy (PA), and prediction confidence (PC), with a maximum hidden fraction of  $F$ . PA and PC are used to drive sample move back decisions. Samples in the training list are processed using uniform sampling without replacement. The loss and the prediction accuracy, calculated from the training process, are reused to filter samples in the next epoch. For samples on the hidden list, KAKURENBO only calculates the loss and PA by performing the forward pass at the end of each epoch.
drawn proportional to its importance; the more important the sample is, the higher the likelihood it would be selected. The with-replacement strategy of importance sampling maintains the total number of samples the network trains on. Several improvements over importance sampling have been proposed for distributed training [22], or for estimating the importance of samples [12, 23, 24, 25, 26].
Overall, biased with-replacement sampling aims at increasing the convergence speed of SGD by focusing on samples that induce a measurable change in the model parameters, which would allow a reduction in the number of epochs. While these techniques promise to converge in fewer epochs on the whole dataset, each epoch requires computing the importance of samples which is time-consuming.
Data Pruning techniques are used to reduce the size of the dataset by removing less important samples. Pruning the dataset requires training on the full dataset and adds significant overheads for quantifying individual differences between data points [27]. However, the assumption is that the advantage would be a reduced dataset that replaces the original datasets when used by others to train. Several studies investigate the selection of the samples to discard from a dataset[13, 15, 14, 16] [28].
Pruning the dataset does reduce the training time without significantly degrading the accuracy [13, 14]. However, these techniques require fully training the model on the whole dataset to identify the samples to be removed, which is comput intensive.
Selective-Backprop [17] combines importance sampling and online data pruning. It reduces the number of samples to train on by using the output of each sample's forward pass to estimate the sample's importance and cuts a fixed fraction of the dataset at each epoch. While this method shows notable speedups, it has been evaluated only on tiny datasets without providing any measurements on how accuracy is impacted. In addition, the authors allow up to  $10\%$  reduction in test error in their experiments.
Grad-Match [18] is an online method that selects a subset of the samples that would minimize the gradient matching error. The authors approximate the gradients by only using the gradients of the last layer, use a per-class approximation, and run data selection every  $R$  epochs, in which case, the same subsets and weights will be used between epochs. Due to the infrequent selection of samples, Grad-Match often needs a larger number of epochs to converge to the same validation accuracy that can be achieved by the baseline [29]. Moreover, Grad-Match is impractical in distributed training, which is a de facto requirement in large dataset and models. Distributed Grad-Match would require very costly collective communication to collect the class approximations and to do the matching optimization. This is practically a very high cost for communication per epoch that could even exceed the average time per epoch.
3 KAKURENBO: Adaptively Hiding Samples
In this work, we reduce the amount of work in training by adaptively choosing samples to hide in each epoch. We consider a model with a loss function  $\ell(\mathbf{w},\mathbf{x}_n,\mathbf{y}_n)$  where  $\{\mathbf{x}_n,\mathbf{y}_n\}_{n=1}^N$  is a dataset of  $N$  sample-label pairs  $(x_n \in X)$ , and  $G: X \to X$  is a function that is applied to hide certain samples during training, e.g., by ranking and cut-off some samples. Using SGD with a learning-rate  $\eta$  and batch size of  $B$ , the update rule for each batch when training with original full dataset is
$$
\mathbf {w} _ {t + 1} = \mathbf {w} _ {t} - \eta \frac {1}{B} \sum_ {n \in \mathcal {B} (k (t))} \nabla_ {\mathbf {w}} \ell \left(\mathbf {w} _ {t}, \mathbf {x} _ {n}, \mathbf {y} _ {n}\right) \tag {1}
$$
where  $k(t)$  is sampled from  $[N / B] \triangleq \{1, \dots, N / B\}$ ,  $\mathcal{B}(k)$  is the set of samples in batch  $k$  (to simplify,  $B$  is divisible by  $N$ ). We propose to hide  $M$  examples by applying the a hiding function  $G$ . We modify the learning rule to be
$$
\mathbf {w} _ {t + 1} = \mathbf {w} _ {t} - \eta \frac {1}{B} \sum_ {n \in \mathcal {B} (k (t))} \nabla_ {\mathbf {w}} \ell \left(\mathbf {w} _ {t}, G (\mathbf {x} _ {n}), \mathbf {y} _ {n}\right) \tag {2}
$$
using  $B$  batch at each step, which is composed of  $N / B$  steps. Since we exclude  $M$  samples, the aggregate number of steps is reduced from  $N / B$  to become  $(N - M) / B$ , i.e., fixing the batch size and reducing the number of samples reduces the number of SGD iterations that are performed for each epoch.
Sample hiding happens before presenting the input to each epoch. The training set that excludes the hidden samples  $(N - M)$  is then shuffled for the training to process with the typical w/o replacement uniform sampling method.
Based on the above training strategy, we propose KAKURENBO, a mechanism to dynamically reduce the dataset during model training by selecting important samples. The workflow of our scheme is summarized in Figure 1. First, (B.1) we sort the samples of a dataset according to their loss. We then (B.2) select a subset of the dataset by hiding a fixed fraction  $F$  of the data: the samples with the lowest loss are removed from the training set. Next, (B.3) hidden samples that maintain a correct prediction with high confidence (see Section 3.1) are moved back to the epoch training set. The training process (C) uses uniform sampling without replacement to pick samples from the training list. KAKURENBO adapts the learning rate (C.2) to maintain the pace of the SGD. At the end of the epoch, we perform the forward pass on samples to compute their loss and the prediction information on the up-to-date model (D). However, because calculating the loss for all samples in the dataset is prohibitively computc intensive [11], we propose to reuse the loss computed during the training process, which we call lagging loss (D.2). We only recompute the loss of samples from the hidden list (D.1). In the following, we detail the steps of KAKURENBO.
3.1 Hidden Samples Selection
We first present our proposed algorithm to select samples to hide in each epoch. We follow the observation in [11] that not all the samples are equal so that not-too-important samples can be hidden during training. An important sample is defined as the one that highly contributes to the model update, e.g., the gradient norm  $\nabla_{\mathbf{w}}\ell (\mathbf{w}_t,\mathbf{x}_n,\mathbf{y}_n)$  in Equation 1. Removing the fraction  $F$  of samples with the least impact on the training model from the training list could reduce the training time, i.e., the required computing resource, without affecting the convergence of the training process. Selecting the fraction  $F$  is arbitrary and driven by the dataset/model. If the fraction  $F$  is too high, the accuracy could drop. In contrast, the performance gained from hiding samples will be limited if  $F$  is small, or potentially less than the overhead to compute the importance of samples. In this work, we aim to design an adaptive method to select the fraction  $F^{*}$  in each epoch. We start from a tentative maximum fraction  $F$  at the beginning of the training process. We then carefully select the hidden samples from  $F$  based on their importance and then move the remaining samples back to the training set. That is, at each epoch a dynamic hiding fraction  $F^{*}$  is applied.
It is worth noting that the maximum fraction number  $F$  does not need to be strictly accurate in our design; it is a maximum ceiling and not the exact amount of samples that will be hidden. However, if the negative impact of hiding samples, i.e.  $\frac{\sum_{n\in 1}^{F^* \times N}\|\nabla_{\mathbf{w}}\ell(\mathbf{w}_t,\mathbf{x}_n,\mathbf{y}_n)\|}{\sum_{n\in 1}^{N}\|\nabla_{\mathbf{w}}\ell(\mathbf{w}_t,\mathbf{x}_n,\mathbf{y}_n)\|}$ , becomes too high, it could
significantly affect the accuracy. For example, when a high maximum fraction  $F$  is set and/or when most of the samples have nearly the same absolute contribution to the update, e.g., at the latter epoch of the training process. We investigate how to choose the maximum hiding fraction in each epoch in Section 3.3.
Moving Samples Back: since the loss is computed in the forward pass, it is frequently used as the metric for the importance of the sample, i.e. samples with high loss contribute more to the update and are thus important [11, 22]. However, the samples with the smallest loss do not necessarily have the least impact (i.e., gradient norm) on the model, which is particularly true at the beginning of the training, and removing such high-impact samples may hurt accuracy. To mitigate the misselection of important samples as unimportant ones, we propose an additional rule to filter the low-loss samples based on the observation of historical prediction confidence [13]. The authors in [13] observed that some samples have a low frequency of toggling back from being classified correctly to incorrectly over the training process. Such samples can be pruned from the training set eternally. Because estimating the per-sample prediction confidence before training (i.e., offline) is compute-intensive, in this work, we perform an online estimation to decide whether an individual sample has a history of correct prediction with high confidence or not in a given epoch. Only samples that have low loss and sustain correct prediction with high confidence in the current epoch are hidden in the following epoch.
A sample is correctly predicted with high confidence at an epoch  $e$  if it is predicted correctly (PA) and the prediction confidence (PC) is no less than a threshold  $\tau$ , which we call the prediction confidence threshold, at the previous epoch. In addition to the prediction confidence of a given sample  $(x, y)$  is the probability that the model predicts this sample to map to label  $y$ :
$$
o u t = m o d e l \left(\mathbf {w} _ {e}, x, y\right)
$$
$$
P C = \max  _ {k} (\sigma (o u t _ {k})) \tag {3}
$$
where  $\sigma$  is a sigmoid (softmax) activation function. In this work, unless otherwise mentioned, we set the prediction confidence threshold to  $\tau = 0.7$  as investigated in Section 4.3.
3.2 Reducing the Number of Iterations in Batch Training: Learning Rate Adjustment
After hiding samples, KAKURENBO uses uniform without replacement sampling to train on the remaining samples from the training set. In this section, we examine issues related to convergence when reducing the number of samples and we provide insight into the desirable convergence properties of adaptively hiding examples.
Implicit bias in the SGD training process may lead to convergence problems [30]: when reducing the total number of iterations at fixed batch sizes, SGD selects minima with worse generalization. We examine the selection mechanism in SGD when reducing the number of iterations at a fixed batch size. For optimizations of the original datasets, i.e., without example hiding, we use loss functions of the form
$$
f (\mathbf {w}) = \frac {1}{N} \sum_ {n = 1} ^ {N} \ell (\mathbf {w}, \mathbf {x} _ {n}, \mathbf {y} _ {n}), \tag {4}
$$
where  $\{\mathbf{x}_n,\mathbf{y}_n\}_{n = 1}^N$  is a dataset of  $N$  data example-label pairs and  $\ell$  is the loss function. We use SGD with batch of size  $B$  and learning-rate  $\eta$  with the update rule
$$
\mathbf {w} _ {t + 1} = \mathbf {w} _ {t} - \eta \frac {1}{B} \sum_ {n \in \mathcal {B} (k (t))} \nabla_ {\mathbf {w}} \ell \left(\mathbf {w} _ {t}, \mathbf {x} _ {n}, \mathbf {y} _ {n}\right). \tag {5}
$$
for without replacement sampling,  $B$  divisible by  $N$  (to simplify), and  $k(t)$  sampled uniformly from  $\{1,\dots ,N / B\}$ . When using an over-parameterized model as is the case with deep neural networks, we typically converge to a minimum  $\mathbf{w}^*$  that is a global minimum on all data points  $N$  in the training set [31, 14]. Following Hoffer et al. [32], linearizing the dynamics of Eq. 5 near  $\mathbf{w}^*$  ( $\forall n:\nabla_{\mathbf{w}}\ell (\mathbf{w}^{*},\mathbf{x}_{n},\mathbf{y}_{n}) = 0$ ) gives
$$
\mathbf {w} _ {t + 1} = \mathbf {w} _ {t} - \eta \frac {1}{B} \sum_ {n \in \mathcal {B} (k (t))} \mathbf {H} _ {n} \mathbf {w} _ {t}, \tag {6}
$$
where we assume  $\mathbf{w}^{*} = 0$  since the models we target are over-parameterized (i.e., deep networks) leading to converge to a minimum  $\mathbf{w}^{*}$ . We also assume  $\mathbf{H}_n \triangleq \nabla_{\mathbf{w}}^2 \ell(\mathbf{w}, \mathbf{x}_n, \mathbf{y}_n)$  represents the per-example loss Hessian. SGD can select only certain minima from the many potential different global minima for the loss function of a given the full training set  $N$  (and without loss of generality, for the training dataset after hiding samples  $N - M$ ). The selection of minima by SGD depends on the batch sizes and learning rate through the averaged Hessian over batch  $k$
$$
\langle \mathbf {H} \rangle_ {k} \triangleq \frac {1}{B} \sum_ {n \in \mathcal {B} (k)} \mathbf {H} _ {n}
$$
and the maximum over the maximal eigenvalues of  $\{\langle \mathbf{H}\rangle_k\}_{k = 1}^{N / B}$
$$
\lambda_ {\max } = \max  _ {k \in [ N / B ]} \max  _ {\forall \mathbf {v}: \| \mathbf {v} \| = 1} \mathbf {v} ^ {\top} \left\langle \mathbf {H} \right\rangle_ {k} \mathbf {v}. \tag {7}
$$
This  $\lambda_{\mathrm{max}}$  affects SGD through the Theorem proved by Hoffer et al. [32]: the iterates of SGD (Eq. 6) will converge if
$$
\lambda_ {\mathrm {m a x}} <   \frac {2}{\eta}
$$
The theorem implies that a high learning rate leads to convergence to be for global minima with low  $\lambda_{\mathrm{max}}$  and low variability of  $\mathbf{H}_n$ . Since in this work we are fixing the batch size, we maintain  $\lambda_{\mathrm{max}}$ , the variability of  $\langle \mathbf{H}\rangle_k$ . Therefore, certain minima with high variability in  $\mathbf{H}_n$  will remain accessible to SGD. Now SGD may converge to these high variability minima, which were suggested to exhibit worse generalization performance than the original minima [33].
We mitigate this problem by reducing the delta by which the original learning rate decreases the learning rate (after the warm-up phase [34]). That way we make these new minima inaccessible again while keeping the original minima accessible. Specifically, KAKURENBO adjusts the learning rate at each epoch (or each iteration)  $e$  by the following rule:
$$
\eta_ {e} = \eta_ {\text {b a s e}, e} \times \frac {1}{1 - F _ {e}} \tag {8}
$$
where  $\eta_{base,e}$  is the learning rate at epoch  $e$  in the non-hiding scenario and  $F_{e}$  is the hiding fraction at epoch  $e$ . By multiplying the base learning rate with a fraction  $\frac{1}{1 - F_e}$ , KAKURENBO is independent of the learning rate scheduler of the baseline scenario and any other techniques related to the learning rate.
3.3 Adjusting the Maximum Hidden Fraction  $F$
Merely changing the learning rate may not be sufficient, when some minima with high variability and low variability will eventually have similar  $\lambda_{\mathrm{max}}$ , so SGD will not be able to discriminate between these minima.
To account for this, we introduce a schedule to reduce the maximum hidden fraction. For the optimum of the set of hidden samples,  $\mathbf{w}_{\mathbf{M}} = G(\mathbf{x}_n)$  and an overall loss function  $F(\cdot)$  that acts as a surrogate loss for problems which are sums of non-convex losses  $f_{i}(\mathbf{w})$  , where each is individually non-convex in w. With Lipschitz continuous gradients with constant  $L_{i}$  we can assume
$$
\left\| \nabla f _ {i} (\mathbf {w} _ {1}) - \nabla f _ {i} (\mathbf {w} _ {2}) \right\| \leq L _ {i} \| \mathbf {w} _ {1} - \mathbf {w} _ {2} \|
$$