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

MethodError: (::ProjectTo{NoTangent, @NamedTuple{}})(::Thunk) is ambiguous #685

Open
cossio opened this issue Feb 10, 2025 · 1 comment
Open

Comments

@cossio
Copy link

cossio commented Feb 10, 2025

julia> using Zygote, ChainRules, ChainRulesCore

julia> x = BitArray([0])
julia> _, back = rrule(AbstractArray{Float64}, x)
julia> (::ProjectTo{NoTangent})(::AbstractThunk) = NoTangent()

julia> back([1.0])
(NoTangent(), NoTangent())

julia> back(@thunk([1.0]))
ERROR: MethodError: (::ProjectTo{NoTangent, @NamedTuple{}})(::Thunk{var"#1#2"}) is ambiguous.

CC @oxinabox @mcabbott @ToucheSir

From a conversation on Slack, the fix seems to be to define the method:

(::ProjectTo{NoTangent}(::Thunk) = NoTangent()
@oxinabox
Copy link
Member

You also need

(::ProjectTo{NoTangent}(::AbstractThunk) = NoTangent()

So that the sane thing bug written with
InplaceableThunks doesn't have the same problem.


This should give a performance win,
because it avoids unthunking

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

2 participants