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
impl GgufFile
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self, GgufError>
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());Sourcepub fn save(&self, path: impl AsRef<Path>) -> Result<(), GgufError>
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")?;Sourcepub fn array_keys(&self) -> Result<Vec<String>, GgufError>
pub fn array_keys(&self) -> Result<Vec<String>, GgufError>
Returns array keys in deterministic lexical order.
Sourcepub fn get_array(&self, key: &str) -> Result<Option<Array>, GgufError>
pub fn get_array(&self, key: &str) -> Result<Option<Array>, GgufError>
Returns a new independently owned MLX array handle for key.
Sourcepub fn arrays(&self) -> Result<HashMap<String, Array>, GgufError>
pub fn arrays(&self) -> Result<HashMap<String, Array>, GgufError>
Copies the array namespace into independently owned MLX handles.
Sourcepub fn insert_array(
&mut self,
key: impl AsRef<str>,
value: &Array,
) -> Result<(), GgufError>
pub fn insert_array( &mut self, key: impl AsRef<str>, value: &Array, ) -> Result<(), GgufError>
Inserts an array, rejecting duplicate keys and unsupported writer dtypes.
Sourcepub fn metadata_kind(
&self,
key: &str,
) -> Result<Option<GgufMetadataKind>, GgufError>
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.
Sourcepub fn get_metadata(
&self,
key: &str,
) -> Result<Option<GgufMetadataValue>, GgufError>
pub fn get_metadata( &self, key: &str, ) -> Result<Option<GgufMetadataValue>, GgufError>
Returns a metadata value, or None when the key is absent.
Sourcepub fn get_metadata_array(&self, key: &str) -> Result<Option<Array>, GgufError>
pub fn get_metadata_array(&self, key: &str) -> Result<Option<Array>, GgufError>
Returns array metadata, or None when the key is absent.
Sourcepub fn get_metadata_string(
&self,
key: &str,
) -> Result<Option<String>, GgufError>
pub fn get_metadata_string( &self, key: &str, ) -> Result<Option<String>, GgufError>
Returns string metadata, or None when the key is absent.
Sourcepub fn get_metadata_strings(
&self,
key: &str,
) -> Result<Option<Vec<String>>, GgufError>
pub fn get_metadata_strings( &self, key: &str, ) -> Result<Option<Vec<String>>, GgufError>
Returns string-list metadata, or None when the key is absent.
Sourcepub fn insert_metadata<V>(
&mut self,
key: impl AsRef<str>,
value: V,
) -> Result<(), GgufError>where
V: Into<GgufMetadataValue>,
pub fn insert_metadata<V>(
&mut self,
key: impl AsRef<str>,
value: V,
) -> Result<(), GgufError>where
V: Into<GgufMetadataValue>,
Inserts metadata, rejecting duplicate keys and unsupported metadata arrays.
Trait Implementations§
Auto Trait Implementations§
impl !Send for GgufFile
impl !Sync for GgufFile
impl Freeze for GgufFile
impl RefUnwindSafe for GgufFile
impl Unpin for GgufFile
impl UnsafeUnpin for GgufFile
impl UnwindSafe for GgufFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
Source§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
Option.