Live data from Hacker News

Tangent: Source-To-Source Autodiff for Python

research.googleblog.com

1–4 of 4 posts

Re: Tangent: Source-To-Source Autodiff for Python

#2
No nested differentiation:

  >>> import tangent
  >>> import numpy as np
  >>> tangent.grad(tangent.grad(np.sin))
  Traceback (most recent call last):
    File "", line 1, in 
    File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 178, in grad
      node, namespace = grad_tree(func, wrt, motion, mode, preserve_result, verbose)
    File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 97, in grad_tree
      namespace.update(six.get_function_globals(func))
  AttributeError: 'numpy.ufunc' object has no attribute '__globals__'

Re: Tangent: Source-To-Source Autodiff for Python

#3

No nested differentiation: >>> import tangent >>> import numpy as np >>> tangent.grad(tangent.grad(np.sin)) Traceback (most recent call last): File " ", line 1, in File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 178, in grad node, namespace = grad_tree(func, wrt, motion, mode, preserve_result, verbose) File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 97, in grad_tree n…

^I get that error with just `tangent.grad(np.sin)`.

So, it's not a nested differentiation problem, so much as a problem with "ufuncs". If you wrap np.sin in your own function then it takes the gradient just fine.

def sin(x): return np.sin(x)

negative_sin = tangent.grad(tangent.grad(sin))

Re: Tangent: Source-To-Source Autodiff for Python

#4
post #3

No nested differentiation: >>> import tangent >>> import numpy as np >>> tangent.grad(tangent.grad(np.sin)) Traceback (most recent call last): File " ", line 1, in File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 178, in grad node, namespace = grad_tree(func, wrt, motion, mode, preserve_result, verbose) File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 97, in grad_tree n…

^I get that error with just `tangent.grad(np.sin)`. So, it's not a nested differentiation problem, so much as a problem with "ufuncs". If you wrap np.sin in your own function then it takes the gradient just fine. def sin(x): return np.sin(x) negative_sin = tangent.grad(tangent.grad(sin))

Ah, good point, thanks!