The current pip wheels use the CUDA PyPI wheels as their dependencies. We are specifying the used versions explicitly, so pip install torch will download these libs directly, but you could try to install newer versions e.g. via pip install nvidia-cudnn-cu12==8.9.7.29 etc. as they should be backwards compatible.
The safer way would be to build PyTorch from source.