Skip to content

Commit fd8e6cc

Browse files
committed
Update torch patch for 3.12
1 parent 0f3476f commit fd8e6cc

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

graalpython/lib-graalpython/patches/torch-2.4.1.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,46 @@ index 7c9b4be00..b8edbcfda 100644
645645
}
646646

647647
ExtraState* init_and_set_extra_state(PyCodeObject* code) {
648+
diff --git a/torch/csrc/dynamo/guards.cpp b/torch/csrc/dynamo/guards.cpp
649+
index b7fde50a9..712e3613b 100644
650+
--- a/torch/csrc/dynamo/guards.cpp
651+
+++ b/torch/csrc/dynamo/guards.cpp
652+
@@ -26,7 +26,7 @@
653+
// https://github.com/python/cpython/blob/9afc6d102d16080535325f645849cd84eb04d57d/Objects/tupleobject.c#L1058-L1062
654+
// To handle this, we manually copy the struct here and manually cast it to this
655+
// new struct. From 3.12, the struct is included in the header file.
656+
-#if IS_PYTHON_3_12_PLUS
657+
+#if 0 // GraalPy change
658+
659+
#define Py_BUILD_CORE
660+
// Bring _PyTupleIterObject from the header file
661+
@@ -596,7 +596,7 @@ static PyObject* check_obj_id(PyObject* dummy, PyObject* args) {
662+
}
663+
}
664+
665+
-#if IS_PYTHON_3_12_PLUS
666+
+#if 0 // GraalPy change
667+
668+
static std::unordered_map<PyObject*, uint64_t> dict_version_map;
669+
static int dict_version_watcher_id;
670+
@@ -617,7 +617,7 @@ static int dict_version_watch_callback(
671+
#endif
672+
673+
static uint64_t get_dict_version_unchecked(PyObject* dict) {
674+
-#if IS_PYTHON_3_12_PLUS
675+
+#if 0 // GraalPy change
676+
677+
if (PyDict_Watch(dict_version_watcher_id, dict)) {
678+
throw std::runtime_error("failed to add version watcher to dict!");
679+
@@ -4013,7 +4013,7 @@ PyObject* torch_c_dynamo_guards_init() {
680+
"install_no_tensor_aliasing_guard", install_no_tensor_aliasing_guard);
681+
682+
// initialize dict_version_map watcher for 3.12
683+
-#if IS_PYTHON_3_12_PLUS
684+
+#if 0 // GraalPy change
685+
686+
dict_version_watcher_id = PyDict_AddWatcher(dict_version_watch_callback);
687+
if (dict_version_watcher_id == -1) {
648688
diff --git a/torch/csrc/jit/python/python_tracer.cpp b/torch/csrc/jit/python/python_tracer.cpp
649689
index 92e6e2d3a..4d2ec0bfe 100644
650690
--- a/torch/csrc/jit/python/python_tracer.cpp

graalpython/lib-graalpython/patches/torch-2.7.0.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,46 @@ index b839fb26f..b7853029f 100644
750750
}
751751

752752
#else
753+
diff --git a/torch/csrc/dynamo/guards.cpp b/torch/csrc/dynamo/guards.cpp
754+
index 60fb339d1..28d07734a 100644
755+
--- a/torch/csrc/dynamo/guards.cpp
756+
+++ b/torch/csrc/dynamo/guards.cpp
757+
@@ -42,7 +42,7 @@
758+
// To handle the older python versions, we manually copy the struct here and
759+
// manually cast it to this new struct. For newer versions, the struct is
760+
// included in the header file.
761+
-#if IS_PYTHON_3_12_PLUS
762+
+#if 0 // GraalPy change
763+
764+
#define Py_BUILD_CORE
765+
#include <internal/pycore_range.h> // _PyRangeIterObject
766+
@@ -707,7 +707,7 @@ static PyObject* check_obj_id(PyObject* dummy, PyObject* args) {
767+
}
768+
}
769+
770+
-#if IS_PYTHON_3_12_PLUS
771+
+#if 0 // GraalPy change
772+
773+
static std::unordered_map<PyObject*, uint64_t> dict_version_map;
774+
static int dict_version_watcher_id;
775+
@@ -728,7 +728,7 @@ static int dict_version_watch_callback(
776+
#endif
777+
778+
static uint64_t get_dict_version_unchecked(PyObject* dict) {
779+
-#if IS_PYTHON_3_12_PLUS
780+
+#if 0 // GraalPy change
781+
782+
if (PyDict_Watch(dict_version_watcher_id, dict)) {
783+
throw std::runtime_error("failed to add version watcher to dict!");
784+
@@ -6090,7 +6090,7 @@ PyObject* torch_c_dynamo_guards_init() {
785+
py_m.def("profile_guard_manager", profile_guard_manager);
786+
787+
// initialize dict_version_map watcher for 3.12
788+
-#if IS_PYTHON_3_12_PLUS
789+
+#if 0 // GraalPy change
790+
791+
dict_version_watcher_id = PyDict_AddWatcher(dict_version_watch_callback);
792+
if (dict_version_watcher_id == -1) {
753793
diff --git a/torch/csrc/jit/python/python_tracer.cpp b/torch/csrc/jit/python/python_tracer.cpp
754794
index 876186743..041348257 100644
755795
--- a/torch/csrc/jit/python/python_tracer.cpp

0 commit comments

Comments
 (0)