Skip to content

Running GPU Jobs via GitLab CI & Slurm

This guide explains how researchers can run GPU-accelerated workloads (PyTorch, CUDA compilation, model training, and benchmarking) directly from a GitLab repository using our Slurm GPU Runner.

When you push code to GitLab, the CI pipeline routes your job to the slurm-gpu runner, stages your repository on shared high-speed storage (/data), and schedules your execution onto one of our GPU partitions via Slurm.

1. Available GPU Partitions & Hardware

Select the Slurm partition (SLURM_PARTITION) and GPU count (SLURM_GPUS) that best match your workload's VRAM and compute requirements:

Partition Name (SLURM_PARTITION) GPU Hardware Nodes × GPUs/Node Total GPUs Default CPUs / GPU Default RAM / GPU Max Job Duration
gpu-h200 NVIDIA H200 1 × 4 GPUs 4 32 vCPUs 128 GB (131072 MB) 5 days (5-00:00:00)
rtx-6000-pro NVIDIA RTX 6000 Pro 1 × 8 GPUs 8 16 vCPUs 64 GB (65536 MB) 5 days (5-00:00:00)
rtx-6000 NVIDIA RTX 6000 3 × 1 GPU 3 16 vCPUs 64 GB (65536 MB) 5 days (5-00:00:00)

Choosing the Right Partition

  • Use rtx-6000 (SLURM_GPUS: "1") for rapid single-GPU testing, CI unit tests, and smaller models—with 3 independent nodes, queue wait times are minimal.
  • Use rtx-6000-pro (SLURM_GPUS: "1" to "8") for multi-GPU distributed training (DDP) or high-concurrency workloads.
  • Use gpu-h200 (SLURM_GPUS: "1" to "4") for large language models, memory-bandwidth-bound kernels, or jobs requiring up to 128 GB system RAM per GPU.

2. Prerequisites in GitLab

Before submitting jobs to the cluster, ensure you have the following set up:

  1. DCU Computing GitLab Account: You must have an active account on gitlab.computing.dcu.ie where your project repository is hosted.

  2. Add your SSH Private Key (if using project-level SSH auth): Go to Settings → CI/CD → Variables in your repository on gitlab.computing.dcu.ie and add a masked/protected variable named SLURM_SSH_PRIVATE_KEY containing the base64-encoded private key authorized for gitlab-ci.

  3. Increase the Project Job Timeout (for multi-hour / multi-day runs): By default, GitLab terminates jobs after 1h. To allow jobs to queue and run for up to 5 days:

  4. Navigate to Settings → CI/CD → General pipelines.

  5. Set Timeout to 5d (or 120h) and click Save changes.

Project Timeout Limit

Even if you specify timeout: 5d in your .gitlab-ci.yml, GitLab enforces whichever timeout is smaller between your project settings and your YAML file. Always update General pipelines → Timeout if your training runs exceed 1 hour.

3. Example GitLab Projects

You can inspect or fork these working reference repositories on gitlab.computing.dcu.ie to see complete .gitlab-ci.yml configurations, Slurm environment variables, and GPU scripts in action:

  • example-gitlab-slurm-gpu-runner — Minimal starter template demonstrating how to route a GitLab CI job to the slurm-gpu runner, allocate GPUs via srun, and return benchmark artifacts.
  • asiera-demo-killarney-2026 — End-to-end demo repository showcasing GPU workload execution and container/environment setup on the DCU Slurm cluster.

4. Quickstart .gitlab-ci.yml Template

Create a .gitlab-ci.yml file in the root of your repository using the template below.

=== "Single-GPU Job (rtx-6000 / gpu-h200)"

```yaml
stages:
  - gpu-run

run-gpu-workload:
  stage: gpu-run
  timeout: 5d
  image:
    name: alpine:3.24
  tags:
    - slurm-gpu
  variables:
    GIT_DEPTH: "1"
    RUNNER_SCRIPT_TIMEOUT: "119h"
    RUNNER_AFTER_SCRIPT_TIMEOUT: "15m"
    # --- Slurm & Hardware Configuration ---
    SLURM_USER: "gitlab-ci"
    SLURM_PARTITION: "rtx-6000"   # Options: gpu-h200 | rtx-6000-pro | rtx-6000
    SLURM_GPUS: "1"               # Max per node: 4 (h200), 8 (rtx-6000-pro), 1 (rtx-6000)
    SLURM_TIME: "5-00:00:00"
    SLURM_LOGIN_HOST: "slurm-login-slinky.slurm.svc.cluster.local"
    # --- Shared Storage Paths (/data) ---
    SHARED_BASE: "/data/ci/gitlab-ci/${CI_PROJECT_PATH_SLUG}/${CI_JOB_ID}"
    VENV_DIR: "/data/venvs/gitlab-ci/${CI_PROJECT_PATH_SLUG}"
    SSH_OPTS: "-o BatchMode=yes -o IdentitiesOnly=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=120 -i ~/.ssh/id_ed25519"

  before_script:
    - apk add --no-cache openssh-client tar
    - mkdir -p ~/.ssh && chmod 700 ~/.ssh
    - |
      if [ -n "$SLURM_SSH_PRIVATE_KEY" ]; then
        echo "$SLURM_SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_ed25519
        chmod 600 ~/.ssh/id_ed25519
      fi
    - ssh-keyscan -H "$SLURM_LOGIN_HOST" >> ~/.ssh/known_hosts 2>/dev/null

  script:
    # 1. Stage repository files onto shared /data storage
    - |
      ssh $SSH_OPTS "${SLURM_USER}@${SLURM_LOGIN_HOST}" "bash -se" << EOF
        set -euo pipefail
        mkdir -p "${SHARED_BASE}" "\$(dirname "${VENV_DIR}")"
        chmod 0700 "/data/ci/gitlab-ci" "\$(dirname "${VENV_DIR}")"
      EOF
    - tar --exclude='.git' -cf - . | ssh $SSH_OPTS "${SLURM_USER}@${SLURM_LOGIN_HOST}" "tar --no-same-owner --no-same-permissions -xf - -C '${SHARED_BASE}'"

    # 2. Allocate GPU(s) via Slurm and run your code
    - |
      ssh $SSH_OPTS "${SLURM_USER}@${SLURM_LOGIN_HOST}" "bash -se" << EOF
        set -euo pipefail
        srun --partition=${SLURM_PARTITION} \
             --gres=gpu:${SLURM_GPUS} \
             --time=${SLURM_TIME} \
             --job-name=ci-${CI_JOB_ID} \
             bash -euo pipefail -c '
          cd "${SHARED_BASE}"
          export PIP_CACHE_DIR="/data/.cache/gitlab-ci/pip"

          echo "=== Node & GPU Allocation ==="
          hostname
          nvidia-smi -L

          # Create or reuse cached Python virtual environment on /data
          LOCK_DIR="${VENV_DIR}.lockdir"
          while ! mkdir "\$LOCK_DIR" 2>/dev/null; do sleep 2; done
          trap "rmdir \"\$LOCK_DIR\" 2>/dev/null || true" EXIT

          REQ_HASH=\$(sha256sum requirements.txt | awk "{print \$1}")
          if [ ! -f "${VENV_DIR}/bin/activate" ] || [ "\$(cat "${VENV_DIR}/.req_hash" 2>/dev/null)" != "\$REQ_HASH" ]; then
            rm -rf "${VENV_DIR}"
            python3 -m venv "${VENV_DIR}"
            "${VENV_DIR}/bin/pip" install --upgrade pip
            "${VENV_DIR}/bin/pip" install -r requirements.txt
            echo "\$REQ_HASH" > "${VENV_DIR}/.req_hash"
          else
            echo "Reusing cached virtual environment: ${VENV_DIR}"
          fi

          rmdir "\$LOCK_DIR" 2>/dev/null || true
          trap - EXIT

          source "${VENV_DIR}/bin/activate"

          echo "=== Executing Training / Benchmark Script ==="
          python train.py
        '
      EOF

    # 3. Retrieve output files back to GitLab for artifact storage
    - ssh $SSH_OPTS "${SLURM_USER}@${SLURM_LOGIN_HOST}" "test -f '${SHARED_BASE}/results.txt' && cat '${SHARED_BASE}/results.txt'" > results.txt || true

  after_script:
    - apk add --no-cache openssh-client >/dev/null 2>&1 || true
    - ssh -o BatchMode=yes -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 "${SLURM_USER}@${SLURM_LOGIN_HOST}" "rm -rf '${SHARED_BASE}'" || true

  artifacts:
    paths:
      - results.txt
    when: always
```

=== "Multi-GPU Job (gpu-h200 / rtx-6000-pro)"

To run across multiple GPUs on a single node (e.g., 4× H200 or 8× RTX 6000 Pro), set `SLURM_PARTITION` and `SLURM_GPUS` accordingly and launch with `torchrun`:

```yaml
variables:
  SLURM_PARTITION: "rtx-6000-pro"
  SLURM_GPUS: "4"
```

Inside the `srun` execution block, invoke your distributed launcher using `$SLURM_GPUS`:

```bash
torchrun --standalone --nproc_per_node=${SLURM_GPUS} train_ddp.py
```

5. Storage, Caching & Artifacts Best Practices

  • Shared Filesystem (/data): Both the Slurm login pod and all GPU compute nodes mount the same persistent volume at /data. Any code staged into ${SHARED_BASE} on the login pod is immediately visible on the GPU node.

  • Persistent Virtual Environments (VENV_DIR): Installing PyTorch and CUDA dependencies over shared storage on every commit takes several minutes. Keep VENV_DIR pointed at /data/venvs/gitlab-ci/<your-project>—the template hashes requirements.txt and only rebuilds the environment when your dependencies change.

  • Ephemeral Job Workspace (SHARED_BASE): The after_script stage automatically deletes ${SHARED_BASE} (/data/ci/gitlab-ci/.../${CI_JOB_ID}) when the job finishes or is canceled. Always copy any checkpoints, logs, or metrics you want to keep either into GitLab artifacts: or into a dedicated persistent directory under /data/.

6. Troubleshooting Common Issues

My job sits at srun: job <ID> queued and waiting for resources

All GPUs in your chosen partition are currently allocated to other active jobs. Your job will automatically start as soon as enough GPUs free up (up to your 5-day timeout). If you only need 1 GPU, switching SLURM_PARTITION to "rtx-6000" spreads jobs across 3 separate nodes and usually reduces queue wait times.

My job was canceled after 1 hour (execution took longer than 1h0m0s)

Your GitLab project's CI/CD pipeline timeout is still at the 1-hour default. Go to Settings → CI/CD → General pipelines → Timeout in GitLab and set it to 5d.

srun fails immediately with Requested node configuration is not available

You requested more GPUs than a single node in that partition provides:

  • rtx-6000 supports max SLURM_GPUS: "1" per job.
  • gpu-h200 supports max SLURM_GPUS: "4" per job.
  • rtx-6000-pro supports max SLURM_GPUS: "8" per job.