How to use PyTorch
Preparation for use
PyTorch for GPU is installed in Genkai and can be used from node groups B and C.
The following modules need to be loaded when using PyTorch. (Note the version of the module to be loaded.)
cuda/12.2.2
, cudnn/8.9.7
, nccl/2.22.3
, pytorch-cuda/2.3.1-12.2.2
The Python version must be 3.11 (python3.11
command).
Note that it is possible to run PyTorch using the CPU on node group A.
Please load gcc/8
and pytorch/2.3.1
.
You need to use Python version 3.11 (python3.11
command) as well as the GPU version.
If you need additional Python modules, please use pip3.11 install --user
to install and use the modules.
If you want to use a different version of PyTorch, please consider installing it yourself or using a container.
(If you load the cuda module, you will see the cudnn and pytorch-cuda modules in the result of module avail
. Similarly, loading the gcc module will cause the pytorch module to appear in the module avail
results).
Usage Example: Target Program
Let’s run the following sample program, which is publicly available as a sample of PyTorch.
This program can switch between CPU and GPU execution by rewriting the torch.device
at the beginning, so let’s execute the one for GPU as pytorch_sample_gpu.py
and the one for CPU as pytorch_sample_cpu.py
. Let’s try it.
|
Execution by GPU
The following is an example of batch job execution on node group B.
The following job script is used to execute the job.
|
Execution by CPU
Although PyTorch is often executed using a GPU, we will also show an example of batch job execution using a CPU on node group A.
Prepare and run the following job script.
|
Execution results
An example of the execution result is shown below.
The print statement in the for loop prints out the progress, and the final print statement prints out the result.
Since the input data is generated using random numbers, the values vary greatly each time it is executed.
|