SeriesDeep Learning16 / 20

Scalable Training

Module 15 of CS 7643 - Deep Learning @ Georgia Tech.

Overview#

Modern deep learning libraries such as torch provide direct integration with the Graphics Processing Unit (GPU) to drastically increase computational efficiency via parallelization. Whenever possible, we should prefer torch operations over base Python to benefit from this enhanced efficiency.

Script Mode#

Additionally, torch has different modes depending on the level of desired optimization:

We can convert normal functions to programs optimized by JIT using torch.jit.script. For example…

a = torch.rand(5)
def func(x):
for i in range(10):
x = x*x
return x
scripted_func = torch.jit.script(func)
%timeit func(a)
# 18.5 microseconds per loop
%timeit scripted_func(a)
# 4.41 microseconds per loop

JIT performs various types of optimization to increase efficiency.

JIT

End-to-End Scalable Training#

Ingesting Data#

How can we efficiently load + use data as part of our machine learning workflow? PyTorch provides the following classes to interact with data:

from torch.utils.data import DataLoader, RandomSampler
dataloader = DataLoader(
dataset, # only for map-style dataset
batch_size=8, # balance speed and convergence
num_workers=2, # non-blocking when > 0
sampler=RandomSampler,
pin_memory=True
)

Pinned memory (also known as page-locked memory) refers to a specific hardware optimization concept for transferring data from the CPU to the GPU. Normal RAM is pageable, meaning it is separated into bocks called pages that can be swapped out to the disk as needed. In contrast, pinned memory is page-locked such that the operating system cannot swap it to disk. Before CUDA can send data from CPU to GPU, it must first create a page-locked version of the data. In the case of pinned_memory=True, torch loads the data into page-locked memory to avoid the expensive copy operation when sending to GPU.

For a more thorough overview of pinned memory, check out the PyTorch guide.

Distributed Computing#

We have primarily discussed Parallelism in terms of the operations performed by a single GPU. In this section, we will extend our discussion of parallelism to include distributed computing, whether in terms of multiple GPUs on a single machine or multiple machines.

In deep learning, we frame distributed parallelism from two major perspectives:

Here are a few examples of parallelized implementations:

single-machine-data-parallel
single-machine-model-parallel
distributed-data-parallel
distributed-data-parallel-with-single-machine-model-parallel

(all images obtained from Georgia Tech DL course materials)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts