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

inject_hyperparams starts with step_count=1 when using schedules #415

Closed
mkunesch opened this issue Sep 13, 2022 · 0 comments
Closed

inject_hyperparams starts with step_count=1 when using schedules #415

mkunesch opened this issue Sep 13, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@mkunesch
Copy link
Member

This is inconsistent with e.g. scale_by_schedule which starts with step_count = 0 in the first update.

To reproduce:

import jax.numpy as jnp
import optax

opt = optax.inject_hyperparams(optax.scale)(step_size=lambda count: count)
opt1 = optax.scale_by_schedule(step_size_fn=lambda count: count)

state = opt.init(jnp.ones(1))
updates, state = opt.update(jnp.ones(1), state)

state1 = opt1.init(jnp.ones(1))
updates1, state = opt1.update(jnp.ones(1), state1)

assert updates == updates1, f"{updates=} not equal to {updates1=}"

Leads to:
AssertionError: updates=DeviceArray([1.], dtype=float32) not equal to updates1=DeviceArray([0.], dtype=float32)

@mkunesch mkunesch added the bug Something isn't working label Sep 13, 2022
@mkunesch mkunesch self-assigned this Sep 13, 2022
copybara-service bot pushed a commit that referenced this issue Sep 13, 2022
This fixes issue #415. Previously, `inject_hyperparams` started with
`step_count=1` in the first update when using schedules (it incremented before
passing it to the schedule) whereas `scale_by_schedule` started with
`step_count=0`. To make this consistent, this PR changes `inject_hyperparams`
to also start at 0, i.e. increment the count only after passing it to the
schedule.

The PR comes with a test that breaks without the change. Furthermore, the step
counts in the existing tests of `inject_hyperparams` had to be decremented by
one in order for the tests to pass.

PiperOrigin-RevId: 474015093
copybara-service bot pushed a commit that referenced this issue Sep 13, 2022
This fixes issue #415. Previously, `inject_hyperparams` started with
`step_count=1` in the first update when using schedules (it incremented before
passing it to the schedule) whereas `scale_by_schedule` started with
`step_count=0`. To make this consistent, this PR changes `inject_hyperparams`
to also start at 0, i.e. increment the count only after passing it to the
schedule.

The PR comes with a test that breaks without the change. Furthermore, the step
counts in the existing tests of `inject_hyperparams` had to be decremented by
one in order for the tests to pass.

PiperOrigin-RevId: 474015093
copybara-service bot pushed a commit that referenced this issue Oct 7, 2022
This fixes issue #415. Previously, `inject_hyperparams` started with
`step_count=1` in the first update when using schedules (it incremented before
passing it to the schedule) whereas `scale_by_schedule` started with
`step_count=0`. To make this consistent, this PR changes `inject_hyperparams`
to also start at 0, i.e. increment the count only after passing it to the
schedule.

The PR comes with a test that breaks without the change. Furthermore, the step
counts in the existing tests of `inject_hyperparams` had to be decremented by
one in order for the tests to pass.

PiperOrigin-RevId: 474015093
copybara-service bot pushed a commit that referenced this issue Oct 7, 2022
This fixes issue #415. Previously, `inject_hyperparams` started with
`step_count=1` in the first update when using schedules (it incremented before
passing it to the schedule) whereas `scale_by_schedule` started with
`step_count=0`. To make this consistent, this PR changes `inject_hyperparams`
to also start at 0, i.e. increment the count only after passing it to the
schedule.

The PR comes with a test that breaks without the change. Furthermore, the step
counts in the existing tests of `inject_hyperparams` had to be decremented by
one in order for the tests to pass.

PiperOrigin-RevId: 474015093
copybara-service bot pushed a commit that referenced this issue Oct 7, 2022
This fixes issue #415. Previously, `inject_hyperparams` started with
`step_count=1` in the first update when using schedules (it incremented before
passing it to the schedule) whereas `scale_by_schedule` started with
`step_count=0`. To make this consistent, this PR changes `inject_hyperparams`
to also start at 0, i.e. increment the count only after passing it to the
schedule.

The PR comes with a test that breaks without the change. Furthermore, the step
counts in the existing tests of `inject_hyperparams` had to be decremented by
one in order for the tests to pass.

PiperOrigin-RevId: 479553657
@hbq1 hbq1 closed this as completed Oct 18, 2022
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