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

friendly error when using rule instead of state #181

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

CarloLucibello
Copy link
Member

No description provided.

src/interface.jl Outdated
Comment on lines 71 to 73
error("""update! must be called with an optimiser state, not a rule.
Call `opt_state = setup(rule, model)` first, then `update!(opt_state, model, grad)`.
""")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error("""update! must be called with an optimiser state, not a rule.
Call `opt_state = setup(rule, model)` first, then `update!(opt_state, model, grad)`.
""")
throw(ArgumentError("""update! must be called with an optimiser state tree, not a rule.
Call `opt_state = setup(rule, model)` first, then `update!(opt_state, model, grad)`.
"""))

To better match language used elsewhere in the docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test needs to change to match, I think.

Co-authored-by: Brian Chen <[email protected]>
@mcabbott
Copy link
Member

mcabbott commented Oct 14, 2024

I like friendly errors, but I think this is going to produce ambiguities with Flux, method 7:

julia> using Flux, Optimisers

julia> methods(Optimisers.update!)
# 8 methods for generic function "update!" from Optimisers:
 [1] update!(x::AbstractArray, x̄)
     @ Flux ~/.julia/packages/Flux/HBF2N/src/deprecations.jl:21
 [2] update!(opt::Flux.Optimise.AbstractOptimiser, ::Params, grads::Union{Tuple, NamedTuple})
     @ Flux ~/.julia/packages/Flux/HBF2N/src/deprecations.jl:175
 [3] update!(opt::Flux.Optimise.AbstractOptimiser, x::AbstractArray, x̄)
     @ Flux.Optimise ~/.julia/packages/Flux/HBF2N/src/optimise/train.jl:22
 [4] update!(opt::Flux.Optimise.AbstractOptimiser, xs::Params, gs)
     @ Flux.Optimise ~/.julia/packages/Flux/HBF2N/src/optimise/train.jl:28
 [5] update!(opt::Flux.Optimise.AbstractOptimiser, model::Chain, grads::Tuple)
     @ Flux ~/.julia/packages/Flux/HBF2N/src/deprecations.jl:169
 [6] update!(opt::Flux.Optimise.AbstractOptimiser, model, grad)
     @ Flux ~/.julia/packages/Flux/HBF2N/src/deprecations.jl:149
 [7] update!(opt, model::Chain, grads::Tuple)
     @ Flux ~/.julia/packages/Flux/HBF2N/src/deprecations.jl:162
 [8] update!(tree, model, grad, higher...)
     @ ~/.julia/packages/Optimisers/yDIWk/src/interface.jl:70

I guess we can fix that in Flux, but should not forget.

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

Successfully merging this pull request may close these issues.

3 participants