mirror of
https://github.com/wassname/minicache.git
synced 2026-06-27 16:30:51 +08:00
c42bea207a2d8f871b6eab72ab96ea403cdb57ff
Removes the required positional `kind` and `cachedir` from the decorator,
drops the `state_fn` concept entirely. New defaults: kind from fn.__name__,
cachedir from DEFAULT_CACHEDIR = Path("cache").
Primary usage is now just:
@cached(exclude=["model", "tok"])
def run_eval(model, tok, *, model_id, name, batch_size):
...
Explicit-key form unchanged:
cache_call("eval", "qwen-27b|nf4|classic|bs=16", lambda: ...)
Version bumped to 0.2.0.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
minicache — tiny disk cache for ML / research code.
This wraps function calls and stores returns on disk (gzip + cloudpickle). Solves
the four pain points that stdlib functools.lru_cache + pickle and existing
function-cache libraries (anycache, cachier) hit on ML code:
- Loaded models can't be hashed. So we use a arg blacklist (
exclude=["model", "tok"]). Here, excluded args pass through to the function but never enter the cache key. - Tensors / pandas / closures can't be picked* → we use cloudpickle which extends to many more objects.
- Pickle files grow large → gzip on disk save 20-50%
Quick use
Install
uv add git+https://github.com/wassname/minicache.git
from minicache import cached, cache_call
# 1. Decorator: hashes (state, included args). Excludes drop out of key.
@cached("eval", cachedir="out/cache",
state_fn=lambda *, model_id, **_: f"{model_id}|nf4|r00+r02",
exclude=["model", "tok"])
def run_eval(model, tok, *, model_id, name, batch_size):
return tinymfv_evaluate(model, tok, name=name, batch_size=batch_size)
report = run_eval(model, tok, model_id="qwen-27b", name="classic", batch_size=16)
# 2. Explicit key: no introspection, you compose the key
key = "qwen-27b|nf4|r00+r02|eval|classic|bs=16"
report = cache_call("eval", key, lambda: tinymfv_evaluate(model, tok, ...),
cachedir="out/cache")
See also
Description
Languages
Python
100%