Prerequisites

# Download the torch source code. The 2.1.0 version is used as an example.
git clone -b v2.1.0 https://github.com/pytorch/pytorch.git pytorch-2.1.0
cd pytorch-2.1.0
git submodule sync
git submodule update --init --recursive

# Install the torch dependency.
pip install -r requirements.txt

# Download the torch_npu source code. The version must match that of torch.
git clone -b v2.1.0 https://gitee.com/ascend/pytorch.git torch_npu

Modify the CMakeLists.txt file in the source code directory of torch and comment out the following line to mask alarms (this line is not needed for later-version torch):

append_cxx_flag_if_supported("-Werror=cast-function-type" CMAKE_CXX_FLAGS)
Figure 1 Code comment example