ARTIFICIAL INTELLIGENCE
AI Knowledge Base by Sunil Marella

Local AI/ML Lab Setup

Building a Local AI/ML Lab on Windows with WSL2, Ubuntu and NVIDIA GPU

1. Check the Laptop Hardware

Before installing anything, identify the CPU, GPU, NPU, RAM and storage.

2. Check WSL

Run:

wsl --status

Then:

wsl --version

Example:

WSL version: 2.6.3.0
Kernel version: 6.6.87.2-1

Check installed distributions:

wsl -l -v

Initially there may be no Linux distributions installed.


3. Enable WSL2 Virtual Machine Platform

If WSL reports:

WSL2 is not supported with your current machine configuration.

Please enable the "Virtual Machine Platform"
optional component.

and virtualization is already enabled in BIOS, run PowerShell as Administrator:

wsl --install --no-distribution

Restart Windows afterward.

Then check again:

wsl --status

A message saying WSL1 is unsupported is not a problem if the lab uses WSL2.


4. Find Available Ubuntu Versions

Run:

wsl --list --online

Ubuntu 24.04 LTS was selected because it has broad compatibility with AI/ML tooling.


5. Install Ubuntu 24.04

Run:

wsl --install -d Ubuntu-24.04

Windows downloads and provisions Ubuntu.

You will be asked to create a Linux user:

Create a default Unix user account:
sunil

New password:
********

This Linux password is independent of the Windows password.


6. Verify Ubuntu Uses WSL2

Exit Ubuntu if necessary:

exit

Then from PowerShell:

wsl -l -v

Expected:

NAME            STATE      VERSION
Ubuntu-24.04    Running    2

This confirms:

Ubuntu 24.04
     ↓
WSL2

7. Launch Ubuntu

From PowerShell:

wsl -d Ubuntu-24.04

The prompt changes from something like:

PS C:\Users\username>

to:

sunil@hostname:~$

That means you are now running Linux.


8. Windows Commands vs Linux Commands

Commands such as:

wsl -l -v

belong to Windows PowerShell.

Inside Ubuntu, use Linux commands such as:

pwd
ls
cd
python3
nvidia-smi

9. Move to the Linux Home Directory

If Ubuntu opens in a mounted Windows directory, move to the Linux home directory:

cd ~

Verify:

pwd

Expected:

/home/sunil

For AI development, keep projects under the Linux filesystem rather than /mnt/c/... wherever practical.


10. Test NVIDIA GPU from WSL

Inside Ubuntu run:

nvidia-smi

The GPU should appear successfully, for example:

NVIDIA GeForce RTX 4060 Laptop GPU
8188 MiB VRAM

This confirms:

Windows NVIDIA driver
        ↓
WSL2
        ↓
Ubuntu
        ↓
NVIDIA GPU interface
        ↓
RTX 4060

Important

Do not install a separate NVIDIA Linux display driver inside WSL.

WSL obtains GPU access through the Windows NVIDIA driver.


11. Create the AI Lab Directory

Inside Ubuntu:

cd ~
mkdir -p ~/ai-lab
cd ~/ai-lab

Verify:

pwd

Expected:

/home/sunil/ai-lab

12. Install Basic Development Tools

Update Ubuntu:

sudo apt update

Install Python, virtual environment support, pip and Git:

sudo apt install -y \
python3 \
python3-venv \
python3-pip \
git

Check:

python3 --version
git --version

13. Create a Python Virtual Environment

From:

/home/sunil/ai-lab

run:

python3 -m venv .venv

Activate it:

source .venv/bin/activate

The shell changes to:

(.venv) sunil@hostname:~/ai-lab$

The virtual environment isolates Python packages for this AI project.


14. Upgrade Python Packaging Tools

Run:

python -m pip install --upgrade pip setuptools wheel

Verify which Python is being used:

which python

Expected:

/home/sunil/ai-lab/.venv/bin/python

15. Install PyTorch

With .venv active:

pip install torch torchvision torchaudio

In this environment, PyTorch reported:

PyTorch 2.14.0+cu130

16. Create the First GPU Test

Create:

/home/sunil/ai-lab/gpu-test.py

Do not put source files inside .venv.

Correct structure:

ai-lab/
│
├── .venv/
│
└── gpu-test.py

Example:

import torch

print("PyTorch version:", torch.__version__)
print("CUDA available:", torch.cuda.is_available())

if torch.cuda.is_available():
    print("GPU:", torch.cuda.get_device_name(0))
    print("CUDA version:", torch.version.cuda)
    print("GPU count:", torch.cuda.device_count())

Run:

python gpu-test.py

Example result:

PyTorch version: 2.14.0+cu130
CUDA available: True
GPU: NVIDIA GeForce RTX 4060 Laptop GPU
CUDA version: 13.0
GPU count: 1

This confirms:

Python
   ↓
PyTorch
   ↓
CUDA
   ↓
RTX 4060

17. Install Visual Studio Code

VS Code is used as the graphical development environment.

Architecture:

Windows
   │
   └── VS Code GUI
           │
           ▼
      WSL Ubuntu
           │
           ▼
       Python
           │
        PyTorch
           │
         CUDA
           │
       RTX 4060

Install these Microsoft VS Code extensions:

  • WSL
  • Python
  • Python Debugger
  • Jupyter
  • Pylance (recommended)

18. Connect VS Code to Ubuntu

In VS Code:

Ctrl + Shift + P

Search for:

WSL: Connect to WSL

Select:

Ubuntu-24.04

VS Code should indicate something similar to:

WSL: Ubuntu-24.04

This means the VS Code GUI is running on Windows while the project environment is running inside Ubuntu.


19. Open the AI Lab in VS Code

Open:

/home/sunil/ai-lab

The project should look approximately like:

AI-LAB
│
├── .venv
│
└── gpu-test.py

20. Select the Correct Python Interpreter

Use:

Ctrl + Shift + P

Then:

Python: Select Interpreter

Select:

/home/sunil/ai-lab/.venv/bin/python

or the environment displayed as:

Python 3.12 (.venv)

This ensures VS Code uses the same Python environment where PyTorch is installed.


21. Test GPU Usage

Run:

nvidia-smi

An idle GPU might show:

GPU-Util: 0%
Memory:
0 MiB / 8188 MiB

During GPU workloads, this changes.

For example:

GPU-Util: 25%
Memory:
797 MiB / 8188 MiB

Continuously monitor the GPU using:

watch -n 1 nvidia-smi

Press:

Ctrl+C

to stop monitoring.


22. Suggested Lab Directory Structure

The lab can gradually develop into:

~/ai-lab/
│
├── .venv/
├── gpu-test.py
├── notebooks/
│   ├── 01-gpu-basics.ipynb
│   ├── 02-pytorch-basics.ipynb
│   ├── 03-neural-network.ipynb
│   ├── 04-transformers.ipynb
│   ├── 05-embeddings.ipynb
│   └── 06-rag.ipynb
│
├── projects/
│   ├── local-llm/
│   ├── rag-demo/
│   └── ai-observability/
│
├── models/
├── data/
└── README.md

Create the main directories with:

mkdir -p notebooks projects models data

23. Lab 1 Current Status

At this stage, the infrastructure foundation is complete.

Hardware discovery                 ✅

CPU
Intel Core Ultra 9 185H            ✅

NPU
Intel AI Boost                     ✅

Integrated GPU
Intel Arc                          ✅

AI GPU
RTX 4060 8 GB                      ✅

RAM
24 GB DDR5                         ✅

Storage
1 TB NVMe                          ✅

Virtualization
Enabled                            ✅

WSL2
Working                            ✅

Ubuntu
24.04 LTS                          ✅

GPU from Ubuntu
Detected                           ✅

Python
Installed                          ✅

Python virtual environment
Created                            ✅

PyTorch
Installed                          ✅

CUDA from PyTorch
Working                            ✅

RTX 4060 from PyTorch
Detected                           ✅

VS Code
Connected to WSL                   ✅

The important final test was:

torch.cuda.is_available()

returning:

True

and:

torch.cuda.get_device_name(0)

returning:

NVIDIA GeForce RTX 4060 Laptop GPU