coremltools
coremltools copied to clipboard
RuntimeError: PyTorch convert function for op 'bernoulli_' not implemented
- Name of layer type: bernoulli_
- Is this a PyTorch or a TensorFlow layer type: PyTorch
- Your version of coremltools: 6.0b1
- Your version of PyTorch/TensorFlow: PyTorch 1.11.0
- Impact of supporting this layer type. Why is adding support for this layer type important? Is it necessary to support a popular model or use case?
I am trying to convert EfficientNet-B0 model into .mlmodel and I have got the following issue.
model = ct.convert(traced_model, File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/_converters_entry.py", line 426, in convert mlmodel = mil_convert( File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 182, in mil_convert return _mil_convert(model, convert_from, convert_to, ConverterRegistry, MLModel, compute_units, **kwargs) File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 209, in _mil_convert proto, mil_program = mil_convert_to_proto( File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 272, in mil_convert_to_proto prog = frontend_converter(model, **kwargs) File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 104, in __call__ return load(*args, **kwargs) File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 52, in load return _perform_torch_convert(converter, debug) File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 99, in _perform_torch_convert raise e File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 91, in _perform_torch_convert prog = converter.convert() File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/converter.py", line 263, in convert convert_nodes(self.context, self.graph) File "/.../anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 86, in convert_nodes raise RuntimeError( RuntimeError: PyTorch convert function for op 'bernoulli_' not implemented.
We do have a MIL op for random_bernoulli
. However it not clear to me how to use that to replicate the behavior of torch.Tensor.bernoulli_.
@Sehaba95 - are you calling .eval()
on your PyTorch model before you call coremltools.convert(...)
? I believe that may solve this issue.
Calling .eval()
is not going to solve this problem. I can reproduce the issue with the following code:
import torch
import coremltools as ct
class MyModel(torch.nn.Module):
def forward(self, x):
x.bernoulli_()
return x
m = MyModel()
m.eval()
a = torch.empty(3, 3).uniform_(0, 1)
m = torch.jit.trace(m, a)
ct.convert(m, inputs=[ct.TensorType(shape=a.shape)])