model_weights_sweep
The sweep that deletes model weights stores no live process can read.
A store's key lives only in the memory of the process that owns it, so a store whose owner is gone is unreadable bytes. The sweep deletes:
host-*stores whose host process is gone (pid plus create time).host-<own scope>-<key id>stores of this host under a key it has replaced.proc-*stores whose process is gone.- Legacy
bitfount_model_weights_*directories under the cache directory that are older than this boot. Their names carry no pid, so one from this boot is kept: it may belong to a live process.
The pod applies all four rules, at start, on a daemon thread. A background run applies only rule 3, as only the pod knows its host's scope and key id, on a daemon thread it starts at its first model lookup. Names that do not match, symlinks, non-directories and live owners are never touched, and neither is this host's store under its current key. Racing another remover is never a failure: a directory already gone when the sweep looks at it counts as nothing, and one that goes while the sweep is removing it counts as deleted.
Module
Functions
legacy_weights_root
def legacy_weights_root() ‑> pathlib.Path:Return where earlier versions kept their per-process weights directories.
Returns The configured cache directory.
run_model_weights_sweep
def run_model_weights_sweep( root: Path, *, include_host_rules: bool,) ‑> WeightsSweep:Sweep root, report the result, and log it when anything was removed.
With the host rules, this host's scope and key id come from the installed
host cache key, and legacy directories are looked for in the cache
directory. Nothing is swept when settings.model_weights_shared_cache_enabled
is false. Never raises.
Arguments
root: The store root.include_host_rules: Whether to apply the host rules; only the pod does.
Returns What the sweep did; all zeros when it did not run or failed.
start_model_weights_sweep_thread
def start_model_weights_sweep_thread( root: Path | None = None, *, include_host_rules: bool = True,) ‑> threading.Thread | None:Start a daemon thread that sweeps the model weights stores; never raises.
The pod sweeps the resolved store root with every rule. A background run passes its own root with the host rules off, so that a slow sweep never holds up the model load that started it.
Arguments
root: The store root, orNoneforresolve_model_weights_root(), resolved on the thread.include_host_rules: Whether to apply the host rules; only the pod does.
Returns
The started thread, or None when
settings.model_weights_shared_cache_enabled is false (nothing is
touched on disk) or the thread could not be started.
sweep_model_weights
def sweep_model_weights( root: Path, *, include_host_rules: bool, own_scope: str | None = None, own_key_id: str | None = None, legacy_root: Path | None = None,) ‑> WeightsSweep:Delete the model weights stores under root that no live process can read.
Never raises. A root that is not private to this user is not swept at all.
Arguments
root: The store root.include_host_rules: Whether to apply the host rules: dead hosts' stores, this host's replaced keys and legacy directories. Without them only dead processes'proc-*stores are deleted.own_scope: This host's scope. Withown_key_id, enables the replaced-key rule.own_key_id: This host's current key id.legacy_root: Where legacy directories are. With the host rules, enables the legacy rule.
Returns What was deleted, what failed and what was kept.
Classes
WeightsSweep
class WeightsSweep( deleted: int, failed: int, bytes_reclaimed: int, legacy_deleted: int, kept_live: int,):What one sweep did.
Attributes
deleted: Directories deleted, legacy ones included.failed: Directories that could not be deleted.bytes_reclaimed: Bytes freed by the deletions.legacy_deleted: Of those deleted, legacy directories.kept_live: Matching directories kept because their owner may be live.