Running Fastbook on Windows 10 Locally using the GPU without WSL/Anaconda

Hey guys I am on Windows 10. I have a lot of coding experience and for whatever reason I just cannot get myself to go through the course on the “cloud”. I tried like 3-4 times in the last 5 months and I can’t stand not running code on my own machine. I’ve spent many hours sifting through the threads asking the same question I am asking but I can’t seem to find a single coherent guide.

I have a Nvidia RTX 3050 set-up with cuda confirmed working (ran a matrix multiplication test using the CPU as well as the GPU).
I use PyCharm Pro IDE.

I am stuck on actually using the fastbook course with Jupyter notebooks. I have anaconda installed, was able to install PyTorch, Jupyter, etc… but anaconda doesn’t find fastai.

Is it possible to run the notebooks without using anaconda? (I am comfortable with venv/pip)
Is there a guide anywhere for that? If not, and it is possible, I will make one.

Short answer is that yes, it is possible to run just using venv.

I did a fresh install and decided to skip using anaconda and just use a venv.

From windows powershell (running as admin) I did the following:

# make and than cd to the dir you want to use
cd A:\.code\py\standalone\2024\fastbook
# setup the venv
python -m venv fastai-env
# activate venv
.\fastai-env\Scripts\activate
# install pytorch (custom pip command here: https://pytorch.org/get-started/locally/)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# install fastai and jupyter notebook
pip install fastai
pip install notebook

I than started my IDE (Pycharm Pro) and selected the folder I created A:\.code\py\standalone\2024\fastbook as the base dir for my project.
I selected the venv I created as my project interpreter.

I than created a regular py file and ran the following test code:

import fastai
from fastai.vision.all import *
from pathlib import Path


# Adjusted label_func to handle both str and Path objects
def label_func(f): return Path(f).name[0].isupper()


def main():
    print(f"FastAI Version: {fastai.__version__}")
    print(f"PyTorch Version: {torch.__version__}")

    path = untar_data(URLs.PETS)
    print(f'Image Path: {path}')
    files = get_image_files(path / "images")

    # Sanity check: Ensure files are loaded
    if not files:
        print("No image files found. Check the dataset path and contents.")
        return
    print(f"Number of files: {len(files)}")

    dls = ImageDataLoaders.from_name_func(
        path, files, label_func, item_tfms=Resize(224), bs=64, num_workers=0
    )

    # Additional sanity checks
    print(f"Train DataLoader length: {len(dls.train)}")
    print(f"Valid DataLoader length: {len(dls.valid)}")

    # Display a batch to ensure DataLoader is working
    dls.show_batch(max_n=4)

    learn = vision_learner(dls, resnet34, metrics=error_rate)

    # For debugging, we'll bypass lr_find and use a hardcoded learning rate
    print("Starting training with a hardcoded learning rate...")
    learn.fine_tune(1, base_lr=1e-3)  # Example learning rate

    print("Training complete!")


if __name__ == '__main__':
    main()

I kept get NaN results but solved that by adding num_workers=0 to the ImageDataLoaders code.
Which finally worked! Giving the results below:

FastAI Version: 2.7.14
PyTorch Version: 2.2.2+cu121
Image Path: C:\Users\H1\.fastai\data\oxford-iiit-pet
Number of files: 7390
Train DataLoader length: 92
Valid DataLoader length: 24
Starting training with a hardcoded learning rate...
epoch     train_loss  valid_loss  error_rate  time    
0         0.227548    0.019236    0.008119    01:06     
epoch     train_loss  valid_loss  error_rate  time    
0         0.044756    0.014205    0.004060    01:14     
Training complete!

Once this was working, I opened up the first lesson Jupyter notebook and got it working!

Fingers crossed that I don’t run into any other major issues in the next lessons. Happy to make a better structured guide or youtube video if people are interested. Really happy to be able to work on this on my local machine!