Skip to main content

LoadedModel

Struct LoadedModel 

Source
pub struct LoadedModel { /* private fields */ }
Expand description

A parsed model file: metadata plus a directory of tensors, backed by one open file.

This type intentionally never constructs a Tensor. kopitiam-tensor owns that type and is being developed independently of this crate; a loader that returned tensors would have to depend on (and track the in-flux API of) a crate it has no need to know about. Instead, LoadedModel hands out exactly what a tensor needs to be built — dtype, shape, and raw bytes — and lets whoever owns Tensor do the building.

Implementations§

Source§

impl LoadedModel

Source

pub fn metadata(&self) -> &ModelMetadata

The format-agnostic hyperparameters and raw metadata bag.

Source

pub fn format(&self) -> &'static str

"gguf" or "safetensors" — matches the format field of any Error::MalformedModel this model’s loader could have produced.

Source

pub fn tensor_count(&self) -> usize

Number of tensors in the file.

Source

pub fn tensor_names(&self) -> impl Iterator<Item = &str>

Tensor names, in file order.

Source

pub fn tensor(&self, name: &str) -> Option<&TensorEntry>

Looks up a tensor’s name/dtype/shape by name, without touching its bytes.

Source

pub fn tensors(&self) -> impl Iterator<Item = &TensorEntry>

All tensor entries, in file order.

Source

pub fn tensor_bytes(&self, name: &str) -> Result<&[u8]>

The raw bytes of the named tensor.

This is the loader/tensor boundary: whoever builds a kopitiam_tensor::Tensor from a loaded model calls this to get the bytes, combines them with TensorEntry::dtype and TensorEntry::shape (available via LoadedModel::tensor), and constructs the tensor on their side of the boundary. The bytes returned are exactly the on-disk encoding for dtype — still block-quantized if dtype is quantized, still f16/bf16 if the file stored it that way. This loader does not dequantize or convert anything.

Trait Implementations§

Source§

impl Debug for LoadedModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Deliberately hand-written rather than #[derive]d: the backing storage can be a multi-gigabyte mmap, and a derived Debug would either fail to compile (memmap2::Mmap is not Debug) or, worse, succeed and dump gigabytes of tensor bytes into a log line. This prints only what is useful for diagnostics: the format, tensor count and names, and the metadata.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.