Auto-bump spec version to iOS18 for models with no inputs#2684
Auto-bump spec version to iOS18 for models with no inputs#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 ( |
Summary
Models that take no inputs require Core ML specification version ≥ 9 (iOS18). Without this fix,
ct.convert(...)falls back to the default mlprogram spec version 6 (iOS15) and the resulting mlpackage fails to compile at predict time with:After the MIL
Programis built, detect thatmainhas no inputs and bump the target spec version up to iOS18 (with a warning). If the user explicitly requested an older target, the existingcheck_deployment_compatibilitystep at the entry point surfaces the conflict.Test plan
TestTorchExportConversionAPI::test_no_input_model_bumps_spec_versionexercises the issue repro and assertsspec.specificationVersion >= ct.target.iOS18.value, then runsverify_prediction(mlmodel).minimum_deployment_target=ct.target.iOS18with no input: stays at 9, no warning.minimum_deployment_target=ct.target.iOS15with no input: bumps + the existing compatibility check raises a clear error.pytest test_torch_export_conversion_api.py -k "image_input or default_io_names or source_dialect_metadata"regression — 3 passed.Fixes #2578.