Skip to content

Commit 5233fc2

Browse files
committed
Update torch patch
1 parent cd514c8 commit 5233fc2

File tree

1 file changed

+74
-8
lines changed

1 file changed

+74
-8
lines changed

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

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,85 @@ index 3b128027..b670f3f2 100644
439439
torch::jit::IntType::get());
440440
}
441441
}
442+
diff --git a/torch/csrc/autograd/python_variable_indexing.h b/torch/csrc/autograd/python_variable_indexing.h
443+
index 688ea19b..5c9c1ecb 100644
444+
--- a/torch/csrc/autograd/python_variable_indexing.h
445+
+++ b/torch/csrc/autograd/python_variable_indexing.h
446+
@@ -38,15 +38,16 @@ static inline UnpackedSlice __PySlice_Unpack(PyObject* _r) {
447+
return val;
448+
};
449+
450+
- if (r->step == Py_None) {
451+
+ PyObject* stepObj = PySlice_Step(r);
452+
+ if (stepObj == Py_None) {
453+
step_sym = c10::SymInt(1);
454+
} else {
455+
- if (torch::is_symint(r->step)) {
456+
- auto step_sym = py::handle(r->step).cast<c10::SymInt>();
457+
+ if (torch::is_symint(stepObj)) {
458+
+ auto step_sym = py::handle(stepObj).cast<c10::SymInt>();
459+
} else {
460+
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
461+
Py_ssize_t step;
462+
- if (!_PyEval_SliceIndex(r->step, &step)) {
463+
+ if (!_PyEval_SliceIndex(stepObj, &step)) {
464+
throw python_error();
465+
}
466+
if (step == 0) {
467+
@@ -58,29 +59,31 @@ static inline UnpackedSlice __PySlice_Unpack(PyObject* _r) {
468+
}
469+
}
470+
471+
- if (torch::is_symint(r->start)) {
472+
- start_sym = py::handle(r->start).cast<c10::SymInt>();
473+
- } else if (r->start == Py_None) {
474+
+ PyObject* startObj = PySlice_Start(r);
475+
+ if (torch::is_symint(startObj)) {
476+
+ start_sym = py::handle(startObj).cast<c10::SymInt>();
477+
+ } else if (startObj == Py_None) {
478+
start_sym = c10::SymInt(step_sym < 0 ? PY_SSIZE_T_MAX : 0);
479+
} else {
480+
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
481+
Py_ssize_t start;
482+
- if (!_PyEval_SliceIndex(r->start, &start)) {
483+
+ if (!_PyEval_SliceIndex(startObj, &start)) {
484+
throw python_error();
485+
}
486+
start = clip_val(start);
487+
start_sym = c10::SymInt(start);
488+
}
489+
490+
- if (torch::is_symint(r->stop)) {
491+
- stop_sym = py::handle(r->stop).cast<c10::SymInt>();
492+
- } else if (r->stop == Py_None) {
493+
+ PyObject* stopObj = PySlice_Stop(r);
494+
+ if (torch::is_symint(stopObj)) {
495+
+ stop_sym = py::handle(stopObj).cast<c10::SymInt>();
496+
+ } else if (stopObj == Py_None) {
497+
stop_sym = c10::SymInt(
498+
step_sym < 0 ? c10::SymInt::min_representable_int() : PY_SSIZE_T_MAX);
499+
} else {
500+
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
501+
Py_ssize_t stop;
502+
- if (!_PyEval_SliceIndex(r->stop, &stop)) {
503+
+ if (!_PyEval_SliceIndex(stopObj, &stop)) {
504+
throw python_error();
505+
}
506+
stop = clip_val(stop);
442507
diff --git a/torch/csrc/dynamo/cpython_defs.c b/torch/csrc/dynamo/cpython_defs.c
443-
index 5d249d99..df9b631d 100644
508+
index 5d249d99..d00c18bf 100644
444509
--- a/torch/csrc/dynamo/cpython_defs.c
445510
+++ b/torch/csrc/dynamo/cpython_defs.c
446-
@@ -15,7 +15,7 @@
447-
448-
// NOTE: all `assert`s below are converted to `CHECK`s
511+
@@ -1,3 +1,4 @@
512+
+#if 0
513+
#include <torch/csrc/dynamo/cpython_defs.h>
449514

450-
-#if IS_PYTHON_3_11_PLUS
451-
+#if IS_PYTHON_3_11_PLUS && !defined(GRAALVM_PYTHON)
515+
#ifdef _WIN32
516+
@@ -360,3 +361,4 @@ THP_PyFrame_Clear(_PyInterpreterFrame *frame)
517+
}
452518

453-
// Problem in CPython includes when mixing core and non-core build
454-
// The fix was not backported to 3.12 so this is needed here
519+
#endif
520+
+#endif
455521
diff --git a/torch/csrc/dynamo/eval_frame.c b/torch/csrc/dynamo/eval_frame.c
456522
index 0245b192..f195d97d 100644
457523
--- a/torch/csrc/dynamo/eval_frame.c

0 commit comments

Comments
 (0)