apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.41k stars 636 forks source link

PyTorch convert function for op 'l1_loss' not implemented #2331

Open hex41434 opened 2 months ago

hex41434 commented 2 months ago

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:

Thank you for your attention to this issue!

YifanShenSZ commented 1 month ago

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