CoreML Conversion hangs with minimal pipeline when 16-bit cast pass is specified
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
## 🐞Describing the bug
When converting a model with a minimal pipeline, adding 16-bit passes causes the conversion to hang indefinitely, and it can only be stopped with an external `kill`. This also happens in the default pipeline when `compute_precision=ct.precision.FLOAT16` is specified.
## To Reproduce
```python
import coremltools as ct
def convert_to_coreml_with_consistent_results(model):
pipeline = ct.PassPipeline(
pass_names=[
"common::const_elimination",
"common::const_deduplication",
"common::remove_symbolic_reshape",
"common::noop_elimination",
"common::merge_consecutive_relus",
"common::merge_consecutive_reshapes",
"common::merge_consecutive_transposes",
"common::dedup_op_and_var_names",
"common::dead_code_elimination", # always end with dce
],
pipeline_name="minimal_pipeline",
)
ml_model = ct.convert(
model,
outputs=[
ct.TensorType(
name="depth_b1hw",
),
ct.TensorType(
name="mask_logits_b1hw",
),
],
debug=False,
compute_units=ct.ComputeUnit.ALL,
compute_precision=ct.precision.FLOAT32,
minimum_deployment_target=ct.target.iOS17,
pass_pipeline=pipeline,
)
ml_model.save("ConsistentResults.mlmodel")
def convert_to_coreml_hangs(model):
pipeline = ct.PassPipeline(
pass_names=[
"common::const_elimination",
"common::const_deduplication",
"common::remove_symbolic_reshape",
"common::noop_elimination",
"common::merge_consecutive_relus",
"common::merge_consecutive_reshapes",
"common::merge_consecutive_transposes",
"common::dedup_op_and_var_names",
"common::add_fp16_cast",
"common::add_int16_cast",
"common::update_output_dtypes",
"common::dead_code_elimination",
],
pipeline_name="minimal_pipeline",
)
ml_model = ct.convert(
model,
outputs=[
ct.TensorType(
name="depth_b1hw",
),
ct.TensorType(
name="mask_logits_b1hw",
),
],
compute_units=ct.ComputeUnit.ALL,
compute_precision=ct.precision.FLOAT16,
minimum_deployment_target=ct.target.iOS17,
pass_pipeline=pipeline,
)
# we never get here but just in case
ml_model.save("Hangs.mlmodel")
```
## System environment (please complete the following information):
- coremltools version: 8.3.0
- OS (e.g. MacOS version or Linux type): MacOS Version 15.7.1 (24G231)
- Any other relevant version information (e.g. PyTorch or TensorFlow version):
torch==2.5.1
torchvision==0.20.1
Contributor guide
Research direction
Start by running the provided Python reproducer with coremltools 8.3.0, comparing the minimal pipeline with and without common::add_fp16_cast and common::add_int16_cast. Trace the PassPipeline and ct.convert path to identify where conversion stops, then verify that the conversion completes and reaches ml_model.save for the FLOAT16 configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100