Add getDirty to TensorCache avoiding clearing tensors when not needed #187
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.
The global static TensorCache has a get method, which attempts to return a tensor of same type and shape from the cache. Tensors are always cleared when they are released to the cache. However there are many cases, maybe most of them where we do not need to clear the tensor as the next user will typically overwrite it entirely:
{noformat}
Response{responseText='The best thing to do is to look for the plant that best suits your needs. Avocados are a type of fruit that are grown in the Americas, specifically in Mexico, Central America, and South America. They are known for their creamy, buttery texture and rich, nutty flavor.', responseTextWithSpecialTokens='The best thing to do is to look for the plant that best suits your needs. Avocados are a type of fruit that are grown in the Americas, specifically in Mexico, Central America, and South America. They are known for their creamy, buttery texture and rich, nutty flavor.', finishReason=STOP_TOKEN, promptTokens=65, generatedTokens=64, promptTimeMs=10018, generateTimeMs=10779}
tensorcache.dirtyget 130
tensorcache.get 111609
tensorcache.get.hit 111582
tensorcache.getdirty.hit 126
{noformat}
I only put the method in place in a couple of places as I dont have enough knoweldge to put it in place everywhere:
edwardcapriolo/deliverance#4