Repository navigation
Warn when exporting a @script() function under the placeholder domain this - #3046
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The warning checks the root function instead of the local functions actually serialized into the model, and regression tests are missing.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Adds a warning intended to prevent exporting local functions under the placeholder this domain.
Changes:
- Imports Python warning support.
- Emits a
UserWarningduring model export.
| File | Description |
|---|---|
onnxscript/_internal/values.py |
Adds placeholder-domain warning logic. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| warnings.warn( | ||
| "Exporting a function under the placeholder domain 'this': no explicit " | ||
| "opset was provided to @script(). Pass an explicit opset " | ||
| "(e.g. @script(opset16)) to give the exported function a stable, " | ||
| "collision-free domain.", | ||
| UserWarning, | ||
| stacklevel=2, |
f5e9ef1 to
22e7ee2
Compare
|
Addressed the Copilot review feedback:
Verified locally: 3/3 new tests pass, and the existing |
| @@ -0,0 +1,70 @@ | |||
| # Copyright (c) Microsoft Corporation. | |||
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3046 +/- ##
=======================================
Coverage 72.73% 72.73%
=======================================
Files 265 265
Lines 32358 32361 +3
Branches 3069 3070 +1
=======================================
+ Hits 23536 23539 +3
Misses 7779 7779
Partials 1043 1043 ☔ View full report in Codecov by Harness. |
…text - drop the 'collision-free domain' claim for @script(opset16), since opset16 uses the empty standard domain and cannot guarantee collision-free identifiers. State only that it assigns a non-placeholder domain. Signed-off-by: SIDDARTHA REDDY <75976672+SIDDARTHAREDDY8@users.noreply.github.com>
22e7ee2 to
f3c249b
Compare
|
Addressed Copilot review finding (discussion r4189880748): the warning no longer claims script (@script)(opset16) gives a collision-free domain - opset16 uses the empty standard domain, so the text now only promises a non-placeholder domain. Pushed f3c249b. |
Mohammed Alkindi (MohammedAlkindi)
left a comment
There was a problem hiding this comment.
The suggested fix produces an invalid model. Running _model_with_explicit_domain_helper.to_model_proto() from the new test gives a local function in domain "", and both onnx.checker.check_model(full_check=True) and onnxruntime reject it with "No Op registered for _explicit_domain_helper with domain_version of 17". The this variant passes both. A custom domain, values.Opset("my.domain", 1) with default_opset=op, checks and runs cleanly, so the warning text and the negative test could point there instead of @script(opset16).
…main Signed-off-by: SIDDARTHA REDDY <75976672+SIDDARTHAREDDY8@users.noreply.github.com>
|
Thanks for catching this. You are right: script (@script)(opset16) puts the helper in the empty domain, and that model fails the checker. Updated in 3e3ce9f: the warning now points to a custom domain (e.g. script (@script)(Opset('my.domain', 1), default_opset=opset17)) and explains the empty-domain problem, and the negative test now uses Opset("my.domain", 1) with default_opset=opset17 for the explicit-domain helper. Verified locally: the bundled helper lands in my.domain, onnx.checker.check_model(full_check=True) passes, the placeholder-domain case still warns, and all 3 tests in this_domain_warning_test.py pass. |


Fixes #3044.
@script()with no explicitopsetsilently defaults tovalues.Opset("this", 1), so the exported function lands in.onnxfiles under the literal domain"this"— which reads like a real namespace and collides when two such models are composed (e.g. viaonnx.compose), as seen in real Hugging Face uploads.This change emits a
UserWarningfromOnnxFunction.to_model_proto()when the function being exported still carries the placeholder domain, pointing users at passing an explicit opset (e.g.@script(opset16)). Warning-only: no behavior change, and functions with an explicit domain are unaffected.Testing: the edited module compiles cleanly (
py_compile); the change is additive and guarded, so existing export paths are unchanged apart from the warning. I could not run the full test suite in this environment.