DavidG
(David G)
1
I am trying to convert a PyTorch model to CoreML but CoreML needs a traced model BUT does not support all the ops generated by torch.jit.trace
For example, trying to coremltools.converters.convert
a traced PyTorch model and I got an error:
PyTorch convert function for op 'intimplicit' not implemented
I am trying to convert a RVC model from github.
I traced the model with torch.jit.trace
and it fails. So I traced down the problematic part to the WN layer:
import torch
import coremltools as ct
from infer.lib.infer_pack.modules import WN
model = WN(192, 5, dilation_rate=1, n_layers=16, gin_channels=256, p_dropout=0)
model.remove_weight_norm()
model.eval()
test_x = torch.rand(1, 192, 200)
test_x_mask = torch.rand(1, 1, 200)
test_g = torch.rand(1, 256, 1)
traced_model = torch.jit.trace(model, (test_x, test_x_mask, test_g), check_trace = True)
x = ct.TensorType(name='x', shape=test_x.shape)
x_mask = ct.TensorType(name='x_mask', shape=test_x_mask.shape)
g = ct.TensorType(name='g', shape=test_g.shape)
mlmodel = ct.converters.convert(traced_model, inputs=[x, x_mask, g])
I got an error RuntimeError: PyTorch convert function for op 'intimplicit' not implemented.
How could I modify the WN::forward
so it does not generate an intimplicit
operator ?
Thanks
David
DavidG
(David G)
2
I finally found the source of this issue.
Model is calling a function that has @torch.jit.script
decorator :
Removing this decorator, torch.jit.trace
no longer add a intimplicit
operator in the trace and CoreML tools could succesfully convert the model.