Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the compilation invocation is missing the typical includes, maybe something broke with detecting the toolchain? #18

Closed
doctorpangloss opened this issue Nov 18, 2024 · 7 comments

Comments

@doctorpangloss
Copy link

doctorpangloss commented Nov 18, 2024

Logs showing a failure to configure the toolchain using your automatic discovery code:

...
  File "D:\appmana\.venv\Lib\site-packages\torch\_dynamo\output_graph.py", line 1465, in _call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e) from e
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
CppCompileError: C++ compile error

Command:
cl /I C:/Python311/Include /I C:/Python311/Include /I D:/appmana/.venv/Lib/site-packages/torch/include /I D:/appmana/.venv/Lib/site-packages/torch/include/torch/csrc/api/include /I D:/appmana/.venv/Lib/site-packages/torch/include/TH /I D:/appmana/.venv/Lib/site-packages/torch/include/THC /I D:/appmana/.venv/Lib/site-packages/torch/include /I D:/appmana/.venv/Lib/site-packages/torch/include/torch/csrc/api/include /I D:/appmana/.venv/Lib/site-packages/torch/include/TH /I D:/appmana/.venv/Lib/site-packages/torch/include/THC /D TORCH_INDUCTOR_CPP_WRAPPER /D C10_USING_CUSTOM_GENERATED_MACROS /DLL /MD /O2 /std:c++20 /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /wd4624 /wd4067 /wd4068 /EHsc /openmp /openmp:experimental C:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/7y/c7yrfm3iaowmw7pxtfocroyfi2lhjbwx2nf37nea2ifm27kd2qcl.cpp /LD /FeC:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/7y/c7yrfm3iaowmw7pxtfocroyfi2lhjbwx2nf37nea2ifm27kd2qcl.pyd /link /LIBPATH:D:/appmana/.venv/Scripts/libs /LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib /LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib /LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib torch.lib torch_cpu.lib torch_python.lib sleef.lib c10.lib

Output:
Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32822 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9025 : overriding '/openmp' with '/openmp:experimental'
c7yrfm3iaowmw7pxtfocroyfi2lhjbwx2nf37nea2ifm27kd2qcl.cpp
C:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/vu/cvuvp4i7roujum4xemrfwnb3t4c5t3r3mihr4b7iegh6tcqvdg43.h(3): fatal error C1083: Cannot open include file: 'algorithm': No such file or directory


Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information

...

cvuvp4i7roujum4xemrfwnb3t4c5t3r3mihr4b7iegh6tcqvdg43.h:

#pragma once

#include <algorithm>
#include <atomic>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <memory>
#include <optional>
#include <map>
#include <omp.h>

// WARNING: be extra careful when including more ATen/c10 header files here!
// Because AOTInductor generated code will copy-paste this cpp_prefix.h for
// the CPU backend, we have to make sure the used headers are implemented
// in a header-only way, i.e. all the function and class definitions are
// in .h files instead of .cpp files, to avoid ABI backward-compatiblity breakage.

#include <ATen/NumericUtils.h>
#include <ATen/core/PhiloxRNGEngine.h>
...

This is using the latest binaries from your site with torch 2.5.1.

Generally, the best way to install MSVC on Windows is using chocolately:

choco install -y visualstudio2022buildtools
# purposefully executed separately
choco install -y visualstudio2022-workload-vctools

This will result in the installation path:
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.37.32822\include correctly has algorithm in it. This is the only toolchain that is installed on this machine.

CUDA SDK will not correctly copy in its cmake package config into VS 2022, which is another pain point.

Executing with vcvars causes python311.lib to not be found:

  File "D:\appmana\.venv\Lib\site-packages\torch\_dynamo\output_graph.py", line 1465, in _call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e) from e
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
CppCompileError: C++ compile error

Command:
cl /I C:/Python311/Include /I C:/Python311/Include /I D:/appmana/.venv/Lib/site-packages/torch/include /I D:/appmana/.venv/Lib/site-packages/torch/include/torch/csrc/api/include /I D:/appmana/.venv/Lib/site-packages/torch/include/TH /I D:/appmana/.venv/Lib/site-packages/torch/include/THC /I D:/appmana/.venv/Lib/site-packages/torch/include /I D:/appmana/.venv/Lib/site-packages/torch/include/torch/csrc/api/include /I D:/appmana/.venv/Lib/site-packages/torch/include/TH /I D:/appmana/.venv/Lib/site-packages/torch/include/THC /D TORCH_INDUCTOR_CPP_WRAPPER /D C10_USING_CUSTOM_GENERATED_MACROS /D CPU_CAPABILITY_AVX2 /DLL /MD /O2 /std:c++20 /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /wd4624 /wd4067 /wd4068 /EHsc /openmp /openmp:experimental C:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/jw/cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.cpp /arch:AVX2 /LD /FeC:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/jw/cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.pyd /link /LIBPATH:D:/appmana/.venv/Scripts/libs /LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib /LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib /LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib torch.lib torch_cpu.lib torch_python.lib sleef.lib c10.lib

Output:
Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32822 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9025 : overriding '/openmp' with '/openmp:experimental'
cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.cpp
D:/appmana/.venv/Lib/site-packages/torch/include\ATen/cpu/vec/vec_half.h(16): warning C4556: value of intrinsic immediate argument '8' is out of range '0 - 7'
D:/appmana/.venv/Lib/site-packages/torch/include\ATen/cpu/vec/vec256/vec256_bfloat16.h(119): warning C4556: value of intrinsic immediate argument '8' is out of range '0 - 7'
D:/appmana/.venv/Lib/site-packages/torch/include\ATen/cpu/vec/vec256/vec256_bfloat16.h(124): warning C4556: value of intrinsic immediate argument '8' is out of range '0 - 7'
D:/appmana/.venv/Lib/site-packages/torch/include\ATen/cpu/vec/vec256/vec256_bfloat16.h(126): warning C4556: value of intrinsic immediate argument '8' is out of range '0 - 7'
C:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/jw/cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.cpp(66): warning C4849: OpenMP 'simdlen' clause ignored in 'simd' directive
C:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/jw/cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.cpp(155): warning C4849: OpenMP 'simdlen' clause ignored in 'simd' directive
C:\Users\bberman\AppData\Local\Temp\1\torchinductor_bberman\jw\cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.cpp(67) : info C5002: Omp simd loop not vectorized due to reason '1303'
C:\Users\bberman\AppData\Local\Temp\1\torchinductor_bberman\jw\cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.cpp(156) : info C5002: Omp simd loop not vectorized due to reason '1303'
Microsoft (R) Incremental Linker Version 14.37.32822.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/dll
/implib:C:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/jw/cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.lib
/out:C:/Users/bberman/AppData/Local/Temp/1/torchinductor_bberman/jw/cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.pyd
/LIBPATH:D:/appmana/.venv/Scripts/libs
/LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib
/LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib
/LIBPATH:D:/appmana/.venv/Lib/site-packages/torch/lib
torch.lib
torch_cpu.lib
torch_python.lib
sleef.lib
c10.lib
cjwvbdt66kypnofw2s5az6aowvbc4tihhkvxoeeuvdn3f6kirjor.obj
LINK : fatal error LNK1104: cannot open file 'python311.lib'

The generated compilation command appears to be referencing the wrong paths for libraries. After providing the Python lib path, everything works.

Reproducing

Requirements: 24GB VRAM NVIDIA GPU with Ampere or better; 30GB of disk space.

You can reproduce this issue using:

# strongly recommended to use uv so that this doesn't take forever to install
uv venv --seed
& .venv\scripts\activate.ps1
uv pip install "comfyui[withtriton]@git+https://github.com/hiddenswitch/ComfyUI.git"
comfyui --create-directories
comfyui --reserve-vram=-1.0 

Visit http://localhost:8188, then drag and drop this file into the work area, and click Queue:

mochi_text_to_video_example.json

You will need 24GB of VRAM or more.

@woct0rdho
Copy link
Owner

Please paste the whole stack trace. This looks like a problem of torch rather than triton

@doctorpangloss
Copy link
Author

doctorpangloss commented Dec 6, 2024

stack.md

@woct0rdho
Copy link
Owner

woct0rdho commented Dec 16, 2024

It seems to be an error when TorchInductor was compiling something to CPU, and my code in this repo does not modify that. The header file <algorithm> was not found, but this file exists in the path like C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\include\, and it should be found if the paths of MSVC are correctly set.

Did you use vcvars64.bat to set the paths of MSVC, as in this tutorial?
https://pytorch.org/tutorials/prototype/inductor_windows_cpu.html

(Personally I don't like to use vcvars64.bat, but let's first follow this tutorial and see what happens)

@doctorpangloss
Copy link
Author

Yes, there are some details:

without vcvars: I have previously seen your package working, and now, it does not work
using vcvars: Everything is found except python311.lib
using vcvars + manually copying python libs into a place they can be found: working

@oliverban
Copy link

Yes, there are some details:

without vcvars: I have previously seen your package working, and now, it does not work using vcvars: Everything is found except python311.lib using vcvars + manually copying python libs into a place they can be found: working

When you say "a place they can be found" where did you copy it?

And am I right to assume you did:
ACTIVATE Comfy VENV
vcvars64.bat to init MSVC
python main.py (to start Comfy)

and then your compile worked?

@doctorpangloss
Copy link
Author

doctorpangloss commented Dec 18, 2024

This is a working procedure:

choco install -y visualstudio2022buildtools
choco install -y visualstudio2022-workload-vctools
choco install -y cuda
# close and reopen the terminal to refresh your environment variables for CUDA_SDK

# start cmd with vcvars enabled
C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\AUXILI~1\Build\VCVARS~1.BAT amd64
# now start powershell, this inherits vcvars
powershell
# strongly recommended to use uv so that this doesn't take forever to install
uv venv --seed
& .venv\scripts\activate.ps1
uv pip install "comfyui[withtriton]@git+https://github.com/hiddenswitch/ComfyUI.git"
comfyui --create-directories
# this starts comfyui, there's no python main.py
comfyui --reserve-vram=-1.0 
# todo: you must copy python311.lib into your venv's libs, this is system specific

Visit http://localhost:8188, then drag and drop this file into the work area, and click Queue:
mochi_text_to_video_example.json

This successfully compiled.

@doctorpangloss
Copy link
Author

When you say "a place they can be found" where did you copy it?

I think in .venv/libs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants