Skip to content

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

@metascroy

Description

@metascroy

🐞Describing the bug

coremltools does not correctly infer the minimum_deployment_target for models with no inputs. It should infer iOS18+.

Stack Trace

scikit-learn version 1.7.1 is not supported. Minimum required version: 0.17. Maximum required version: 1.5.1. Disabling scikit-learn conversion API.
Torch version 2.9.0.dev20250725 has not been tested with coremltools. You may run into unexpected errors. Torch 2.5.0 is the most recent version that has been tested.
W0731 17:22:46.830000 79296 site-packages/torch/distributed/elastic/multiprocessing/redirects.py:29] NOTE: Redirects are currently not supported in Windows or MacOs.
When both 'convert_to' and 'minimum_deployment_target' not specified, 'convert_to' is set to "mlprogram" and 'minimum_deployment_target' is set to ct.target.iOS15 (which is same as ct.target.macOS12). Note: the model will not run on systems older than iOS15/macOS12/watchOS8/tvOS15. In order to make your model run on older system, please set the 'minimum_deployment_target' to iOS14/iOS13. Details please see the link: https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html
Converting PyTorch Frontend ==> MIL Ops:   0%|                                                                                                                   | 0/1 [00:00<?, ? ops/s]
Running MIL frontend_pytorch pipeline: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 12475.62 passes/s]
Running MIL default pipeline: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████| 89/89 [00:00<00:00, 11976.42 passes/s]
Running MIL backend_mlprogram pipeline: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 12/12 [00:00<00:00, 51941.85 passes/s]
/opt/miniconda3/envs/et/lib/python3.10/site-packages/coremltools/models/model.py:560: RuntimeWarning: You will not be able to run predict() on this Core ML model. Underlying exception message was: Error compiling model: "compiler error: Error reading protobuf spec. validator error: Empty input is only valid in specification verison >= 9. This model has version 6".
  _warnings.warn(
Traceback (most recent call last):
  File "/Users/scroy/Desktop/executorch/test.py", line 80, in <module>
    out = mlmodel.predict(predict_inputs)
  File "/opt/miniconda3/envs/et/lib/python3.10/site-packages/coremltools/models/model.py", line 804, in predict
    raise self._framework_error
  File "/opt/miniconda3/envs/et/lib/python3.10/site-packages/coremltools/models/model.py", line 549, in _get_proxy_and_spec
    _MLModelProxy(
RuntimeError: Error compiling model: "compiler error: Error reading protobuf spec. validator error: Empty input is only valid in specification verison >= 9. This model has version 6".

To Reproduce

import torch

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        
    def forward(self):
        return torch.ones(5, 5)

model = Model()
inputs = (
)

print(inputs)

eager_outputs = model(*inputs)
print(f"Eager: {eager_outputs.shape} {eager_outputs}")

ep = torch.export.export(model.eval(), inputs)
print(ep)


import coremltools as ct
import numpy as np
ep = ep.run_decompositions({})

eager_outputs = model(*inputs)

mlmodel = ct.convert(ep)

coreml_inputs = mlmodel.get_spec().description.input
coreml_outputs = mlmodel.get_spec().description.output
predict_inputs = {str(ct_in.name): pt_in.detach().cpu().numpy().astype(np.int32) for ct_in, pt_in in zip(coreml_inputs, inputs)}
out = mlmodel.predict(predict_inputs)

print("Eager", eager_outputs)
print("CoremL", out)

Model conversion succeeds, but it does not correctly set the required minimum_deployment_target for models with no inputs (iOS18+).

System environment (please complete the following information):

  • coremltools version: 8.3
  • OS (e.g. MacOS version or Linux type): macOS15

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected behaviour that should be corrected (type)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions