From: albanD <desmaison.alban@gmail.com>
Date: Wed, 18 Jan 2023 15:23:48 +0000
Subject: Add missing gc untrack for cpp autograd Nodes (#92351)

Fixes https://github.com/pytorch/pytorch/issues/91161 the assertion after the warning seems to be linked to the fact that we didn't untrack this properly.
In 3.11 they added a warning when this is not called properly before tp_free
Pull Request resolved: https://github.com/pytorch/pytorch/pull/92351
Approved by: https://github.com/ezyang
---
 torch/csrc/autograd/python_cpp_function.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/torch/csrc/autograd/python_cpp_function.cpp b/torch/csrc/autograd/python_cpp_function.cpp
index 1353139..4be9152 100644
--- a/torch/csrc/autograd/python_cpp_function.cpp
+++ b/torch/csrc/autograd/python_cpp_function.cpp
@@ -101,6 +101,7 @@ int THPCppFunction_clear(PyObject* self) {
 }
 
 void THPCppFunction_dealloc(PyObject* self) {
+  PyObject_GC_UnTrack(self);
   THPCppFunction_clear(self);
   ((THPCppFunction*)self)->cdata.~shared_ptr();
   Py_TYPE(self)->tp_free(self);
