[API Proposal]: Add TensorPool<T> #115201
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Numerics.Tensors
untriaged
New issue has not been triaged by the area owner
Background and motivation
Due to the nature of the usage of tensors they tend to be really big.
In addition, due to usage patterns creating copies with different operations applied to them, many of which can't be in place, applications using Tensors create many temporaries which are large.
In my ML application, there are fixed number of threads running operations on batches of sentences, so there are a constant number of tensors active at each moment.
I am spending ~1% of my time in the GC, mostly on the large 500KB Tensors I am tokenizing and processing.
I have not measured the overhead of the allocations and GC pauses in my server example, but I assume it will be larger since I do not have all of the requests ahead of time and so have to create more tensors.
Bucketing the tensors by size and pooling instances will reduce the allocations done by the server, reduce the GC time, and increase throughput.
This is almost exactly like
ArrayPool<T>
, and should probably be a wrapper of it.This is something I discussed with @tannergooding but I didn't see any API proposals.
I will state, that like
ArrayPool<T>
, this pool might in some situations be overkill and cause more harm than benefit, as the GC is doing an amazing job.API Proposal
API Usage
Alternative Designs
Risks
No response
The text was updated successfully, but these errors were encountered: