Exported model assumes that the input should always be similar to the tracing example
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
## πDescribing the bug
The bug isn't detected while exporting the model, no error is shown, however, when I try using the model in Swift I got this error:
```
Thread 17: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=0 "MultiArray shape (1 x 27200) does not match the shape (1 x 16000) specified in the model description" UserInfo={NSLocalizedDescription=MultiArray shape (1 x 27200) does not match the shape (1 x 16000) specified in the model description}
```
On this line:
```swift
let output = try! self.inferenceModule.prediction(input: input)
```
There is a problem in exporting somehow that makes the tracing not work as expected, it keeps assuming that my input is always the same as the one passed to the trace function.
The first thing to think of here is that the tracing is failing, but that's not the case because I am able to export the model using Pytorch lighting and use it with the LibTorch C++ library without any problem.
## Stack Trace
```
When both 'convert_to' and 'minimum_deployment_target' not specified, 'convert_to' is set to "mlprogram" and 'minimum_deployment_targer' 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://coremltools.readme.io/docs/unified-conversion-api#target-conversion-formats
Support for converting Torch Script Models is experimental. If possible you should use a traced model for conversion.
Tuple detected at graph output. This will be flattened in the converted model.
Converting PyTorch Frontend ==> MIL Ops: 0%| | 0/486 [00:00 MIL Ops: 71%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | 345/486 [00:00<00:00, 3449.42 ops/s]Saving value type of int64 into a builtin type of int32, might lose precision!
Saving value type of int64 into a builtin type of int32, might lose precision!
Converting PyTorch Frontend ==> MIL Ops: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 484/486 [00:00<00:00, 3123.51 ops/s]
Running MIL frontend_pytorch pipeline: 0%| | 0/5 [00:00
Contributor guide
Research direction
Start with the shown ct.convert call and its TensorType shape declarations, then reproduce the export using the 16,000-sample trace input and the 27,200-sample Swift input. Done means the exported model's declared input behavior matches the supported variable-length inputs, or the exporter reports the mismatch clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch, swift
- Domain
- machine-learning, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100