Skip to content
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

[SOT][3.11] fix eval frame for python 3.11 #57490

Merged
merged 8 commits into from
Sep 21, 2023

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Sep 19, 2023

PR types

Bug fixes

PR changes

Others

Description

  • 目前 Eval Frame 会在几处根据 PyInterpreterFrame 创建 PyFrameObject,但是这样是有可能影响原来的 PyInterpreterFrame 的,这就导致在发生 Fallback 时,需要跑原来的 PyInterpreterFrame,而这个影响可能就会导致段错误,目前的 test_tensor_dtype_in_guard 单测就是因为这个原因,修改后已正常通过
  • 3.8-3.10 的 frame 就是 PyFrameObject,是一个 PyObject,因此可以直接传递给 Python 端,但 Python 3.11 不是这样的,而如果通过上面说的的方式从 PyInterpreterFrame 创建 PyFrameObject 则会产生影响,因此我们需要使用其他方式来创建一个 PyObject 传递给 Python 端 eval frame callback,这里创建了一个数据 Proxy 类 PyInterpreterFrameProxy,就是代理了其内部的 PyInterpreterFrame,用来间接访问 f_codef_globalsf_localsf_builtins 属性,我们目前只访问了这四个属性,因此不会有问题,相关参考如下:
  • eval_custom_code 中,我们会创建一个 shadow frame,在 3.8-3.10 我们会利用 PyFrame_New 创建 PyFrameObject,但这也是有问题的,这样创建的 PyFrameObject 会强行 complete,见 https://github.com/python/cpython/blob/17a335dd0291d09e1510157a4ebe02932ec632dd/Objects/frameobject.c#L1070 ,这会导致 RESUME 之前的,包括 RESUME 都不会跑到,其中包括了 MAKE_CELL,为了避免这一问题,我们需要寻找其他的创建新 Frame 的方法
  • 同样是 eval_custom_code 中,3.11 fastlocals 布局与之前版本是不一样的,通过 co_localsplusnames 可以获得 index -> name 的映射关系,因此利用 old 初始化 new 时候需要 new[new_idx] = old[old_idx],即 new[new_name_to_idx[old_idx_to_name[old_idx]]] = old[old_idx]
  • 清理 _custom_eval_frame 中 callback 返回 None 的情况,我们现在永远只会返回 CustomCode

PCard-66972

@paddle-bot
Copy link

paddle-bot bot commented Sep 19, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@SigureMo SigureMo marked this pull request as ready for review September 20, 2023 15:36
@SigureMo SigureMo changed the title [SOT] fix eval frame for python 3.11 [SOT][3.11] fix eval frame for python 3.11 Sep 21, 2023
Copy link
Contributor

@2742195759 2742195759 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SigureMo SigureMo merged commit 69ad173 into PaddlePaddle:develop Sep 21, 2023
@SigureMo SigureMo deleted the sot/fix-eval-frame-311 branch September 21, 2023 10:39
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
* [SOT] fix eval frame for python 3.11

* fix missing `()`

* fix no Paddle_PyInterpreterFrameProxyType in < 3.11

* `Paddle_PyInterpreterFrameProxy` -> `PyInterpreterFrameProxy`

* compat for eval_custom_code

* clean callback result is None logic

* refine internal API name

* refine comments
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 16, 2023
* [SOT] fix eval frame for python 3.11

* fix missing `()`

* fix no Paddle_PyInterpreterFrameProxyType in < 3.11

* `Paddle_PyInterpreterFrameProxy` -> `PyInterpreterFrameProxy`

* compat for eval_custom_code

* clean callback result is None logic

* refine internal API name

* refine comments
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
* [SOT] fix eval frame for python 3.11

* fix missing `()`

* fix no Paddle_PyInterpreterFrameProxyType in < 3.11

* `Paddle_PyInterpreterFrameProxy` -> `PyInterpreterFrameProxy`

* compat for eval_custom_code

* clean callback result is None logic

* refine internal API name

* refine comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants