Comments (4)
You can fix this by writing something like sum(x.^2)
instead. Ideally we should just catch sum(f, x)
and implement it with broadcast.
from zygote.jl.
I get the same problem on Julia v1.0 (stable release), Zygote#master
.
Information on whether this is a bug or just incorrect usage would help a lot.
from zygote.jl.
I can confirm that I get the same bug on Julia version 1.0.0, Zygote#master
:
julia> using Zygote
[ Info: Precompiling Zygote [e88e6eb3-aa80-5325-afca-941959d7151f]
[ Info: Precompiling IRTools [7869d1d1-7146-5819-86e3-90919afe41df]
julia> f(x) = -sum(abs2, x)
f (generic function with 1 method)
julia> a = ones(10)
10-element Array{Float64,1}:
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
julia> f(a)
-10.0
julia> f'(a)
ERROR: BoundsError: attempt to access 4-element Array{Int32,1} at index [5]
Stacktrace:
[1] getindex at ./array.jl:731 [inlined]
[2] reverse_ir(::Zygote.Primal) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:296
[3] Zygote.Adjoint(::Zygote.Primal) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:378
[4] #Adjoint#65 at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:382 [inlined]
[5] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:varargs,),Tuple{Nothing}}, ::Type{Zygote.Adjoint}, ::Core.Compiler.IRCode) at ./none:0
[6] _lookup_grad(::Type) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/emit.jl:121
[7] #s18#630 at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface2.jl:17 [inlined]
[8] #s18#630(::Any, ::Any, ::Any) at ./none:0
[9] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:506
[10] f at ./REPL[2]:1 [inlined]
[11] (::Zygote.J{Tuple{typeof(f),Array{Float64,1}},Tuple{typeof(f),Array{Float64,1},getfield(Zygote, Symbol("##701#back2#402")){getfield(Zygote, Symbol("##400#401"))},Zygote.J{Tuple{typeof(sum),typeof(abs2),Array{Float64,1}},Tuple{typeof(sum)}}}})(::Int64) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface2.jl:0
[12] #66 at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:28 [inlined]
[13] gradient at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:34 [inlined]
[14] derivative at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:37 [inlined]
[15] (::getfield(Zygote, Symbol("##68#69")){typeof(f)})(::Array{Float64,1}) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:39
[16] top-level scope at none:0
julia> Zygote.gradient(f, a)
ERROR: BoundsError: attempt to access 4-element Array{Int32,1} at index [5]
Stacktrace:
[1] getindex at ./array.jl:731 [inlined]
[2] reverse_ir(::Zygote.Primal) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:296
[3] Zygote.Adjoint(::Zygote.Primal) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:378
[4] #Adjoint#65 at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:382 [inlined]
[5] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:varargs,),Tuple{Nothing}}, ::Type{Zygote.Adjoint}, ::Core.Compiler.IRCode) at ./none:0
[6] _lookup_grad(::Type) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/emit.jl:121
[7] #s18#630 at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface2.jl:17 [inlined]
[8] #s18#630(::Any, ::Any, ::Any) at ./none:0
[9] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:506
[10] f at ./REPL[2]:1 [inlined]
[11] (::Zygote.J{Tuple{typeof(f),Array{Float64,1}},Tuple{typeof(f),Array{Float64,1},getfield(Zygote, Symbol("##701#back2#402")){getfield(Zygote, Symbol("##400#401"))},Zygote.J{Tuple{typeof(sum),typeof(abs2),Array{Float64,1}},Tuple{typeof(sum)}}}})(::Int64) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface2.jl:0
[12] (::getfield(Zygote, Symbol("##66#67")){Zygote.J{Tuple{typeof(f),Array{Float64,1}},Tuple{typeof(f),Array{Float64,1},getfield(Zygote, Symbol("##701#back2#402")){getfield(Zygote, Symbol("##400#401"))},Zygote.J{Tuple{typeof(sum),typeof(abs2),Array{Float64,1}},Tuple{typeof(sum)}}}}})(::Int64) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:28
[13] gradient(::Function, ::Array{Float64,1}) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:34
[14] top-level scope at none:0
julia> Zygote.derivative(f, a)
ERROR: BoundsError: attempt to access 4-element Array{Int32,1} at index [5]
Stacktrace:
[1] getindex at ./array.jl:731 [inlined]
[2] reverse_ir(::Zygote.Primal) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:296
[3] Zygote.Adjoint(::Zygote.Primal) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:378
[4] #Adjoint#65 at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/reverse.jl:382 [inlined]
[5] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:varargs,),Tuple{Nothing}}, ::Type{Zygote.Adjoint}, ::Core.Compiler.IRCode) at ./none:0
[6] _lookup_grad(::Type) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/emit.jl:121
[7] #s18#630 at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface2.jl:17 [inlined]
[8] #s18#630(::Any, ::Any, ::Any) at ./none:0
[9] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:506
[10] f at ./REPL[2]:1 [inlined]
[11] (::Zygote.J{Tuple{typeof(f),Array{Float64,1}},Tuple{typeof(f),Array{Float64,1},getfield(Zygote, Symbol("##701#back2#402")){getfield(Zygote, Symbol("##400#401"))},Zygote.J{Tuple{typeof(sum),typeof(abs2),Array{Float64,1}},Tuple{typeof(sum)}}}})(::Int64) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface2.jl:0
[12] (::getfield(Zygote, Symbol("##66#67")){Zygote.J{Tuple{typeof(f),Array{Float64,1}},Tuple{typeof(f),Array{Float64,1},getfield(Zygote, Symbol("##701#back2#402")){getfield(Zygote, Symbol("##400#401"))},Zygote.J{Tuple{typeof(sum),typeof(abs2),Array{Float64,1}},Tuple{typeof(sum)}}}}})(::Int64) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:28
[13] gradient(::Function, ::Array{Float64,1}) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:34
[14] derivative(::Function, ::Array{Float64,1}) at /Users/dilum/.julia/packages/Zygote/tOamD/src/compiler/interface.jl:37
[15] top-level scope at none:0
from zygote.jl.
Thanks for confirming this. Is this something that is supposed to work though? I am not sure I am using the package right.
from zygote.jl.
Related Issues (20)
- Zygote-0.6.64 precompile error with julia-1.9.3 HOT 1
- `repeat(X; outer, inner)` triggers scalar indexing error with CUDA HOT 1
- Missing support for muladd in case of brodcasting with a complex argument HOT 1
- `nothing` in output of a `pullback` HOT 2
- Assignment to multiple arrays is not differentiable on GPU since Zygote.jl 0.6.67 HOT 5
- Spurious "Output is complex, so the gradient is not defined" error HOT 2
- NaN in gradient of abs() on complex 0 HOT 1
- Pullback on mean() gives illegal memory access code 700 HOT 32
- test
- Type unstable gradients (@code_warntype) HOT 1
- Type unstable gradients HOT 1
- Zygote gradients different from ForwardDiff/ReverseDiff on Julia 1.10-rc2 HOT 3
- try/catch is not supported when attempting to use `remake` with Zygote HOT 1
- gradient of SVD not working for complex input HOT 1
- `Zygote` doesn't properly work with `Metal.jl` and half precision. HOT 4
- `gradient` broken for `(*)(::Diagonal{Real}, ::Matrix{Complex}, ::Diagonal{Real})` when updating Julia 1.8 -> 1.9 HOT 6
- Method ambiguities reported by Aqua
- slow/high allocation gradient with mapreduce and iterators HOT 11
- error in summation of product iterator HOT 2
- `sort(x; rev=true)` is not supported HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zygote.jl.