Build PyTorch from source failure

I’m using

➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
➜  ~ gcc --version
gcc (GCC) 10.3.1 20210627
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

➜  ~ python --version
Python 3.8.10
FAILED: third_party/onnx-tensorrt/CMakeFiles/nvonnxparser_static.dir/ModelImporter.cpp.o 
/usr/bin/ccache /usr/local/bin/c++ -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -I....../pytorch/cmake/../third_party/benchmark/include -I....../pytorch/cmake/../third_party/cudnn_frontend/include -I....../pytorch/build/caffe2/contrib/aten -I....../pytorch/third_party/onnx -I....../pytorch/build/third_party/onnx -I....../pytorch/third_party/foxi -I....../pytorch/build/third_party/foxi -isystem ....../pytorch/build/third_party/gloo -isystem ....../pytorch/cmake/../third_party/gloo -isystem ....../pytorch/cmake/../third_party/googletest/googlemock/include -isystem ....../pytorch/cmake/../third_party/googletest/googletest/include -isystem ....../pytorch/third_party/protobuf/src -isystem ....../pytorch/third_party/gemmlowp -isystem ....../pytorch/third_party/neon2sse -isystem ....../pytorch/third_party/XNNPACK/include -isystem ....../pytorch/third_party -isystem ....../pytorch/cmake/../third_party/eigen -isystem /usr/include/python3.8 -isystem ~/.local/lib/python3.8/site-packages/numpy/core/include -isystem ....../pytorch/cmake/../third_party/pybind11/include -isystem /usr/local/cuda/include -isystem ....../pytorch/cmake/../third_party/zstd/lib -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DTENSORRT_VERSION_MAJOR=8 -DTENSORRT_VERSION_MINOR=0 -Wall -Wno-deprecated-declarations -Wno-unused-function -O3 -DNDEBUG -fPIC -DCAFFE2_USE_GLOO -std=gnu++11 -MD -MT third_party/onnx-tensorrt/CMakeFiles/nvonnxparser_static.dir/ModelImporter.cpp.o -MF third_party/onnx-tensorrt/CMakeFiles/nvonnxparser_static.dir/ModelImporter.cpp.o.d -o third_party/onnx-tensorrt/CMakeFiles/nvonnxparser_static.dir/ModelImporter.cpp.o -c ....../pytorch/third_party/onnx-tensorrt/ModelImporter.cpp
In file included from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.hpp:28,
                 from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.cpp:23:
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp: In function ‘bool {anonymous}::convert_dims(const OnnxDims&, nvinfer1::Dims&)’:
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:43:25: error: ‘DimensionType’ is not a member of ‘nvinfer1’; did you mean ‘IDimensionExpr’?
   43 |   std::vector<nvinfer1::DimensionType> onnx_type_vector;
      |                         ^~~~~~~~~~~~~
      |                         IDimensionExpr
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:43:25: error: ‘DimensionType’ is not a member of ‘nvinfer1’; did you mean ‘IDimensionExpr’?
   43 |   std::vector<nvinfer1::DimensionType> onnx_type_vector;
      |                         ^~~~~~~~~~~~~
      |                         IDimensionExpr
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:43:38: error: template argument 1 is invalid
   43 |   std::vector<nvinfer1::DimensionType> onnx_type_vector;
      |                                      ^
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:43:38: error: template argument 2 is invalid
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:46:22: error: request for member ‘push_back’ in ‘onnx_type_vector’, which is of non-class type ‘int’
   46 |     onnx_type_vector.push_back(static_cast<nvinfer1::DimensionType>(0));
      |                      ^~~~~~~~~
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:46:54: error: ‘DimensionType’ in namespace ‘nvinfer1’ does not name a type; did you mean ‘IDimensionExpr’?
   46 |     onnx_type_vector.push_back(static_cast<nvinfer1::DimensionType>(0));
      |                                                      ^~~~~~~~~~~~~
      |                                                      IDimensionExpr
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:54:30: error: request for member ‘begin’ in ‘onnx_type_vector’, which is of non-class type ‘int’
   54 |   std::copy(onnx_type_vector.begin(), onnx_type_vector.end(), trt_dims.type);
      |                              ^~~~~
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:54:56: error: request for member ‘end’ in ‘onnx_type_vector’, which is of non-class type ‘int’
   54 |   std::copy(onnx_type_vector.begin(), onnx_type_vector.end(), trt_dims.type);
      |                                                        ^~~
....../pytorch/third_party/onnx-tensorrt/onnx_utils.hpp:54:72: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
   54 |   std::copy(onnx_type_vector.begin(), onnx_type_vector.end(), trt_dims.type);
      |                                                                        ^~~~
In file included from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.hpp:30,
                 from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.cpp:23:
....../pytorch/third_party/onnx-tensorrt/common.hpp: At global scope:
....../pytorch/third_party/onnx-tensorrt/common.hpp:63:10: error: looser exception specification on overriding virtual function ‘virtual void common::TRT_Logger::log(nvinfer1::ILogger::Severity, const char*)’
   63 |     void log(Severity severity, const char* msg) override {
      |          ^~~
In file included from /usr/local/cuda/include/NvInferLegacyDims.h:53,
                 from /usr/local/cuda/include/NvInfer.h:53,
                 from ....../pytorch/third_party/onnx-tensorrt/NvOnnxParser.h:26,
                 from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.hpp:25,
                 from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.cpp:23:
/usr/local/cuda/include/NvInferRuntimeCommon.h:1222:18: note: overridden function is ‘virtual void nvinfer1::ILogger::log(nvinfer1::ILogger::Severity, const AsciiChar*) noexcept’
 1222 |     virtual void log(Severity severity, AsciiChar const* msg) noexcept = 0;
      |                  ^~~
In file included from ....../pytorch/third_party/onnx-tensorrt/onnx2trt_utils.hpp:26,
                 from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.cpp:26:
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp: In function ‘nvinfer1::Dims onnx2trt::insert_dim(const Dims&, int, int)’:
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:69:14: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
   69 |     new_dims.type[i] = dims.type[i];
      |              ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:69:29: error: ‘const Dims’ {aka ‘const class nvinfer1::Dims32’} has no member named ‘type’
   69 |     new_dims.type[i] = dims.type[i];
      |                             ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:74:14: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
   74 |     new_dims.type[i] = dims.type[i - 1];
      |              ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:74:29: error: ‘const Dims’ {aka ‘const class nvinfer1::Dims32’} has no member named ‘type’
   74 |     new_dims.type[i] = dims.type[i - 1];
      |                             ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp: In function ‘nvinfer1::Dims onnx2trt::remove_dim(const Dims&, int)’:
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:85:14: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
   85 |     new_dims.type[i] = dims.type[i];
      |              ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:85:29: error: ‘const Dims’ {aka ‘const class nvinfer1::Dims32’} has no member named ‘type’
   85 |     new_dims.type[i] = dims.type[i];
      |                             ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:89:14: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
   89 |     new_dims.type[i] = dims.type[i + 1];
      |              ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:89:29: error: ‘const Dims’ {aka ‘const class nvinfer1::Dims32’} has no member named ‘type’
   89 |     new_dims.type[i] = dims.type[i + 1];
      |                             ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:95:14: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
   95 |     new_dims.type[0] = nvinfer1::DimensionType::kCHANNEL;
      |              ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:95:34: error: ‘nvinfer1::DimensionType’ has not been declared
   95 |     new_dims.type[0] = nvinfer1::DimensionType::kCHANNEL;
      |                                  ^~~~~~~~~~~~~
In file included from ....../pytorch/third_party/onnx-tensorrt/onnx2trt_utils.hpp:26,
                 from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.cpp:26:
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp: In function ‘nvinfer1::Dims onnx2trt::set_dims_CHW(const Dims&)’:
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:146:12: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
  146 |   new_dims.type[0] = nvinfer1::DimensionType::kCHANNEL;
      |            ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:146:32: error: ‘nvinfer1::DimensionType’ has not been declared
  146 |   new_dims.type[0] = nvinfer1::DimensionType::kCHANNEL;
      |                                ^~~~~~~~~~~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:148:14: error: ‘using Dims = class nvinfer1::Dims32’ {aka ‘class nvinfer1::Dims32’} has no member named ‘type’
  148 |     new_dims.type[i] = nvinfer1::DimensionType::kSPATIAL;
      |              ^~~~
....../pytorch/third_party/onnx-tensorrt/trt_utils.hpp:148:34: error: ‘nvinfer1::DimensionType’ has not been declared
  148 |     new_dims.type[i] = nvinfer1::DimensionType::kSPATIAL;
      |                                  ^~~~~~~~~~~~~
In file included from ....../pytorch/third_party/onnx-tensorrt/ModelImporter.cpp:26:
....../pytorch/third_party/onnx-tensorrt/onnx2trt_utils.hpp: At global scope:
....../pytorch/third_party/onnx-tensorrt/onnx2trt_utils.hpp:38:1: error: expected class-name before ‘{’ token
   38 | {
      | ^