Release backward inputs per static graph ref count #20804
Merged
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.
Release backward inputs per static graph ref count
For the output buffer marked as external output:
Before the change:
One of the backward inputs is 3.9GB, it lives until the backward ends.
With the change:
The 3.9GB is released when the last node depending on that tensor completed.
Be noted: the peak did not change though, we have more work to do to reduce on the peak.
Others
It is found there are few tests that were updated to use incorrect expected values in previous code refactoring a81faee#diff-9e8fbae7d3dff24106cd17564949f320e943cb3048eae07813c7de144f140419L382.
This PR tries to fix them back, and I think now all test cases are back to normal.
Motivation and Context