MLX supports multiple array serialization formats for saving and loading arrays.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ml-explore/mlx/llms.txt
Use this file to discover all available pages before exploring further.
Serialization Formats
| Format | Extension | Function | Notes |
|---|---|---|---|
| NumPy | .npy | mx.save() | Single arrays only |
| NumPy archive | .npz | mx.savez() and mx.savez_compressed() | Multiple arrays |
| Safetensors | .safetensors | mx.save_safetensors() | Multiple arrays |
| GGUF | .gguf | mx.save_gguf() | Multiple arrays |
mx.load() function will load any of the supported serialization formats. It determines the format from the extensions. The output of mx.load() depends on the format.
Saving Single Arrays
Here’s an example of saving a single array to a file:a will be saved in the file array.npy (notice the extension is automatically added). Including the extension is optional; if it is missing it will be added.
Saving Multiple Arrays
Here’s an example of saving several arrays to a single file:numpy.savez, the MLX savez() takes arrays as arguments. If the keywords are missing, then default names will be provided.
Loading Multiple Arrays
This can be loaded with:mx.load() returns a dictionary of names to arrays.
Safetensors and GGUF
The functionsmx.save_safetensors() and mx.save_gguf() are similar to mx.savez(), but they take as input a dict of string names to arrays: