Inverse not implemented for type Variable

Hey guys,

I’ve been trying to play around with some gradients and came across an error while running this command:

return torch.inverse(torch.mm(x, x.t()))

This gave me the error:
TypeError: Type Variable doesn’t implement stateless method inverse

Is there an issue with my syntax, or is the inverse not implemented? Thanks!

Abhimanyu

torch.inverse takes tensor as an argument not Variable. You can get tensor out of a Variable using .data

1 Like

Thanks! I will try it out, however I need it to be differentiable. Will converting it to a tensor preserve the gradients?

Hey, I tried your suggestion - doesn’t work. The .data call is:
return torch.inverse(torch.mm(x, x.t()).data)

And I get the error:
AttributeError: 'FloatTensor' object has no attribute 'data'

The gradient of the inverse is not implemented, and apparently won’t be implemented in the nearby future, see https://github.com/pytorch/pytorch/issues/440

1 Like

That’s what the error was suggesting but apparently torch.mm returns a tensor and not a variable.
I don’t know why are you getting an error in the first place cuz I tried following code and it didn’t give any error:

mat1 = torch.randn(3, 3)
torch.inverse(torch.mm(mat1, mat1.t()))

@Rinku_Jadhav2014 in his code snippet, x is a Variable

Thanks for the link @fmassa! In my case, all eigenvalues of the variable are going to be <1 without exception, so I’ll just approximate the inverse with a power series I think.