coremltools
coremltools copied to clipboard
Support for torch.linalg.lstsq operation
❓Question about torch.linalg.lstsq Operation Support
Summary
I am attempting to convert a PyTorch model that uses torch.linalg.lstsq
to CoreML using coremltools
, but it seems that this operation is not supported as well as other torch.linalg ops
Issue Details
When I try to convert my model, I get an error stating that torch.linalg
is unsupported. This is causing significant issues as there doesn't seem to be a straightforward workaround.
Version
coremltools 7.1 Latest
Code Sample
ref, residuals, rank, singular_values = torch.linalg.lstsq(
A_regul * weights_regul, b_regul * weights_regul)
In order to support torch.linalg.lstsq
it needs to be implemented using our MIL ops. Looking at the documentation for that PyTorch op, I think it's not going to be possible to implement it using our current set of MIL ops. If anyone has any ideas here, please share.
Yeah our MIL ops do not have anything to solve linear algebra (linear equation, inverse, eigen value, ...), do we?
@YifanShenSZ - we don't have any MIL ops like that. However, let's leave this issue open since it is not resolved.
@TobyRoseman I'm also using a model that needs torch.linalg.lstsq
, so I think it could be worthwhile to implement since it seems like Tensorflow has similar operations too. I would be happy to work on this and see if I can create new MIL ops for some common linear algebra operations
@dhruvmk - By all means, feel free to work on this issue. However as I said before, I don't think this is currently going to be possible, given the MIL ops we have right now, but let us know if you make progress.
@TobyRoseman I understand that this can't be done using the MIL ops currently available, so I was thinking I would create custom MIL ops to support this as outlined here. Am I misunderstanding this issue?
@zack-dev-cm I've implemented a CoreML custom layer and a MIL op for torch.linalg.lstsq
.
It supports multi-batch input tensors and gelsd
driver:
https://github.com/dneprDroid/Lstsq-CoreML
You can try the demo app and the example converter script to generate a CoreML model with custom layers.