google-deepmind / google-deepmind/optax
Support for loss function with auxiliary data in linesearch
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 369
- Avg merge
- 10h 15m
- Merged PRs (30d)
- 7
Description
I have a loss function that returns `(loss_value, extra_data)`. Native jax supports this kind of construct with `jax.value_and_grad(loss_fn, has_aux=True)` ([doc](https://jax.readthedocs.io/en/latest/_autosummary/jax.value_and_grad.html)). The differentiated function returns `((loss_value, extra_data), grad)`.
In optax, when using the linesearch algorithms (for example as part of L-BFGS), I can use `optax.value_and_grad_from_state(loss_fn)` ([doc](https://optax.readthedocs.io/en/latest/api/utilities.html#optax.value_and_grad_from_state)) which uses the optimizer state to save function evaluations done inside the linesearch. Unfortunately, the linesearch algorithms and `optax.value_and_grad_from_state` don't support auxiliary data.
I added support for this to the optax code. It works for my use case. Are you interested in merging this upstream? I don't have time for proper testing, documentation, etc though, so would appreciate getting some assistance.
Contributor guide
Assessment
This issue has not been assessed yet.