Incrementally free initializers while saving to OrtValue instances - #12485
Merged
Scott McKay (skottmckay) merged 9 commits intoAug 9, 2022
Merged
Conversation
…aphResolveMemoryCost
…ue to reduce peak memory usage.
…ializersWhileSavingToOrtValue
Member
|
Just curious if it is possible/safe to just clear the under-lying ModelProto held the Model instance after its job is done in the Graph instance ? |
Pranav Sharma (pranavsharma)
previously approved these changes
Aug 8, 2022
Co-authored-by: Pranav Sharma <prs@microsoft.com>
Pranav Sharma (pranavsharma)
approved these changes
Aug 8, 2022
| virtual common::Status GetPreallocatedBuffer(int ort_value_index, const char* name, | ||
| * @return | ||
| */ | ||
| virtual common::Status GetPreallocatedBuffer(int ort_value_index, const std::string& name, |
Contributor
Contributor
Author
There was a problem hiding this comment.
The current usage only involves 'name' coming from a TensorProto so is always a std::string.
Scott McKay (skottmckay)
deleted the
skottmckay/FreeInitializersWhileSavingToOrtValue
branch
August 9, 2022 00:59
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description:
After copying each TensorProto to an OrtValue free the TensorProto. This helps reduce peak memory usage during model initialization vs. the current approach of copying all the initializers before freeing them.
Also fix an unnecessary conversion of the TensorProto name from std::string to const char*. The usage of that value required std::string so converting to const char* incurred an unnecessary std::string construction in every usage of the value.
Motivation and Context
Reduce peak memory usage to enable 1P production scenario.
For a ~13.5MB model the peak memory usage was reduced by ~10MB.