jax.fwd_and_bwd silently discards keyword arguments
Author: the-ShallowCreated Sep 29, 2026Updated Sep 30, 2026
Labelsbugtype:Bug
Description
Summary
The fwd function returned by jax.fwd_and_bwd declares **kwargs in its signature but
passes an empty dict to argnums_partial2, so keyword arguments are silently dropped.
When the wrapped function has defaults for those parameters, fwd silently returns the
wrong primal output and bwd silently returns the wrong gradients, with no error.
Reproducing the Bug
import jax
import jax.numpy as jnp
def fun(x, scale=1.0):
return jnp.sum(x * scale)
x = jnp.array([1.0, 1.0, 1.0])
fwd, bwd = jax.fwd_and_bwd(fun, argnums=0)
y, res = fwd(x, scale=0.5)
assert y == fun(x, scale=0.5) # 3.0 != 1.5
assert jnp.allclose(bwd(res, 1.0), jax.grad(fun)(x, scale=0.5)) # [1,1,1] != [.5,.5,.5]
Fix
```diff
--- a/jax/_src/api.py
+++ b/jax/_src/api.py
@@ -690,7 +690,7 @@ def fwd_and_bwd(
argnums = _ensure_index(argnums)
def fwd(*args, **kwargs):
- f_partial, dyn_args = argnums_partial2(fun, argnums, args, {})
+ f_partial, dyn_args = argnums_partial2(fun, argnums, args, kwargs)
return vjp(f_partial, *dyn_args, has_aux=has_aux)System info (python version, jaxlib version, accelerator, etc.)
JAX 0.11.2 / jaxlib 0.11.2 OS/architecture: Linux x86-64
Source: jax-ml/jax