How to Set Up GPU Acceleration for Deep Learning Training: 5 Proven Methods from Microsoft's AI For Beginners

Training deep learning models on a GPU reduces training time from hours to minutes by parallelizing matrix operations across thousands of CUDA cores.

Deep learning workloads in the Microsoft AI For Beginners curriculum are designed to leverage GPU acceleration for optimal performance. This guide covers every GPU setup pathway documented in the repository, from local workstations to cloud platforms, with exact configuration steps and verification commands.

Local GPU Setup on Linux, macOS, or Windows

The AGENTS.md file contains the definitive local GPU configuration steps for this curriculum.

Prerequisites and Driver Installation

  1. Install a recent NVIDIA driver with matching CUDA toolkit (e.g., CUDA 12)
  2. Verify installation with nvidia-smi:
nvidia-smi

You should see GPU information, driver version, and CUDA version.

Conda Environment Configuration

Navigate to the repository root and create the environment using the provided specification:

conda env create -f environment.yml
conda activate ai4beg

The environment.yml pins GPU-enabled TensorFlow and PyTorch packages. Inspect this file to confirm your CUDA version matches the package requirements.

Verification Commands

TensorFlow GPU detection:

import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))

PyTorch GPU detection:

import torch
print(torch.cuda.is_available())

Expected output: a list of GPU devices for TensorFlow, or True for PyTorch.

Azure Data Science Virtual Machine (Cloud GPU)

For dedicated GPU resources without local hardware, the lessons/0-course-setup/how-to-run.md file recommends Azure DSVM with NC-series instances.

Provisioning Steps

  1. Create an Azure DSVM with NC-series GPU (e.g., NC6)
  2. SSH into the VM and clone the repository
  3. Execute the same conda setup as local installation
  4. Launch Jupyter or VS Code — the VM GPU is automatically available

This approach provides persistent GPU access with full environment control.

Azure Machine Learning Notebooks

Azure Machine Learning (AML) offers managed GPU compute without VM administration.

  1. Create an AML workspace
  2. Launch a notebook with GPU-enabled compute instance
  3. Open repository notebooks directly in the workspace

The AML notebook service automatically provisions and attaches GPU resources to your kernel.

Google Colab (Free GPU Tier)

All multilingual README files in the repository (e.g., translations/zh-CN/lessons/0-course-setup/how-to-run.md) document Colab GPU access for zero-cost experimentation.

Runtime Configuration

  1. Open any notebook in Google Colab
  2. Select Runtime → Change runtime type → Hardware accelerator → GPU
  3. Install missing dependencies:
!pip install -r requirements.txt

TensorFlow and PyTorch automatically detect the assigned Colab GPU (typically NVIDIA T4 or K80).

Managing GPU Memory in TensorFlow

The translated documentation (e.g., translations/zh-CN/lessons/5-NLP/README.md) includes a critical optimization: dynamic GPU memory allocation. By default, TensorFlow reserves all GPU memory, causing out-of-memory errors when multiple processes compete for resources.

Add this snippet at the start of any TensorFlow notebook:

import tensorflow as tf

gpus = tf.config.list_physical_devices('GPU')
if gpus:
    try:
        for gpu in gpus:
            tf.config.experimental.set_memory_growth(gpu, True)
    except RuntimeError as e:
        print(e)

This allows TensorFlow to allocate GPU memory incrementally rather than monopolizing the entire device.

Complete Training Example on GPU

Here's a verified PyTorch training loop from the curriculum that explicitly targets GPU:

import torch
import torch.nn as nn
import torch.optim as optim

# Device selection with automatic fallback

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Model definition and GPU transfer

model = nn.Sequential(
    nn.Linear(784, 256),
    nn.ReLU(),
    nn.Linear(256, 10)
).to(device)

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters())

# Data generation and device transfer

inputs = torch.randn(32, 784).to(device)
targets = torch.randint(0, 10, (32,)).to(device)

# Training step

optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, targets)
loss.backward()
optimizer.step()

print(f"Step completed on {device}")

Key pattern: call .to(device) on both the model and all tensors. Missing either causes device mismatch errors.

Key Configuration Files

File Purpose
environment.yml Specifies exact GPU package versions for conda
AGENTS.md Master reference for all GPU execution environments
lessons/0-course-setup/how-to-run.md Cloud GPU setup instructions
Translation READMEs (e.g., translations/zh-CN/lessons/5-NLP/README.md) TensorFlow memory optimization snippets

Summary

  • Local setup requires NVIDIA drivers, CUDA toolkit, and conda environment from environment.yml
  • Azure DSVM provides dedicated cloud GPU with full environment control
  • Azure ML offers managed GPU compute with automatic resource provisioning
  • Google Colab delivers free GPU access for experimentation via runtime configuration
  • TensorFlow memory growth prevents OOM errors through set_memory_growth() configuration
  • Always verify GPU availability with framework-specific detection commands before training

Frequently Asked Questions

How do I confirm my GPU is actually being used during training?

Check GPU utilization with nvidia-smi during training — you should see memory allocation and GPU activity. In code, monitor torch.cuda.memory_allocated() for PyTorch or tf.config.list_physical_devices('GPU') for TensorFlow. The repository's verification snippets in AGENTS.md provide one-liners for instant confirmation.

Why does TensorFlow crash with "CUDA out of memory" on my GPU?

TensorFlow pre-allocates all GPU memory by default. Insert the memory growth snippet from translations/zh-CN/lessons/5-NLP/README.md at the start of your notebook: iterate through tf.config.list_physical_devices('GPU') and call tf.config.experimental.set_memory_growth(gpu, True) on each device.

Can I use AMD or Apple Silicon GPUs with this curriculum?

The repository's environment.yml targets NVIDIA CUDA. AMD ROCm and Apple Metal Performance Shaders (MPS) require different PyTorch builds not specified in the official curriculum. For Apple Silicon, you can attempt torch.device('mps') but this is not officially supported in the course materials.

What's the difference between NC6 and NC6_v3 Azure instances?

NC6 uses K80 GPUs; NC6_v3 uses V100 GPUs with significantly better performance for deep learning. The lessons/0-course-setup/how-to-run.md documentation recommends NC-series generally — choose NC6_v3 or newer for transformer-based models in later lessons.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →