pub struct Graph<M: BaseMetadata + Serialize + Clone + Default> {
pub created: Duration,
pub metadata: M,
/* private fields */
}
Expand description
Wrapper of the wasmedge_wasi_nn::Graph
struct
Fields§
§created: Duration
§metadata: M
Implementations§
Source§impl<M: BaseMetadata + Serialize + Clone + Default> Graph<M>
impl<M: BaseMetadata + Serialize + Clone + Default> Graph<M>
Sourcepub fn new(metadata: M) -> Result<Self, LlamaCoreError>
pub fn new(metadata: M) -> Result<Self, LlamaCoreError>
Create a new computation graph from the given metadata.
Sourcepub fn update_metadata(&mut self) -> Result<(), LlamaCoreError>
pub fn update_metadata(&mut self) -> Result<(), LlamaCoreError>
Update metadata
Sourcepub fn set_input<T: Sized>(
&mut self,
index: usize,
tensor_type: TensorType,
dimensions: &[usize],
data: impl AsRef<[T]>,
) -> Result<(), WasiNnError>
pub fn set_input<T: Sized>( &mut self, index: usize, tensor_type: TensorType, dimensions: &[usize], data: impl AsRef<[T]>, ) -> Result<(), WasiNnError>
Sourcepub fn compute(&mut self) -> Result<(), WasiNnError>
pub fn compute(&mut self) -> Result<(), WasiNnError>
Compute the inference on the given inputs.
Sourcepub fn compute_single(&mut self) -> Result<(), WasiNnError>
pub fn compute_single(&mut self) -> Result<(), WasiNnError>
Compute the inference on the given inputs.
Note that this method is used for the stream mode. It generates one token at a time.
Sourcepub fn get_output<T: Sized>(
&self,
index: usize,
out_buffer: &mut [T],
) -> Result<usize, WasiNnError>
pub fn get_output<T: Sized>( &self, index: usize, out_buffer: &mut [T], ) -> Result<usize, WasiNnError>
Copy output tensor to out_buffer, return the output’s size in bytes.
Sourcepub fn get_output_single<T: Sized>(
&self,
index: usize,
out_buffer: &mut [T],
) -> Result<usize, WasiNnError>
pub fn get_output_single<T: Sized>( &self, index: usize, out_buffer: &mut [T], ) -> Result<usize, WasiNnError>
Copy output tensor to out_buffer, return the output’s size in bytes.
Note that this method is used for the stream mode. It returns one token at a time.
Sourcepub fn finish_single(&mut self) -> Result<(), WasiNnError>
pub fn finish_single(&mut self) -> Result<(), WasiNnError>
Clear the computation context.
Note that this method is used for the stream mode. It clears the context after the stream mode is finished.
Trait Implementations§
Auto Trait Implementations§
impl<M> Freeze for Graph<M>where
M: Freeze,
impl<M> RefUnwindSafe for Graph<M>where
M: RefUnwindSafe,
impl<M> Send for Graph<M>where
M: Send,
impl<M> Sync for Graph<M>where
M: Sync,
impl<M> Unpin for Graph<M>where
M: Unpin,
impl<M> UnwindSafe for Graph<M>where
M: UnwindSafe,
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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