pytorch get gpu number

To get the GPU number in PyTorch, you can use the torch.cuda.current_device() function. This function returns the index of the current GPU device being used by PyTorch. Here's an example code snippet:

import torch

# Check if CUDA is available
if torch.cuda.is_available():
    # Get the GPU number
    gpu_number = torch.cuda.current_device()
    print("GPU Number:", gpu_number)
else:
    print("CUDA is not available.")

Please note that this code assumes that you have PyTorch and CUDA installed correctly on your system. If CUDA is not available or if you don't have a GPU, the code will print "CUDA is not available."

I hope this helps!