pub struct MemoizingDynamicInferer { /* private fields */ }Expand description
The dynamic memoizing batch inferer generates execution plans to fit each batch perfectly, achieving near-perfect performance no matter how much data you have - with a hefty up-front cost for each new batch size.
The dynamic batcher has the highest potential throughput when the amount of data isn’t known. By dynamically generating execution plans to fit the exact amount of elements in each batch, it will give tract optimal knowledge for execution each time. The downside of this is that setting up a new plan is fairly costly, so doing this for a batch size that is only seen once will waste memory and compute resources.
While plans are cached; this still means that if your expected batch size is can vary greatly, you’ll end up with noticeable spikes each time a new plan is generated. If you know you’ll have one or a few batch sizes - but not the exact size - this batcher will end up providing good value and inform tuning for a fixed batcher later.
If you know some batch sizes but not all, you can preload the batcher with those plans to avoid having to build them at runtime.
§Pros
- Optimal amortized performance without tuning
- Requires no tuning for good results
§Cons
- For small amounts of data and large models the spikes can offset amortized gains significantly
Implementations§
Source§impl MemoizingDynamicInferer
impl MemoizingDynamicInferer
Sourcepub fn from_model(
model: InferenceModel,
preloaded_sizes: &[usize],
) -> TractResult<Self>
pub fn from_model( model: InferenceModel, preloaded_sizes: &[usize], ) -> TractResult<Self>
Create an inferer for the provided inference model.
§Errors
Will only forward errors from the tract_core::model::Graph optimization and graph building steps.
Sourcepub fn from_typed(
model: TypedModel,
preloaded_sizes: &[usize],
) -> TractResult<Self>
pub fn from_typed( model: TypedModel, preloaded_sizes: &[usize], ) -> TractResult<Self>
Create an inferer for the provided typed model.
§Errors
Will only forward errors from the tract_core::model::Graph optimization and graph building steps.
Trait Implementations§
Source§impl Inferer for MemoizingDynamicInferer
impl Inferer for MemoizingDynamicInferer
Source§fn select_batch_size(&self, max_count: usize) -> usize
fn select_batch_size(&self, max_count: usize) -> usize
Source§fn infer_raw(&self, pad: &mut ScratchPadView<'_>) -> Result<(), Error>
fn infer_raw(&self, pad: &mut ScratchPadView<'_>) -> Result<(), Error>
Source§fn raw_input_shapes(&self) -> &[(String, Vec<usize>)]
fn raw_input_shapes(&self) -> &[(String, Vec<usize>)]
Source§fn raw_output_shapes(&self) -> &[(String, Vec<usize>)]
fn raw_output_shapes(&self) -> &[(String, Vec<usize>)]
fn begin_agent(&self, _id: u64)
fn end_agent(&self, _id: u64)
Source§impl IntoStateful for MemoizingDynamicInferer
impl IntoStateful for MemoizingDynamicInferer
Source§fn into_stateful<WrapStack: InfererWrapper>(
self,
wrapper_stack: WrapStack,
) -> StatefulInferer<WrapStack, Self>
fn into_stateful<WrapStack: InfererWrapper>( self, wrapper_stack: WrapStack, ) -> StatefulInferer<WrapStack, Self>
StatefulInferer by wrapping this concrete
inferer with the given wrapper stack.Auto Trait Implementations§
impl !Freeze for MemoizingDynamicInferer
impl !RefUnwindSafe for MemoizingDynamicInferer
impl Send for MemoizingDynamicInferer
impl Sync for MemoizingDynamicInferer
impl Unpin for MemoizingDynamicInferer
impl !UnwindSafe for MemoizingDynamicInferer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> InfererExt for Twhere
T: Inferer,
impl<T> InfererExt for Twhere
T: Inferer,
Source§fn with_default_epsilon(self, key: &str) -> Result<EpsilonInjector<Self>>
fn with_default_epsilon(self, key: &str) -> Result<EpsilonInjector<Self>>
Source§fn with_epsilon<G: NoiseGenerator>(
self,
generator: G,
key: &str,
) -> Result<EpsilonInjector<Self, G>>
fn with_epsilon<G: NoiseGenerator>( self, generator: G, key: &str, ) -> Result<EpsilonInjector<Self, G>>
Source§fn into_batched(self) -> Batched<Self>
fn into_batched(self) -> Batched<Self>
Source§fn infer(
&mut self,
observations: HashMap<u64, State<'_>>,
) -> Result<HashMap<u64, Response<'_>>, Error>
fn infer( &mut self, observations: HashMap<u64, State<'_>>, ) -> Result<HashMap<u64, Response<'_>>, Error>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more