Infrastructure for deep learning
# Infrastructure for Deep Learning Research OpenAI's 2016 post argues that the quality of a research group's infrastructure multiplies its rate of progress in deep learning, which is an empirical science. The authors describe how deep learning work moves from rapid, ad-hoc experiments to long, carefully managed multi-GPU training runs, and explain the stack they built to support both phases. They also open-source kubernetes-ec2-autoscaler, a batch-optimized scaling manager for Kubernetes. ## The Research Workflow Deep learning research happens in two distinct phases, and the infrastructure has to serve both: - **Early exploration** is fast and unstructured. Researchers want to SSH into a machine, run a script in `screen`, and see a result within an hour. - **Scaling up** requires multi-day jobs on many GPUs, careful experiment tracking, and deliberate hyperparameter selection. - Making a model work often means watching it fail in many ways, so infrastructure must support flexible introspection of models rather than only summary statistics. ## A Worked Example: Improved GAN Training The post traces how one idea moved from concept to large-scale result. The idea was to give the GAN discriminator a whole minibatch of samples instead of one, so it can detect when the generator collapses to a single output. - The idea was prototyped on MNIST and CIFAR-10 with small models, producing some of the best CIFAR-10 samples the team had seen. - Scaling to ImageNet required parallelizing across multiple GPUs, with jobs driving machines to about 90% CPU and GPU utilization and training for many days. - The authors note that the final results were good but short of expectations, and they have not yet identified the reason. ## Software and Hardware Choices - **Software:** Mostly Python 2.7 with TensorFlow (occasionally Theano), with Keras used on top in some cases. Anaconda handles difficult packages such as OpenCV. - **GPUs:** Multi-GPU scaling is usually sublinear, so top-of-the-line GPUs matter. CPU-heavy workloads such as simulators and reinforcement learning environments run separately from GPU workloads. - **Hybrid cloud:** AWS donated compute for CPU instances and horizontally scaled GPU jobs, while the team also runs physical servers, mainly with Titan X GPUs, to experiment with different hardware. ## Provisioning and Orchestration - **Provisioning:** Terraform manages AWS resources, Chef configures Ubuntu nodes on both cloud and physical hardware, and Packer pre-bakes cluster AMIs for faster spin-up. Clusters use non-overlapping IP ranges and connect over OpenVPN and strongSwan. - **Storage:** Home directories, datasets, and results live on NFS for physical hardware and on EFS or S3 in AWS. - **Scheduling:** Kubernetes schedules jobs across three AWS regions, since bursty demand can exhaust capacity in a single region. Each job runs as a Docker container for dependency isolation and code snapshotting, and tooling ships laptop code into a standard image to avoid slow rebuilds. - **Networking:** Kubernetes' flannel network is exposed directly to researchers' laptops, so services like TensorBoard are reachable without creating a Kubernetes Service for each port. ## kubernetes-ec2-autoscaler Research workloads are bursty. One experiment grew from a single Titan X to 60 Titan Xs and then to nearly 1,600 AWS GPUs within weeks. Standard Auto Scaling policies add nodes piecemeal, and scale-in can kill in-flight jobs unless nodes are drained first. - The autoscaler runs as a normal Pod and requires only that worker nodes belong to Auto Scaling groups. - It polls the Kubernetes master to compute the cluster's resource demand and capacity, then sizes Auto Scaling groups to match in one step. - Excess nodes are drained and terminated. Drained nodes can be uncordoned to skip spin-up time when demand returns. - It handles multiple Auto Scaling groups, resources beyond CPU (memory and GPUs), and constraints such as region and instance size. - When AWS reports capacity errors, it fails over to a secondary region. The authors chose to build on Kubernetes rather than raw EC2 because the surrounding tooling for logging, monitoring, and managing physical nodes was worth keeping, and making Kubernetes autoscale was simpler than rebuilding that ecosystem.