8000 ERROR `no method matching increment_field!!(::Base.TwicePrecision{Float64}, ::Float64, ::Val{:lo})` · Issue #551 · chalk-lab/Mooncake.jl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ERROR no method matching increment_field!!(::Base.TwicePrecision{Float64}, ::Float64, ::Val{:lo}) #551

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

Open
Moelf opened this issue Apr 13, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@Moelf
Copy link
Moelf commented Apr 13, 2025
function _ff(x, p)
    rx = x ./ 13600
    @. p[1] * (1 - rx)^p[2] * rx^(p[3])
end
DI.gradient(x -> sum(_ff(x, [1.0, 2.0, 3.0])), DI.AutoMooncake(; config=nothing), 100:1:105)

A different backend works:

DI.gradient(x -> sum(_ff(x, [1.0, 2.0, 3.0])), DI.AutoForwardDiff(), 100:1:105)

6-element Vector{Float64}:
 1.1693493343981998e-8
 1.1926169107999864e-8
 1.2161089728860294e-8
 1.2398253829652019e-8
 1.2637660033721705e-8
 1.2879306964673936e-8
@Moelf
Copy link
Author
Moelf commented Apr 13, 2025

Notice, this is wrong:

DI.gradient(x -> sum(_ff(x, [1.0, 2.0, 3.0])), DI.AutoMooncake(; config=nothing), collect(100:1:105))

6-element Vector{Mooncake.NoTangent}:
 Mooncake.NoTangent()
 Mooncake.NoTangent()
 Mooncake.NoTangent()
 Mooncake.NoTangent()
 Mooncake.NoTangent()
 Mooncake.NoTangent()

You have to specifically do:

DI.gradient(x -> sum(_ff(x, [1.0, 2.0, 3.0])), DI.AutoMooncake(; config=nothing), collect(100:1.0:105))

6-element Vector{Float64}:
 1.1693493343982001e-8
 1.1926169107999864e-8
 1.2161089728860293e-8
 1.2398253829652017e-8
 1.2637660033721706e-8
 1.287930696467394e-8

@willtebbutt
Copy link
Collaborator

Thanks for opening this. I'll have a quick look at the first point -- the twice-precision arithmetic interacts in a slightly weird way with Mooncake, so I suspect that your work-around (collecting) the vector is the correct thing to do.

Notice, this is wrong:

This is actually intended behaviour. Mooncake draws a distinction between integers and reals -- gradients w.r.t. integers are always zero.

@willtebbutt
Copy link
Collaborator

I've had a quick look at this -- the source of the problem is some function that's grabbing the lo field of a TwicePrecision. I'll have to have a dig around at some point to figure out what's actually needed here. In the mean time, your collecting strategy seems sensible.

@willtebbutt willtebbutt added the enhancement New feature or request label Apr 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants
0