Depending how you’ve installed PyTorch, you can pick between the CPU and CUDA runtimes as described in the install instructions.
Check print(torch.version.cuda) as well as python -m torch.utils.collect_env and make sure a CUDA runtime is found.
If that’s the case, your local setup is most likely broken (e.g. via updating an NVIDIA driver without a restart etc.).
Again, it depends on your setup. If you’ve installed the pip wheels or conda binaries with a CUDA runtime, the local CUDA toolkit won’t be used unless you are building a custom CUDA extension, as the binaries already ship with their own CUDA runtime.