Understand Data Preprocessing for Effective End-to-End Training of Deep
  Neural Networks
In this paper, we primarily focus on understanding the data preprocessing
pipeline for DNN Training in the public cloud. First, we run experiments to
test the performance implications of the two major data preprocessing methods
using either raw data or record files. The preliminary results show that data
preprocessing is a clear bottleneck, even with the most efficient software and
hardware configuration enabled by NVIDIA DALI, a high-optimized data
preprocessing library. Second, we identify the potential causes, exercise a
variety of optimization methods, and present their pros and cons. We hope this
work will shed light on the new co-design of ``data storage, loading pipeline''
and ``training framework'' and flexible resource configurations between them so
that the resources can be fully exploited and performance can be maximized.
Ping Gong, Yuxin Ma, Cheng Li, Xiaosong Ma, Sam H. Noh
# Understand Data Preprocessing for Effective End-to-End Training of Deep Neural Networks

###### Abstract.

In this paper, we primarily focus on understanding the data preprocessing pipeline for DNN Training in the public cloud. First, we run experiments to test the performance implications of the two major data preprocessing methods using either raw data or record files. The preliminary results show that data preprocessing is a clear bottleneck, even with the most efficient software and hardware configuration enabled by NVIDIA DALI, a high-optimized data preprocessing library. Second, we identify the potential causes, exercise a variety of optimization methods, and present their pros and cons. We hope this work will shed light on the new co-design of "data storage, loading pipeline" and "training framework" and flexible resource configurations between them so that the resources can be fully exploited and performance can be maximized.

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

+
Footnote †: journal: Computer Vision and Pattern Recognition

## 1. Introduction

One major contributor to the huge success of deep learning (DL) is the existence of diverse and large datasets, while another is the abundance of massive computing power, mostly from accelerators like GPUs. Popular DL frameworks, such as MXNet (Maswani et al., 2017), TensorFlow (Krizhevsky et al., 2014), and PyTorch (Krizhevsky et al., 2014), connect these two driving forces to train deep neural network (DNN) models, iteratively feeding GPUs with batches of data samples from a collection of raw data such as images, videos, and text. Before being efficiently consumed by armies of GPU cores, raw data must first be loaded into memory and processed through a sequence of transformation operators such as decode, crop, resize, and normalize.

To effectively utilize the massive GPU parallelism available today, such data preprocessing must also be effective enough to continually pump data to satisfy the GPUs' appetite. Unfortunately, most existing studies have focused on just the training part, often neglecting the data preprocessing pipeline (Deng et al., 2015; Goyal et al., 2016; Goyal et al., 2016). Fortunately, though a few recent studies have started to consider this issue. _E.g._, Uber and Apple introduced their data platforms, with data models and methods to store and manage data for machine learning tasks (Goyal et al., 2016; Goyal et al., 2016). Yang and Gong proposed a distributed cache to speed up the I/O steps in data preparation for distributed DNN training (Xiao et al., 2017), while OneAccess applies a similar idea to avoid redundant data loading for concurrent hyper-parameter tuning experiments sharing datasets (Goyal et al., 2016). Still, none of the existing studies provide a comprehensive overview of DL data preprocessing pipeline, its performance, or major systems design issues involved.

This work examines the data preprocessing pipeline in three major frameworks, specifically, TensorFlow, MXNet, and PyTorch, and its performance implications on overall training efficiency. Our major findings are as follows:

* The widely used DL frameworks have long and highly similar data preprocessing pipelines, with the common data format and data structure choices.
* Different DNN models, meanwhile, show different relative speeds in data preprocessing and actual training. With most studies focused on training performance, the majority of model training workflows have bottlenecks at data loading and preprocessing.
* While the aforementioned three major frameworks all perform data preprocessing on CPUs and training on GPUs, the new NVIDIA framework DALI (Goyal et al., 2016) does deliver better overall performance by enabling CPU-GPU co-processing for preparing training data samples. However, it possesses caveats such as potential OutOf-Memory (OOM) problems, currently requiring a manual search for a proper batch size to avoid OOM while preserving high throughput.
* Nevertheless, a single time-consuming step (such as image decoding, currently placed at the CPU side by DALI) may dominate the pipeline execution time, making GPUs wait for data. To eliminate this bottleneck, one would need to add more CPU resources.
* Our preliminary results indicate that more flexible node configurations would allow more cost-effective executions of diverse DL pipelines: 7.86% and 3.03% speedup of training speed for AlexNet and ResNet50 with more CPU resources allocated, respectively, and 75% reduction in CPU resource allocation for ResNet50 with relatively comparable performance. Loading data samples from SSD-based storage options almost delivers the best training speed for ResNet18, while using DRAM introduces a 1.84\(\times\) speedup for AlexNet.
Our study chimes in the argument for _resource disaggregation_(Cordes and McAllester, 2011; Chen et al., 2013; Chen et al., 2014; Chen et al., 2015), a new trend in cloud infrastructure design featuring composable and disaggregated resource deployment, delivering comparable performance, while retaining strong flexibility at the same time (Zhou et al., 2015; Zhang et al., 2016). Currently, some cloud providers such as Google Cloud and EC2 are enabling this feature to some extent, by allowing the number of vC-PUs for GPU machines to be adjusted, though under particular constraints (Chen et al., 2013). We believe that the data preprocessing-training resource balancing problem described in this paper lends a common and resource-intensive use case to upcoming cloud resource disaggregation offerings. In particular, to avoid time-consuming manual configuration, there should be tools making such configuration and scaling decisions automatic, for higher overall user DL model training throughput (per hour or dollar) and simultaneously, for better overall system utilization from the cloud provider's point of view.

## 2. Understanding the Training Pipeline

It is necessary to train DNN models with vast amounts of data to achieve accurate results. However, the real-world data sets are often not in a suitable form such that they can be directly fed into the neural network. The data set often goes through a data preprocessing pipeline, spanning across loading, decoding, decompression, data augmentation, format conversion, and resizing. Given that the performance of accelerators, including GPUs, is rapidly improving, this data loading pipeline phase of end-to-end training will inevitably become more and more significant.

### Iterative DNN training

Training DNN models are computationally intensive and time-consuming. To shorten the training process and make DNN models quickly deployable, current common practice explores the massive parallelism offered by multiple GPUs for collective training following a mini-batch stochastic gradient descent (SGD) algorithm (Srivastava et al., 2014). This phase of training, which is depicted (and denoted "DNN model") on the rightmost side of Figure 1, has been the focus of the majority of studies on improving DNN training. This training process works iteratively: at each round, a small batch of data samples will be fetched and loaded into the GPU memory as input for the neural network model training. However, for such training, typically, the application-specific raw data stored in persistent storage need to be transformed into _tensors_, a unified data format consumed by various training frameworks. We refer to this phase of training as a data preprocessing pipeline, which is depicted in the left part of Figure 1.

### Overview of data preprocessing pipeline

We analyze four different implementations of the data preprocessing pipeline, where the first three are built-in solutions for three widely adopted training frameworks, namely, TensorFlow, MXNet, and PyTorch, and the last one is a unified interface for all three aforementioned frameworks developed by NVIDIA called DALI (Nvidia et al., 2015). Despite being implemented by different communities, the composition of their pipelines looks almost the same. As follows, we report two major data preprocessing methods, namely, loading from raw data and loading from record files. For simplicity, in this paper, we describe the image processing scenario as an example. However, we observe that the general scenario holds across tasks ranging from Natural Language Processing (NLP) to Video Processing.

#### 2.2.1. Raw data preprocessing

The numbers in the black circle in Figure 1 depict the preprocessing pipeline for raw data.

Figure 1. The end-to-end training pipeline where the first stage is the data preprocessing for Computer Vision tasks.
First, Data Preprocessor (or short, DPP) reads a sequential metadata file, and stores it in memory as a dictionary for retrieving the actual data later on. The metadata file is usually generated offline, and each of its tuples contains the index (sequentially assigned), label, and path of each image. Then, \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) DPP partitions the whole file identifier list into a set of smaller sequences and shuffles them. \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) DPP continues to get the file ids from each sequence, uses ids to look up the corresponding labels and paths in the memory dictionary, loads the raw image files pointed by the paths, and decodes them into tensors. When tensors of the raw image files are ready, \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) DPP moves to the "augmentation" step, where tensors are transformed into new ones via a sequence of steps such as random crop, flip, rotation, etc. Finally, \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) Data Loader combines multiple tensors to form batches and \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) load these batches to the GPUs.

#### 2.2.2. Record file preprocessing

As indicated in Figure 1 by the white circled numbers, in addition to raw data preprocessing, there is another method, which makes use of record files. These record files are generated, through offline processing, \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) - \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) by reading a large number of raw image files stored on disks and then, appending them into a few large sequential record files. These files include images as well as their label and id. Then, during runtime, these record files are \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) read into memory and partitioned into smaller chunks. These chunks are \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) decoded, and thereafter, the remaining steps \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) - \(\mathtt{\raisebox{-1.0pt}{\includegraphics[width=1.0pt]{fig-1.0pt}{fig-1.0pt}} }\) are the same as the raw data preprocessing method.

There are two major reasons for designing this record file loading method. First, compared to raw data, record files transform random accesses into sequential accesses, which can lead to performance gains if data are stored in slow storage or scattered across multiple machines. Second, it is possible to offload some operators, such as crop and resize, in the data preprocessing pipeline to the record file generation phase for improved data loading efficiency. In essence, the record file loading method is trading extra processing time and storage space for training speed improvement.

Finally, one would think it feasible to take all tasks along the data preprocessing pipeline offline so that the runtime can be optimized. While this is feasible in terms of performance, this may not be the best approach for DNNs. This is because the training process requires some form of randomness from data sample inputs to improve the robustness and universality of DNN models, which is achieved by executing some non-deterministic operators in the pipeline such as random rotates and flips. Such randomness is required for the best results in DNN. Therefore, the preferable choice is to just append images to sequential record files with no further preprocessing.

#### 2.2.3. CPU-GPU co-processing

All the four data loading pipeline implementations that we consider allow both raw data and record file loading methods. The main difference between the three built-in data loading libraries in the TensorFlow, MXNet, and PyTorch frameworks and DALI is that while the former three-run the data loading pipeline on CPUs only, DALI makes use of the GPUs to speed up the task by offloading parts of the pipeline to GPUs. We refer readers to DALI code examples (B
**Models and data sets:** We train five DNN models, namely, AlexNet (Krizhevsky et al., 2015), ShuffleNet (Zie et al., 2015), ResNet18(He et al., 2017), ResNet50 (He et al., 2017), and ResNet152 (He et al., 2017), on the widely used ImageNet data set (Krizhevsky et al., 2015). We enable mixed-precision training (FP16 option on) to fully exploit GPU resources. For AlexNet, ShuffleNet, and ResNet18, we adopt a batch size of 512 as larger batches produce little performance improvement. The other two models are much larger due to having more layers, so ResNet50 uses a batch size of 192 and ResNet152 uses 128, due to memory constraints.

**Metrics:** We measure data preprocessing and model training throughput, in samples per second. For reference, we also plot the "ideal" training performance, where training reuses a single batch preloaded into GPU memory. In addition, we measure both the CPU and GPU utilization levels.

### Overall performance

Figure 2 gives overall training performance across preprocessing methods. First, most models see improvement when using record files and especially when adopting hybrid data preprocessing. The former benefits from a higher ratio of sequential I/O, which is advantageous even on NVMe SSDs. The latter allows powerful GPUs to ease the data preprocessing bottleneck on CPUs and achieve more balanced system utilization.

However, we observe that for three of the five models, their best end-to-end training throughput is significantly lower than the ideal one. This demonstrates the performance impact of the data preprocessing pipeline and GPU underutilization. That is, the data preprocessing pipeline is not able to fill the GPUs fast enough such that the GPUs are being underutilized, which is validated in the following section. In particular, for AlexNet, its peak performance under record-hybrid is only 23% of the ideal case. Considering these three fast data consumers where hybrid data preprocessing helps the most (exemplified by the large jump from green bar to red bar), as the GPUs otherwise starved for data is used to offload data preparation from CPUs, we observe 98% to 114% throughput improvement for them compared to record-CPU. Interestingly, even for these three models, hybrid processing does not help when raw files are used, as random I/O dominates loading and CPUs alone can match the I/O speed. ResNet50 and Resnet152, in contrast, are much more computation-intensive in training (with much lower ideal training throughput than the other models), rendering data loading less influential.

To further investigate why offloading portions of preprocessing to the GPUs significantly improves training performance, here, we report the latency breakdown of different steps along the data loading pipeline. In so doing, we do not enable training, instead, only focus on running the data preprocessing pipeline and exercising the performance of its individual operators. We plot the times spent in different data augmentation operators in Figure 3. Note that we are reporting breakdowns when only the CPU is being used for data preprocessing. The results highlight that all data preprocessing operators consume nearly 95% of the whole pipeline cost. Among these operators, image decoding is most time-consuming, which accounts for 47.7% of the total time. When record-hybrid is used in our experiments, data preprocessing splits the operators such that most of the decoding and beyond are performed by the GPU, reducing the overall preprocessing time.

Note that the performance benefits of record-hybrid come at a cost. First, it requires extra work offline to produce record files. Second, effective pipeline design requires concurrent data preprocessing and model training on the GPUs. This comes with two consequences. One is that there is a potential cause for OOM errors, which will require manual intervention to avoid. The other is that, as we show later in Figure 5, training throughput may be negatively affected due to the sharing of the GPUs.

### Resource Utilization

Figure 4 plots the utilization level of different resources during the training process under record-hybrid for AlexNet and ResNet50, each, respectively, representing a fast and slow data consumer. It is worth noting that the roughly first one-third of each curve corresponds to the initialization of training. For ResNet50, GPUs are nearly saturated for the last two-thirds of the entire process while CPU utilization is

Figure 3. 100% stacked bar graph showing breakdown latency of major steps for preprocessing a single image on CPU, which takes 14.26 ms in total (Numbers are percentages.)

Figure 2. End-to-end training performance
at a much lower 38% and the I/O bandwidth-consuming only 147MB/s, also much lower than its maximum capacity. We observe that ResNet50 is GPU-bound where training data consumption is slow enough to hide I/O and data preprocessing. Thus, we find that CPU and storage devices are being underutilized. We also see that even though GPU resources are precious, DAI is making use of these resources for data loading, which is an unwise choice of use.

AlexNet, on the other hand, is a fast data consumer making quick use of the loaded data and then waiting for more data to arrive. This is reflected in the fluctuation of GPU utilization. Overall, the GPU is utilized under 50%. In contrast, we see that the CPU utilization much higher than that of ResNet50 (Figure 3(b)) and that the I/O bandwidth is also considerably higher (Figure 3(c)). We see that record-hybrid is helpful in this case as it helps improve the utilization of the GPUs. However, we see that the CPUs are not enough to satiate the data needs of the GPU and that the more CPUs need to be allocated to the data preprocessing pipeline.

## 4. Effect of Resource Balancing

Public cloud providers are beginning to offer more flexible instance configurations. Table 1 lists available GPU VM instances on Amazon EC2 and Google Cloud. With a given instance type associated with fixed GPU resources, both platforms allow users to specify the desired number of vCPUs within a preset range. EC2 further enables I/O throughput (proportional to persistent storage capacity requested), while Google Cloud provide a limited number of storage choices. Along with such flexible configurations come fined-grained charging policies. _E.g._, on the listed Google Cloud instances, GPU and vCPU cost 2.48 and 0.033$/hour, respectively, while memory costs 0.00445/GB-hour.

While such flexible configurations provide consumers with better choices, selecting the best configuration for a DNN model is not an easy task. Our eventual goal is to develop a tool that will propose model-specific, fine-grained resource configurations for a model training workflow while maintaining high throughput performance. Our findings described in the previous section show that such a tool will be valuable.

In this section, we present some results that may be possible once this tool is developed. In particular, we investigate the performance implications of adjusting the number of vCPUs. Again, in the interest of space, we focus on the two representative DNN models evaluated earlier, AlexNet and ResNet50.

First, consider the preprocessing-bound AlexNet, where we fix the number of GPUs to 4 and adjust the number of

\begin{table}
\begin{tabular}{c||c|c|c|c} Type & \#GPU & \#vCPU & I/O & \$/h \\ \hline \hline p3.2xlarge & 1 & \(\leq 8\) & Configurable & \(<3.06\) \\ p3.16xlarge & 8 & \(\leq 64\) & Configurable & \(<24.48\) \\ p3dn.24xlarge & 8 & \(\leq 96\) & Configurable & \(<31.21\) \\ \hline V100-1 & 1 & \(\leq 12\) & Options & \(<3.22\) \\ V100-4 & 4 & \(\leq 48\) & Options & \(<12.90\) \\ V100-8 & 8 & \(\leq 96\) & Options & \(<25.80\) \\ \hline \end{tabular}
\end{table}
Table 1. VM instances commonly used for DNN model training on AWS EC2 (Gupta et al., 2017) (top), and Google Cloud (Gupta et al., 2017) (bottom). All GPUs are V100.

Figure 4. Resource stats of AlexNet and ResNet50 corresponding to the best performed record-hybrid experiments in Figure 2.

Figure 5. End-to-end training performance of AlexNet and ResNet50 with CPU resources adjusted for GPUs
vCPUs. With all 64 vCPUs available for the 4 GPUs, we investigate one additional loading method (aside from the hybrid mode evaluated earlier), which performs decoding on CPU and the rest of preprocessing on GPU, denoted as hybrid-0. This mode uses more CPU resources while relieving the more expensive GPU resources to training. Recall that in a hybrid image decoding is jointly performed by CPU and GPU. Figure (a)a shows that, while hybrid saturates training at 24 vCPUs (6 per GPU), hybrid-0 delays its saturation point to 44 vCPUs (11 per GPU). This results in a 7.86% increase in training speed as depicted by a higher line beyond 11 vCPUs in the figure.

Now consider the training-bound ResNet50, where the GPU is the clear bottleneck. Thus, we make use of all 8 GPUs for these experiments. Here we can explore reducing vCPU allocation without performance degradation or improving performance by re-configuring the CPU-GPU co-processing tasks. Figure (b)b confirms that the number of required vCPUs here is much lower than available in such instances. For instance, under the hybrid mode, 16 vCPUs (2 per GPU) can adequately feed the GPUs. To further reserve GPUs for the time-consuming training, we push DALI optimization back to using solely CPU for data preparation, _i.e._, the cpu mode, denoted CPU in the figure. Now we need 48 vCPUs (6 per GPU) to saturate the training pipeline, paying more CPU costs, for a training speed improvement of 3.03%. We further observe (but not shown here) that moving from ResNet50 to ResNet152, with deeper layers, the training pipeline becomes even more GPU-bound, reducing the vCPU requirement to 8 vCPUs (1 per GPU). Note that in both the AlexNet and ResNet50 examples, we observe that employing GPUs for the data preprocessing pipeline, though helpful for the pipeline, results in reduced throughput.

Finally, we shift our attention to exploring the performance implications of using different storage media for hosting training data. For this purpose, we deploy AlexNet and ResNet18 on an EC2 p3dn.24xlarge instance, and train them with 4 V100 GPUs, each assisted by 12 vCPU cores. We vary the storage devices, testing EBS (up to 7500 IOPS), two NVMe SSDs (default setting by EC2), and DRAM. Figure 6 reports the end-to-end training performance.

We observe that loading data samples directly from EBS and NVMe SSDs (corresponding to 1 in Figure 1) achieves almost the same training performance for the two models. This is because EBS is a highly optimized storage option exploring SSDs and it offers similar I/O bandwidths as the attached NVMe SSDs. Interestingly, when loading data samples from DRAM, the training performance of ResNet18 has been just improved by 8.8%. This is a direct consequence of the fact that ResNet18, like ResNet50, is computation-intensive and the bandwidths of EBS and NVMe SSDs are sufficient to meet the needs of the training phase in GPU. In contrast, using DRAM leads to a 1.84\(\times\) speedup of the AlexNet training performance against the other two storage options. This is because the computation of AlexNet is much faster than ResNet18, and it demands larger I/O bandwidth beyond the capacity of both EBS and NVMe SSDs. Therefore, the performance impact of storage configuration is model dependent. For certain models, investing in high-bandwidth storage may significantly improve the overall cost-effectiveness of DNN training.

## 5. Conclusion and Future Directions

It is commonly accepted that DNN training requires considerable resources in terms of GPU/accelerator and network infrastructure. While studies to expedite training through better management of these resources have been the focus of many studies, we contend that there is another aspect that is as important, which, to date, has been largely neglected. Specifically, data has to be fed to the accelerators such that the accelerators can be fully utilized.

In this work, we examine the data preparation process of widely used deep learning model training frameworks. We have found that different frameworks have highly similar data loading and preprocessing pipelines, while the relative overhead of data preparation to that of in-memory model training varies significantly across popular DNN models. Based on our performance results, our contention is that this pipeline is currently inefficient, often leading to considerable resource waste, especially the under-utilization of expensive GPU resources. We further verify the effectiveness in hybrid CPU-GPU data preparation and propose model-specific, fine-grained cloud instance configuration for efficient and cost-effective model training.

In future work, we will extend our performance analysis to both NLP and video processing models. Following that,

Figure 6. End-to-end training performance of ResNet18 and AlexNet, loading data samples from different storage options
we plan to build a tool that enables automatic resource configuration to adapt to the demand for diverse deep learning training workloads.
