PYTorch
PyTorch is a machine learning framework based on the Torch library, used for applications such as computer vision and natural language processing, originally developed by Meta AI and now part of the Linux Foundation umbrella. It is free and open-source software released under the modified BSD license.
Slurm Script
#!/bin/bash
#SBATCH -J mytorch_codejob # Job name
#SBATCH -o mytorch_output.%j.out # Name of stdout output file (%j expands to jobId)
#SBATCH -p CUIQue # Queue name
#SBATCH -N 1 # Total number of nodes requested
#SBATCH -n 16 # Total number of mpi tasks requested
module load py-torch/1.11.0 python/3.8.12 py-numpy/1.22.4
python3.8 helloworld.py
helloworld.py Code
import torch print("Hello from Pytorch, version",torch.__version__) dtype = torch.float device = torch.device("cpu") # This executes all calculations on the CPU # Creation of a tensor and filling of a tensor with random numbers a = torch.randn(2, 3, device=device, dtype=dtype) print(a) # Output of tensor A # Output: tensor([[-1.1884, 0.8498, -1.7129], # [-0.8816, 0.1944, 0.5847]]) # Creation of a tensor and filling of a tensor with random numbers b = torch.randn(2, 3, device=device, dtype=dtype) print(b) # Output of tensor B # Output: tensor([[ 0.7178, -0.8453, -1.3403], # [ 1.3262, 1.1512, -1.7070]]) print(a*b) # Output of a multiplication of the two tensors # Output: tensor([[-0.8530, -0.7183, 2.58], # [-1.1692, 0.2238, -0.9981]]) print(a.sum()) # Output of the sum of all elements in tensor A # Output: tensor(-2.1540) print(a[1,2]) # Output of the element in the third column of the second row (zero based) # Output: tensor(0.5847) print(a.max()) # Output of the maximum value in tensor A # Output: tensor(0.8498)
Submit the job to the scheduler as
sbatch pytorchexample.slurm
For managing your “job” , refer to this guide.
For more on Pytorch framework, refer to their official documentation
https://pytorch.org/tutorials/