Skip to main content

ModelSource

Trait ModelSource 

Source
pub trait ModelSource: Send + Sync {
    // Required methods
    fn metadata(&self) -> &ModelMetadata;
    fn tensor_names(&self) -> Vec<String>;
    fn open_tensor(&self, name: &str) -> Result<TensorReader<'_>>;
    fn tokenizer(&self) -> Result<TokenizerSpec>;
    fn sampler_defaults(&self) -> Option<SamplerConfig>;
}
Expand description

The central adapter trait: a source of model weights + config, independent of the on-disk format (LiteRT-LM ModelResources equivalent).

Implementations must be cheap to query for metadata and names, and lazy / zero-copy (e.g. mmap-backed) when opening tensors.

Required Methods§

Source

fn metadata(&self) -> &ModelMetadata

Architecture + hyperparameter metadata.

Source

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

Names of all tensors available in this source.

Source

fn open_tensor(&self, name: &str) -> Result<TensorReader<'_>>

Opens a tensor by name, returning a lazy reader over the raw bytes.

Source

fn tokenizer(&self) -> Result<TokenizerSpec>

Tokenizer specification (path to tokenizer.json + added tokens).

Source

fn sampler_defaults(&self) -> Option<SamplerConfig>

Sampler defaults from generation_config.json, if present.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: ModelSource + ?Sized> ModelSource for Box<T>

Blanket forwarding so Box<dyn ModelSource> (returned by open_model_source) can be passed anywhere a &dyn ModelSource goes.

Implementors§