fix: use resolved path and cache_key in WinMLAutoModel.from_onnx#856
Open
chinazhangchao wants to merge 5 commits into
Open
fix: use resolved path and cache_key in WinMLAutoModel.from_onnx#856chinazhangchao wants to merge 5 commits into
chinazhangchao wants to merge 5 commits into
Conversation
- from_onnx: replace onnx_path.stem with str(onnx_path.resolve()) for get_model_dir so two ONNX files with the same filename but different paths get distinct cache directories - from_onnx: compute cache_key = get_cache_key(task_abbrev, config hash) (mirrors from_pretrained) and pass it to build_onnx_model so different build configs produce different artifact filenames in the same dir - build_onnx_model: add cache_key param and _name() helper (same pattern as build_hf_model) so all artifact paths are optionally prefixed; rebuild cleanup uses cache_key-scoped glob to avoid removing unrelated artifacts from other config variants Fixes #827
…inazhangchao/fix-winmlautomodel-cache-dir-name
xieofxie
reviewed
Jun 10, 2026
xieofxie
reviewed
Jun 10, 2026
xieofxie
reviewed
Jun 11, 2026
| def get_onnx_model_hash(model_path: str | Path) -> str: | ||
| """Compute a content hash for an ONNX model and referenced external data.""" | ||
| model_path = Path(model_path).resolve() | ||
| hash_obj = hashlib.sha256() |
Contributor
There was a problem hiding this comment.
how about use hash path + size + mtime? weight could be big
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #827
Problem
Two cache-naming bugs in
WinMLAutoModel.from_onnxintroduced after PR #659:Cache directory collision –
from_onnxcalledget_model_dir(onnx_path.stem, ...), so two ONNX files with the same filename (e.g.model.onnx) from different directories would map to the same cache directory and overwrite each other's build outputs.Config change not reflected in cache –
build_onnx_modelhad nocache_keysupport (unlikebuild_hf_model), so different build configs for the same ONNX file would collide on the samemodel.onnxartifact path.Fix
src/winml/modelkit/models/auto.py—from_onnxget_model_dir(onnx_path.stem, ...)withget_model_dir(str(onnx_path.resolve()), ...)so the cache dir is unique per absolute file path.cache_key = get_cache_key(task_abbrev, config.generate_cache_key())(mirrorsfrom_pretrained) and pass it tobuild_onnx_model.src/winml/modelkit/build/onnx.py—build_onnx_modelcache_key: str | None = Noneparameter._name()helper (same pattern asbuild_hf_model) so all artifact paths are optionally prefixed — enabling multiple config variants to coexist in one directory.Tests
test_auto_onnx.py: resolved path used for model dir, same-stem/different-path collision prevention, cache_key passed through.test_onnx.py:cache_key=Nonebackward compat, prefixed final artifact, prefixed config path, reuse with prefixed path, unrelated artifact preservation on rebuild.