Setting Up Environment
Some excercises in this course will have somewhat extensive compute requirements which means you will have to think about how you will want to run your code. The simplest approach is to run your code locally (i.e., on your own computer). If that ends up being too slow, we describe how to use Google Colab or RunPod for this course below.
Please note that if you plan on running our code primarily on Google Colab, you won't have to install anything manually. If you are running locally, you will have to install a few basic requirements: PyTorch, Matplotlib, etc. If you are running on RunPod, you will find that many of the basic requirements listed on this page are already installed. One less conventional package you will need to install is our own xlab-security package which you will use for utility functions and running tests.
Running Coding Exercises
Different stages of this course will require different compute requirements. For example, in some sections, you will be calling APIs which take up nearly zero computational resources on your own machine. In others, you will have to run an LLM with 1.6B parameters (which is ~3.29G of data). For users who cannot run models this large on their own computers (we expect this to be most students) we explain how you can run our exercises for free or for very low cost using either Google Colab or Lambda Labs.
Option #1: Local
For every notebook, we will have a link to our GitHub where you can download a notebook to run the code exercises locally on your computer. For some students, this will be the most familiar and convenient setup. For others, it may be hard to configure or slow to run.
Being able to ML code locally is an important research skill. By running code locally, you will gain experience managing python packages and optimizing for less than ideal hardware. Therefore, we encourage all students to run code locally when possible. We will indicate on the website which sections we expect to be not feasible to run locally, but we encourage this to be your default option.
For managing python packages locally, we recommend using a virtual environment. For our own internal development, we use uv.
Option #2: Colab
Colab has both a paid and free option. We have tested all notebooks on the free version so you shouldn’t have to sign up for Colab premium.
In order to get the advantages of Colab you will have to pay careful attention to the runtime you connect to. At the top right corner you should find a dropdown with an option to “Change runtime type.” You are free to play around with the different options, but as long as you select a machine that is not “cpu” you should be fine.
Option #3: Runpod
Runpod is a paid service for cloud computing. There are many powerful machines you can rent out for less than 5 dollars an hour. If you want even fast compute (even though this shouldn’t be necessary) or if you want to use the code you write in this course to play around with larger models, we highly recommend using Runpod.
To run your exercises using SSH, follow Runpod's documentation (or see here if you prefer using SSH with VSCode or Cursor). If you'd prefer using JupyterLab to run your code (which is perhaps the most beginner-friendly method), see here.
Because setting up SSH forwarding (e.g. to git commit from your remote connection) is a bit difficult, we provide some additional steps to do this below:
- Make sure your public key is added to the Runpod public keys in the settings.
- Start your desired Runpod instance (ensure it is a secure cloud pod, which are TCP enabled by default) and ensure to confirm SSH terminal access before deploying.
- Copy the command to connect via SSH using exposed TCP.
- Add the comand to your
~/.ssh/configfile. For example, you'd turnssh root@123.456.789 -p 1234 -i ~/.ssh/id_ed25519into
Host runpod
HostName 123.456.789
Port 1234
User root
IdentityFile ~/.ssh/id_ed25519
ForwardAgent yes
- Add your github SSH key to your ssh agent:
ssh-add ~/.ssh/<GITHUB_PRIVATE_KEY>. - Run
ssh runpod. - Confirm that you can access github on the Runpod instance:
ssh -T git@github.com.
Installing xlab-security
To install xlab-security all you will need to do is run:
pip install xlab-security
Or within a jupyter notebook:
!pip install xlab-security
To import the package within a python file or jupyter notebook, you may run:
import xlab
We will always show you how to use the package within the notebooks so there is nothing new here you need to learn. The package is still in development, so if something isn't working as expected, you should submit an issue on our GitHub or flag it in our slack. Before you alert us of the error, always make sure that you have updated your package to the most recent version. You can update the package by running:
pip install --upgrade xlab-security
Installing other packages
In addition to having python3, we will assume that you have installed the following packages already:
huggingface_hub: install huggingface_hubpytorch: instal pytorchmatplotlib: install matplotlibnumpy: install numpypeft: install peft
For the most part, you will not actually need to know much about how to use matplotlib. However, some parts of the coding exercises will include cells with matplotlib code we have completed for you for useful visualizations.