FluxML / Zygote.jl

21st century AD
https://fluxml.ai/Zygote.jl/
Other
1.48k stars 213 forks source link

Zygote's `gradient` returns `nothing` on the example mentioned in the tutorial #1186

Open vinsis opened 2 years ago

vinsis commented 2 years ago

Link to tutorial: https://fluxml.ai/Zygote.jl/latest/

Julia version: v1.7 Zygote version: v0.6.36

mcabbott commented 2 years ago

The problematic step seems to be the conversion to Lab space:

julia> using Zygote, Colors

julia> gradient(x -> abs2(x.r), RGB(1, 0, 0))  # weird numbers are OK
((r = 0.996N0f8, g = nothing, b = nothing),)

julia> @less Colors._colordiff(RGB(1, 0, 0), RGB(0, 1, 0), Colors.DE_2000())  # converts

julia> gradient(x -> convert(Lab, x).l, RGB(1, 0, 0))
(nothing,)
vinsis commented 2 years ago

I see. Did something change in Colors or Zygote? If this is expected behavior, I guess we should remove the example from the website.

mcabbott commented 2 years ago

Yes, I assume something changed. You can try different versions to bisect where & when, since I assume it worked when the docs were first written.