coremltools icon indicating copy to clipboard operation
coremltools copied to clipboard

pytorch inverse op implementation

Open shiron8bit opened this issue 4 years ago • 3 comments

❓Question

Hello, when i'm trying to convert pytorch model which uses torch.inverse(), i get the following error: 'RuntimeError: PyTorch convert function for op 'inverse' not implemented.'

OS: Ubuntu 18.04.4 LTS coremltools version: 4.0b4

Any chances that it will be implemented soon?

shiron8bit avatar Oct 07 '20 14:10 shiron8bit

Actually i've made a stop-gap solution for 2x2 matriсes, but this is really a dirty hack : )

def inverter(t):
    res = t.clone()
    tmp =  t[:,:,0,0]*t[:,:,1,1]-t[:,:,0,1]*t[:,:,1,0]
    tmp = tmp.view(-1,1,1)
    tmp = torch.div(t,tmp)
    res[:,:,0,0] = tmp[:,:,1,1]
    res[:,:,1,1] = tmp[:,:,0,0]
    res[:,:,0,1] = -tmp[:,:,0,1]
    res[:,:,1,0] = -tmp[:,:,1,0]
    return res

shiron8bit avatar Oct 15 '20 09:10 shiron8bit

Does coremltools support torch.inverse now?

jianwenyyy avatar Sep 25 '23 15:09 jianwenyyy

Does coremltools support torch.inverse now?

Coremltools does not support this PyTorch op. I don't think there is any reasonable way to compute the inverse of a matrix using the current MIL ops; I think this will require a new MIL op which would be a change in the Core ML Framework.

Please submit this feature request for the Core ML Framework using the Feedback Assistant.

TobyRoseman avatar Sep 25 '23 18:09 TobyRoseman