-
Notifications
You must be signed in to change notification settings - Fork 5.7k
【CINN】Enable AutoLayoutPass flag in train process #71891
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3dd291b
enable flag
liuruyan c0f50b5
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liuruyan a642e3d
use guard
liuruyan 8387ef4
fix bug
liuruyan 440e28b
polish code
liuruyan 83720e7
add paddle.is_compiled_with_cuda()
liuruyan 01cc9ca
remove error env flag set
liuruyan 8da3223
fix invalid use of getenv
liuruyan a482fe3
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liuruyan fefb064
enable flag in cinn
liuruyan d0fd224
polish code
liuruyan f1b21b6
add infer flag
liuruyan f0da52e
polish code
liuruyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -745,6 +745,36 @@ def is_api_in_module_helper(obj, module_prefix): | |
return m is not None and m.__name__.startswith(module_prefix) | ||
|
||
|
||
def auto_layout_guard(backend, guard_creators): | ||
# AutoLayoutPass may change layout of bn to NHWC, if not enable `FLAGS_cudnn_batchnorm_spatial_persistent`, it will revert to NCHW. So if the user does not set this Flag, we set it to True. | ||
if ( | ||
auto_layout_is_enabled() | ||
and backend.is_cinn() | ||
and paddle.is_compiled_with_cuda() | ||
and os.getenv("FLAGS_cudnn_batchnorm_spatial_persistent") is None | ||
): | ||
guard_creators.append( | ||
lambda: paddle.base.framework.flag_guard( | ||
"FLAGS_cudnn_batchnorm_spatial_persistent", | ||
True, | ||
) | ||
) | ||
|
||
|
||
@contextmanager | ||
def train_guards(backend): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx,将下一个PR中进行修复。 |
||
""" | ||
train_guards is the guard method before program execution, which can integrate and add various guards. | ||
""" | ||
guard_creators = [] | ||
# Add FLAGS_cudnn_batchnorm_spatial_persistent guard | ||
auto_layout_guard(backend, guard_creators) | ||
# add more guards here | ||
|
||
with compose_guards(*guard_creators)(): | ||
yield | ||
|
||
|
||
def auto_layout_is_enabled(): | ||
return paddle.get_flags(["FLAGS_enable_auto_layout_pass"])[ | ||
"FLAGS_enable_auto_layout_pass" | ||
|
Oops, something went wrong.
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.
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.
这个为啥要叫
guard
呢?或许应该叫add_auto_layout_guard
?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.
thx,将下一个PR中进行修复。