coremltools icon indicating copy to clipboard operation
coremltools copied to clipboard

PyTorch convert function for op 'pad' not implemented.

Open piraka9011 opened this issue 3 years ago • 0 comments

  • Name of layer type: pad
  • Is this a PyTorch or a TensorFlow layer type: PyTorch
  • Your version of coremltools: 6.0b2
  • Your version of PyTorch/TensorFlow: 1.12.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? Yes, support for Confomer models for audio.

piraka9011 avatar Aug 03 '22 15:08 piraka9011

I’ll second the request for an official pad implementation when PyTorch 1.12.0 support rolls out, though as a workaround I’ve been able to compile torchaudio.models.Conformer to CoreML with PyTorch 1.11.0 and torchaudio 0.11.0, if that’s any help.

iansampson avatar Aug 11 '22 02:08 iansampson

@iansampson thanks for the info. I'm trying to convert another implementation from nvidia/NeMo instead. Were you also able to run it/any console warnings? Are you using it in a streaming or offline context?

piraka9011 avatar Aug 11 '22 14:08 piraka9011

Well now this is interesting...

https://github.com/apple/coremltools/blob/6.0b1/coremltools/converters/mil/frontend/torch/test/test_torch_ops.py#L4229-L4286

🤔

mallman avatar Aug 11 '22 23:08 mallman

Well now this is interesting...

https://github.com/apple/coremltools/blob/6.0b1/coremltools/converters/mil/frontend/torch/test/test_torch_ops.py#L4229-L4286

🤔

So apparently this is for some specific padding ops, and this test only passes for pytorch < 1.12.

In my case I was able to use torch.constant_pad_nd as a replacement for torch.nn.functional.pad. Check it out.

mallman avatar Aug 12 '22 18:08 mallman

Ok, so the issue here is supporting PyTorch version 1.12.0, not a missing layer type.

TobyRoseman avatar Aug 12 '22 23:08 TobyRoseman

@iansampson thanks for the info. I'm trying to convert another implementation from nvidia/NeMo instead. Were you also able to run it/any console warnings? Are you using it in a streaming or offline context?

@piraka9011 Yep, the conformer module works as expected – no console warnings as far as I can remember. I’m experimenting with both streaming and offline processing (for speech enhancement, not speech recognition).

And thanks for the tip @mallman – I’ll give torch.constant_pad_nd a try.

iansampson avatar Aug 15 '22 17:08 iansampson

FYI, gelu has a new argument ("approximation") in pytorch 1.12. coremltools has issues converting models with the gelu activation in pytorch 1.12

jonmorton avatar Sep 14 '22 22:09 jonmorton