Raise a clear error when a no-input model targets below iOS18#2684
Raise a clear error when a no-input model targets below iOS18#2684john-rocky wants to merge 2 commits into
Conversation
Models that take no inputs require Core ML specification version >= 9 (iOS18). Without this fix, `ct.convert(...)` defaults to spec version 6 (iOS15) and the resulting mlpackage fails to compile at predict time with: Error reading protobuf spec. validator error: Empty input is only valid in specification version >= 9. This model has version 6. After the prog is built, detect that `main` has no inputs and bump the target spec version up to iOS18 (with a warning). If the user explicitly requested an older target, the existing `check_deployment_compatibility` step at the entry point surfaces the conflict. Fixes apple#2578.
0d97c52 to
8d1a548
Compare
| and spec_version is not None | ||
| and spec_version < _SPECIFICATION_VERSION_IOS_18 | ||
| ): | ||
| main_func = prog.functions.get(prog.default_function_name) |
There was a problem hiding this comment.
In this case I think we should fail, with a clear error message that telling the user they need to change their deployment target.
| assert mlmodel.user_defined_metadata[_METADATA_SOURCE_DIALECT] == dialect_name | ||
|
|
||
| @pytest.mark.parametrize("frontend", frontends) | ||
| def test_no_input_model_bumps_spec_version(self, frontend): |
There was a problem hiding this comment.
Let's also check the error case here, see my other comment.
|
Thanks — agreed, failing with a clear error is the right behavior. Reworked in Behavior change (
Test change (
Verified locally on the same toy model ( |
|
Reworked per your suggestion: instead of auto-bumping the spec version, conversion now raises a clear Verified locally that the default (iOS15) target now raises that error rather than producing a version-6 model that fails to compile with "Empty input is only valid in specification version >= 9". |
Summary
A model with no inputs requires Core ML specification version ≥ 9 (iOS18 / macOS15). Below that, the produced mlpackage fails to compile at predict time with:
Per review feedback, rather than silently bumping the user's requested deployment target, surface the requirement at conversion time: when an
mlprogramhas no inputs and the requested target maps to a spec version below iOS18, raise aValueErrorthat names the requirement and points the user atminimum_deployment_target=ct.target.iOS18.Test plan
TestTorchExportConversionAPI::test_no_input_model_requires_ios18covers both paths: the default (iOS15) target raises the actionableValueError, and an explicitiOS18target converts and predicts successfully.Fixes #2578.