User Tools

Site Tools


compute:pythongpu

Using GPU with python

Python offers some modules to communicate with a GPU
Both Tensorflow and Torch have been used on this cluster succesfully.

An example setup using Python venv, run these commands :

python3 -m venv myTorch
source myTorch/bin/activate
pip install torch

The new Python virtual environment has been created and activated, torch package installed
And the correct CUDA library is also installed
Please run a simple test with python code to make sure you can communicate with the GPU
One example command to test torch
if torch.cuda.is_available() print(“GPU”)
But you must run this code test with sbatch, send your job to the cluster
Create a python file dummy.py with the test-GPU command

Update the sbatch script file, mine is called oneJob.sh
Remove lines below last #SBatch
Add 2 lines
source myTorch/bin/activate
python3 dummy.py
[SAVE]
Run the command sbatch oneJob.sh
The response should be Submitted batch job XXX
Then check your log file (default name is myJob.log) for the result

Installing Tensorflow is same process, we recommend using a different virtual environment if you want to try both of them
Make sure to instruct pip in this way, to get all necessary packages pip install “tensorflow[and-cuda]”

Those version have also been used before and known to work
ModuleVersionPython version
Tensorflow 2.17.0 3.11.10
Torch 2.0.1 3.9.7


compute/pythongpu.txt · Last modified: 2024/12/11 15:48 by bjorns