Struct llama_core::graph::Graph
source · pub struct Graph {
pub created: Duration,
pub metadata: Metadata,
/* private fields */
}
Expand description
Wrapper of the wasmedge_wasi_nn::Graph
struct
Fields§
§created: Duration
§metadata: Metadata
Implementations§
source§impl Graph
impl Graph
sourcepub fn new(metadata: &Metadata) -> Result<Self, LlamaCoreError>
pub fn new(metadata: &Metadata) -> Result<Self, LlamaCoreError>
Create a new computation graph from the given metadata.
sourcepub fn prompt_template(&self) -> PromptTemplateType
pub fn prompt_template(&self) -> PromptTemplateType
Get the prompt template type
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 Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnwindSafe for Graph
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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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