Repository: pytorch
Issue: forward program terminated from __cxa_pure_virtual
Labels: needs reproduction,module: crash,module: cpp,module: autograd,triaged,shadow review


## Issue description

C++ program terminated when model forward. The core stack:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007f42d82df7f1 in __GI_abort () at abort.c:79
#2  0x00007f42d8b53957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007f42d8b59ae6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007f42d8b59b21 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007f42d8b5a8ff in __cxa_pure_virtual () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007f42a4cc9acb in at::TensorBase::grad_fn (this=0x7f40ce00be00) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/Tensor.cpp:120
#7  0x00007f42a93469d3 in torch::autograd::impl::gradient_edge (self=...) at /data/work/soft/pytorch-1.10.0/torch/csrc/autograd/variable.cpp:227
#8  0x00007f42a8554933 in torch::autograd::detail::MakeNextFunctionList::operator() (this=0x7f42c1e90e50, variable=...) at /data/work/soft/pytorch-1.10.0/torch/csrc/autograd/function.h:561
#9  0x00007f42a8569479 in at::IterArgs<torch::autograd::detail::MakeNextFunctionList>::apply<at::Tensor const&> (this=0x7f42c1e90e50, arg=...) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/Variadic.h:32
#10 0x00007f42a8560595 in torch::autograd::collect_next_edges<at::Tensor const&> () at /data/work/soft/pytorch-1.10.0/torch/csrc/autograd/function.h:616
#11 0x00007f42a88f7194 in torch::autograd::VariableType::(anonymous namespace)::t (ks=..., self=...) at /data/work/soft/pytorch-1.10.0/torch/csrc/autograd/generated/VariableType_3.cpp:8723
#12 0x00007f42a89600a5 in c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor(c10::DispatchKeySet, const at::Tensor&), torch::autograd::VariableType::(anonymous namespace)::t>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, const at::Tensor&> >::operator() (args#1=..., args#0=..., this=0x55f08e475030) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/impl/WrapFunctionIntoFunctor.h:13
#13 c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor(c10::DispatchKeySet, const at::Tensor&), torch::autograd::VariableType::(anonymous namespace)::t>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, const at::Tensor&> >, at::Tensor(c10::DispatchKeySet, const at::Tensor&)>::call(c10::OperatorKernel *, c10::DispatchKeySet, const at::Tensor &) (functor=0x55f08e475030, 
    dispatchKeySet=..., args#0=...) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h:440
#14 0x00007f42a578408e in c10::callUnboxedKernelFunction<at::Tensor, at::Tensor const&> (
    unboxed_kernel_func=0x7f42a896001b <c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor(c10::DispatchKeySet, const at::Tensor&), torch::autograd::VariableType::(anonymous namespace)::t>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, const at::Tensor&> >, at::Tensor(c10::DispatchKeySet, const at::Tensor&)>::call(c10::OperatorKernel *, c10::DispatchKeySet, const at::Tensor &)>, functor=0x55f08e475030, dispatchKeySet=...) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/KernelFunction_impl.h:57
#15 0x00007f42a5c18fc8 in c10::KernelFunction::call<at::Tensor, at::Tensor const&> (dispatchKeySet=..., opHandle=..., this=0x55f08cfd9fd0) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/KernelFunction_impl.h:67
#16 c10::Dispatcher::call<at::Tensor, at::Tensor const&>(c10::TypedOperatorHandle<at::Tensor (at::Tensor const&)> const&, at::Tensor const&) const (op=..., this=0x7f42b6a95c40 <c10::Dispatcher::realSingleton()::_singleton>)
    at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/dispatch/Dispatcher.h:531
#17 c10::TypedOperatorHandle<at::Tensor (at::Tensor const&)>::call(at::Tensor const&) const (args#0=..., this=<optimized out>) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/dispatch/Dispatcher.h:397
#18 at::_ops::t::call (self=...) at /data/work/soft/pytorch-1.10.0/build/aten/src/ATen/Operators_3.cpp:4256
#19 0x00007f42a4eb8a78 in at::Tensor::t (this=0x7f40ce00be00) at /data/work/soft/pytorch-1.10.0/build/aten/src/ATen/core/TensorBody.h:3270
#20 0x00007f42a4f5ba47 in at::native::linear (input=..., weight=..., bias_opt=...) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/native/Linear.cpp:37
#21 0x00007f42a62b5e50 in at::(anonymous namespace)::(anonymous namespace)::wrapper__linear (input=..., weight=..., bias=...) at /data/work/soft/pytorch-1.10.0/build/aten/src/ATen/RegisterCompositeImplicitAutograd.cpp:3043
#22 0x00007f42a63c2bc0 in c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor(const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&), at::(anonymous namespace)::(anonymous namespace)::wrapper__linear>, at::Tensor, c10::guts::typelist::typelist<const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&> >::operator() (args#2=..., args#1=..., args#0=..., this=0x55f08d9dedf0)
    at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/impl/WrapFunctionIntoFunctor.h:13
#23 c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor(const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&), at::(anonymous namespace)::(anonymous namespace)::wrapper__linear>, at::Tensor, c10::guts::typelist::typelist<const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&> >, at::Tensor(const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&)>::call(c10::OperatorKernel *, c10::DispatchKeySet, const at::Tensor &, const at::Tensor &, const c10::optional<at::Tensor> &) (functor=0x55f08d9dedf0, args#0=..., args#1=..., args#2=...)
    at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h:423
#24 0x00007f42a57a6120 in c10::callUnboxedKernelFunction<at::Tensor, at::Tensor const&, at::Tensor const&, c10::optional<at::Tensor> const&> (
    unboxed_kernel_func=0x7f42a63c2aff <c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor(const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&), at::(anonymous namespace)::(anonymous namespace)::wrapper__linear>, at::Tensor, c10::guts::typelist::typelist<const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&> >, at::Tensor(const at::Tensor&, const at::Tensor&, const c10::optional<at::Tensor>&)>::call(c10::OperatorKernel *, c10::DispatchKeySet, const at::Tensor &, const at::Tensor &, const c10::optional<at::Tensor> &)>, functor=0x55f08d9dedf0, dispatchKeySet=...)
    at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/KernelFunction_impl.h:57
#25 0x00007f42a5624c88 in c10::KernelFunction::call<at::Tensor, at::Tensor const&, at::Tensor const&, c10::optional<at::Tensor> const&> (dispatchKeySet=..., opHandle=..., this=0x55f08d0da620)
    at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/boxing/KernelFunction_impl.h:67
#26 c10::Dispatcher::call<at::Tensor, at::Tensor const&, at::Tensor const&, c10::optional<at::Tensor> const&>(c10::TypedOperatorHandle<at::Tensor (at::Tensor const&, at::Tensor const&, c10::optional<at::Tensor> const&)> const&, at::Tensor const&, at::Tensor const&, c10::optional<at::Tensor> const&) const (op=..., this=0x7f42b6a95c40 <c10::Dispatcher::realSingleton()::_singleton>) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/dispatch/Dispatcher.h:531
#27 c10::TypedOperatorHandle<at::Tensor (at::Tensor const&, at::Tensor const&, c10::optional<at::Tensor> const&)>::call(at::Tensor const&, at::Tensor const&, c10::optional<at::Tensor> const&) const (args#2=..., args#1=..., args#0=..., 
    this=<optimized out>) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/core/dispatch/Dispatcher.h:397
#28 at::_ops::linear::call (input=..., weight=..., bias=...) at /data/work/soft/pytorch-1.10.0/build/aten/src/ATen/Operators_0.cpp:2715
#29 0x00007f42a4c2155d in at::linear (input=..., weight=..., bias=...) at /data/work/soft/pytorch-1.10.0/build/aten/src/ATen/Functions.h:3109
#30 0x00007f42a505347d in at::native::(anonymous namespace)::CellParams::linear_ih (this=0x7f40e2297320, input=...) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/native/RNN.cpp:120
#31 0x00007f42a508702c in at::native::(anonymous namespace)::FullBidirectionalLayer<std::tuple<at::Tensor, at::Tensor>, at::native::(anonymous namespace)::CellParams>::operator() (this=0x7f42c1e91770, input=..., input_hidden={...}, 
    params={...}) at /data/work/soft/pytorch-1.10.0/aten/src/ATen/native/RNN.cpp:921
#32 0x00007f42a5074da2 in at::native::(anonymous namespace)::apply_layer_stack<at::Tensor, std::pair<std::tuple<at::Tensor, at::Tensor>, std::tuple<at::Tensor, at::Tensor> >, std::pair<at::native::(anonymous namespace)::CellParams, at::native::(anonymous namespace)::CellParams> > (layer=..., input=..., hiddens=std::vector of length 3, capacity 3 = {...}, weights=std::vector of length 3, capacity 3 = {...}, num_layers=3, dropout_p=0, train=false)
---Type <return> to continue, or q <return> to quit---
    at /data/work/soft/pytorch-1.10.0/aten/src/ATen/native/RNN.cpp:1125



## Code example
   std::vector<float> input_values_;
    ...
    torch::Tensor input_tensor = torch::from_blob(input_values_.data() + (begin_index * column_num_), {1, row_num_, column_num_}, options_).clone(); 

   std::vector<torch::jit::IValue> inputs_;

    inputs_.push_back(input_tensor);

    if(inputs_.size() == 0)
    {   
        return ret;
    }   

    // Terminated from this line ====>
    at::Tensor output = module_.forward(inputs_).toTensor();

## System Info

- PyTorch version: v1.10.0
- Python version: 3.7
- CPU forward



cc @jbschlosser @ezyang @albanD @zou3519 @gqchen @pearu @nikitaved @soulitzer @Lezcano @Varal7