Skip to content

Raise a clear error when a no-input model targets below iOS18#2684

Open
john-rocky wants to merge 2 commits into
apple:mainfrom
john-rocky:fix-no-input-deployment-target
Open

Raise a clear error when a no-input model targets below iOS18#2684
john-rocky wants to merge 2 commits into
apple:mainfrom
john-rocky:fix-no-input-deployment-target

Conversation

@john-rocky
Copy link
Copy Markdown
Contributor

@john-rocky john-rocky commented May 1, 2026

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:

validator error: Empty input is only valid in specification version >= 9. This model has version 6.

Per review feedback, rather than silently bumping the user's requested deployment target, surface the requirement at conversion time: when an mlprogram has no inputs and the requested target maps to a spec version below iOS18, raise a ValueError that names the requirement and points the user at minimum_deployment_target=ct.target.iOS18.

Test plan

  • New test TestTorchExportConversionAPI::test_no_input_model_requires_ios18 covers both paths: the default (iOS15) target raises the actionable ValueError, and an explicit iOS18 target converts and predicts successfully.

Fixes #2578.

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.
@john-rocky john-rocky force-pushed the fix-no-input-deployment-target branch from 0d97c52 to 8d1a548 Compare May 6, 2026 00:28
and spec_version is not None
and spec_version < _SPECIFICATION_VERSION_IOS_18
):
main_func = prog.functions.get(prog.default_function_name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also check the error case here, see my other comment.

@john-rocky
Copy link
Copy Markdown
Contributor Author

Thanks — agreed, failing with a clear error is the right behavior. Reworked in 4f65a78:

Behavior change (converter.py)

  • No-input + spec version < iOS18 now raises ValueError instead of bumping. Message points the user at the fix:

    Model has no inputs, which requires a deployment target of iOS18 / macOS15 or later (specification version 9); the requested target maps to specification version 6. Re-run ct.convert(...) with minimum_deployment_target=ct.target.iOS18 (or a later target).

  • Dropped the now-unused _logger import.

Test change (test_torch_export_conversion_api.py, renamed test_no_input_model_requires_ios18)

  • Asserts pytest.raises(ValueError, match=r"minimum_deployment_target=ct\.target\.iOS18") for the default target.
  • Then re-runs with minimum_deployment_target=ct.target.iOS18 and verifies spec.specificationVersion >= ct.target.iOS18.value + verify_prediction(mlmodel) for the happy path.

Verified locally on the same toy model (forward(self): return torch.ones(5, 5)): default target raises the new error, iOS18 target converts through MIL cleanly.

@TobyRoseman
Copy link
Copy Markdown
Collaborator

@john-rocky john-rocky changed the title Auto-bump spec version to iOS18 for models with no inputs Raise a clear error when a no-input model targets below iOS18 May 22, 2026
@john-rocky
Copy link
Copy Markdown
Contributor Author

Reworked per your suggestion: instead of auto-bumping the spec version, conversion now raises a clear ValueError that points the user at minimum_deployment_target=ct.target.iOS18, and the test exercises both the error path and the iOS18 happy path. I've updated the title and description to match.

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coremltools does not correctly infer the minimum_deployment_target for models with no inputs

2 participants