In case I uninstalled pytorch, torchvision and torchaudio before doing the process, I don’t know if it was ok.
(base) C:\Users\MIPC>pip uninstall torch
Found existing installation: torch 1.8.1+cu111
Uninstalling torch-1.8.1+cu111:
  Would remove:
    c:\users\mipc\anaconda3\lib\site-packages\caffe2\*
    c:\users\mipc\anaconda3\lib\site-packages\torch-1.8.1+cu111.dist-info\*
    c:\users\mipc\anaconda3\lib\site-packages\torch\*
    c:\users\mipc\anaconda3\scripts\convert-caffe2-to-onnx.exe
    c:\users\mipc\anaconda3\scripts\convert-onnx-to-caffe2.exe
Proceed (y/n)? y
  Successfully uninstalled torch-1.8.1+cu111

(base) C:\Users\MIPC>pip uninstall torchvision
Found existing installation: torchvision 0.9.1+cu111
Uninstalling torchvision-0.9.1+cu111:
  Would remove:
    c:\users\mipc\anaconda3\lib\site-packages\torchvision-0.9.1+cu111.dist-info\*
    c:\users\mipc\anaconda3\lib\site-packages\torchvision\*
Proceed (y/n)? y
  Successfully uninstalled torchvision-0.9.1+cu111

(base) C:\Users\MIPC>pip uninstall torchaudio
Found existing installation: torchaudio 0.8.1
Uninstalling torchaudio-0.8.1:
  Would remove:
    c:\users\mipc\anaconda3\lib\site-packages\torchaudio-0.8.1.dist-info\*
    c:\users\mipc\anaconda3\lib\site-packages\torchaudio\*
Proceed (y/n)? y
  Successfully uninstalled torchaudio-0.8.1

And then I followed this process using git, in the Anaconda Prompt
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
git submodule sync
git submodule update --init --recursive

Now, should I reinstall Pytorch from the link on its official website and run programs from Anaconda Prompt? Or do I need to do something else before reinstalling pytorch?
In this case, do you recommend the stable version?
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

or the nightly version ?
pip install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu111/torch_nightly.html

Is it really necessary to use Visual Studio?
I have Visual Studio 2019 ver. 16.8.30804.86
" Note: There’s a compilation issue in several Visual Studio 2019 versions since 16.7.1, so please make sure your Visual Studio 2019 version is not in 16.7.1 ~ 16.7.5"  In theory it should work, right?
To run programs using CUDA from the console, should I do this?
NVTX is needed to build Pytorch with CUDA. NVTX is a part of CUDA distributive, where it is called "Nsight Compute". To install it onto already installed CUDA run CUDA installation once again and check the corresponding checkbox. Make sure that CUDA with Nsight Compute is installed after Visual Studio.

Currently, VS 2017 / 2019, and Ninja are supported as the generator of CMake. If ninja.exe is detected in PATH, then Ninja will be used as the default generator, otherwise, it will use VS 2017 / 2019.
If Ninja is selected as the generator, the latest MSVC will get selected as the underlying toolchain.

Where should I download these libraries?
Additional libraries such as Magma, oneDNN, a.k.a MKLDNN or DNNL, and Sccache are often needed. Please refer to the installation-helper to install them.

Or only use this commands in the prompt or cmd, and then pytorch will be activate?
cmd

:: [Optional] If you want to build with the VS 2017 generator for old CUDA and PyTorch, please change the value in the next line to `Visual Studio 15 2017`.
:: Note: This value is useless if Ninja is detected. However, you can force that by using `set USE_NINJA=OFF`.
set CMAKE_GENERATOR=Visual Studio 16 2019

:: Read the content in the previous section carefully before you proceed.
:: [Optional] If you want to override the underlying toolset used by Ninja and Visual Studio with CUDA, please run the following script block.
:: "Visual Studio 2019 Developer Command Prompt" will be run automatically.
:: Make sure you have CMake >= 3.12 before you do this when you use the Visual Studio generator.
set CMAKE_GENERATOR_TOOLSET_VERSION=14.27
set DISTUTILS_USE_SDK=1
for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version [15^,16^) -products * -latest -property installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%

:: [Optional] If you want to override the CUDA host compiler
set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\cl.exe

python setup.py install