coremltools icon indicating copy to clipboard operation
coremltools copied to clipboard

PyTorch convert function for op 'l1_loss' not implemented

Open hex41434 opened this issue 1 year ago • 1 comments

Hi,

I encountered an error while attempting to convert a PyTorch model to Core ML using the CoreMLTools convert function. The model utilizes the l1_loss operation, and during the conversion process, I received the following error:

RuntimeError: PyTorch convert function for op 'l1_loss' not implemented.

Request:

I am requesting either:

  • Implementation support for the l1_loss operation in the CoreMLTools conversion process, or
  • Guidance on recommended practices or alternative methods for handling l1_loss during model conversion.

Thank you for your attention to this issue!

hex41434 avatar Sep 03 '24 15:09 hex41434

Hi @hex41434, could you please elaborate your use case a bit? Concretely, why would a loss function present in inference?

As a temporary workaround, you may explicitly decompose your torch.nn.L1Loss layer with torch.mean(torch.abs(y - x))

The long term solution will be to add an op translation. Here is an example for Frobenius norm

YifanShenSZ avatar Sep 06 '24 19:09 YifanShenSZ