Repository: pytorch
Issue: [JIT] Interleaved C++-Python execution loses inner Python stacks
Labels: oncall: jit

I triggered a recent shape propagation test failure:

```
14:56:59 ======================================================================
14:56:59 ERROR: test_pow_scalar_constant (__main__.TestJitGenerated)
14:56:59 ----------------------------------------------------------------------
14:56:59 Traceback (most recent call last):
14:56:59   File "test_jit.py", line 3940, in do_test
14:56:59     check(name)
14:56:59   File "test_jit.py", line 3921, in check
14:56:59     fn, (self_variable,) + args_variable)
14:56:59   File "test_jit.py", line 3831, in check_against_reference
14:56:59     outputs_test = func(*nograd_inputs)
14:56:59   File "test_jit.py", line 3807, in script_fn
14:56:59     return output_process_fn(CU.the_method(*tensors))
14:56:59 RuntimeError: 
14:56:59 Expected object of type CPUDoubleType but found type CPUFloatType for argument #2 'exponent' (checked_cast_tensor at /var/lib/jenkins/workspace/aten/src/ATen/Utils.h:32)
14:56:59 frame #0: at::CPUDoubleType::s_pow(at::Tensor const&, at::Tensor const&) const + 0x6b (0x7fb4526c795b in /opt/python/2.7/lib/python2.7/site-packages/torch/lib/libcaffe2.so)
14:56:59 frame #1: at::Type::pow(at::Tensor const&, at::Tensor const&) const + 0x161 (0x7fb4527d2931 in /opt/python/2.7/lib/python2.7/site-packages/torch/lib/libcaffe2.so)
14:56:59 frame #2: <unknown function> + 0x497796 (0x7fb453c52796 in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #3: <unknown function> + 0x33735e (0x7fb453af235e in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #4: <unknown function> + 0x337ccf (0x7fb453af2ccf in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #5: <unknown function> + 0x339a6b (0x7fb453af4a6b in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #6: torch::jit::PropagateInputShapes(torch::jit::Graph&, torch::jit::ArgumentSpec const&) + 0x3b9 (0x7fb453af4f39 in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #7: torch::jit::GraphExecutorImpl::run(torch::jit::variable_tensor_list) + 0xd5c (0x7fb453aa0e3c in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #8: torch::jit::GraphExecutor::run(torch::jit::variable_tensor_list&&) + 0x47 (0x7fb453a9aa97 in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #9: <unknown function> + 0x54f249 (0x7fb453d0a249 in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #10: <unknown function> + 0x22db98 (0x7fb4539e8b98 in /opt/python/2.7/lib/python2.7/site-packages/torch/_C.so)
14:56:59 frame #11: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #12: <unknown function> + 0x63095 (0x7fb4641ba095 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #13: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #14: <unknown function> + 0xc2a45 (0x7fb464219a45 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #15: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #16: PyEval_EvalFrameEx + 0x3077 (0x7fb464260f77 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #17: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #18: <unknown function> + 0x867e0 (0x7fb4641dd7e0 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #19: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #20: PyEval_EvalFrameEx + 0x3077 (0x7fb464260f77 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #21: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #22: PyEval_EvalFrameEx + 0x7ed2 (0x7fb464265dd2 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #23: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #24: PyEval_EvalFrameEx + 0x7ed2 (0x7fb464265dd2 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #25: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #26: PyEval_EvalFrameEx + 0x7ed2 (0x7fb464265dd2 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #27: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #28: <unknown function> + 0x868b5 (0x7fb4641dd8b5 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #29: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #30: PyEval_EvalFrameEx + 0x3077 (0x7fb464260f77 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #31: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #32: <unknown function> + 0x867e0 (0x7fb4641dd7e0 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #33: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #34: <unknown function> + 0x63095 (0x7fb4641ba095 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #35: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #36: <unknown function> + 0xc2a45 (0x7fb464219a45 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #37: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #38: PyEval_EvalFrameEx + 0x3b78 (0x7fb464261a78 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #39: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #40: <unknown function> + 0x868b5 (0x7fb4641dd8b5 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #41: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #42: PyEval_EvalFrameEx + 0x3077 (0x7fb464260f77 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #43: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #44: <unknown function> + 0x867e0 (0x7fb4641dd7e0 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #45: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #46: <unknown function> + 0x63095 (0x7fb4641ba095 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #47: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #48: <unknown function> + 0xc2a45 (0x7fb464219a45 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #49: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #50: PyEval_EvalFrameEx + 0x3b78 (0x7fb464261a78 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #51: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #52: <unknown function> + 0x868b5 (0x7fb4641dd8b5 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #53: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #54: PyEval_EvalFrameEx + 0x3077 (0x7fb464260f77 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #55: PyEval_EvalCodeEx + 0x80d (0x7fb4642676fd in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #56: <unknown function> + 0x867e0 (0x7fb4641dd7e0 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #57: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #58: <unknown function> + 0x63095 (0x7fb4641ba095 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #59: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #60: <unknown function> + 0xc2a45 (0x7fb464219a45 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #61: PyObject_Call + 0x43 (0x7fb4641ab373 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #62: PyEval_EvalFrameEx + 0x3b78 (0x7fb464261a78 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 frame #63: PyEval_EvalFrameEx + 0x7f86 (0x7fb464265e86 in /opt/python/2.7.15/lib/libpython2.7.so.1.0)
14:56:59 :
14:56:59 operation failed shape propagation:
14:56:59 
14:56:59 def the_method(i0):
14:56:59     return i0.pow(3.14)
14:56:59            ~~~~~~ <--- HERE
14:56:59 
```

You can see in the C++ backtrace that we go back into Python when shape propagation occurs. We should be able to extract a useful Python trace when this occurs; however, it seems to be lost.