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

fix epsilon for Float16 #190

Merged
merged 5 commits into from
Nov 7, 2024
Merged

fix epsilon for Float16 #190

merged 5 commits into from
Nov 7, 2024

Conversation

CarloLucibello
Copy link
Member

Fix #167 adding ϵ = max(ϵ, eps(T(0))).

Also fix #189

@CarloLucibello CarloLucibello added this to the 0.4 milestone Nov 6, 2024
src/rules.jl Outdated
Comment on lines 133 to 134
η, ρ, ϵ = T(o.eta), T(o.rho), T(o.epsilon)
ϵ = max(ϵ, eps(T(0)))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this does the right thing:

julia> eps(Float32)  # roughly what we hard-code now
1.1920929f-7

julia> eps(0f0)  # what this PR uses
1.0f-45

I think a better pattern is this:

Suggested change
η, ρ, ϵ = T(o.eta), T(o.rho), T(o.epsilon)
ϵ = max(ϵ, eps(T(0)))
η, ρ, ϵ = T(o.eta), T(o.rho), max(T(o.epsilon), eps(T))

Copy link
Member Author

Choose a reason for hiding this comment

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

I chose eps(T(0)) because i didn't want to change the current behavior eps=1f-8 for Float32 but do the minimal change needed for Float16

julia> eps(Float16)
Float16(0.000977)

julia> eps(Float16(0))
Float16(6.0e-8)

Copy link
Member

Choose a reason for hiding this comment

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

Ok. How broadly is 6e-8 big enough for this purpose? It seems a little random... maybe I'd be happier to hard-code an obviously chosen number, which is what 1e-8 is... like _eps(::Type{Float16}, e) = max(1e-7, e)?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

src/Optimisers.jl Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@CarloLucibello CarloLucibello merged commit 4a78a55 into master Nov 7, 2024
3 of 4 checks passed
mashu pushed a commit to mashu/Optimisers.jl that referenced this pull request Nov 14, 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
3 participants