mlx.AdapterCodec
Compresses and decompresses a homogeneous-dtype safetensors LoRA adapter.
Usage
mlx.AdapterCodec()Each tensor’s bytes are grouped by byte position within the dtype (byte-shuffle) before zstd compression. Subclasses override DIR, ZST, and CONFIG to point at their shipped package data.
Example
class ShippedCodec(AdapterCodec): … DIR = Path(file).parent … ZST = DIR / “adapters.safetensors.zst” … CONFIG = DIR / “adapter_config.json” ShippedCodec.encode(Path(“trained/adapters.safetensors”))
Methods
| Name | Description |
|---|---|
| decode() |
Decompress ZST and write the restored safetensors adapter to dst.
|
| digest() |
Return the first 16 hex digits of the SHA-256 of the compressed adapter ZST.
|
| dtype() |
Return the safetensors dtype shared by the compressed adapter’s tensors, e.g. "BF16".
|
| encode() |
Compress the safetensors adapter at src into ZST.
|
decode()
Decompress ZST and write the restored safetensors adapter to dst.
Usage
decode(dst)Parameters
dst: Path- Destination path for the safetensors file.
digest()
Return the first 16 hex digits of the SHA-256 of the compressed adapter ZST.
Usage
digest()dtype()
Return the safetensors dtype shared by the compressed adapter’s tensors, e.g. "BF16".
Usage
dtype()encode()
Compress the safetensors adapter at src into ZST.
Usage
encode(src)Byte-shuffles each tensor’s data, then compresses with zstd at COMPRESSION_LEVEL. All tensors must share one dtype drawn from TYPESIZES.
Parameters
src: Path- Path to the adapter’s safetensors file.