onnxruntime
d58b31e6 - Fix prepacked weight reference lifetime (#32040)

Commit
2 days ago
Fix prepacked weight reference lifetime (#32040) This pull request introduces a new method to the `PrepackedWeightsForGraph` class to improve how prepacked weights are managed, particularly when saving models. The main change is the addition of a `DiscardAndReplaceWithReferenceIfSaving` method, which either replaces a prepacked weight with a reference or removes it, depending on whether the save mode is enabled. Corresponding updates are made to usage sites and comprehensive unit tests are added to verify the new behavior. **Enhancements to prepacked weights management:** * Added the `DiscardAndReplaceWithReferenceIfSaving` method to the `PrepackedWeightsForGraph` class. This method replaces an existing entry with a reference to another weight when in save mode, or removes it from the container otherwise. [[1]](diffhunk://#diff-beaf819b642665d791baf27f6931969a7ed44776f27939c16660038b2b76e760R111-R121) [[2]](diffhunk://#diff-8f7cf3c97f7f9c93fd52a849ade7a4da4375b05f0debe357a8e52dd2090c8e2cR124-R129) * Updated the call site in `SessionState::PrepackConstantInitializedTensors` to use the new method, ensuring correct handling of prepacked weights during model save operations. **Testing improvements:** * Added new unit tests in `tensorutils_test.cc` to verify the behavior of `DiscardAndReplaceWithReferenceIfSaving` in both save mode and non-save mode, ensuring correct reference replacement and removal of weights as appropriate.
Author
Parents
Loading