pub struct FixedBatchInferer { /* private fields */ }Expand description
A reliable batched inferer that is a good fit if you know how much data you’ll have and want stable performance.
As an added bonus, it’ll subdivide your data into minibatches if the batching doesn’t fit perfectly. To make this work, it’ll add a single-element mode as well to ensure all data is consumed - such as if you feed it 9 elements with a configured batch size of 8.
You can configure a wide number of different batch sizes, and the largest one will be used. Note that the overhead for execution still is fairly large, but this helps amortize some of that cost away. For example; if you use a setup of [1, 2, 4, 8] as your supported batch sizes a batch of 15 elements would run each plan once.
§Pros
- Good and predictable performance if you know amount of data
- Flexible if you sometimes get extra data to deal with
§Cons
- Mini-batches add overhead
- Diminishing returns on each supported batch size.
Implementations§
Source§impl FixedBatchInferer
impl FixedBatchInferer
Sourcepub fn from_model(model: InferenceModel, sizes: &[usize]) -> TractResult<Self>
pub fn from_model(model: InferenceModel, 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, sizes: &[usize]) -> TractResult<Self>
pub fn from_typed(model: TypedModel, 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 FixedBatchInferer
impl Inferer for FixedBatchInferer
Source§fn infer_raw(&self, batch: &mut ScratchPadView<'_>) -> Result<(), Error>
fn infer_raw(&self, batch: &mut ScratchPadView<'_>) -> Result<(), Error>
Source§fn select_batch_size(&self, max_count: usize) -> usize
fn select_batch_size(&self, max_count: usize) -> usize
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 FixedBatchInferer
impl IntoStateful for FixedBatchInferer
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 FixedBatchInferer
impl !RefUnwindSafe for FixedBatchInferer
impl Send for FixedBatchInferer
impl Sync for FixedBatchInferer
impl Unpin for FixedBatchInferer
impl !UnwindSafe for FixedBatchInferer
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