How did you build for /MT
?
How you activated the VC shell more than once?
Let’s continue with your first code block. Would you please try the following commands?
set PYTORCH_ROOT=C:\pytorch
cd %PYTORCH_ROOT%
set BUILD_SHARED_LIBS=OFF
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=14.27
set CL=/DFBGEMM_STATIC#1
python tools\build_libtorch.py