Key EPContext cache by compile identity - #1295
Key EPContext cache by compile identity#1295Qiong Wu (qiowu) (DingmaomaoBJTU) wants to merge 7 commits into
Conversation
xieofxie
left a comment
There was a problem hiding this comment.
The strict compile identity and per-identity locking solve a real correctness problem. However, the PR currently grows that fix into an unbounded immutable-generation/content-addressed publication system. I think the core direction is right, but the storage lifecycle should be bounded and the identity contract completed before taking on this maintenance surface.
xieofxie
left a comment
There was a problem hiding this comment.
The follow-up fixes cleanup after compile_to_file() failure and adds coverage for absolute file-backed options. Retention is still incomplete, though, and the new pruning path introduces a race with runtime session construction. I would not consider the cache lifecycle resolved until these cases are addressed.
xieofxie
left a comment
There was a problem hiding this comment.
The cache-hit lease now covers InferenceSession construction, which resolves the original prune-before-open race. However, the markerless lifecycle currently deletes the active model path immediately, and the new canonicalization/pruning logic has correctness gaps. These should be fixed before considering the lifecycle complete.
xieofxie
left a comment
There was a problem hiding this comment.
Quick re-review: no new high-confidence findings in this delta. The markerless EPContext is now retained through perf() reopen and finalized before reset, unpublished generations are cleaned on final-identity failure, pruning revalidates the marker while holding its lease, and file canonicalization is limited to explicitly declared provider-option keys. The previously raised lifecycle concerns appear resolved.
xieofxie
left a comment
There was a problem hiding this comment.
The previously raised cache lifecycle, pruning, markerless artifact, and file-backed option concerns are resolved. No remaining high-confidence blockers from my review.
Summary
WinMLSessionmtime-only EPContext reuse with a strict compile identityProblem
WinMLSession.compile()previously reused<model>_<device>_ctx.onnxwhenever it was newer than the source ONNX. The cache key omitted the EP/source/version, hardware, provider/session options, embed mode, ORT version, external-data sidecars, and context binary integrity. Different configurations could therefore reuse or overwrite one shared EPContext artifact.Behavior
SessionOptionsand uncertain source identity use unique non-cacheable generationsValidation
Using cached EPContextmodel_qnn_ctx.onnxreferencesmodel_qnn_ctx_qnn.<sha256>.binmodel_qnn_ctx_qnn.binalias remains present with matching sizeuv lock --offline --checkcould not resolve uncached Linuxonnxmetadata on this ARM64 host. The lockfile TOML parses and the added unit test verifies that every direct project dependency is represented in both the editable package dependencies andrequires-distmetadata; CI runs on the supported AMD64 environment.