09. WSL2 Problems

Chapter 9 of 15 · 20 min

GPU Access in WSL2

WSL2 requires Windows 11 (or Windows 10 21H2+) with WSLg and NVIDIA driver installed on Windows. The CUDA driver inside WSL2 must match the Windows driver.

# Inside WSL2: verify CUDA
nvcc --version
nvidia-smi
# Inside WSL2: verify PyTorch sees CUDA
python -c "import torch; print(torch.cuda.is_available())"

If nvidia-smi works inside WSL2 but PyTorch reports CUDA unavailable, the PyTorch installation was compiled for a different CUDA version than installed.

Memory Allocation

WSL2 by default limits memory to 50% of total RAM or 8GB, whichever is less. For large model inference:

# Create .wslconfig in Windows home directory (C:\Users\yourname\)
[wsl2]
memory=16GB
processors=8

Then restart WSL:

wsl --shutdown
wsl

Disk Space

WSL2 virtual disk files do not automatically reclaim space after deleting files inside Linux. Compacting requires:

# From Windows PowerShell (not inside WSL)
wsl --shutdown
# Run diskpart
diskpart
select vdisk file="C:\Users\yourname\AppData\Local\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Inside WSL2, run nvidia-smi and note the driver version. Compare it to the Windows NVIDIA driver version shown in Windows Task Manager → Performance → GPU tab. If they differ by more than one minor version, update the Windows driver.