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

[Dy2static-Fallback] add set_eval_frame function in pybind. #52006

Merged
merged 10 commits into from
May 18, 2023

Conversation

2742195759
Copy link
Contributor

@2742195759 2742195759 commented Mar 22, 2023

PR types

New features

PR changes

Others

Description

PCard-66972

add set_eval_frame function in pybind.

import paddle
import collections
import dis

CustomCode = collections.namedtuple("CustomCode", ["code"])

def mul(a, b):
    return a * b

print(dis.dis(mul))
code = CustomCode(mul.__code__)

def callback(frame_obj):
    # Do your callback function here and return a object with `.code`
    if frame_obj.f_code.co_name == "add":
        return code
    return my_code(code=frame_obj.f_code)   # do nothing.

def add(a, b):
    return a + b 

x = 1
y = 2

paddle.fluid.core.set_eval_frame(callback)
assert add (x, y) == 2, "should be 2"
paddle.fluid.core.set_eval_frame(None)
assert add (x, y) == 3, "should be 3"

1. add set_eval_frame function in pybind.
@paddle-bot
Copy link

paddle-bot bot commented Mar 22, 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.

@paddle-bot
Copy link

paddle-bot bot commented Mar 22, 2023

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

paddle/fluid/pybind/jit.cc Outdated Show resolved Hide resolved
@paddle-ci-bot
Copy link

paddle-ci-bot bot commented May 5, 2023

Sorry to inform you that affdb4a's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM for overall

Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM for overall

@PaddlePaddle PaddlePaddle deleted a comment from paddle-ci-bot bot May 17, 2023
@2742195759 2742195759 merged commit 7b1695a into PaddlePaddle:develop May 18, 2023
@2742195759 2742195759 deleted the new_dy2static branch May 18, 2023 05:56
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.

None yet

3 participants