fix: guard optimize/quantize/compile against EPContext models (#256 #257)#265
Merged
Merged
Conversation
) Running winml optimize or winml quantize on a compiled QNN EPContext model crashes deep in ORT with a NOT_IMPLEMENTED error. Add an is_compiled_onnx() guard before processing starts in all three commands so users get a clear, actionable error message instead of an ORT traceback. Also guards winml compile against re-compiling an already-compiled model, which would silently produce incorrect output.
timenick
reviewed
Apr 8, 2026
Collaborator
timenick
left a comment
There was a problem hiding this comment.
Two suggestions on guard placement — see inline comments.
Collaborator
Author
|
Fixed in 90a8503 — moved both guards to fail-fast positions:
|
timenick
approved these changes
Apr 8, 2026
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.
Summary
winml optimizeandwinml quantizecrash with an ORTNOT_IMPLEMENTEDerror when given a compiled QNN EPContext model. The crash happens deep inside ORT's session initialization, which gives no indication that the real problem is that the input model is already compiled.Add an
is_compiled_onnx()guard at the start of all three commands that operate on uncompiled ONNX models. Also adds the guard towinml compileto catch re-compilation attempts.Changes
src/winml/modelkit/commands/optimize.py— EPContext guard before the optimizer runssrc/winml/modelkit/commands/quantize.py— EPContext guard before quantization runssrc/winml/modelkit/commands/compile.py— EPContext guard to prevent re-compilation (bonus, found during review)All guards use the existing
is_compiled_onnx()helper fromwinml.modelkit.onnx.Before / After
winml optimize— Before:winml optimize— After:winml quantize— Before:winml quantize— After:winml compile(bonus) — After:Closes #256
Closes #257