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

Incorrect nothing gradient #1538

Closed
juliohm opened this issue Nov 8, 2024 · 4 comments
Closed

Incorrect nothing gradient #1538

juliohm opened this issue Nov 8, 2024 · 4 comments

Comments

@juliohm
Copy link

juliohm commented Nov 8, 2024

MWE:

julia> using Zygote

julia> f(x, y) = y
f (generic function with 1 method)

julia> gradient(f, 0, 0)
(nothing, 1.0)

On a fresh environment with the latest stable release of Zygote.jl

@CarloLucibello
Copy link
Member

Zygote can return nothing in place of zero, this is expected

@juliohm
Copy link
Author

juliohm commented Nov 8, 2024

Thank you @CarloLucibello for clarifying this. Shouldn't this nothing value be handled for end-users though with multiple dispatch? It becomes difficult to write generic math when nothing is returned sometimes.

As people suggested on Zulip, one could define:

denothing(x) = x
denothing(::Nothing) = 0.0

to automatically return 0.0 in all cases?

@CarloLucibello
Copy link
Member

Nothing can be returned in correspondence of variables of any type (numbers, arrays, custom types) so take that into account.

@juliohm
Copy link
Author

juliohm commented Nov 8, 2024

Should there be a special Zero singleton type that behaves like zero every time? Why can't we rely on zero(T) for example?

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