Comments (2)
julia> using SLEEF, BenchmarkTools, ForwardDiff
julia> using Zygote: @grad, derivative
[ Info: Precompiling Zygote [e88e6eb3-aa80-5325-afca-941959d7151f]
[ Info: Precompiling IRTools [7869d1d1-7146-5819-86e3-90919afe41df]
julia> @grad SLEEF.sin(x) = (SLEEF.sin(x), Δ -> (Δ * SLEEF.cos(x),))
julia> foo(x) = sin(x)^2 + exp(sin(x)/4)/12.3
foo (generic function with 1 method)
julia> sfoo(x) = SLEEF.sin(x)^2 + exp(SLEEF.sin(x)/4)/12.3
sfoo (generic function with 1 method)
julia> @btime ForwardDiff.derivative(foo, 1.2)
40.227 ns (0 allocations: 0 bytes)
0.6847607046969565
julia> @btime derivative(foo, 1.2)
48.593 ns (1 allocation: 16 bytes)
0.6847607046969566
julia> @btime derivative(sfoo, 1.2)
116.762 ns (1 allocation: 16 bytes)
0.6847607046969566
I wish I could use SLEEF.sincos
like this:
@grad function SLEEF.sin(x)
sinx, cosx = SLEEF.sincos(x)
sinx, cosx
sinx, Δ -> (Δ * cosx, )
end
but that function is very slow.
For what it's worth. SLEEF.sin
and SLEEF.cos
are each about 20ns slower on my computer than sin
and cos
, explaining the difference in run time between sfoo
and foo
.
from zygote.jl.
Ohhh, I misunderstood the section on how to define custom gradients. My mistake.
from zygote.jl.
Related Issues (20)
- `sort(x; rev=true)` is not supported HOT 1
- Incorrect gradients for `plan_rfft(x) * x` HOT 2
- Gradient of scalar function of gradient giving mutating array error HOT 4
- `sum` with CUDA and view on array errors HOT 3
- Cannot take gradient of sort on 2D CuArray HOT 1
- `Ref` and broadcasting issue HOT 2
- Strip zygote frames from mutation error stack trace HOT 1
- Zygote in Julia 1.10+ not reading rrules for default constructors HOT 7
- Few issues in the Zygote Home Page documentation HOT 1
- OOM when computing the gradient in an embarrassingly parallel problem HOT 1
- Pullback over jacobian HOT 6
- `withjacobian` flattens the output when it is a matrix HOT 1
- Gradient wrt to a sparse matrix is mathematically wrong HOT 6
- Increasing memory usage in each call of gradient HOT 1
- Precompilation error in Julia nightly HOT 1
- Gradient involving `LinearAlgebra.tr` errors HOT 1
- Device-to-host copies with GPU code HOT 11
- Inferring `Any` on gradient w.r.t. wrapper of recursive type
- Manually changing the Flux parameters and optimizing using Zygote
- Support try/catch by assuming try branch HOT 4
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.