Theano-based Large-Scale Visual Recognition with Multiple GPUs

Weiguang Ding, Ruoyan Wang, Fei Mao, Graham W. Taylor

TL;DR

This paper introduces the first open-source Python-based implementation of AlexNet using Theano, bridging the gap between flexible research frameworks and large-scale performance. By implementing naive data parallelism across two GPUs, the authors achieved training speeds comparable to the then-state-of-the-art Caffe library while maintaining the benefits of automatic differentiation.

What Problem Does This Paper Address?

In 2015, the deep learning landscape was divided. On one side were high-performance, C++-heavy frameworks like Caffe and cuda-convnet, which were excellent for training standard architectures like AlexNet on the massive ImageNet dataset but difficult to modify for experimental research. On the other side was Theano, a Python library beloved by researchers for its automatic differentiation—a feature that saves users from the error-prone task of manually deriving gradient functions for new architectures.

However, Theano lacked a proven track record for large-scale experiments like the ImageNet Large Scale Visual Recognition Challenge (ILSVRC). The primary challenge was performance: training a model as large as AlexNet on millions of images required multi-GPU support and efficient data handling, features that were not yet natively robust in Theano.

Methods

The authors implemented a Theano-based version of AlexNet and introduced two primary optimizations to handle the scale of ImageNet:

  1. Parallel Data Loading: To prevent the GPU from sitting idle while waiting for the CPU to fetch and preprocess images, the authors used a multi-process approach. One process handles the training on the current minibatch, while a second process concurrently loads the next batch from disk, performs preprocessing (like cropping and flipping), and moves it to GPU memory.

    Figure 1: Illustration of parallelized training and loading (1 or 2 GPUs)
  2. Naive Data Parallelism: The implementation scales training across two GPUs. Two identical AlexNet models are initialized. In each training step, each GPU processes a different minibatch. After the local updates, the parameters (weights, biases, and momentum) are exchanged between the GPUs and averaged. This ensures both models remain synchronized while effectively doubling the throughput of processed images.

    Figure 2: Illustration of exchanging and averaging weights (2 GPUs)

The implementation leverages the cuDNN wrapper for optimized convolution operations and PyCUDA for efficient inter-process communication and memory management.

Datasets

The model was trained and evaluated on the ILSVRC 2012 (ImageNet) dataset, which contains over 1 million training examples across 1,000 categories. This served as the benchmark to prove that a Python-based framework could compete in the "big leagues" of computer vision.

Key Insights and Ideas

  • Flexibility vs. Performance: The core "aha" moment is that you don't have to sacrifice Theano's flexibility for speed. By wrapping high-performance kernels (like cuDNN) and managing data flow intelligently in Python, researchers can have the best of both worlds.
  • The GIL Workaround: Python’s Global Interpreter Lock (GIL) prevents true multi-threading. The authors bypassed this by using multiple processes and specialized CUDA context syncing, showing a viable path for parallelization in the Python ecosystem.
  • Communication is Key: The authors highlight that for data parallelism to be effective, the communication overhead (exchanging weights) must be minimized. They achieved this by ensuring GPUs were under the same PCI-E switch to enable fast peer-to-peer memory copies.

Key Results

The authors demonstrated that their Theano implementation was highly competitive:

  • Speed: Using two GPUs with parallel loading (cuDNN-R2), the training time was 19.72 seconds per 20 iterations. This outperformed a single-GPU Caffe setup (26.26s) and was on par with Caffe using cuDNN (20.25s).
  • Accuracy: After 65 epochs, the model achieved a top-1 validation error of 42.6% and a top-5 error of 19.9%. These results were within 0.5% of the standard Caffe implementation, proving that the parallelization and averaging techniques did not degrade model quality.

Limitations and Future Work

The authors noted several constraints:

  • Hardware Dependency: The fast peer-to-peer communication requires GPUs to be on the same PCI-E switch; otherwise, latency increases significantly as data must pass through host memory.
  • Scaling: The study was limited to a 2-GPU setup due to hardware availability at the time.
  • Parallelism Strategy: The report focuses solely on data parallelism. The authors suggest that future work could incorporate model parallelism (splitting a single model across multiple GPUs), which is often necessary for even larger architectures that cannot fit into the memory of a single card.

At the time of writing, native multi-GPU support for Theano was still under development, making this implementation a vital "work-around" for the community.

Summary updated

BibTeX
@inproceedings{ding2015theano,
  author = {Weiguang Ding and Ruoyan Wang and Fei Mao and Graham W. Taylor},
  title = {{Theano-based Large-Scale Visual Recognition with Multiple GPUs}},
  booktitle = {International Conference on Learning Representations},
  year = {2015},
  url = {http://arxiv.org/abs/1412.2302},
}
Figure