-
Notifications
You must be signed in to change notification settings - Fork 63
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
ProjectTo access to undefined reference #579
Comments
Can you give more context? I don't think it makes much sense to track gradients with respect to undefined quantities. |
I have quite a bit of code that I would like to differentiate through, but it seems fairly cumbersome to avoid mutation. As a workaround I tried this quick'n dirty hack:
the plan is to then write a macro that automatically translate setindex! calls to _setindex This then runs into the mentioned error, as in my code I currently initialize a Vector{T}(undef,length), and then fill it up with _setindex. Zygote wants to calculate the adjoint of _setindex, which calls ProjectTo. I'm not sure at what level I should tackle this - I can either try to fix _setindex, or maybe this can be solved at the level of chainrules? |
Alternatively, is there a more canonical workaround? It seems more people require something like this ( https://gist.github.com/sdewaele/9a9c705eb4e8da9d798056d18d04c383 , https://discourse.julialang.org/t/zygote-and-setindex/44554 ). I tried to fix it like :
but this function also doesn't work (aside from JuliaLang/julia#45633 ) I give it something with type T subtyping AbstractArray, and I get a projector to AbstractArrays (no attempt is made at restoring T). Then, the tangent type I give it in my function is something constructed by Zygote (a Tangent - namedtuple), which in turn simply passes through the tangent. The Tangent type itself is also problematic - it's a Tangent{Any,...}... - so it somehow lost its primal type. How do I properly hook into chainrulescore to prevent this? Is there documentation that I am missing? I have a very simple type that pretty much acts like an abstractarray, and I want the tangent types to be of the same type (or at least to be indexeable) |
I feel handling things containing
Except it is monkeypatching the basic behavour what is wrong is that it is defining only the constructor for the
Zygote always does this. it isn't on you.
https://juliadiff.org/ChainRulesCore.jl/dev/rule_author/superpowers/projectto.html We should get documentation |
I don't know what to make of undef in the primal. But I do wonder whether we ought to simplify ProjectTo in a way which would probably solve this: Maybe we should just let it ignore the contents of a container. Arrays of non-numbers to start with, possibly tuples, etc too. Whatever operations act on their contents should already impose projection, and perhaps there is no need to do it again? This would mean removing the methods which store an array of projections. That always seems like quite a lot of overhead (although I have not benchmarked anything). It would also mean that containers like this could be left alone, rather than being julia> ProjectTo(eachcol(rand(2,3)))(eachcol(ones(2,3))) # 1.9, destroys Slices
3-element Vector{SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}:
[1.0, 1.0]
[1.0, 1.0]
[1.0, 1.0] This would, I think, incidentally remove the undef error above. |
fails, as ProjectTo tries to iterate the elements of the vector, which are not defined
The text was updated successfully, but these errors were encountered: