-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[GLCC]Part-2: @to_static support for PyLayer #56531
[GLCC]Part-2: @to_static support for PyLayer #56531
Conversation
e911cb6
to
8abc4d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for interpreter_util
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
Others
Description
Original requirements
It is expected that the PyLayer mechanism in the dynamic graph of the Paddle can interoperate with the @to_staitc of the Paddle's dynamic to static, supporting the custom layer of the PyLayer in the model to be perceived by the @to_static and correctly generating the static graph Program, and supporting the training of the dynamic to static and the exporting for inference.
So our main objective is to Enable PyLayer to Support @to_static. In this PR, we support
@to_static
to percept and translate the logic of forward function and backward function fromPyLayer
and also make effort to percept and processPyLayerContext
in dy2st module.Related issues
【Feature Request】 PyLayer 功能支持动转静 @to_static 🚀: #54120
Related PR
[GLCC]Part-1: Add pylayer op to Support @to_static: #56108
Project Records
https://github.com/MarioLulab/GLCC2023-Paddle-Record
Main works
@to_static
to sense and handle the computational logic in theforward()
andbackward()
functions in dygraph PyLayer, by modifying the functionconvert_load
and returningStaticPyLayer
.StaticPyLayer
can complete dy2st code translation, andStaticPyLayer.apply
can create forward block and backward block.PyLayerContext
withStaticPyLayerContext
to percept the logic ofPyLayerContext
. And we use theSTEP_SCOPES
andskip_gc_vars
to solve the problem of pass intermediate variables between forward and backward. We modify the code of garbage collection to support keeping neccessary Variables in step_scope after finishing executing forward graph.@to_static
support forPyLayer
andstatic_pylayer
APIFuture works
Refine the
prune.cc
to support pylayer op forjit.save()
for inference.static_pylayer
API support not only positional argument but also keyword argument.static_pylayer
API support not onlypaddle.Tensor
but also non-Tensor objects will be included in the argument list.static_pylayer
API supportstop_gradient = False
for some inputs andstop_gradient = True
for the other inputs.StaticPyLayerContext
support more features (e.g.mark_not_inplace
) which align with dygraph PyLayer