Could you create a new virtual environment and reinstall PyTorch there?
Alternatively, uninstall all PyTorch installations from the current environment and reinstall it. Make sure to run the uninstall commands multiple times, as e.g. binary installations might have been installed on top of source builds.
PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier and enables the forum search to index the post.