Repository: pytorch
Issue: elements of STL get converted to an `IValue` and cannot be converted to an STL.
Labels: module: cpp-extensions,module: cpp,triaged

### 🐛 Describe the bug

I think that the following snippet

```C++
#include <torch/extension.h>
struct h: torch::CustomClassHolder{
    h(std::vector<std::pair<torch::ScalarType, std::vector<int64_t>>>){

    }
    void push(std::vector<std::pair<torch::ScalarType, std::vector<int64_t>>>){}
};
TORCH_LIBRARY(testthing, m) {
    m.class_<h>("h")
        // .def(torch::init<std::vector<std::pair<torch::ScalarType, std::vector<int64_t>>>>());
        .def("push", &h::push);


}
```

 should compile but it fails with

```
/usr/bin/c++ -DPROTOBUF_USE_DLLS -DUSE_C10D_GLOO -DUSE_C10D_NCCL -DUSE_DISTRIBUTED -DUSE_RPC -DUSE_TENSORPIPE -D_GLIBCXX_USE_CXX11_ABI=1 -Dbugreport_EXPORTS -I/usr/include/python3.12 -I/home/user/third_party/fmt/include -isystem /usr/include -isystem /usr/include/torch/csrc/api/include -isystem /home/user/third_party/pybind11/include -fPIC -Wall -pipe -Wextra -Wno-register -Wfatal-errors -g -march=native -g -std=gnu++20 -fPIC -D_GLIBCXX_USE_CXX11_ABI=1 -MD -MT csrc/CMakeFiles/bugreport.dir/bugreport.cc.o -MF csrc/CMakeFiles/bugreport.dir/bugreport.cc.o.d -o csrc/CMakeFiles/bugreport.dir/bugreport.cc.o -c /home/user/csrc/bugreport.cc
In file included from /usr/include/ATen/core/ivalue.h:1555,
                 from /usr/include/ATen/core/List_inl.h:4,
                 from /usr/include/ATen/core/List.h:490,
                 from /usr/include/ATen/core/IListRef_inl.h:3,
                 from /usr/include/ATen/core/IListRef.h:631,
                 from /usr/include/ATen/WrapDimUtils.h:3,
                 from /usr/include/ATen/TensorNames.h:3,
                 from /usr/include/ATen/NamedTensorUtils.h:3,
                 from /usr/include/torch/csrc/autograd/variable.h:11,
                 from /usr/include/torch/csrc/autograd/autograd.h:3,
                 from /usr/include/torch/csrc/api/include/torch/autograd.h:3,
                 from /usr/include/torch/csrc/api/include/torch/all.h:7,
                 from /usr/include/torch/extension.h:5,
                 from /home/user/csrc/bugreport.cc:1:
/usr/include/ATen/core/ivalue_inl.h: In instantiation of 'T c10::generic_to(IValue, _fake_type<T>) [with T = std::pair<ScalarType, std::vector<long int> >]':
/usr/include/ATen/core/ivalue_inl.h:1964:20:   required from 'typename c10::detail::ivalue_to_const_ref_overload_return<T>::type c10::IValue::to() const & [with T = std::pair<c10::ScalarType, std::vector<long int> >; typename c10::detail::ivalue_to_const_ref_overload_return<T>::type = std::pair<c10::ScalarType, std::vector<long int> >]'
/usr/include/ATen/core/List_inl.h:127:35:   required from 'c10::impl::ListElementReference<T, Iterator>::operator std::conditional_t<std::is_reference<typename c10::detail::ivalue_to_const_ref_overload_return<T>::type>::value, const T&, T>() const [with T = std::pair<c10::ScalarType, std::vector<long int> >; Iterator = __gnu_cxx::__normal_iterator<c10::IValue*, std::vector<c10::IValue> >; std::conditional_t<std::is_reference<typename c10::detail::ivalue_to_const_ref_overload_return<T>::type>::value, const T&, T> = std::pair<c10::ScalarType, std::vector<long int> >; typename c10::detail::ivalue_to_const_ref_overload_return<T>::type = std::pair<c10::ScalarType, std::vector<long int> >]'
/usr/include/ATen/core/ivalue_inl.h:1775:3:   required from 'std::vector<T> c10::generic_to(IValue, _fake_type<std::vector<T> >) [with Elem = std::pair<ScalarType, std::vector<long int> >]'
/usr/include/ATen/core/ivalue_inl.h:1951:20:   required from 'T c10::IValue::to() && [with T = std::vector<std::pair<c10::ScalarType, std::vector<long int> > >]'
/usr/include/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h:325:32:   required from 'static decltype(auto) c10::impl::ivalue_to_arg<T, AllowDeprecatedTypes>::call(c10::IValue&) [with T = std::vector<std::pair<c10::ScalarType, std::vector<long int> > >; bool AllowDeprecatedTypes = false]'
/usr/include/torch/custom_class_detail.h:144:28:   required from 'typename c10::guts::infer_function_traits<Functor>::type::return_type torch::detail::call_torchbind_method_from_stack(Functor&, torch::jit::Stack&, std::index_sequence<_Idx ...>) [with Functor = WrapMethod<void (h::*)(std::vector<std::pair<c10::ScalarType, std::vector<long int> > >)>; bool AllowDeprecatedTypes = false; long unsigned int ...ivalue_arg_indices = {0, 1}; typename c10::guts::infer_function_traits<Functor>::type::return_type = void; c10::guts::infer_function_traits_t<FuncType> = c10::guts::function_traits<void(c10::intrusive_ptr<h, c10::detail::intrusive_target_default_null_type<h> >, std::vector<std::pair<c10::ScalarType, std::vector<long int> > >)>; torch::jit::Stack = std::vector<c10::IValue>; std::index_sequence<_Idx ...> = std::integer_sequence<long unsigned int, 0, 1>]'
/usr/include/torch/custom_class_detail.h:153:73:   required from 'typename c10::guts::infer_function_traits<Functor>::type::return_type torch::detail::call_torchbind_method_from_stack(Functor&, torch::jit::Stack&) [with Functor = WrapMethod<void (h::*)(std::vector<std::pair<c10::ScalarType, std::vector<long int> > >)>; bool AllowDeprecatedTypes = false; typename c10::guts::infer_function_traits<Functor>::type::return_type = void; c10::guts::infer_function_traits_t<FuncType> = c10::guts::function_traits<void(c10::intrusive_ptr<h, c10::detail::intrusive_target_default_null_type<h> >, std::vector<std::pair<c10::ScalarType, std::vector<long int> > >)>; torch::jit::Stack = std::vector<c10::IValue>]'
/usr/include/torch/custom_class_detail.h:174:50:   required from 'void torch::detail::BoxedProxy<void, Func>::operator()(torch::jit::Stack&, Func&) [with Func = torch::detail::WrapMethod<void (h::*)(std::vector<std::pair<c10::ScalarType, std::vector<long int> > >)>; torch::jit::Stack = std::vector<c10::IValue>]'
/usr/include/torch/custom_class.h:406:42:   required from 'torch::jit::Function* torch::class_<CurClass>::defineMethod(std::string, Func, std::string, std::initializer_list<torch::arg>) [with Func = torch::detail::WrapMethod<void (h::*)(std::vector<std::pair<c10::ScalarType, std::vector<long int> > >)>; CurClass = h; std::string = std::__cxx11::basic_string<char>]'
/usr/include/torch/custom_class.h:159:17:   required from 'torch::class_<CurClass>& torch::class_<CurClass>::def(std::string, Func, std::string, std::initializer_list<torch::arg>) [with Func = void (h::*)(std::vector<std::pair<c10::ScalarType, std::vector<long int> > >); CurClass = h; std::string = std::__cxx11::basic_string<char>]'
/home/user/csrc/bugreport.cc:11:13:   required from here
/usr/include/ATen/core/ivalue_inl.h:1819:9: error: no type named 'element_type' in 'std::__remove_pointer_helper<std::pair<c10::ScalarType, std::vector<long int> >, std::pair<c10::ScalarType, std::vector<long int> > >::type' {aka 'struct std::pair<c10::ScalarType, std::vector<long int> >'}
 1819 |   using ElemType = typename std::remove_pointer<T>::type::element_type;
      |         ^~~~~~~~
compilation terminated due to -Wfatal-errors.
ninja: build stopped: subcommand failed.
```

Using `torch::List` does not solve the problem, only hide it.

Sorry if this is a duplicate or by design.



### Versions

```bash
Collecting environment information...
PyTorch version: 2.3.0.post301
Is debug build: False
CUDA used to build PyTorch: 12.0
ROCM used to build PyTorch: N/A

OS: Fedora release 40 (Forty) (x86_64)
GCC version: (conda-forge gcc 13.2.0-7) 13.2.0
Clang version: 18.1.7 (https://github.com/conda-forge/clangdev-feedstock 1b91969d0c6b64ef555f9c04fc02d7758335f4b3)
CMake version: version 3.29.5
Libc version: glibc-2.39

Python version: 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0] (64-bit runtime)
Python platform: Linux-6.8.11-300.fc40.x86_64-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        48 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               16
On-line CPU(s) list:                  0-15
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen 7 7840U w/ Radeon  780M Graphics
CPU family:                           25
Model:                                116
Thread(s) per core:                   2
Core(s) per socket:                   8
Socket(s):                            1
Stepping:                             1
CPU(s) scaling MHz:                   34%
CPU max MHz:                          6076.0000
CPU min MHz:                          400.0000
BogoMIPS:                             6587.21
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca flush_l1d
Virtualization:                       AMD-V
L1d cache:                            256 KiB (8 instances)
L1i cache:                            256 KiB (8 instances)
L2 cache:                             8 MiB (8 instances)
L3 cache:                             16 MiB (1 instance)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-15
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Vulnerable: Safe RET, no microcode
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.3
[pip3] torch==2.3.0.post301
[conda] libmagma                  2.7.2                h173bb3b_2    conda-forge
[conda] libmagma_sparse           2.7.2                h173bb3b_3    conda-forge
[conda] libtorch                  2.3.0           cuda120_h2b0da52_301    conda-forge
[conda] mkl                       2023.2.0         h84fe81f_50496    conda-forge
[conda] numpy                     1.26.4          py312heda63a1_0    conda-forge
[conda] pytorch                   2.3.0           cuda120_py312h26b3cf7_301    conda-forge
```



cc @malfet @zou3519 @jbschlosser