8000 [dynamo] fix 3.11+ refleak by williamwen42 · Pull Request #124238 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[dynamo] fix 3.11+ refleak #124238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update on "[dynamo] fix 3.11+ refleak"
Fixes #119607 for 3.11+.

In 3.11+, `_PyFrame_FastToLocalsWithError` could implicity run `COPY_FREE_VARS` on the original frame, leading to double incref's since the dynamo shadow frame can rerun `COPY_FREE_VARS`. So the solution is to skip the first `COPY_FREE_VARS` instruction in the shadow frame if it was already executed in the original frame.

Also move the location for clearing the original frame in 3.12 to handle error cases more thoroughly.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang

[ghstack-poisoned]
  • Loading branch information
williamwen42 committed Apr 17, 2024
commit 00d9627c597848fea8a0b4c210985e7a0ed6b81e
2 changes: 1 addition & 1 deletion torch/csrc/dynamo/eval_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ inline static PyObject* eval_custom_code_impl(
// for 3.11+, if free_vars_copied is true, we do not need to
// run the first COPY_FREE_VARS since THP_PyFrame_FastToLocalsWithError
// already did the equivalent action.
if (free_vars_copied) {
if (free_vars_copied && _Py_OPCODE(_PyCode_CODE(shadow->f_code)[0]) == COPY_FREE_VARS) {
shadow->prev_instr = _PyCode_CODE(shadow->f_code);
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0