Repository: pytorch
Issue: test/test_ops.py is segfaulting on master build with DEBUG assets
Labels: high priority,module: ci,triaged,module: testing

### 🐛 Describe the bug

```
test_dtypes__refs_add_cpu (__main__.TestCommonCPU) ... terminate called after throwing an instance of 'c10::Error'
  what():  !c10::impl::HermeticPyObjectTLS::get_state() INTERNAL ASSERT FAILED at "/scratch/chourdiaanjali/work/pytorch/torch/csrc/autograd/python_variable.cpp":310, please report a bug to PyTorch.
Exception raised from decref at /scratch/chourdiaanjali/work/pytorch/torch/csrc/autograd/python_variable.cpp:310 (most recent call first):
frame #0: <unknown function> + 0xce7f5 (0x7ff1c2c247f5 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #1: std::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > ()>::operator()() const + 0x4c (0x7ff1f6293cb0 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #2: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x40 (0x7ff1c2c23676 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #3: c10::detail::torchCheckFail(char const*, char const*, unsigned int, char const*) + 0x97 (0x7ff1c2c216f6 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #4: <unknown function> + 0xae356e (0x7ff204ef856e in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #5: <unknown function> + 0x10ad050 (0x7ff2054c2050 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #6: c10::TensorImpl::destroy_pyobj_if_needed() + 0x102 (0x7ff1c2beb724 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #7: c10::TensorImpl::~TensorImpl() + 0x2a (0x7ff1c2bea318 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #8: c10::TensorImpl::~TensorImpl() + 0x18 (0x7ff1c2bea390 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #9: <unknown function> + 0x291d0e8 (0x7ff1f0ab40e8 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #10: <unknown function> + 0x29f757e (0x7ff1f0b8e57e in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #11: <unknown function> + 0x29f6242 (0x7ff1f0b8d242 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #12: torch::autograd::SavedVariable::reset_data() + 0x3d (0x7ff1f61ab019 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #13: <unknown function> + 0x6874cc9 (0x7ff1f4a0bcc9 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #14: torch::autograd::deleteNode(torch::autograd::Node*) + 0x33 (0x7ff1f613653f in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #15: std::_Sp_counted_deleter<torch::autograd::generated::PowBackward1*, void (*)(torch::autograd::Node*), std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() + 0x2c (0x7ff1f4c1f7d4 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #16: std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() + 0x42 (0x7ff204f0dec4 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #17: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() + 0x27 (0x7ff204f08ad3 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #18: <unknown function> + 0x68660b4 (0x7ff1f49fd0b4 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #19: <unknown function> + 0x68660d0 (0x7ff1f49fd0d0 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #20: <unknown function> + 0x7f603fc (0x7ff1f60f73fc in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #21: <unknown function> + 0x7f60444 (0x7ff1f60f7444 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_cpu.so)
frame #22: std::default_delete<c10::AutogradMetaInterface>::operator()(c10::AutogradMetaInterface*) const + 0x2e (0x7ff205170d88 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #23: std::unique_ptr<c10::AutogradMetaInterface, std::default_delete<c10::AutogradMetaInterface> >::~unique_ptr() + 0x49 (0x7ff20516effb in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #24: c10::TensorImpl::~TensorImpl() + 0x6a (0x7ff1c2bea358 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #25: c10::TensorImpl::~TensorImpl() + 0x18 (0x7ff1c2bea390 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libc10.so)
frame #26: <unknown function> + 0xaf9a5a (0x7ff204f0ea5a in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #27: <unknown function> + 0xaf4498 (0x7ff204f09498 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #28: <unknown function> + 0xae4420 (0x7ff204ef9420 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #29: <unknown function> + 0xae44a2 (0x7ff204ef94a2 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #30: <unknown function> + 0x10c5e2c (0x7ff2054dae2c in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #31: <unknown function> + 0x10ae081 (0x7ff2054c3081 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #32: THPVariable_subclass_dealloc(_object*) + 0x32e (0x7ff2054caa34 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
<omitting python frames>
frame #43: THPSize_NewFromSymSizes(at::Tensor const&) + 0x64 (0x7ff205397d3b in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #44: THPVariable_get_shape(THPVariable*, void*) + 0xb9 (0x7ff2054c7e55 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #60: <unknown function> + 0x18add45 (0x7ff205cc2d45 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #61: <unknown function> + 0x18b21b4 (0x7ff205cc71b4 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #62: c10::BoxedKernel::makeFromFunctor<torch::impl::dispatch::PythonKernelHolder>(std::unique_ptr<torch::impl::dispatch::PythonKernelHolder, std::default_delete<torch::impl::dispatch::PythonKernelHolder> >)::{lambda(c10::OperatorKernel*, c10::OperatorHandle const&, c10::DispatchKeySet, std::vector<c10::IValue, std::allocator<c10::IValue> >*)#1}::_FUN(c10::OperatorKernel*, c10::OperatorHandle const&, c10::DispatchKeySet, std::vector<c10::IValue, std::allocator<c10::IValue> >*) + 0x38 (0x7ff205cc71ef in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)
frame #63: c10::BoxedKernel::callBoxed(c10::OperatorHandle const&, c10::DispatchKeySet, std::vector<c10::IValue, std::allocator<c10::IValue> >*) const + 0x85 (0x7ff2054d5f27 in /scratch/chourdiaanjali/work/pytorch/torch/lib/libtorch_python.so)

Aborted (core dumped)

```

### Versions

master

cc @ezyang @gchanan @zou3519 @seemethere @malfet @pytorch/pytorch-dev-infra