veloxquant_mlx.artifacts package¶
Concrete ArtifactStore backends for precomputed quantization artifacts.
Groups the implementations of core.abstractions.ArtifactStore (rotation
matrices, codebooks, JL sketch matrices): NpyArtifactStore persists
them to .npy files on disk, and InMemoryArtifactStore keeps them
in plain dicts for tests and other disk-free use cases.
- class veloxquant_mlx.artifacts.InMemoryArtifactStore[source]
Bases:
ArtifactStoreIn-memory artifact store for testing — performs no disk I/O.
All artifacts are stored in plain Python dicts keyed by descriptor tuples. Rotation and JL matrices are stored as float16 and codebooks as float32 numpy arrays, wrapped in MLX on load.
- Parameters:
None.
- load_rotation_matrix(d, seed)[source]
Look up a rotation matrix by
(d, seed); raises if never saved this run.
- save_rotation_matrix(Pi, d, seed)[source]
Store
Pi(cast to fp16) under(d, seed), silently overwriting any prior entry.
- load_codebook(distribution, b, d)[source]
Look up a codebook by
(distribution, b, d); raises if never saved this run.
- save_codebook(cb, distribution, b, d)[source]
Store
cb(as fp32) under(distribution, b, d), silently overwriting any prior entry.Kept in fp32 so a warm load encodes identically to the cold run (#659).
- load_jl_matrix(d, m, seed)[source]
Look up a JL matrix by
(d, m, seed); raises if never saved this run.
- save_jl_matrix(S, d, m, seed)[source]
Store
S(cast to fp16) under(d, m, seed), silently overwriting any prior entry.
- exists(artifact_type, **kwargs)[source]
Check whether a rotation/codebook/JL artifact is already stored.
artifact_typemust be one of"rotation","codebook", or"jl";kwargsmust supply that type’s identifying parameters (e.g.d=/seed=for a rotation). ReturnsFalsefor an unrecognizedartifact_typerather than raising.
- class veloxquant_mlx.artifacts.NpyArtifactStore(root_dir)[source]
Bases:
ArtifactStoreArtifact store that reads and writes
.npyfiles from a local directory.- File naming conventions:
rotation_d{d}_seed{seed}.npy codebook_{distribution}_b{b}_d{d}.npy jl_d{d}_m{m}_seed{seed}.npy
- Parameters:
root_dir (
str|Path) – Path to the directory where artifacts are stored. Created automatically on first save if absent.
- load_rotation_matrix(d, seed)[source]
Load the rotation matrix at
rotation_d{d}_seed{seed}.npy, raising if absent.
- save_rotation_matrix(Pi, d, seed)[source]
Atomically write
Pi(cast to fp16) torotation_d{d}_seed{seed}.npy, silently overwriting any prior file.
- load_codebook(distribution, b, d)[source]
Load the codebook at
codebook_{distribution}_b{b}_d{d}.npy, raising if absent.
- save_codebook(cb, distribution, b, d)[source]
Atomically write
cb(as fp32) tocodebook_{distribution}_b{b}_d{d}.npy, silently overwriting any prior file.Kept in fp32: fp16 rounding of tightly spaced centroids changes the nearest-centroid choice, so a warm store would encode differently from the cold run that computed the codebook (#659).
- load_jl_matrix(d, m, seed)[source]
Load the JL matrix at
jl_d{d}_m{m}_seed{seed}.npy, raising if absent.
- save_jl_matrix(S, d, m, seed)[source]
Atomically write
S(cast to fp16) tojl_d{d}_m{m}_seed{seed}.npy, silently overwriting any prior file.
- exists(artifact_type, **kwargs)[source]
Check whether a rotation/codebook/JL artifact file is already on disk.
artifact_typemust be one of"rotation","codebook", or"jl";kwargsmust supply that type’s identifying parameters (e.g.d=/seed=for a rotation). ReturnsFalsefor an unrecognizedartifact_typerather than raising.