You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 from PyLayer and also make effort to percept and process PyLayerContext in dy2st module.
Enable @to_static to sense and handle the computational logic in the forward() and backward() functions in dygraph PyLayer, by modifying the function convert_load and returning StaticPyLayer. StaticPyLayer can complete dy2st code translation, and StaticPyLayer.apply can create forward block and backward block.
We subtitude PyLayerContext with StaticPyLayerContext to percept the logic of PyLayerContext. And we use the STEP_SCOPES and skip_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.
Add some testcases of @to_static support for PyLayer and static_pylayer API
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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