Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyTorch Linear Algebra Gradients

I'm looking to back-propagate gradients through a singular value decomposition for regularisation purposes. PyTorch currently does not support backpropagation through a singular value decomposition.

I know that I could write my own custom function that operates on a Variable; takes its .data tensor, applies the torch.svd to it, wraps a Variable around its singular values and returns it in the forward pass, and in the backward pass applies the appropriate Jacobian matrix to the incoming gradients.

However, I was wondering whether there was a more elegant (and potentially faster) solution, where I could overwrite the "Type Variable doesn't implement stateless method svd" Error directly, call Lapack, etc. ?

If someone could guide me through the appropriate steps and source files I need to look at, I'd be very grateful. I suppose these steps would similarly apply to other linear algebra operations which have no associated backward method currently.

like image 535
mbpaulus Avatar asked Jun 29 '17 15:06

mbpaulus


People also ask

How do you get PyTorch gradients?

To compute the gradients, a tensor must have its parameter requires_grad = true. The gradients are same as the partial derivatives. For example, in the function y = 2*x + 1, x is a tensor with requires_grad = True. We can compute the gradients using y.

Does PyTorch use Autograd?

torch. autograd is PyTorch's automatic differentiation engine that powers neural network training.

How does Autograd in PyTorch work?

Autograd is reverse automatic differentiation system. Conceptually, autograd records a graph recording all of the operations that created the data as you execute operations, giving you a directed acyclic graph whose leaves are the input tensors and roots are the output tensors.


1 Answers

torch.svd with forward and backward pass is now available in the Pytorch master:

http://pytorch.org/docs/master/torch.html#torch.svd

You need to install Pytorch from source: https://github.com/pytorch/pytorch/#from-source

like image 51
iacolippo Avatar answered Oct 04 '22 11:10

iacolippo