Skip to main content

WeightSource

Trait WeightSource 

Source
pub trait WeightSource: Send + Sync {
    // Required methods
    fn tensor_names(&self) -> Vec<String>;
    fn load_tensor(&mut self, name: &str) -> ModelResult<Vec<f32>>;
    fn contains(&self, name: &str) -> bool;
    fn total_bytes_estimate(&self) -> u64;
}
Expand description

A streaming/incremental source of model weight tensors.

Implementations must be Send + Sync so that they can be passed across thread boundaries when used with multi-threaded inference runtimes.

The primary operations are:

Required Methods§

Source

fn tensor_names(&self) -> Vec<String>

Return the names of all tensors available in this source.

Source

fn load_tensor(&mut self, name: &str) -> ModelResult<Vec<f32>>

Load and dequantize the tensor identified by name, returning a flat Vec<f32>.

§Errors

Returns ModelError if the tensor is not found, the file cannot be read, or dequantization fails.

Source

fn contains(&self, name: &str) -> bool

Return true if the source contains a tensor with the given name.

Source

fn total_bytes_estimate(&self) -> u64

Return a rough estimate of the total number of bytes occupied by all tensor data in the underlying file (used for progress reporting).

Implementors§