Pytorch

      Comments Off on Pytorch

Do NOT use PyTorch < 2.10.0


https://nvd.nist.gov/vuln/detail/CVE-2026-24747

Description

PyTorch is an open-source scientific computing and machine learning library, primarily used for deep learning. It enables users to build, train, and deploy neural networks in a flexible and efficient way, with native GPU support.

Set up the environment

Using a Python virtual environment

ml pytorch/2.10.0-py313-cu130
  • Available version(s) : 2.10.0
    • 2.10.0-py311-cu126 (Python 3.11 and CUDA 12.6)
    • 2.10.0-py311-cu128 (Python 3.11 and CUDA 12.8)
    • 2.10.0-py313-cu130 (Python 3.13 and CUDA 13.0) – default
  • No possibility to install new libraries
  • Loading the associated Python module is not required

Using an Apptainer image

ml utils/apptainer
apptainer run /softs/apps/pytorch/pytorch-2.10.0-cuda12.9-cudnn9.sif 
  • Available version(s) : 2.10.0
    • pytorch:2.10.0-cuda12.9-cudnn9

Tutorials

Version of pytorch

ml pytorch
python3 -c "import torch; print(f'Version: {torch.__version__}')"

Quick test

  • Python test script: mytest.py
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
  • Job launch script launch.sh
#!/bin/sh
#SBATCH --job-name=test_pytorch
#SBATCH --partition=bigpu
#SBATCH --gres=gpu:1
#SBATCH --time=0:10:00 
#SBATCH --mem=4G 
#SBATCH --nodes=1 
#SBATCH --ntasks-per-node=1  

echo "=== through an virtual environment ==="
ml pytorch/2.10.0-py313-cu130
python3 --version
python3 mytest.py

echo ""
echo "=== through an image apptainer ==="
ml utils/apptainer
apptainer run /softs/apps/pytorch/pytorch-2.10.0-cuda12.9-cudnn9.sif 
python3 --version
python3 mytest.py
  • Launching the job
sbatch launch.sh

Detection of a GPU

# Loading pytorch
ml pytorch
# Detection of the GPU
python -c "import torch; print(f'Version: {torch.__version__}'); print(f'GPU disponible: {torch.cuda.is_available()}'); print(f'Nom du GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"N/A\"}')" 

Documentation