-
Notifications
You must be signed in to change notification settings - Fork 714
Open
Labels
bugUnexpected behaviour that should be corrected (type)Unexpected behaviour that should be corrected (type)
Description
🐞Describing the bug
torch.nn.ReplicationPad3d fails at runtime when there is padding, but ideally it would fail ahead of time.
To Reproduce
import torch
class Model(torch.nn.Module):
def __init__(self):
super().__init__()
self.pad = torch.nn.ReplicationPad3d(padding=2)
def forward(self, x):
return self.pad(x)
model = Model()
inputs = (
torch.randn(1, 6, 6, 6, 6),
)
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({})
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("CoremL", out)
This fails at runtime with the following error, but ideally it would fail ahead of time during mlmodel creation:
/opt/miniconda3/envs/op-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: "Failed to parse the model specification. Error: Unable to parse ML Program: in operation pad_cast_fp16: Padding for more than two dimensions only supports `constant` mode".
_warnings.warn(
Traceback (most recent call last):
File "/Users/scroy/Desktop/executorch/test.py", line 158, in <module>
out = mlmodel.predict(predict_inputs)
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/models/model.py", line 804, in predict
raise self._framework_error
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/models/model.py", line 549, in _get_proxy_and_spec
_MLModelProxy(
RuntimeError: Error compiling model: "Failed to parse the model specification. Error: Unable to parse ML Program: in operation pad_cast_fp16: Padding for more than two dimensions only supports `constant` mode".
System environment (please complete the following information):
- coremltools version: 8.3
- OS (e.g. MacOS version or Linux type): macOS15
Metadata
Metadata
Assignees
Labels
bugUnexpected behaviour that should be corrected (type)Unexpected behaviour that should be corrected (type)