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

Possible bug: acprop explodes during initial steps #1132

Open
carlosgmartin opened this issue Nov 9, 2024 · 0 comments
Open

Possible bug: acprop explodes during initial steps #1132

carlosgmartin opened this issue Nov 9, 2024 · 0 comments

Comments

@carlosgmartin
Copy link
Contributor

carlosgmartin commented Nov 9, 2024

There appears to be a bug in acprop that causes it to explode during its initial steps in some situations:

Code
import jax
import optax
from jax import lax, numpy as jnp
from matplotlib import pyplot as plt, rcParams


def rosenbrock_function(params, a=1, b=100):
    x, y = params
    return jnp.square(a - x) + b * jnp.square(y - jnp.square(x))


def main():
    lr = 1e-4
    iters = 1000

    params = jnp.zeros(2)

    fig, ax = plt.subplots(constrained_layout=True)

    for label, opt in [
        ("sgd", optax.sgd(lr)),
        ("adam", optax.adam(lr)),
        ("adabelief", optax.adabelief(lr)),
        ("acprop", optax.contrib.acprop(lr)),
    ]:

        def update(state, _):
            params, opt_state = state
            value, grads = jax.value_and_grad(rosenbrock_function)(params)
            updates, opt_state = opt.update(grads, opt_state, params)
            params = optax.apply_updates(params, updates)
            return (params, opt_state), value

        opt_state = opt.init(params)
        _, values = lax.scan(update, (params, opt_state), length=iters)
        ax.plot(values, label=label)

    ax.legend()
    ax.set(xlabel="iteration", ylabel="value", yscale="log")
    ax.grid(True, "both", alpha=0.1)
    rcParams["savefig.dpi"] = 300
    plt.show()


if __name__ == "__main__":
    main()

Zooming in:

I'm currently investigating this.

@carlosgmartin carlosgmartin changed the title Bug with acprop Possible bug: acprop explodes during initial steps Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant