[[Category:Software]][[Category:AI and Machine Learning]] [http://pytorch.org/ PyTorch] is a Python package that provides two high-level features: * Tensor computation (like NumPy) with strong GPU acceleration * Deep neural networks built on a tape-based autograd system If you are porting a PyTorch program to one of our clusters, you should follow [[Tutoriel Apprentissage machine/en|our tutorial on the subject]]. = Disambiguation = PyTorch has a distant connection with [[Torch]], but for all practical purposes you can treat them as separate projects. PyTorch developers also offer [[#LibTorch|LibTorch]], which allows one to implement extensions to PyTorch using C++, and to implement pure C++ machine learning applications. Models written in Python using PyTorch can be converted and used in pure C++ through [https://pytorch.org/tutorials/advanced/cpp_export.html TorchScript]. = Installation = ==Latest available wheels== To see the latest version of PyTorch that we have built: {{Command|avail_wheels torch}} For more information, see [[Python#Available_wheels |Available wheels]]. ==Installing our wheel== The preferred option is to install it using the Python [https://pythonwheels.com/ wheel] as follows: :1. Load a Python [[Utiliser_des_modules/en#Sub-command_load|module]], thus module load python :2. Create and start a [[Python#Creating_and_using_a_virtual_environment|virtual environment]]. :3. Install PyTorch in the virtual environment with pip install. ==== GPU and CPU ==== :{{Command|prompt=(venv) [name@server ~]|pip install --no-index torch }} {{Note|With H100 gpus, torch 2.3 and higher is required.}} Note: There are known issues with PyTorch 1.10 on our clusters (except for Narval). If you encounter problems while using distributed training, or if you get an error containing c10::Error, we recommend installing PyTorch 1.9.1 using pip install --no-index torch==1.9.1. ====Extra==== In addition to torch, you can install torchvision, torchtext and torchaudio: {{Command|prompt=(venv) [name@server ~]|pip install --no-index torch torchvision torchtext torchaudio }} = Job submission = Here is an example of a job submission script using the python wheel, with a virtual environment inside a job: {{File |name=pytorch-test.sh |lang="bash" |contents= #!/bin/bash #SBATCH --gres=gpu:1 # Request GPU "generic resources" #SBATCH --cpus-per-task=6 # Cores proportional to GPUs: 6 on Cedar, 16 on Graham. #SBATCH --mem=32000M # Memory proportional to GPUs: 32000 Cedar, 64000 Graham. #SBATCH --time=0-03:00 #SBATCH --output=%N-%j.out module load python/