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
impl LoadedModel
Sourcepub fn metadata(&self) -> &ModelMetadata
pub fn metadata(&self) -> &ModelMetadata
The format-agnostic hyperparameters and raw metadata bag.
Sourcepub fn format(&self) -> &'static str
pub fn format(&self) -> &'static str
"gguf" or "safetensors" — matches the format field of any
Error::MalformedModel this model’s loader could have produced.
Sourcepub fn tensor_count(&self) -> usize
pub fn tensor_count(&self) -> usize
Number of tensors in the file.
Sourcepub fn tensor_names(&self) -> impl Iterator<Item = &str>
pub fn tensor_names(&self) -> impl Iterator<Item = &str>
Tensor names, in file order.
Sourcepub fn tensor(&self, name: &str) -> Option<&TensorEntry>
pub fn tensor(&self, name: &str) -> Option<&TensorEntry>
Looks up a tensor’s name/dtype/shape by name, without touching its bytes.
Sourcepub fn tensors(&self) -> impl Iterator<Item = &TensorEntry>
pub fn tensors(&self) -> impl Iterator<Item = &TensorEntry>
All tensor entries, in file order.
Sourcepub fn tensor_bytes(&self, name: &str) -> Result<&[u8]>
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
impl Debug for LoadedModel
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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.