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

CacheEntry

One package in the cache and what its sidecar says about it.

Functions

default_cache_dir(→ pathlib.Path)

$RGPYCRUMBS_UMA_CACHE, else $XDG_CACHE_HOME/rgpycrumbs/uma.

package_path(→ pathlib.Path)

sidecar_path(→ pathlib.Path)

read_sidecar(→ dict[str, Any] | None)

Return the sidecar of pt2, or None when it is absent or unreadable.

lookup(→ pathlib.Path | None)

Return the cached package for key, or None on a miss.

embedded_metadata(→ dict[str, Any])

Metadata torch embedded in the package, as rgpot's loader reads it.

_literal(→ Any)

embedded_mismatches(→ list[str])

Fields where a package's embedded metadata disagrees with key.

key_lock(→ collections.abc.Iterator[bool])

Hold the exclusive lock of one cache entry.

partial_dir(→ pathlib.Path)

Fresh private directory for one exporter run, after dropping stale ones.

_write_json_atomic(→ None)

install(→ pathlib.Path)

Move a finished package into the cache with its sidecar.

entries(→ list[CacheEntry])

Every .pt2 in the cache, sorted by name.

find_entry(→ CacheEntry)

Resolve a path, a file name, a stem, or a unique stem prefix or digest.

remove(→ bool)

Delete one entry under its key lock. False when it is being prepared.

stale_partials(→ list[pathlib.Path])

Partial exporter directories whose key is not locked by a live run.

Module Contents

rgpycrumbs.uma._cache.SIDECAR_SUFFIX = '.pt2.json'[source]
rgpycrumbs.uma._cache._LOCK_DIR = '.locks'[source]
rgpycrumbs.uma._cache._PARTIAL_PREFIX = '.partial-'[source]
rgpycrumbs.uma._cache._EMBEDDED_PATTERN = '*/data/aotinductor/*/*_metadata.json'[source]
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 key field 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 own AOTI_* 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._literal(text: Any) → Any[source]
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 records z_set and the traced input shapes. rgpot’s exporter also embeds natoms, the per-element counts (JSON of atomic number to count), and the model, torch_version and fairchem_version that compiled it; rgpot’s UmaPot refuses 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=False it yields False instead of blocking when another process holds it. The lock is flock on .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.

built must be on the cache’s filesystem (inside partial_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]
sidecar: dict[str, Any] | None[source]
property key: rgpycrumbs.uma._key.AotiKey | None[source]
property stem: str[source]
property size: int[source]
rgpycrumbs.uma._cache.entries(cache_dir: pathlib.Path) → list[CacheEntry][source]

Every .pt2 in 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.