Skip to main content

Executor

Struct Executor 

Source
pub struct Executor<B: Backend> { /* private fields */ }
Expand description

A graph, its weights on one backend, and a plan per bucket built on first use. More graphs can share the weights, see Executor::add_graph.

Implementations§

Source§

impl<B: Backend> Executor<B>

Source

pub fn new( backend: B, tensors: &[HostTensor<'_>], graph: Graph, buckets: &Buckets, stage: &str, vocab: usize, types: usize, ) -> Result<Self>

Uploads the weights. vocab and types bound the token ids and question types a batch may hold, and stage names the buckets to use from buckets.

§Errors

From Backend::upload.

Source

pub fn add_graph( &mut self, graph: Graph, buckets: &Buckets, stage: &str, ) -> usize

Adds a graph that runs on the weights already uploaded, in the buckets of stage, and returns the lane to pass to Executor::run_lane. The graph may only read weights the first graph reads, the way the first graph reads them, such as the encoder alone.

Source

pub fn backend(&self) -> &B

The backend.

Source

pub fn warm(&self) -> impl Iterator<Item = Bucket> + '_

The buckets with a plan built.

Source

pub fn memory(&self) -> (usize, usize)

Bytes on the device: the weights, and the plans built so far.

Source

pub fn plans_mut(&mut self) -> impl Iterator<Item = &mut B::Plan> + '_

The plans built so far, to inspect or profile.

Source

pub fn prepare(&mut self, bucket: Bucket) -> Result<usize>

Builds the plan for bucket now rather than on first use.

§Errors

From Backend::lower.

Source

pub fn run(&mut self, batch: &Batch<'_>, out: &mut Outputs) -> Result<Bucket>

Runs a batch in the smallest bucket that holds it. Once that bucket’s plan exists and out has grown to the batch size, this allocates nothing.

§Errors

Error::Batch for an inconsistent batch, Error::NoBucket for one too big, and anything the backend reports.

Source

pub fn run_lane( &mut self, lane: usize, batch: &Batch<'_>, out: &mut Outputs, ) -> Result<Bucket>

Executor::run on the graph lane from Executor::add_graph, 0 being the first.

§Errors

As Executor::run.

Trait Implementations§

Source§

impl<B: Debug + Backend> Debug for Executor<B>
where B::Weights: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for Executor<B>
where B: Freeze, <B as Backend>::Weights: Freeze, Vec<Lane<B>>: Freeze,

§

impl<B> RefUnwindSafe for Executor<B>

§

impl<B> Send for Executor<B>
where <B as Backend>::Weights: Send, Vec<Lane<B>>: Send,

§

impl<B> Sync for Executor<B>
where <B as Backend>::Weights: Sync, Vec<Lane<B>>: Sync,

§

impl<B> Unpin for Executor<B>
where B: Unpin, <B as Backend>::Weights: Unpin, Vec<Lane<B>>: Unpin,

§

impl<B> UnsafeUnpin for Executor<B>
where B: UnsafeUnpin, <B as Backend>::Weights: UnsafeUnpin, Vec<Lane<B>>: UnsafeUnpin,

§

impl<B> UnwindSafe for Executor<B>
where B: UnwindSafe, <B as Backend>::Weights: UnwindSafe, Vec<Lane<B>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.