Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Unable to compute Hessian-vector product function if function calls other functions #84

Open
lericson opened this issue Aug 16, 2018 · 2 comments

Comments

@lericson
Copy link

Minimal test case:

import tangent
import numpy as np

def forward(theta, states):
    return states

def loss(theta, states, actions):
    err = forward(theta, actions)
    return np.mean(err, axis=(0,))

dlossdtheta   = tangent.autodiff(loss, mode='reverse')
ddlossddtheta = tangent.autodiff(dlossdtheta, mode='forward')

Fails on computation of ddlossddtheta, with

Traceback (most recent call last):
  File "scratch.py", line 12, in <module>
    ddlossddtheta = tangent.autodiff(dlossdtheta, mode='forward')
[...]
  File "/Users/lericson/devel/.../env/src/tangent/tangent/fence.py", line 256, in visit_IfExp
    self._reject(node, 'Conditional Expressions are not supported')
  File "/Users/lericson/devel/.../env/src/tangent/tangent/fence.py", line 91, in _reject
    self._raise_error(msg)
  File "/Users/lericson/devel/.../env/src/tangent/tangent/fence.py", line 74, in _raise_error
    raise TangentParseError(msg, ('<stdin>', lineno, offset + 1, line))
  File "<stdin>", line 3
    axis_shape = x.shape if axis is None else tuple(x.shape[a] for a in axis)

Replacing the function call with inlining the function solves the issue.

@lericson
Copy link
Author

This is running 6533e83

@lericson
Copy link
Author

I think the state of HVP computation is actually pretty broken in both the latest release and said commit. I can't get HVPs to work for anything that isn't basically an identity function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant