Ensure you are running Windows 10 version 2004 or later (Build 19041) or Windows 11.
- Install the latest NVIDIA drivers from the NVIDIA website.
- Ensure the drivers support WSL 2 GPU passthrough. You can check compatibility on the NVIDIA Driver Downloads page.
Make sure WSL2 is installed and updated:
wsl --updateIf not already installed, install WSL2 and a Linux distribution (e.g., Ubuntu):
wsl --install -d UbuntuEnsure WSL2 is set as the default version:
wsl --set-default-version 2Inside your WSL2 distribution, install the NVIDIA Container Toolkit:
sudo apt-get update
sudo apt-get install -y nvidia-driver-510
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart dockerEdit the .wslconfig file in your Windows user directory (C:\Users\<YourUsername>):
[wsl2]
gpu=true
memory=8GB # Adjust as needed
processors=4 # Adjust as neededRestart WSL2:
wsl --shutdown
wsl --distribution UbuntuRun nvidia-smi to verify the GPU is recognized:
nvidia-smiYou should see output similar to this:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.85.02 Driver Version: 510.85.02 CUDA Version: 11.6 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce GTX 165... Off | 00000000:01:00.0 Off | N/A |
| N/A 41C P8 9W / 175W | 0MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------------------------------------------+
Ensure that the NVIDIA drivers installed on Windows match those expected by the NVIDIA Container Toolkit in WSL2. Reinstall the drivers if necessary.
Install CUDA in your WSL2 distribution if it's not already installed:
sudo apt-get install -y cudaVerify the installation by checking the CUDA version:
cuda --versionRunning AI models in WSL2 with GPU passthrough offers significant performance benefits compared to CPU-only execution. However, there may still be some overhead compared to native Linux due to the virtualization layer. For most practical purposes, the performance should be close to native Linux.
This guide should help you set up and verify GPU passthrough for WSL2, enabling you to run local AI models efficiently on your Windows machine.