Run Your First Job¶
This guide covers running a first job on the Mila cluster. Create a minimal
PyTorch project that checks CUDA and GPU availability, and develop on the
cluster using VSCode on a compute node via the mila
code command from
milatools.
Before you begin¶
-
Get your Mila account, enable cluster access and MFA, then install
uvandmilatoolsto connect via SSH.
VSCode or compatible editor
The mila code command opens VSCode (or a
compatible editor such as Cursor) on a compute node. Install
VSCode on a personal computer
before starting.
What this guide covers¶
- Open VSCode on a compute node with one GPU using
mila code. - Create a minimal PyTorch project with
pyproject.tomlandmain.py. - Run the script with
uv run python main.pyin VSCode.
Open VSCode on a compute node¶
Create the project directory on the cluster¶
From a personal computer, create the project directory on the cluster so
that mila code can open it (the path is on the cluster):
Start VSCode on a GPU node¶
Run mila code with allocation options to request one GPU. This allocates a
compute node and opens VSCode in a project path; everything after --alloc is
passed to Slurm:
[17:35:21] Checking disk quota on $HOME... disk_quota.py:31
[17:35:27] Disk usage: 85.34 / 100.00 GiB and 794022 / 1048576 files disk_quota.py:211
[17:35:29] (mila) $ cd $SCRATCH && salloc --gres=gpu:1 --cpus-per-task=2 --mem=16G --time=01:00:00 --job-name=mila-code compute_node.py:293
salloc: --------------------------------------------------------------------------------------------------
salloc: # Using default long partition
salloc: --------------------------------------------------------------------------------------------------
salloc: Granted job allocation 8888888
[17:35:30] Waiting for job 8888888 to start. compute_node.py:315
[17:35:31] (localhost) $ code --new-window --wait --remote ssh-remote+cn-a003.server.mila.quebec /home/mila/u/username/CODE/my_first_job local_v2.py:55
Wait until the allocation is granted and VSCode opens, connected to a shell on the compute node.
VSCode stuck on "Opening Remote..."?
If VSCode appears to hang while connecting, it may be waiting for an OTP code in a hidden terminal. Enable Remote.SSH: Show Login Terminal in VSCode settings to make the prompt visible:
- Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P).
- Run Preferences: Open Settings (UI).
- Search for
remote.SSH.showLoginTerminaland enable it.
Re-run the mila code command after enabling the setting.
Run a script in VSCode¶
Create the project files¶
In VSCode, create the following two files in the project folder (e.g. in the explorer or via File → New File). The files live on the compute node.
Run the script in the VSCode terminal¶
Open the integrated terminal in VSCode (Terminal → New Terminal). You are on the compute node. From the project directory, run:
The output should confirm that PyTorch is built with CUDA and detects the GPU.
When done, close VSCode and press Ctrl+C in the terminal to end the mila
code session and relinquish the allocation.
Key concepts¶
mila code- Allocates a compute node and opens VSCode on it. Use for interactive development and running scripts with a full editor and terminal.
Next step¶
-
Train a ResNet18 on CIFAR-10 on a single GPU using
sbatch.