rgpycrumbs.uma._cache¶
On-disk cache of UMA AOTI packages.
Layout under the cache directory:
<stem>.pt2 AOTInductor package, the file rgpot's UmaPot loads
<stem>.pt2.json sidecar: the full key, the package's embedded
metadata, compile time and provenance
.locks/<stem>.lock per-key lock held while the package is prepared
.partial-<stem>-*/ exporter output before it is installed
<stem> comes from AotiKey.stem(). A lookup is one stat and
one sidecar read: no scan of the directory. An entry is installed by
renaming the finished package, then its sidecar, into place, so a
reader never sees a partial .pt2 and a sidecar always names a
complete one.
Attributes¶
Classes¶
One package in the cache and what its sidecar says about it. |
Functions¶
|
|
|
|
|
|
|
Return the sidecar of |
|
Return the cached package for |
|
Metadata torch embedded in the package, as rgpot's loader reads it. |
|
|
|
Fields where a package's embedded metadata disagrees with |
|
Hold the exclusive lock of one cache entry. |
|
Fresh private directory for one exporter run, after dropping stale ones. |
|
|
|
Move a finished package into the cache with its sidecar. |
|
Every |
|
Resolve a path, a file name, a stem, or a unique stem prefix or digest. |
|
Delete one entry under its key lock. False when it is being prepared. |
|
Partial exporter directories whose key is not locked by a live run. |
Module Contents¶
- rgpycrumbs.uma._cache.default_cache_dir() pathlib.Path[source]¶
$RGPYCRUMBS_UMA_CACHE, else$XDG_CACHE_HOME/rgpycrumbs/uma.
- rgpycrumbs.uma._cache.package_path(cache_dir: pathlib.Path, key: rgpycrumbs.uma._key.AotiKey) pathlib.Path[source]¶
- rgpycrumbs.uma._cache.sidecar_path(pt2: pathlib.Path) pathlib.Path[source]¶
- rgpycrumbs.uma._cache.read_sidecar(pt2: pathlib.Path) dict[str, Any] | None[source]¶
Return the sidecar of
pt2, or None when it is absent or unreadable.
- rgpycrumbs.uma._cache.lookup(cache_dir: pathlib.Path, key: rgpycrumbs.uma._key.AotiKey) pathlib.Path | None[source]¶
Return the cached package for
key, or None on a miss.A hit needs the package and a sidecar whose stored key equals
keyfield by field, so a digest collision can never return the wrong package.
- rgpycrumbs.uma._cache.embedded_metadata(pt2: pathlib.Path) dict[str, Any][source]¶
Metadata torch embedded in the package, as rgpot’s loader reads it.
The exporter passes its runtime contract through
aot_inductor.metadata; torch stores it, plus its ownAOTI_*device fields, as string values in<name>/data/aotinductor/<model>/*_metadata.json. This reads the archive directly, so it needs no torch.
- rgpycrumbs.uma._cache.embedded_mismatches(meta: collections.abc.Mapping[str, Any], key: rgpycrumbs.uma._key.AotiKey) list[str][source]¶
Fields where a package’s embedded metadata disagrees with
key.Embedded values are strings (torch stores
str(value)). Every package recordsz_setand the traced input shapes. rgpot’s exporter also embedsnatoms, the per-elementcounts(JSON of atomic number to count), and themodel,torch_versionandfairchem_versionthat compiled it; rgpot’sUmaPotrefuses an input whose counts differ. Those fields are checked when present, so a package from an older exporter still passes on the element set and the traced atom count.
- rgpycrumbs.uma._cache.key_lock(cache_dir: pathlib.Path, stem: str, *, wait: bool = True) collections.abc.Iterator[bool][source]¶
Hold the exclusive lock of one cache entry.
Yields True once the lock is held. With
wait=Falseit yields False instead of blocking when another process holds it. The lock isflockon.locks/<stem>.lock; the kernel drops it when the holder exits, so a killed preparation never leaves the key locked.
- rgpycrumbs.uma._cache.partial_dir(cache_dir: pathlib.Path, stem: str) pathlib.Path[source]¶
Fresh private directory for one exporter run, after dropping stale ones.
Call with the key lock held: any older
.partial-<stem>-*then belongs to a run that died.
- rgpycrumbs.uma._cache._write_json_atomic(path: pathlib.Path, payload: collections.abc.Mapping[str, Any]) None[source]¶
- rgpycrumbs.uma._cache.install(cache_dir: pathlib.Path, key: rgpycrumbs.uma._key.AotiKey, built: pathlib.Path, sidecar: collections.abc.Mapping[str, Any]) pathlib.Path[source]¶
Move a finished package into the cache with its sidecar.
builtmust be on the cache’s filesystem (insidepartial_dir()), so the rename is atomic. The package lands first and the sidecar second;lookup()treats a package without a matching sidecar as a miss.
- class rgpycrumbs.uma._cache.CacheEntry[source]¶
One package in the cache and what its sidecar says about it.
- path: pathlib.Path[source]¶
- property key: rgpycrumbs.uma._key.AotiKey | None[source]¶
- rgpycrumbs.uma._cache.entries(cache_dir: pathlib.Path) list[CacheEntry][source]¶
Every
.pt2in the cache, sorted by name.
- rgpycrumbs.uma._cache.find_entry(cache_dir: pathlib.Path, name: str) CacheEntry[source]¶
Resolve a path, a file name, a stem, or a unique stem prefix or digest.
- rgpycrumbs.uma._cache.remove(cache_dir: pathlib.Path, entry: CacheEntry, *, wait: bool = False) bool[source]¶
Delete one entry under its key lock. False when it is being prepared.
- rgpycrumbs.uma._cache.stale_partials(cache_dir: pathlib.Path) list[pathlib.Path][source]¶
Partial exporter directories whose key is not locked by a live run.