Skip to main content

GgufFile

Struct GgufFile 

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

A live two-namespace GGUF container.

Array keys can be enumerated, while the current C ABI does not expose metadata-key enumeration. The handle is intentionally non-cloneable and thread-affine.

use mlx_rs::io::GgufFile;

let file = GgufFile::new()?;
assert!(file.array_keys()?.is_empty());

Implementations§

Source§

impl GgufFile

Source

pub fn new() -> Result<Self, GgufError>

Creates an empty GGUF container.

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self, GgufError>

Loads a GGUF file on the thread-local stream, falling back to CPU.

use mlx_rs::io::GgufFile;

let file = GgufFile::load("model.gguf")?;
println!("{} tensors", file.array_keys()?.len());
Source

pub fn save(&self, path: impl AsRef<Path>) -> Result<(), GgufError>

Saves the container to a .gguf path.

Saving evaluates contained arrays and may allocate row-major materializations. It uses the GGUF writer directly and does not consult the ambient Rust stream.

use mlx_rs::{io::GgufFile, Array};

let mut file = GgufFile::new()?;
file.insert_array("weight", &Array::from_f32(1.0))?;
file.save("model.gguf")?;
Source

pub fn array_keys(&self) -> Result<Vec<String>, GgufError>

Returns array keys in deterministic lexical order.

Source

pub fn get_array(&self, key: &str) -> Result<Option<Array>, GgufError>

Returns a new independently owned MLX array handle for key.

Source

pub fn arrays(&self) -> Result<HashMap<String, Array>, GgufError>

Copies the array namespace into independently owned MLX handles.

Source

pub fn insert_array( &mut self, key: impl AsRef<str>, value: &Array, ) -> Result<(), GgufError>

Inserts an array, rejecting duplicate keys and unsupported writer dtypes.

Source

pub fn metadata_kind( &self, key: &str, ) -> Result<Option<GgufMetadataKind>, GgufError>

Returns the kind of a metadata value, or None when the key is absent.

Source

pub fn get_metadata( &self, key: &str, ) -> Result<Option<GgufMetadataValue>, GgufError>

Returns a metadata value, or None when the key is absent.

Source

pub fn get_metadata_array(&self, key: &str) -> Result<Option<Array>, GgufError>

Returns array metadata, or None when the key is absent.

Source

pub fn get_metadata_string( &self, key: &str, ) -> Result<Option<String>, GgufError>

Returns string metadata, or None when the key is absent.

Source

pub fn get_metadata_strings( &self, key: &str, ) -> Result<Option<Vec<String>>, GgufError>

Returns string-list metadata, or None when the key is absent.

Source

pub fn insert_metadata<V>( &mut self, key: impl AsRef<str>, value: V, ) -> Result<(), GgufError>

Inserts metadata, rejecting duplicate keys and unsupported metadata arrays.

Trait Implementations§

Source§

impl Debug for GgufFile

Source§

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

Formats the value using the given formatter. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Convert into an Option.
Source§

impl<T> IntoStrideBy for T

Source§

fn stride_by(self, stride: i32) -> StrideBy<T>

Create a stride indexing operation.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.