3 minutes
Setup WSL for AI
Setting up WSL for for AI using an Nvidia GPU
This step is simple 🫠, for a Linux/Unix sysadmin. It took me about 10 minutes to figure all of this out, but I’ve realized this might be the hardest step in the adventure for folks who want to do AI/ML work on their own. This guide is intended to let you skip 🚀 the hard parts.
Hardware Required
For this guide to work perfectly, you need an Nvidia GPU > 2000 series which includes support for tensor cores. RTX GPUs with tensor cores have been around since 2018.
Software Required
A Windows 11 computer 💻 with administrative access.
Setup
First open an administrative 🖥️ command prompt. You can do this by typing cmd into your Start/Search text box.
Install wsl by opening a command prompt as an administrator and running.
wsl --install
You’ll see it installing, and if it’s already installed you’ll see this.
Now you can access your WSL anytime by typing “wsl” in a command window (admin window not required).
- ⚠️ Note: All of the following commands must be done in your wsl environment.*
Now we need some package software to run out AI/ML suite. The first two commands will pull and perform updates.
sudo apt update
sudo apt upgrade -y
sudo apt install python3-pip
Lets install our PyTorch ai libraries.
pip3 install torch torchvision torchaudio
Now lets see if this all works by generating some pictures using information from this post : https://matthewrogers.org/posts/stablediffusionxl-gradio/
git clone https://github.com/ramborogers/stablediffusionxl.git
cd stablediffusionxl
pip install -r requirements.txt
The install from pip takes the longest and should finish without any major errors.
Now run this thing.
⚠️ Note: The first run takes a minute or so, the multi-gigabyte ai model must be downloaded.
python3 app.py
Click the link or open your browser to http://127.0.0.1:7860 or whatever your command window tells you.
It works! Lets generate something to test, as it generates take a look at your command window for feedback on the process.
Try the prompt:
A space alien with red eyes that is lost.
In the command window you’ll see it generating like this.
At 100% take a look back at your browser window.
How cool is that! You’re alien should be different.
⚠️ Note: As part of this a seed is generated, if you use the same seed, steps and prompt, you will get reproducible output.
Summary
You’ve installed WSL, setup pyTorch, installed an AI application and generated some art of an alien 👽. If this was helpful or if I made any errors please feel free to comment and I will incorporate and provide attribution.
I hope you have fun with AI! ❤️
Sincerely,
Matthew Rogers