Skip to content

feat(perf): cache per-module builds and honor --rebuild/--ignore-cache#1004

Open
xieofxie wants to merge 1 commit into
mainfrom
hualxie/module_use_cache
Open

feat(perf): cache per-module builds and honor --rebuild/--ignore-cache#1004
xieofxie wants to merge 1 commit into
mainfrom
hualxie/module_use_cache

Conversation

@xieofxie

Copy link
Copy Markdown
Contributor

Summary

winml perf --module built every submodule into a throwaway tempfile.TemporaryDirectory with no cache_key and no rebuild flag, so per-module artifacts were rebuilt on every run and --rebuild / --ignore-cache were silently ignored. The single-model path already honored these flags via WinMLAutoModelauto.py.

This mirrors auto.py's cache logic in _perf_modules:

  • Default: each submodule builds into the model's persistent cache dir (~/.cache/winml/artifacts/<model_slug>/) and is reused on the next run.
  • --rebuild: reuses the cache dir but overwrites artifacts.
  • --ignore-cache: falls back to a temp dir + forced rebuild (prior behavior, now opt-in).

Why per-module caching is collision-free

Each submodule config carries a unique loader.module_path (plus its traced I/O shapes). cfg.generate_cache_key() hashes the full config, so every instance gets a distinct key — even shape-identical siblings — and build_hf_model's cache_key filename prefixing keeps each instance's model.onnx separate within one shared model dir.

Behavior change worth noting

Per-module artifacts now persist by default (more disk use), which is the intended consequence of matching the single-model / auto.py behavior.

Tests

Added TestPerfModuleCache (default → persistent dir + rebuild=False; --rebuildrebuild=True in cache dir; --ignore-cache → temp dir + rebuild=True). Full tests/unit/commands/test_perf_module.py: 15 passed.

Closes #918

🤖 Generated with Claude Code

Per-module benchmarking built every submodule into a throwaway
tempfile.TemporaryDirectory with no cache_key and no rebuild flag, so
artifacts were rebuilt on every run and --rebuild/--ignore-cache were
silently ignored. The single-model path already honored these flags via
WinMLAutoModel.

Mirror auto.py's cache logic in _perf_modules: build into the model's
persistent cache dir keyed per submodule (cfg.generate_cache_key() folds
in loader.module_path and traced I/O shapes, so sibling instances get
distinct keys and coexist in one model dir), and forward rebuild. With
--ignore-cache, fall back to a temp dir + forced rebuild.

Closes #918
@xieofxie xieofxie requested a review from a team as a code owner June 30, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: perf --module should also use cache folder instead of temp dir

1 participant