Comments (4)
From the compiler's perspective this is not so simple :) x^2
actually lowers to something like Base.literal_pow(x, Val(2))
– I just pushed a fix to make sure we're handling that properly. The a+b+c
also involves handling varargs and apply
, which for now is slow; but you can avoid that with (a+b)+c
.
Another sticky point about benchmarking Zygote – for reasons I don't fully understand, but which are probably to do with world ages and function visibility, the optimisations don't kick in properly unless you run things once and then refresh()
. For example, this timing script gives results in under 2ns, whereas a simpler version gives more like 1mus.
using Zygote, BenchmarkTools
using Zygote: gradient
f(x) = (3x^2+2x)+1
gradient(f, 5)
Zygote.refresh()
gradient(f, 5)
@benchmark gradient(f, 5)
from zygote.jl.
I am getting a minor performance improvement, but still around 1 microsecond.
julia> using Zygote, BenchmarkTools
[ Info: Recompiling stale cache file /home/chris/.julia/compiled/v1.0/BenchmarkTools/ZXPQo.ji for BenchmarkTools [6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf]
julia> using Zygote: gradient
julia> f(x) = (3x^2+2x)+1
f (generic function with 1 method)
julia> gradient(f, 5)
(32.0,)
julia> @benchmark gradient(f, 5)
BenchmarkTools.Trial:
memory estimate: 1.73 KiB
allocs estimate: 51
--------------
minimum time: 1.563 μs (0.00% GC)
median time: 1.660 μs (0.00% GC)
mean time: 2.334 μs (26.69% GC)
maximum time: 4.647 ms (99.91% GC)
--------------
samples: 10000
evals/sample: 10
julia> Zygote.refresh()
julia> gradient(f, 5)
(32.0,)
julia> @benchmark gradient(f, 5)
BenchmarkTools.Trial:
memory estimate: 1.23 KiB
allocs estimate: 33
--------------
minimum time: 1.159 μs (0.00% GC)
median time: 1.223 μs (0.00% GC)
mean time: 1.987 μs (35.79% GC)
maximum time: 4.913 ms (99.92% GC)
--------------
samples: 10000
evals/sample: 10
julia> Zygote.refresh()
julia> @benchmark gradient(f, 5)
BenchmarkTools.Trial:
memory estimate: 1.23 KiB
allocs estimate: 33
--------------
minimum time: 1.117 μs (0.00% GC)
median time: 1.197 μs (0.00% GC)
mean time: 1.961 μs (36.38% GC)
maximum time: 4.905 ms (99.93% GC)
--------------
samples: 10000
evals/sample: 10
julia> versioninfo()
Julia Version 1.0.0
Commit ece21e1ae5 (2018-08-29 14:15 UTC)
from zygote.jl.
I got this down to a few hundred ns; not perfect, but at least that gets rid of all the really dumb issues.
For now, you'll need the Julia branch mentioned on the readme to get really good performance. I'm hoping to fix that for many more cases in future.
from zygote.jl.
Note that
julia> versioninfo()
Julia Version 1.0.0
Commit ece21e1ae5 (2018-08-29 14:15 UTC)
is the latest commit on this branch: https://github.com/JuliaLang/julia/tree/mji/zygote
I'll rebuild next time I notice you've pushed updates and test again.
EDIT:
I was accidentally not on Zygote master.
julia> using Zygote, BenchmarkTools
julia> using Zygote: gradient
julia> f(x) = (3x^2+2x)+1
f (generic function with 1 method)
julia> gradient(f, 5)
(32,)
julia> @benchmark gradient(f, 5)
BenchmarkTools.Trial:
memory estimate: 672 bytes
allocs estimate: 23
--------------
minimum time: 424.166 ns (0.00% GC)
median time: 458.955 ns (0.00% GC)
mean time: 592.181 ns (20.64% GC)
maximum time: 249.501 μs (99.78% GC)
--------------
samples: 10000
evals/sample: 199
julia> Zygote.refresh()
julia> gradient(f, 5)
(32,)
julia> @benchmark gradient(f, 5)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 1.232 ns (0.00% GC)
median time: 1.252 ns (0.00% GC)
mean time: 1.276 ns (0.00% GC)
maximum time: 1.724 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
from zygote.jl.
Related Issues (20)
- `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 31
- 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
- Incorrect gradients for `plan_rfft(x) * x` HOT 2
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.