Repository: pytorch
Issue: Autograd test failure on ppc64le
Labels: triaged,module: POWER

After building PyTorch on IBM's ppc64le architecture I ran into test failure in test_autograd.py. The script segfaults when exceptions are being handled on the following lines with the signal SIGABRT:
```
self.assertRaises(RuntimeError, lambda: w.backward(torch.ones(5, 5))):810
self.assertRaises(RuntimeError, lambda: q.backward(torch.ones(5, 5))): 814
self.assertRaises(RuntimeError, lambda: q.backward(torch.ones(5, 5))): 828
self.assertRaises(RuntimeError, lambda: z.backward(torch.ones(5, 5))): 865
```
Which creates the following error output:
```
terminate called after throwing an instance of 'std::runtime_error'
  what():  one of the variables needed for gradient computation has been modified by an inplace operation
./run_test.sh: line 27: 89711 Aborted                 (core dumped) $PYCMD test_autograd.py $@
```
Below is the backtrace log from GDB.

```
#0  0x00003fffb79aedb0 in __GI_raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00003fffb79b1270 in __GI_abort () at abort.c:89
#2  0x00003fff44b6c304 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/powerpc64le-linux-gnu/libstdc++.so.6
#3  0x00003fff44b68b34 in ?? () from /usr/lib/powerpc64le-linux-gnu/libstdc++.so.6
#4  0x00003fff44b68bf0 in std::terminate() () from /usr/lib/powerpc64le-linux-gnu/libstdc++.so.6
#5  0x00003fff44b69034 in __cxa_throw () from /usr/lib/powerpc64le-linux-gnu/libstdc++.so.6
#6  0x00003fff9485a9a8 in torch::autograd::Variable::SavedVariable::unpack (this=0x10f51c30, saved_for=...) at torch/csrc/autograd/variable.cpp:74
#7  0x00003fff94862538 in unpack_saved_variables(THPFunction *, std::function<_object*(std::shared_ptr<torch::autograd::Variable>)>) (self=<optimized out>, unpack_fn=...)
    at torch/csrc/autograd/python_function.cpp:864
#8  0x00003fff94862bfc in THPFunction_saved_variables (self=<optimized out>, _unused=<optimized out>) at torch/csrc/autograd/python_function.cpp:888
#9  0x00003fffb7d81f28 in getset_get (descr=0x3fff956e87a0, obj=0x3fff3ecf7ce8, type=<optimized out>) at Objects/descrobject.c:146
#10 0x00003fffb7dc5e30 in _PyObject_GenericGetAttrWithDict (obj=<optimized out>, name=0x3fffb77efab0, dict=0x0) at Objects/object.c:1439
#11 0x00003fffb7dc613c in PyObject_GenericGetAttr (obj=<optimized out>, name=<optimized out>) at Objects/object.c:1461
#12 0x00003fffb7dc4d9c in PyObject_GetAttr (v=0x3fff3ecf7ce8, name=<optimized out>) at Objects/object.c:1196
#13 0x00003fffb7e54738 in PyEval_EvalFrameEx (f=0x3fff3ea635f0, throwflag=<optimized out>) at Python/ceval.c:2543
#14 0x00003fffb7e5c420 in PyEval_EvalCodeEx (co=0x3fff3f1293b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=<optimized out>, 
    defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3584
#15 0x00003fffb7d9d718 in function_call (func=0x3fff3f13c230, arg=0x3fff3e221b00, kw=0x0) at Objects/funcobject.c:523
#16 0x00003fffb7d52014 in PyObject_Call (func=0x3fff3f13c230, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2547
#17 0x00003fffb7e56750 in ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x3fff3ea5d9a0, func=0x3fff3f13c230) at Python/ceval.c:4666
#18 PyEval_EvalFrameEx (f=0x3fff3ea615a8, throwflag=<optimized out>) at Python/ceval.c:3028
#19 0x00003fffb7e5c420 in PyEval_EvalCodeEx (co=0x3fff3f12e430, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=<optimized out>, 
    defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3584
#20 0x00003fffb7d9d718 in function_call (func=0x3fff3f138398, arg=0x3fff9587fa70, kw=0x0) at Objects/funcobject.c:523
#21 0x00003fffb7d52014 in PyObject_Call (func=0x3fff3f138398, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2547
#22 0x00003fffb7d68140 in instancemethod_call (func=0x3fff3f138398, arg=0x3fff9587fa70, kw=0x0) at Objects/classobject.c:2602
#23 0x00003fffb7d52014 in PyObject_Call (func=0x3fff3f0b1d70, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2547
#24 0x00003fffb7e50d28 in PyEval_CallObjectWithKeywords (func=0x3fff3f0b1d70, arg=0x3fff3e256690, kw=<optimized out>) at Python/ceval.c:4221
#25 0x00003fffb7d51f7c in PyObject_CallObject (o=<optimized out>, a=<optimized out>) at Objects/abstract.c:2535
#26 0x00003fff9486314c in torch::autograd::PyFunction::apply (this=0x3fff3ecf7d40, inputs=std::vector of length 1, capacity 1 = {...}) at torch/csrc/autograd/python_function.cpp:155
#27 0x00003fff94850ab0 in torch::autograd::call_function (task=...) at torch/csrc/autograd/engine.cpp:162
#28 torch::autograd::Engine::evaluate_function (this=<optimized out>, task=...) at torch/csrc/autograd/engine.cpp:167
#29 0x00003fff94850fd0 in torch::autograd::Engine::thread_main (this=0x3fff956cce70 <engine>, queue=std::shared_ptr (count 3, weak 0) 0x10dc2960, device=<optimized out>) at torch/csrc/autograd/engine.cpp:117
#30 0x00003fff948788c0 in PythonEngine::thread_main (this=0x3fff956cce70 <engine>, queue=std::shared_ptr (count 3, weak 0) 0x10dc2960, device=<optimized out>) at torch/csrc/autograd/python_engine.cpp:23
#31 0x00003fff94857958 in std::_Mem_fn_base<void (torch::autograd::Engine::*)(std::shared_ptr<torch::autograd::ReadyQueue>, int), true>::operator()<std::shared_ptr<torch::autograd::ReadyQueue>, int, void>(torch::autograd::Engine*, std::shared_ptr<torch::autograd::ReadyQueue>&&, int&&) const (__object=<optimized out>, this=<optimized out>) at /usr/include/c++/5/functional:600
#32 std::_Bind_simple<std::_Mem_fn<void (torch::autograd::Engine::*)(std::shared_ptr<torch::autograd::ReadyQueue>, int)> (torch::autograd::Engine*, std::shared_ptr<torch::autograd::ReadyQueue>, int)>::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) (this=<optimized out>) at /usr/include/c++/5/functional:1531
#33 std::_Bind_simple<std::_Mem_fn<void (torch::autograd::Engine::*)(std::shared_ptr<torch::autograd::ReadyQueue>, int)> (torch::autograd::Engine*, std::shared_ptr<torch::autograd::ReadyQueue>, int)>::operator()() (this=<optimized out>) at /usr/include/c++/5/functional:1520
#34 std::thread::_Impl<std::_Bind_simple<std::_Mem_fn<void (torch::autograd::Engine::*)(std::shared_ptr<torch::autograd::ReadyQueue>, int)> (torch::autograd::Engine*, std::shared_ptr<torch::autograd::ReadyQueue>, int)> >::_M_run() (this=<optimized out>) at /usr/include/c++/5/thread:115
#35 0x00003fff44ba49a4 in ?? () from /usr/lib/powerpc64le-linux-gnu/libstdc++.so.6
#36 0x00003fffb7c98070 in start_thread (arg=0x3fff3ea5f1a0) at pthread_create.c:335
#37 0x00003fffb7a93a30 in clone () at ../sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S:96
```