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

Question: Is the internal scan forward-mode differentiable? #927

Open
SNMS95 opened this issue Jan 6, 2025 · 1 comment
Open

Question: Is the internal scan forward-mode differentiable? #927

SNMS95 opened this issue Jan 6, 2025 · 1 comment
Labels
question User queries

Comments

@SNMS95
Copy link

SNMS95 commented Jan 6, 2025

Hi Patrick,

I am trying to get both forward as well as reverse modes to work with a loop. Till now, I was using eqx.internals.scan.
From the internal documentation,

I see that when scan is checkpointed, only reverse-mode can be used while in lax mode is the same as jax.lax.scan?

From JAX's docs https://jax.readthedocs.io/en/latest/control-flow.html#summary,
lax.scan is differentiable in both modes (and Jittable as well).

Is there a reason for not supporting both modes here?

@patrick-kidger
Copy link
Owner

The reason is that eqxi.scan(..., kind="checkpointed") uses jax.custom_vjp under the hood. Unfortunately, right now JAX only supports reverse-mode autodifferentiation through jax.custom_vjp.

(FWIW, the benefit of eqxi.scan over jax.lax.scan is that the former uses binomial checkpointing, so requires only logarithmic memory usage (in the number of steps) to backpropagate through.)

@patrick-kidger patrick-kidger added the question User queries label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question User queries
Projects
None yet
Development

No branches or pull requests

2 participants