Optimize LazyValues and SparseValues with Caching Mechanism #4138
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.
Title: Optimize LazyValues and SparseValues with Caching Mechanism
Description:
This PR introduces a caching mechanism to the
LazyValues
andSparseValues
classes in the ONNX GraphSurgeon module of TensorRT. By caching the loaded tensor values, we can avoid redundant data loading operations, improving performance, especially when dealing with large tensors or when theload
method is called multiple times.Motivation:
The
load
methods in bothLazyValues
andSparseValues
classes currently reload tensor data every time they are called, which can be inefficient. Adding a simple caching mechanism ensures that tensor data is loaded once and reused, reducing computational overhead and improving the efficiency of the code.Changes:
_cached_values
attribute to both classes to store the loaded tensor data.load
methods to check for cached data before loading.Code Changes:
Testing:
load
method returns the correct tensor data on first and subsequent calls.Request for Review:
Please review the proposed changes and let me know if there are any concerns or suggestions for improvement. I'm open to feedback and willing to make adjustments as needed.