Installing packages
For this course, we have already installed the required packages, but this section is important for you when you want to install packages on your machine or on the Alliance clusters.
On your machine
On your machine (but not on the Alliance clusters), I recommend that you use uv to create a Python project with your chosen Python version and all the necessary packages. uv installs packages much faster than pip and it is able to resolve dependencies very well. It also manages Python versions.
If you want more information on this, I gave a webinar on uv in May 2025.
Create a Python project (let’s call it jaxai) and cd into it:
uv init --bare jaxai
cd jaxai--bare creates a uv project without files that I am not interested in here such as a README and a main.py.
Install the packages:
uv add dm-pix imageio jax-ai-stack "jax[cuda13]" matplotlib orbax polars scikit-image tqdm "transformers==4.57.3"Quick explanation of packages we are installing:
- dm-pix ➔ for data augmentation
- imageio ➔ to load images into NumPy arrays
- jax-ai-stack ➔ installs JAX for the CPU (if not already installed for the GPU),
Flax—the main NN library,
Optax—optimizers & loss functions,
Orbax—for checkpointing,
Grain—to build efficient dataloaders,
ml_dtypes—NumPy dtype extensions for deep learning
- jax[cuda13] ➔ only if you want to run JAX on GPUs (use an appropriate version of Cuda)
- matplotlib ➔ to display samples
- orbax ➔ checkpointing and saving model
- polars ➔ for DataFrames
- scikit-image ➔ image resizing
- tqdm ➔ display progress bars
- transformers ➔ load model and pre-trained weights from Hugging Face model Hub
We pin the version because v5 will not support JAX anymore
If you install packages which depend on JAX (e.g. Flax), they will by default install the CPU version of JAX. If you want to run JAX on GPUs, make sure to install jax[cuda13] (or whatever Cuda version is suitable).
You will see that the dependencies have automatically populated a pyproject.toml file and that a virtual environment called .venv was created.
As long as you are within the project, you don’t need to activate that virtual environment: all you need to do is run python/jupyter lab/ipython/ptpython/a .py script after uv run.
Examples:
$ uv run python
$ uv run jupyter lab
$ uv run ptpython
$ uv run my_script.pyYou can even launch Jupyter lab within a project without installing it in that project by using:
$ uv run --with jupyter jupyter labAlternatively, if you really want a pip equivalent (for backward compatibility with old pipelines for instance), you can activate it as you would any other Python virtual environment:
source .venv/bin/activateOn an Alliance cluster
I already installed all the necessary packages in the training cluster to save time and space. The instructions for today thus differ from what you would normally do and production cluster instructions in the second tab are for your future reference only.
Look for available Python modules:
module spider pythonLoad version 3.11.5:
module load python/3.11.5I created a virtual Python environment with all necessary packages under /project. All you have to do today is activate it with:
source /project/def-sponsor00/nabirds_venv/bin/activateLook for available Python modules:
module spider pythonLoad the version of your choice:
module load python/3.13.2Create a Python virtual environment:
python -m venv ~/envActivate it:
source ~/env/bin/activateUpdate pip from wheel:
python -m pip install --upgrade --no-index pipWhenever a Python wheel for a package is available on the Alliance clusters, you should use it instead of downloading the package from PyPI. To do this, simply add the --no-index flag to the install command.
You can see whether a wheel is available with avail_wheels <package> or look at the list of available wheels.
Advantages of wheels:
- compiled for the clusters’ hardware,
- ensures no missing or conflicting dependencies,
- much faster installation.
Install libraries from wheel:
python -m pip install --no-index dm-pix imageio jax-ai-stack "jax[cuda]" matplotlib orbax polars scikit-image tqdm "transformers==4.57.1"Don’t forget
--no-indexto install from wheels.On the cluster, we pin the
transformersversion to4.57.1because this is the highest v4 present.
We don’t have cuda13 on the Alliance clusters yet. If you follow JAX official installation instructions and try to install jax[cuda13], pip will default to installing jax (CPU only).
Make sure to use jax[cuda] (or the equivalent jax[cuda12]) instead to have the GPU version installed.
Moving from your computer to the cluster
If you prototyped your project locally and want to move it to an Alliance cluster to run it at scale, here are some tips.
Environment
Install the packages in a Python virtual environment with venv and pip as shown above.
Code
Clone the project from a Git remote (or copy it with scp -r or rsync):
[local]$ scp -r </path/to/local/project> <user>@<cluster>.alliancecan.ca:~/<path/to/remote/project>Data
Deep learning datasets often contain many small files (e.g. images), but clusters are slowed to a crawl by swarms of small files.
Pack the data directory into an archive on your machine and copy the archive to the cluster:
[local]$ tar cf data.tar -C </path/to/local/project/data>
[local]$ scp data.tar <user>@<cluster>.alliancecan.ca:~/projects/def-<user>/If the archive is very large, you can use Globus for the transfer.
Then keep the archive as is on the cluster and only extract it inside jobs.