Torch
It is necessary that the required CUDA library is installed in the system, normally this is under ls -lad /usr/local/cuda*.
…in a python project
First create a new uv project:
export UV_CACHE_DIR=/scratch/userdata/${USER}/CACHE
export UV_NO_CACHE=1
cd /scratch/userdata/${USER}
# uv will create a virtual env for each project
uv init new-uv-project
cd new-uv-project
Customize the file pyproject.toml:
[project]
# the following supports CUDA 12.8 w/ CUDNN 9.10.2.21
requires-python = ">=3.10,<=3.15"
dependencies = [
"torch>=2.9,<=2.10",
"torchvision",
"torchaudio",
]
[tool.uv.sources]
torch = { index = "pytorch" }
[[tool.uv.index]]
name = "pytorch"
# experimental with 2.9 + 2.10
#url = "https://download.pytorch.org/whl/cu130"
# stable support
url = "https://download.pytorch.org/whl/cu128"
explicit = true
Now add packages defined in the pyproject.toml to the new project, the packages will be installed inside a virtual environment:
UV_PYTHON_DOWNLOADS="TRUE" uv sync
If CUDA is installed in a non-standard location, set PATH so that the nvcc you want to use can be found (e.g., export PATH=/usr/local/cuda-12.8/bin:$PATH).
Test if torch works with CUDA:
cat << EOF > torchtest.py
import torch
# run a general test
print("Run a general test:")
x = torch.rand(5, 3)
print(x)
# run CuDNN calculation
if torch.cuda.is_available():
print("Run a GPU test:")
device = torch.device("cuda")
# Enable CuDNN, may fallback if not available?
torch.backends.cudnn.enabled = True
# Create a simple convolutional layer
conv_layer = torch.nn.Conv2d(3, 64, kernel_size=3).to(device)
input_tensor = torch.randn(1, 3, 224, 224).to(device)
output = conv_layer(input_tensor)
print(output)
print("Convolution operation completed.")
# Check if CUDA is available
print("Cuda available?:")
print(torch.cuda.is_available())
# Check if CuDNN is enabled
print("CuDNN available?:")
print(torch.backends.cudnn.is_available())
EOF
uv run torchtest.py
Now you can write your code in this project folder, it maybe is a good idea to add this folder into a git repository (uv already took care of a .gitignore file).


