diff --git a/torch/csrc/jit/python/python_tracer.cpp b/torch/csrc/jit/python/python_tracer.cpp index 83570c85e9b4cc2..c89d54872a07bbc 100644 --- a/torch/csrc/jit/python/python_tracer.cpp +++ b/torch/csrc/jit/python/python_tracer.cpp @@ -27,7 +27,7 @@ namespace tracer { std::vector _pythonCallstack() { pybind11::gil_scoped_acquire gil; PyFrameObject* frame = PyEval_GetFrame(); - Py_INCREF(frame); + Py_XINCREF(frame); std::vector entries; while (nullptr != frame) {