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

error: too few arguments for template template parameter "Tuple" detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> #1024

Closed
lucasjinreal opened this issue Jan 7, 2022 · 18 comments
Labels

Comments

@lucasjinreal
Copy link

C:\ProgramData\Anaconda3\lib\site-packages\torch\include\pybind11\cast.h(1429): error: too few arguments for template template parameter "Tuple"
          detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]"
(1507): here

C:\ProgramData\Anaconda3\lib\site-packages\torch\include\pybind11\cast.h(1503): error: too few arguments for template template parameter "Tuple"
          detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]"
(1507): here

2 errors detected in the compilation of "D:/codes/deps/pytorch3d/pytorch3d/csrc/iou_box3d/iou_box3d.cu".
iou_box3d.cu
@lucasjinreal lucasjinreal changed the title C:\ProgramData\Anaconda3\lib\site-packages\torch\include\pybind11\cast.h(1429): error: too few arguments for template template parameter "Tuple" detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]" (1507): here C:\ProgramData\Anaconda3\lib\site-packages\torch\include\pybind11\cast.h(1503): error: too few arguments for template template parameter "Tuple" detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]" (1507): here 2 errors detected in the compilation of "D:/codes/deps/pytorch3d/pytorch3d/csrc/iou_box3d/iou_box3d.cu". iou_box3d.cu error: too few arguments for template template parameter "Tuple" detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> Jan 7, 2022
@lucasjinreal
Copy link
Author

 cl.exe -V
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30138 版
版权所有(C) Microsoft Corporation。保留所有权利。

cl: 命令行 error D8004 :“/V”需要参数

@lucasjinreal
Copy link
Author

Does there anyway to support this compiler? I got this issue everywhere on any windows machine.

@bottler
Copy link
Contributor

bottler commented Jan 7, 2022

Just like here, there is mention of tuple_caster template template problems in the log in #920 (which I think gets caused by other errors). The solution to that involved commenting out the c++14 in setup.py and downgrading the compiler like #876 (comment) . I think you are using an even newer compiler, which may have the same problem.

What is your version of Visual Studio 2019, and can you check if there are any earlier errors in the log file?

@lucasjinreal
Copy link
Author

@bottler Hi, thanks for your reply. I actually already tried comment out std++14 from setup.py. But same error still got.

Downgrading compiler does there any specific version needed? this is my version:

image

However, why not add newer compiler support since we will move to this new compiler eventually someday.

@bottler
Copy link
Contributor

bottler commented Jan 7, 2022

You have 16.11.8 and a previous problem was with 16.11.5. Downgrading to 16.9.6 was what helped on the other issue.

@bottler
Copy link
Contributor

bottler commented Jan 7, 2022

However, why not add newer compiler support since we will move to this new compiler eventually someday.

The problem is not specific to PyTorch3D. It is an incompatibility with certain CUDA versions (maybe just 11.2 and 11.3). It may get fixed in a future compiler update, or maybe the idea is that people should now use CUDA 11.5 or later.

@lucasjinreal
Copy link
Author

@bottler For your notice am just using CUDA 11.5. I think downgrading to 16.9.6 should be the only solution for now. Does it will break my enviroments if I downgraded visual studio version?

@bottler
Copy link
Contributor

bottler commented Jan 9, 2022

Sorry I cannot be sure. I expect it won't be a problem.

@av-novikov
Copy link

The same issue when i'm trying to build my application with pybind11 includes and CUDA support. Tried VS2017, CUDA 11.4; VS2017, CUDA 11.6; VS2022, CUDA11.6 also with Pybind 2.9.0. Probably, need to address issue for pybind11 repo.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 28, 2022
@bottler
Copy link
Contributor

bottler commented Feb 28, 2022

@mediev Sorry I missed your message. Thanks. That's interesting. So it's not unique to VS2019, and newer CUDA doesn't fix it.

@mrsaleh
Copy link

mrsaleh commented Feb 23, 2023

I have the same issue. I failed to compile multiple libraries. First time I thought maybe its the library issue , but this time it failed with the same message.

Windows 10
Visual Studio 2022
Pytorch compiled with Cuda 11.6
Python 3.10

[1/1] C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v...ute_52,code=compute_52 -gencode=arch=compute_52,code=sm_52
FAILED: E:/PositioningSystem/DPVO/build/temp.win-amd64-3.10/Release/dpvo/altcorr/correlation_kernel.obj
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\nvcc --generate-dependencies-with-compile --dependency-output E:\PositioningSystem\DPVO\build\temp.win-amd64-3.10\Release\dpvo/altcorr/correlation_kernel.obj.d --use-local-env -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcompiler /wd4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcudafe --diag_suppress=field_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed "-ID:\Program Files\Python310\lib\site-packages\torch\include" "-ID:\Program Files\Python310\lib\site-packages\torch\include\torch\csrc\api\include" "-ID:\Program Files\Python310\lib\site-packages\torch\include\TH" "-ID:\Program Files\Python310\lib\site-packages\torch\include\THC" "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include" "-ID:\Program Files\Python310\include" "-ID:\Program Files\Python310\Include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" -c E:\PositioningSystem\DPVO\dpvo\altcorr\correlation_kernel.cu -o E:\PositioningSystem\DPVO\build\temp.win-amd64-3.10\Release\dpvo/altcorr/correlation_kernel.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -O3 -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=cuda_corr -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_52,code=compute_52 -gencode=arch=compute_52,code=sm_52
D:/Program Files/Python310/lib/site-packages/torch/include\c10/macros/Macros.h(138): warning C4067: unexpected tokens following preprocessor directive - expected a newline
D:/Program Files/Python310/lib/site-packages/torch/include\c10/macros/Macros.h(138): warning C4067: unexpected tokens following preprocessor directive - expected a newline
D:\Program Files\Python310\lib\site-packages\torch\include\pybind11\cast.h(624): error: too few arguments for template template parameter "Tuple"
          detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]"
(721): here

D:\Program Files\Python310\lib\site-packages\torch\include\pybind11\cast.h(717): error: too few arguments for template template parameter "Tuple"
          detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]"
(721): here

2 errors detected in the compilation of "E:/PositioningSystem/DPVO/dpvo/altcorr/correlation_kernel.cu".
correlation_kernel.cu
ninja: build stopped: subcommand failed.

@bottler
Copy link
Contributor

bottler commented Feb 23, 2023

@mrsaleh Your problem is not related to pytorch3d but I suspect its cause is similar to this issue here. Whatever library you are trying to compile has the file correlation_kernel.cu and it probably includes (perhaps indirectly) a header from pytorch (e.g. torch/extension.h) which itself includes pybind which the windows nvcc isn't happy with. (Typically these things are not a problem on linux.)

The solution will be to change headers around, and this may necessitate changes to the library to use lower level apis of pytorch - see e.g. 3388d3f . We can't help!

@psc0628
Copy link

psc0628 commented Jul 18, 2023

I use VS2022 and CUDA 11.6. And I found a solution in https://stackoverflow.com/questions/73489837/why-the-base-case-with-no-template-arguments-for-variadic-tuple-is-not-working, which was caused by MSVC 2022 changing the incantation.
Modify torch\include\pybind11\cast.h:
Add an empty tuple_caster class and move two templates before the detailed tuple_caster class.

// Base implementation for std::tuple and std::pair
template <template <typename...> class Tuple, typename... Ts>
class tuple_caster;

template <typename T1, typename T2>
class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {};

template <typename... Ts>
class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};

template <template <typename...> class Tuple, typename... Ts>
class tuple_caster {
(the rest class is identical)

@johnbanq
Copy link

johnbanq commented Aug 24, 2023

I use VS2022 and CUDA 11.6. And I found a solution in https://stackoverflow.com/questions/73489837/why-the-base-case-with-no-template-arguments-for-variadic-tuple-is-not-working, which was caused by MSVC 2022 changing the incantation. Modify torch\include\pybind11\cast.h: Add an empty tuple_caster class and move two templates before the detailed tuple_caster class.

// Base implementation for std::tuple and std::pair template <template <typename...> class Tuple, typename... Ts> class tuple_caster;

template <typename T1, typename T2> class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {};

template <typename... Ts> class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};

template <template <typename...> class Tuple, typename... Ts> class tuple_caster { (the rest class is identical)

To make things easier for whoever needs this, here is the updated cast.h, replacing your torch\include\pybind11\cast.h with it should work.

Besides that, here is the git patch of this change, applying this patch on cast.h should also do the trick as well.

tested on pytorch 1.12.1, it may or may not work for other versions

@lucasjinreal
Copy link
Author

lucasjinreal commented Aug 25, 2023

It's not work.

@Aspen233
Copy link

I use VS2022 and CUDA 11.6. And I found a solution in https://stackoverflow.com/questions/73489837/why-the-base-case-with-no-template-arguments-for-variadic-tuple-is-not-working, which was caused by MSVC 2022 changing the incantation. Modify torch\include\pybind11\cast.h: Add an empty tuple_caster class and move two templates before the detailed tuple_caster class.
// Base implementation for std::tuple and std::pair template <template <typename...> class Tuple, typename... Ts> class tuple_caster;
template <typename T1, typename T2> class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {};
template <typename... Ts> class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};
template <template <typename...> class Tuple, typename... Ts> class tuple_caster { (the rest class is identical)

To make things easier for whoever needs this, here is the updated cast.h, replacing your torch\include\pybind11\cast.h with it should work.

Besides that, here is the git patch of this change, applying this patch on cast.h should also do the trick as well.

tested on pytorch 1.12.1, it may or may not work for other versions

It worked! Thanks soooo much!

@sipkode
Copy link

sipkode commented Mar 21, 2024

For those that come later, manually making the hacks described by @psc0628 worked for me, but @johnbanq 's version did not.

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

No branches or pull requests

8 participants