mixle.inference.production.registry module¶
A versioned model registry: store fitted models + their provenance, list versions, promote/swap.
A filesystem-backed store so a production system can register every fitted model (with its
Header), list and load any version, and promote a chosen version
to an alias (e.g. "production") – the swap point a serving layer reads from. Models serialize through
mixle.utils.serialization (the safe registry-keyed JSON); headers are plain JSON dicts.
- class Registry(root)[source]
Bases:
objectA directory of named models, each with numbered versions and movable aliases.
- Parameters:
root (str)
- versions(name)[source]
Version ids for
namein registration order (v1,v2, …).
- register(model, name, *, header=None, metadata=None)[source]
Store
modelundernameas a new version; return its version id.headerdefaults tomodel.headerif present. The model is serialized with the safe mixle registry; the header (aHeaderor dict) andmetadataare stored alongside.
- checkpointer(name, *, every=1)[source]
Return an
optimize(on_step=...)callback that snapshots the model undernameeveryeveryiterations (recording the iteration + log-density in the version metadata).Each checkpoint records its model
model_hashand the previous checkpoint’sparent_hash, so the saved snapshots form a verifiable chain (seeverify_chain()). Resume an interrupted run from the latest checkpoint:reg = Registry("ckpts") optimize(data, est, on_step=reg.checkpointer("run", every=5)) model, _ = reg.get("run") # latest checkpoint optimize(data, est, prev_estimate=model) # continue training
- get(name, version='latest')[source]
Load
(model, header)for a version ("latest"= highest-numbered).
- header(name, version='latest')[source]
Just the provenance header of a version (no model deserialization).
- metadata(name, version='latest')[source]
Just the
metadataof a version (no model deserialization) – e.g. a checkpoint’s iteration.
- promote(name, version, alias='production')[source]
Point
alias(e.g."production") atversion– the atomic model swap.
- current(name, alias='production')[source]
Load the model an
aliaspoints at (falls back tolatestif the alias is unset).
- verify_chain(name)[source]
Verify the persisted checkpoint lineage for
name(seecheckpointer()).For each version carrying a
model_hash, checks that itsparent_hashmatches the previous such version’s hash and that re-hashing the loaded model reproduces the stored hash (catching corruption or tampering). Returns True when every link holds, or vacuously when no version carries lineage metadata.