-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Memory optimization on Dynamic RNN #7599
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
19 commits
Select commit
Hold shift + click to select a range
42ec7ff
limit variable type to lod tensor in memory optimization transpiler
QiJune 5c4eab9
init
QiJune 62eb0aa
Merge remote-tracking branch 'baidu/develop' into memory_opt_rnn
QiJune 808d9d2
set rnn
QiJune d5ac674
refine policy
QiJune ad26ab5
support while operator
QiJune 3592997
clean code
QiJune db362db
fix code
QiJune f73f550
init
QiJune 63985e0
fix bug
QiJune 06b46c4
Merge remote-tracking branch 'baidu/develop' into memory_opt_rnn
QiJune 4dbb1ab
fix random seed and training data order
QiJune 38e0789
clean code
QiJune b472acd
Merge remote-tracking branch 'baidu/develop' into memory_opt_rnn
QiJune 3fb5aa7
fix code
QiJune 77fb96e
fix bug
QiJune f1a2792
fix conflicts
QiJune 8e169f4
refine get_cfgs method to support multi while operators
QiJune e180fb1
refine codes
QiJune 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
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
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.
I think we can divide the optimization into three levels:
level 1: Only reusing variables with the same
prod(shape)
. Perfect reusing, no memory waste or reallocating.level 2: Reusing variables whose
prod(shape)
is greater than the requiredprod(shape)
. There is no reallocating, but some memory may be wasted. To minimize the waste, the reused variable'sprod(shape)
should be as close to the required one as possible.Optimization of level 1 and level 2 are harmless. Enabling them is definitely better than do nothing. They shall always be applied.
level 3 (Optional): Reusing variables even if whose
prod(shape)
is less than the required one. Obviously, each reusing of this level will result in a reallocating, which may slow training down. So this level is optional. To maximize the reusing efficiency, the reused variable'sprod(shape)
should be as close to the required one as possible.The whole optimization logic may be a bit complex. So I think it's better to warp the
pool
as aclass
and implement the reusing variable picking up logic as one of its member functions.However, It's not necessary to complete all of these in the current PR. We can merge it first and keep refining in the future. I'm also glad to take part in the jobs.
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.
Yes. Actually, we can reuse var if the shape is smaller than the var in cache pool. But, the first dim is batch_size, which is -1 in compile time. We can not get the real size in compile time.
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.
@JiayiFeng Thanks for the detailed optimization policy. Sure, we can merge this PR first and you can work on it later.