-
Notifications
You must be signed in to change notification settings - Fork 701
Schedule QuantizationProfile instructions right after the last node that updates their inputs to shorten lifetimes of buffers #2698
Conversation
|
I wonder why the scheduler is not scheduling the profile nodes early and drags them all the way to the end of the functions. |
I looked at it. The thing is that profile nodes do not free any memory themselves. They have no outputs and all their inputs are |
0ec4e68 to
aa68eb7
Compare
|
Maybe we should change the way we calculate what freeing memory means? Because scheduling these nodes early will reduce memory pressure. No? |
Maybe. I'll check if changing the scheduler would result in an easier solution. |
I added a second commit to this PR, which changes the scheduler. I leave both commits in this PR for now so that it is easier to compare both approaches. |
c1f52cc to
690cd38
Compare
|
I don't think I'll have time to give it a try today. I'll check and give it feedbacks tomorrow. |
|
I did some experiments with resnet50 and a batch size of 512.
This is a nice memory optimization ! :-) Regarding the code itself, the scheduler version looks simpler and has my preference. Both versions nevertheless are specific to |
690cd38 to
fd3ce7e
Compare
Awesome! I'm glad it helps!
I'm proudly presenting the alternative number 3!!! :-D :-D I just pushed it. It is simpler than both previous attempts and it is also node-kind independent. Please give it a try. You can comment out the invocations of two others to see the effect of this one in isolation. |
nadavrot
left a comment
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.
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 suggest mentioning the SaveNode and Profile* nodes as an example,
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.
Why do we need this here? We already checked that the node is not isSheduled(N);
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.
Added a comment. We need to perform an extra isScheduled check here, because the code below may have scheduled the current node while scheduling its children.
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 would continue this commit with "because ...".
... because we don't want to extend the lifetime of this value for no reason. We want to execute and get rid of this node as soon as possible to reduce the memory pressure.
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.
... because nodes that have users can't be scheduled safely without violating dependencies.
fd3ce7e to
09f3b91
Compare
|
I personally like |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
|
@tlepley-cadence Could you check if my last version produces the same good results? |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
|
do not close this |
|
@opti-mix Sorry for the delay. I just come back from holiday. I'll look at this tomorrow. |
|
@opti-mix I finally did the check with the latest solution :) |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
|
Will land soon. This week or next week. |
…and which does not require any additional memory, schedule this user right after the current node This handles QuantizationProfileNode scheduling in a more general way, which is not dependent on the kind of the node. Also, take the opportunity to generalize the "SaveNode hack" in the scheduler and make it independent of the Node's kind.
09f3b91 to
518b458
Compare
facebook-github-bot
left a comment
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.
@opti-mix has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
This handles QuantizationProfileNode scheduling in a more general way, which is not dependent on the kind of the node. It schedules QuantizationProfile instructions right after the last node that updates their inputs to shorten lifetimes of buffers.
Also, take the opportunity to generalize the "SaveNode hack" in the scheduler and make it independent of the Node's kind.
Fixes #2697