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

Not using "strong zeros" for deriatives of constant values #278

Open
MasonProtter opened this issue Mar 11, 2024 · 1 comment
Open

Not using "strong zeros" for deriatives of constant values #278

MasonProtter opened this issue Mar 11, 2024 · 1 comment

Comments

@MasonProtter
Copy link
Contributor

Compare:

julia> using Diffractor, Zygote

julia> var"'"(f) = Zygote.var"'"(f);

julia> exp'(Inf)
Inf

julia> exp''(Inf)
Inf

with

julia> var"'"(f) = Diffractor.PrimeDerivativeFwd(f);

julia> exp'(Inf)
Inf

julia> exp''(Inf)
NaN

You can see in the code_typed that it appears to be subtracting 0.0 * exp(x)^2 from the answer of 1.0 * exp(x), causing the NaN. Ideally this'd instead be 1.0 * exp(x) - ZeroTangent()*exp(x)^2 so that we don't get the NaN.

@oxinabox
Copy link
Member

We used to have this.
We broke this in #189 in order to get type stability.
Because we wanted branches that returned the same type on each side to also have the same partial on each side.
And this is not the case if branches with literals on one side return strong ZeroTangent but branches with nonliteral values do not. e.g relu(x) = x > 0 ? 0.0 : x

Not having that type stability is in theory fine, but in practice the small unions optimization often failed, causing 100x slowdown.
I would like to have our cake and eat it too, but I am not sure how.
One possibility is special inference pass, which @Keno and I talked about at JuliaCon.

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