How to Set Up the AI-for-Beginners Conda Environment with GPU Support

The AI-for-Beginners curriculum provides a pre-configured Conda environment named ai4beg that includes CUDA-enabled PyTorch; you only need to install NVIDIA drivers and run conda env create -f environment.yml to enable GPU acceleration.

Setting up the AI-for-Beginners conda environment with GPU support ensures you can execute the curriculum's deep learning notebooks with hardware acceleration. The microsoft/AI-For-Beginners repository ships with an environment.yml file that defines all necessary dependencies, including a CUDA-enabled PyTorch build, eliminating manual package configuration.

Prerequisites: NVIDIA Drivers and CUDA

Before creating the Conda environment, verify that your host machine has the required NVIDIA driver version installed. The driver must be recent enough for the CUDA version bundled with PyTorch (e.g., driver ≥ 525 for CUDA 12.x).

Verify NVIDIA Driver Installation

Check your current GPU driver status using the following command:

nvidia-smi

This displays your GPU model, driver version, and CUDA capability. If the command fails, install the latest drivers from NVIDIA's official website for your operating system.

CUDA Toolkit Installation (Optional)

Conda automatically pulls the necessary CUDA libraries when installing pytorch::pytorch, making a system-wide CUDA toolkit installation optional. However, installing the toolkit provides development tools like nvcc and enables custom CUDA compilation. Follow the official NVIDIA installation guide for your OS if you require these utilities.

Creating the AI-for-Beginners Conda Environment

The repository root contains the primary environment definition in environment.yml. This file specifies the ai4beg environment name and includes the GPU-ready PyTorch stack among other machine learning dependencies.

Create the environment by running:

conda env create -f environment.yml

This command reads the dependency list from [environment.yml](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) and downloads the appropriate CUDA-enabled binaries from the pytorch channel.

Activate the Environment

Once creation completes, activate the environment:

conda activate ai4beg

Your shell prompt should now indicate the active ai4beg environment, and Python commands will use this isolated package stack.

Verifying GPU Support

After activation, confirm that PyTorch can access your GPU. As implemented in the curriculum source code—specifically in [lessons/5-NLP/18-Transformers/torchnlp.py](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/5-NLP/18-Transformers/torchnlp.py#L7) at line 7 and [lessons/4-ComputerVision/07-ConvNets/pytorchcv.py](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/4-ComputerVision/07-ConvNets/pytorchcv.py#L17) at line 17—you can verify GPU availability programmatically.

Run the following verification script:

import torch
print("CUDA available:", torch.cuda.is_available())

The output should display True, confirming that the ai4beg environment recognizes your NVIDIA GPU and can leverage CUDA acceleration for training and inference.

Alternative Setup: VS Code Dev Container

For containerized development, the repository provides an identical environment definition at [.devcontainer/environment.yml](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml).

Opening the repository in GitHub Codespaces or VS Code with "Reopen in Container" automatically configures the GPU-enabled environment. Ensure your host machine has a compatible GPU and that Docker Desktop (or your container runtime) has GPU passthrough enabled before launching the dev container.

Summary

  • Driver Requirement: Install NVIDIA drivers ≥ 525 (or appropriate for your target CUDA version) before creating the environment.
  • Environment Creation: Use conda env create -f environment.yml to build the ai4beg environment with CUDA-enabled PyTorch.
  • Verification: Run torch.cuda.is_available() in Python to confirm GPU access, matching the checks found in the curriculum notebooks.
  • Container Support: The .devcontainer/environment.yml provides identical GPU configuration for VS Code dev containers and Codespaces.

Frequently Asked Questions

Do I need to manually install CUDA if I use Conda?

No. The environment.yml file in the AI-for-Beginners repository pulls the CUDA runtime libraries automatically when installing pytorch::pytorch. A manual CUDA toolkit installation is only necessary if you need development tools like nvcc or plan to compile custom CUDA extensions outside of the Conda environment.

How do I know if my GPU is compatible with the AI-for-Beginners environment?

Any NVIDIA GPU with compute capability 3.5 or higher should work with the CUDA-enabled PyTorch version specified in the environment. Run nvidia-smi to check your GPU model, then verify its compute capability against NVIDIA's documentation. The curriculum code explicitly checks for GPU availability using torch.cuda.is_available() before executing CUDA operations.

Can I run the notebooks without a GPU?

Yes. The PyTorch code throughout the curriculum falls back to CPU execution when torch.cuda.is_available() returns False. However, training deep learning models without GPU acceleration will be significantly slower, particularly for computer vision and transformer lessons that process large tensors.

What if torch.cuda.is_available() returns False?

First, verify that you activated the correct environment (conda activate ai4beg) and that the environment was created from the official environment.yml file. Next, check nvidia-smi to ensure your drivers are functioning. If using WSL2 on Windows, ensure you have the latest WSL kernel and NVIDIA drivers installed, as GPU passthrough requires specific driver versions compatible with WSL.

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 →