How to build PyTorch with a latest LLVM build?

I have built the LLVM project locally (latest release). I wish to use my clang build to compile PyTorch source code. Currently I am facing issues during the PyTorch build.

...
...
[89/2272] Performing build step for 'nccl_external'
FAILED: nccl_external-prefix/src/nccl_external-stamp/nccl_external-build nccl/lib/libnccl_static.a /home/anurag/pytorch-2.1.2/build/nccl_external-prefix/src/nccl_external-stamp/nccl_external-build /home/anurag/pytorch-2.1.2/build/nccl/lib/libnccl_static.a
cd /home/anurag/pytorch-2.1.2/third_party/nccl/nccl && make -j32 -l32 CXX=/home/anurag/llvm-project-llvmorg-17.0.6/installed/bin/clang++ CUDA_HOME=/usr/local/cuda NVCC=/usr/local/cuda/bin/nvcc NVCC_GENCODE=-gencode=arch=compute_70,code=sm_70 BUILDDIR=/home/anurag/pytorch-2.1.2/build/nccl VERBOSE=0 DEBUG=0 && /usr/local/bin/cmake -E touch /home/anurag/pytorch-2.1.2/build/nccl_external-prefix/src/nccl_external-stamp/nccl_external-build
make -C src build BUILDDIR=/home/anurag/pytorch-2.1.2/build/nccl
make[1]: Entering directory '/home/anurag/pytorch-2.1.2/third_party/nccl/nccl/src'
NVCC_GENCODE is -gencode=arch=compute_70,code=sm_70
...
...
In file included from <built-in>:1:
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/cuda_runtime.h:82:
/usr/local/cuda/bin/../targets/x86_64-linux/include/crt/host_config.h:151:2: error: -- unsupported clang version! clang version must be less than 16 and greater than 3.2 . The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.
  151 | #error -- unsupported clang version! clang version must be less than 16 and greater than 3.2 . The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.
  ...
  ...
  make[1]: Leaving directory '/home/anurag/pytorch-2.1.2/third_party/nccl/nccl/src'
make: *** [Makefile:25: src.build] Error 2
[120/2272] Building CXX object third_party/protobuf/cmake/CMakeFiles/libprotoc.dir/__/src/google/protobuf/compiler/command_line_interface.cc.o
ninja: build stopped: subcommand failed.

My system configurations are as follows:

LLVM version: 17.0.6
Python version: 3.10.8
PyTorch version: 2.1.2
CUDA Driver Version: 545.23.08
CUDA Version: 12.3
nvcc version: release 12.3, V12.3.107

My build configurations are as follows (I put all the following in a .sh file and run it under the pytorch project root):

export CC=/home/anurag/llvm-project-llvmorg-17.0.6/installed/bin/clang; \
export CXX=/home/anurag/llvm-project-llvmorg-17.0.6/installed/bin/clang++; \
export MAX_JOBS=32; \
export DEBUG=1; \
export USE_DISTRIBUTED=OFF; \
export USE_MKLDNN=OFF; \
export USE_CUDA=ON; \
export CMAKE_CXX_FLAGS="-Wmissing-braces"; \
export CMAKE_CUDA_HOST_COMPILER=/home/anurag/llvm-project-llvmorg-17.0.6/installed/bin/clang++; \
export CMAKE_CUDA_FLAGS="-allow-unsupported-compiler -std=c++17"; \
export BUILD_TEST=OFF; \
export USE_FBGEMM=OFF; \
export USE_NNPACK=OFF; \
export USE_QNNPACK=OFF; \
export USE_XNNPACK=OFF; \
export NVCC_GENCODE="-gencode=arch=compute_70,code=sm_70"; \
export USE_GOLD_LINKER=ON; \
python setup.py clean; \
ccache -C; \
ccache -c; \
python setup.py develop;

Can anyone help me out with how to build PyTorch, using a locally built latest LLVM?

(cross posted from dev-discuss forum)

Setting this variable did not make any difference!

For now, I was able to build PyTorch 2.2.0 with CUDA by downgrading my clang compiler (from 17.0.6 to 10):

clear; \
export CC=/usr/bin/clang-10; \
export CXX=/usr/bin/clang++-10; \
#export CC=/home/anurag/llvm-project-llvmorg-17.0.6/installed/bin/clang; \
#export CXX=/home/anurag/llvm-project-llvmorg-17.0.6/installed/bin/clang++; \
export MAX_JOBS=32; \
export DEBUG=1; \
export USE_DISTRIBUTED=OFF; \
export USE_MKLDNN=OFF; \
export USE_CUDA=ON; \
#export CMAKE_CXX_FLAGS="-Wmissing-braces"; \
export CMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc; \
#export CMAKE_CUDA_HOST_COMPILER=/home/anurag/llvm-project-llvmorg-17.0.6/installed/bin/clang++; \
#export CMAKE_CUDA_FLAGS="-allow-unsupported-compiler -std=c++17"; \
export BUILD_TEST=OFF; \
export USE_FBGEMM=OFF; \
export USE_NNPACK=OFF; \
export USE_QNNPACK=OFF; \
export USE_XNNPACK=OFF; \
export NVCC_GENCODE="-gencode=arch=compute_70,code=sm_70"; \
export USE_GOLD_LINKER=ON; \
python setup.py clean; \
ccache -cC; \
python setup.py develop;

(Some more flags may be set according to cmake CUDA flags)

So the real question of how to compile PyTorch with CUDA using newer clang still stands.