Installation & setup
For this course, we have already installed the required packages, but this section will be important when you want to install packages on your machine or on the Alliance clusters.
On your own 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, handles different Python versions extremely smoothly, and resolves dependencies very well.
If you want more information on this, I gave a webinar on uv in May 2025.
Create a Python project (let’s call it pt_project) and cd into it:
uv init --bare pt_project
cd pt_project--bare creates a uv project without the files I am not interested in here, such as a README and a main.py.
Install the packages:
uv add torch torchvision timm torchmetrics datasets safetensors matplotlib open-clip-torchYou 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 Python script after uv run:
uv run python
uv run jupyter lab
uv run ptpython
uv run my_script.pyYou can even launch JupyterLab 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 the Alliance clusters
Modules
You can look at the list of loaded modules with:
module listYou will of course need a Python module:
# Look for available Python modules
module spider python# Look for needed dependencies to load Python 3.14.7
module spider python/3.14.7No CUDA module is required: PyTorch’s wheels ship with their own CUDA libraries.
Some of the packages we are using need the Arrow module (if you try to install without loading it, the error message will hint that you need to load it).
Your turn:
What is the latest available Arrow module?
What are its dependencies?
If you want to use ipython in the terminal for syntax highlighting while prototyping, what do you need to do?
Now that we know which modules to load, let’s load them:
module load StdEnv/2026 python/3.14.7 arrow/26.0.0 ipykernel/2026bVirtual environment
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 the production cluster instructions in the second tab are for your future reference only.
I created a virtual Python environment called pt_env with all necessary packages under /project. All you have to do today is activate it with:
source /project/def-sponsor00/pt_env/bin/activateCreate a Python virtual environment:
python -m venv ~/pt_env # give it the name you wantActivate it:
source ~/pt_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.
If a wheel does not exist on our clusters, you can install it from PyPI by omitting the --no-index flag for that package, or you can open a ticket so that the wheel be installed.
All the packages needed for this course are available in our wheelhouse:
python -m pip install --no-index torch torchvision timm torchmetrics datasets safetensors matplotlib open-clip-torchMoving 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):
scp -r </path/to/local/project> <user>@<cluster>.alliancecan.ca:~/<path/to/remote/project>Data
EuroSAT contains 27,000 small JPEG files. This is common in deep learning, but clusters are slowed to a crawl by swarms of small files. To bypass this problem, pack the data directory into an archive on your machine and copy the archive to the cluster:
tar cf data.tar -C </path/to/local/project/data> .
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.