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§
Sourcefn metadata(&self) -> &ModelMetadata
fn metadata(&self) -> &ModelMetadata
Architecture + hyperparameter metadata.
Sourcefn tensor_names(&self) -> Vec<String>
fn tensor_names(&self) -> Vec<String>
Names of all tensors available in this source.
Sourcefn open_tensor(&self, name: &str) -> Result<TensorReader<'_>>
fn open_tensor(&self, name: &str) -> Result<TensorReader<'_>>
Opens a tensor by name, returning a lazy reader over the raw bytes.
Sourcefn tokenizer(&self) -> Result<TokenizerSpec>
fn tokenizer(&self) -> Result<TokenizerSpec>
Tokenizer specification (path to tokenizer.json + added tokens).
Sourcefn sampler_defaults(&self) -> Option<SamplerConfig>
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.
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.