Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword arguments not working with @jax.custom_gradient #1938

Closed
AlexeyG opened this issue Jan 3, 2020 · 3 comments
Closed

Keyword arguments not working with @jax.custom_gradient #1938

AlexeyG opened this issue Jan 3, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@AlexeyG
Copy link

AlexeyG commented Jan 3, 2020

@jax.custom_gradient
def my_fun(x, y, c=1.):
  return c * (x + y), lambda x, y: (c * (1. + y), c * (x + 1.))

f = lambda x, y: jnp.square(my_fun(x, y, c=2.)).sum()

Calling f(10., 5.) gives

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-55-de80b4d2e2a5> in <module>()
----> 1 f(10., 5.)

<ipython-input-54-d90a45f76782> in <lambda>(x, y)
      3   return c * (x + y), lambda x, y: (1. * c, 1. * c)
      4 
----> 5 f = lambda x, y: jnp.square(my_fun(x, y, c=2.)).sum()

TypeError: __call__() got an unexpected keyword argument 'c'
@mattjj mattjj self-assigned this Jan 3, 2020
@mattjj mattjj added the bug Something isn't working label Jan 3, 2020
@mattjj
Copy link
Collaborator

mattjj commented Jan 7, 2020

I'm working on a custom_gradient overhaul, and I made sure that my prototype passes this test. I hope to have a PR (i.e. a branch you can work off of) this week, and maybe something mergeable next week.

@AlexeyG
Copy link
Author

AlexeyG commented Jan 7, 2020

Sounds great. Thanks a lot, @mattjj !

@mattjj
Copy link
Collaborator

mattjj commented Mar 22, 2020

#2026 changed the API for custom derivatives, and also added support for default argument values and keyword arguments!

@mattjj mattjj closed this as completed Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants