Skip to content

Instantly share code, notes, and snippets.

@moskomule
Forked from apaszke/Rop.py
Created September 18, 2018 08:41
Show Gist options
  • Save moskomule/b1cb7077321ac269a86c2b9fd4053eb3 to your computer and use it in GitHub Desktop.
Save moskomule/b1cb7077321ac269a86c2b9fd4053eb3 to your computer and use it in GitHub Desktop.
def Rop(y, x, v):
"""Computes an Rop.
Arguments:
y (Variable): output of differentiated function
x (Variable): differentiated input
v (Variable): vector to be multiplied with Jacobian from the right
"""
w = torch.ones_like(y, requires_grad=True)
return torch.autograd.grad(torch.autograd.grad(y, x, w), w, v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment