Comments (6)
When you time with @btime
use $
, e.g. @btime Bijectors.forward($cb, $x)
from bijectors.jl.
Looks great to me.
BTW can someone explain a bit on the benchmark time difference with and without $
?
from bijectors.jl.
Also, we'll still keep the "simple" iterative implementation. So we have two different ways of constructing a Composed
; using a Tuple
or Array
. Using Tuple
gives type-stable implementations using @generated
, using Array
gives unstable iterative implementations.
from bijectors.jl.
Nice work @torfjelde . Could you provide some benchmarks for vector-valued transformations? I would imagine that these are where we're most likely to see deeply nested structures, so it would be interesting to know if the performance gains persist here or not.
from bijectors.jl.
It does but actual transformation-cost of course reduces the difference:
julia> using Bijectors: PlanarLayer
julia> b = PlanarLayer(10);
julia> x = randn(10);
julia> @btime Bijectors.forward($cb, $x)
2.912 μs (47 allocations: 4.63 KiB)
(rv = [-0.226818, -5.05146, -1.45391, 2.3923, 2.71439, 1.76895, -0.988026, 1.12392, 3.00605, -2.77136], logabsdetjac = -0.019665352458356412)
julia> @btime Bijectors.forward_gen($cb, $x)
2.922 μs (47 allocations: 4.63 KiB)
(rv = [-0.226818, -5.05146, -1.45391, 2.3923, 2.71439, 1.76895, -0.988026, 1.12392, 3.00605, -2.77136], logabsdetjac = -0.019665352458356412)
julia> @btime Bijectors.forward_it($cb, $x)
3.305 μs (49 allocations: 4.73 KiB)
(rv = [-0.226818, -5.05146, -1.45391, 2.3923, 2.71439, 1.76895, -0.988026, 1.12392, 3.00605, -2.77136], logabsdetjac = -0.019665352458356412)
and for deep ones where recursion is no longer inlined:
julia> cb = foldl(∘, [b for i = 1:50]);
julia> @btime Bijectors.forward($cb, $x)
116.340 μs (1299 allocations: 128.05 KiB)
(rv = [0.56373, -8.38962, -2.83878, 3.42109, 4.44716, 2.13511, -0.910896, 2.02499, 4.82258, -3.82649], logabsdetjac = -168.86605036964167)
julia> @btime Bijectors.forward_gen($cb, $x)
70.403 μs (1151 allocations: 114.88 KiB)
(rv = [0.56373, -8.38962, -2.83878, 3.42109, 4.44716, 2.13511, -0.910896, 2.02499, 4.82258, -3.82649], logabsdetjac = -168.86605036964167)
julia> @btime Bijectors.forward_it($cb, $x)
75.723 μs (1153 allocations: 115.84 KiB)
(rv = [0.56373, -8.38962, -2.83878, 3.42109, 4.44716, 2.13511, -0.910896, 2.02499, 4.82258, -3.82649], logabsdetjac = -168.86605036964167)
A further test, also including an extreme case of Stacked
from #36 (which also uses @generated
for forward
to get type-stability)
julia> using Bijectors, BenchmarkTools
julia> using Bijectors: Logit
julia> D = 100
100
julia> sb = Stacked(tuple([Logit(0.0, 1.0) for i = 1:D]...));
julia> bs = [
("PlanarLayer($D)", PlanarLayer(D)),
("RadialLayer($D)", RadialLayer(D)),
("Stacked{Logit ∘ inv(Logit), $D}", sb ∘ inv(sb))
];
julia> x = randn(D);
julia> for (name, b) in bs
@info "$(name): b ∘ b"
cb = b ∘ b
@btime Bijectors.forward($cb, $x)
@btime Bijectors.forward_gen($cb, $x)
@btime Bijectors.forward_it($cb, $x)
N = 50
@info "$(name): b ∘ b ∘ ... ∘ b ($N times)"
cb = foldl(∘, [b for i = 1:N])
@btime Bijectors.forward($cb, $x)
@btime Bijectors.forward_gen($cb, $x)
@btime Bijectors.forward_it($cb, $x)
end
[ Info: PlanarLayer(100): b ∘ b
4.746 μs (47 allocations: 14.69 KiB)
4.758 μs (47 allocations: 14.69 KiB)
5.091 μs (49 allocations: 14.80 KiB)
[ Info: PlanarLayer(100): b ∘ b ∘ ... ∘ b (50 times)
162.648 μs (1299 allocations: 379.61 KiB)
116.781 μs (1151 allocations: 366.44 KiB)
119.156 μs (1153 allocations: 367.41 KiB)
[ Info: RadialLayer(100): b ∘ b
3.263 μs (35 allocations: 8.53 KiB)
3.287 μs (35 allocations: 8.53 KiB)
3.642 μs (37 allocations: 8.64 KiB)
[ Info: RadialLayer(100): b ∘ b ∘ ... ∘ b (50 times)
131.128 μs (999 allocations: 225.70 KiB)
82.406 μs (851 allocations: 212.53 KiB)
85.703 μs (853 allocations: 213.50 KiB)
[ Info: Stacked{Logit ∘ inv(Logit), 100}: b ∘ b
69.882 μs (2009 allocations: 194.28 KiB)
70.363 μs (2009 allocations: 194.28 KiB)
82.146 μs (2028 allocations: 260.78 KiB)
[ Info: Stacked{Logit ∘ inv(Logit), 100}: b ∘ b ∘ ... ∘ b (50 times)
9.063 ms (55549 allocations: 35.88 MiB)
1.830 ms (50201 allocations: 4.74 MiB)
7.016 ms (50700 allocations: 35.88 MiB)
from bijectors.jl.
Closed by #52
from bijectors.jl.
Related Issues (20)
- Remove heavy usage of `@generated` HOT 2
- Add `rng` to have the reproducibility in `PlanarLayer` and `RadialLayer`
- `logpdf` of `UnivariateTransformed` produces `StackOverflowError` HOT 7
- Zygote is broken for `Stacked` bijectors HOT 5
- filldist, up1 not defined HOT 6
- Adding bijectors for OrderStatistic and JointOrderStatistics HOT 1
- Add API function to retrieve size of bijector output from bijector input HOT 1
- rational quadratic flows not supporting Float32 input HOT 1
- What to do with `CorrBijector` ? HOT 1
- Improve `PDVecBijector`
- Matrix factorization bijectors HOT 4
- Domain Error for VecCholeskyBijector bijector when calling logabsdetjac HOT 4
- Question on simplex bijector implementation HOT 9
- Can't apply Bijectors.ordered to TDist() and MvTDist() HOT 1
- Incorrect bijector for heterogeneous Product distribution HOT 3
- Radial flow to a simplex HOT 5
- Stackoverflow in custom bijector HOT 2
- Missing implementation of `Bijectors.bijector` for `arraydist` distributions. HOT 1
- Bijectors.ordered and MvLogNormal interaction .. only supported for unconstrained distributions. HOT 1
- `TruncatedBijectors` not defined in `Distributions` extension
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 bijectors.jl.