-
Notifications
You must be signed in to change notification settings - Fork 0
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
Tor/benchmark update #17
Changes from all commits
57b5d47
e7c0a76
60ec2c8
eb1b83c
d8afa71
5bb48d2
02484cf
5c59769
f1f1381
a48553a
f2dc062
fa675de
3962da2
53dc571
f5705d5
7f569f7
4a06150
a1cc6bf
3e7e200
c867ae8
96f120b
0460b64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Benchmarking | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
benchmark: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Julia | ||
uses: julia-actions/setup-julia@v2 | ||
with: | ||
version: '1' | ||
|
||
- name: Install Dependencies | ||
run: julia --project=benchmarks/ -e 'using Pkg; Pkg.instantiate()' | ||
|
||
- name: Run Benchmarks and Generate Reports | ||
run: julia --project=benchmarks/ -e 'using DynamicPPLBenchmarks; weave_benchmarks()' | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./benchmarks/results | ||
publish_branch: gh-pages |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,14 +1,14 @@ | ||||||||||||||
```julia | ||||||||||||||
@time model_def(data)(); | ||||||||||||||
@time model_def(data...)(); | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia | ||||||||||||||
m = time_model_def(model_def, data); | ||||||||||||||
m = time_model_def(model_def, data...); | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia | ||||||||||||||
suite = make_suite(m); | ||||||||||||||
results = run(suite); | ||||||||||||||
results = run(suite; seconds=WEAVE_ARGS[:seconds]); | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia | ||||||||||||||
|
@@ -19,13 +19,37 @@ results["evaluation_untyped"] | |||||||||||||
results["evaluation_typed"] | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia | ||||||||||||||
let k = "evaluation_simple_varinfo_nt" | ||||||||||||||
haskey(results, k) && results[k] | ||||||||||||||
end | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia | ||||||||||||||
let k = "evaluation_simple_varinfo_componentarray" | ||||||||||||||
haskey(results, k) && results[k] | ||||||||||||||
end | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia | ||||||||||||||
let k = "evaluation_simple_varinfo_dict" | ||||||||||||||
haskey(results, k) && results[k] | ||||||||||||||
end | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia | ||||||||||||||
let k = "evaluation_simple_varinfo_dict_from_nt" | ||||||||||||||
haskey(results, k) && results[k] | ||||||||||||||
end | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia; echo=false; results="hidden"; | ||||||||||||||
BenchmarkTools.save( | ||||||||||||||
joinpath("results", WEAVE_ARGS[:name], "$(nameof(m))_benchmarks.json"), results | ||||||||||||||
) | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia; wrap=false | ||||||||||||||
```julia; wrap=false; echo=false | ||||||||||||||
if WEAVE_ARGS[:include_typed_code] | ||||||||||||||
typed = typed_code(m) | ||||||||||||||
end | ||||||||||||||
|
@@ -34,16 +58,15 @@ end | |||||||||||||
```julia; echo=false; results="hidden" | ||||||||||||||
if WEAVE_ARGS[:include_typed_code] | ||||||||||||||
# Serialize the output of `typed_code` so we can compare later. | ||||||||||||||
haskey(WEAVE_ARGS, :name) && | ||||||||||||||
serialize(joinpath("results", WEAVE_ARGS[:name], "$(nameof(m)).jls"), string(typed)) | ||||||||||||||
haskey(WEAVE_ARGS, :name) && serialize(joinpath("results", WEAVE_ARGS[:name],"$(nameof(m)).jls"), string(typed)); | ||||||||||||||
end | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```julia; wrap=false; echo=false; | ||||||||||||||
if haskey(WEAVE_ARGS, :name_old) | ||||||||||||||
if WEAVE_ARGS[:include_typed_code] && haskey(WEAVE_ARGS, :name_old) | ||||||||||||||
# We want to compare the generated code to the previous version. | ||||||||||||||
using DiffUtils: DiffUtils | ||||||||||||||
typed_old = deserialize(joinpath("results", WEAVE_ARGS[:name_old], "$(nameof(m)).jls")) | ||||||||||||||
DiffUtils.diff(typed_old, string(typed); width=130) | ||||||||||||||
import DiffUtils | ||||||||||||||
typed_old = deserialize(joinpath("results", WEAVE_ARGS[:name_old], "$(nameof(m)).jls")); | ||||||||||||||
DiffUtils.diff(typed_old, string(typed), width=130) | ||||||||||||||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
end | ||||||||||||||
``` | ||||||||||||||
``` | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,36 +1,43 @@ | ||||||
# Benchmarks | ||||||
`j display("text/markdown", "## $(WEAVE_ARGS[:name]) ##")` | ||||||
|
||||||
## Setup | ||||||
### Setup | ||||||
|
||||||
```julia | ||||||
using BenchmarkTools, DynamicPPL, Distributions, Serialization | ||||||
``` | ||||||
|
||||||
```julia | ||||||
import DynamicPPLBenchmarks: time_model_def, make_suite, typed_code, weave_child | ||||||
using DynamicPPLBenchmarks | ||||||
using DynamicPPLBenchmarks: time_model_def, make_suite, typed_code, weave_child | ||||||
``` | ||||||
|
||||||
## Models | ||||||
### Environment | ||||||
|
||||||
### `demo1` | ||||||
```julia; echo=false; skip="notebook" | ||||||
DynamicPPLBenchmarks.display_environment() | ||||||
``` | ||||||
|
||||||
### Models | ||||||
|
||||||
#### `demo1` | ||||||
|
||||||
```julia | ||||||
@model function demo1(x) | ||||||
m ~ Normal() | ||||||
x ~ Normal(m, 1) | ||||||
|
||||||
return (m=m, x=x) | ||||||
return (m = m, x = x) | ||||||
end | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
|
||||||
model_def = demo1; | ||||||
data = 1.0; | ||||||
data = (1.0,); | ||||||
``` | ||||||
|
||||||
```julia; results="markup"; echo=false | ||||||
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | ||||||
``` | ||||||
|
||||||
### `demo2` | ||||||
#### `demo2` | ||||||
|
||||||
```julia | ||||||
@model function demo2(y) | ||||||
|
@@ -43,17 +50,19 @@ weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | |||||
# Heads or tails of a coin are drawn from a Bernoulli distribution. | ||||||
y[n] ~ Bernoulli(p) | ||||||
end | ||||||
|
||||||
return (; p) | ||||||
end | ||||||
|
||||||
model_def = demo2; | ||||||
data = rand(0:1, 10); | ||||||
data = (rand(0:1, 10),); | ||||||
``` | ||||||
|
||||||
```julia; results="markup"; echo=false | ||||||
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | ||||||
``` | ||||||
|
||||||
### `demo3` | ||||||
#### `demo3` | ||||||
|
||||||
```julia | ||||||
@model function demo3(x) | ||||||
|
@@ -76,7 +85,8 @@ weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | |||||
k[i] ~ Categorical(w) | ||||||
x[:, i] ~ MvNormal([μ[k[i]], μ[k[i]]], 1.0) | ||||||
end | ||||||
return k | ||||||
|
||||||
return (; μ1, μ2, k) | ||||||
end | ||||||
|
||||||
model_def = demo3 | ||||||
|
@@ -88,43 +98,99 @@ N = 30 | |||||
μs = [-3.5, 0.0] | ||||||
|
||||||
# Construct the data points. | ||||||
data = mapreduce(c -> rand(MvNormal([μs[c], μs[c]], 1.0), N), hcat, 1:2); | ||||||
data = (mapreduce(c -> rand(MvNormal([μs[c], μs[c]], 1.0), N), hcat, 1:2),); | ||||||
``` | ||||||
|
||||||
```julia; echo=false | ||||||
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | ||||||
``` | ||||||
|
||||||
### `demo4`: loads of indexing | ||||||
#### `demo4`: lots of variables | ||||||
|
||||||
```julia | ||||||
@model function demo4_1k(::Type{TV}=Vector{Float64}) where {TV} | ||||||
m ~ Normal() | ||||||
x = TV(undef, 1_000) | ||||||
for i in eachindex(x) | ||||||
x[i] ~ Normal(m, 1.0) | ||||||
end | ||||||
|
||||||
return (; m, x) | ||||||
end | ||||||
|
||||||
model_def = demo4_1k | ||||||
data = (); | ||||||
``` | ||||||
|
||||||
```julia; echo=false | ||||||
weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS) | ||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
|
||||||
```julia | ||||||
@model function demo4(n, ::Type{TV}=Vector{Float64}) where {TV} | ||||||
@model function demo4_10k(::Type{TV}=Vector{Float64}) where {TV} | ||||||
m ~ Normal() | ||||||
x = TV(undef, n) | ||||||
x = TV(undef, 10_000) | ||||||
for i in eachindex(x) | ||||||
x[i] ~ Normal(m, 1.0) | ||||||
end | ||||||
|
||||||
return (; m, x) | ||||||
end | ||||||
|
||||||
model_def = demo4 | ||||||
data = (100_000,); | ||||||
model_def = demo4_10k | ||||||
data = (); | ||||||
``` | ||||||
|
||||||
```julia; echo=false | ||||||
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | ||||||
``` | ||||||
|
||||||
```julia | ||||||
@model function demo4_dotted(n, ::Type{TV}=Vector{Float64}) where {TV} | ||||||
@model function demo4_100k(::Type{TV}=Vector{Float64}) where {TV} | ||||||
m ~ Normal() | ||||||
x = TV(undef, n) | ||||||
return x .~ Normal(m, 1.0) | ||||||
x = TV(undef, 100_000) | ||||||
for i in eachindex(x) | ||||||
x[i] ~ Normal(m, 1.0) | ||||||
end | ||||||
|
||||||
return (; m, x) | ||||||
end | ||||||
|
||||||
model_def = demo4_dotted | ||||||
data = (100_000,); | ||||||
model_def = demo4_100k | ||||||
data = (); | ||||||
``` | ||||||
|
||||||
```julia; echo=false | ||||||
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | ||||||
``` | ||||||
|
||||||
#### `demo4_dotted`: `.~` for large number of variables | ||||||
|
||||||
```julia | ||||||
@model function demo4_100k_dotted(::Type{TV}=Vector{Float64}) where {TV} | ||||||
m ~ Normal() | ||||||
x = TV(undef, 100_000) | ||||||
x .~ Normal(m, 1.0) | ||||||
|
||||||
return (; m, x) | ||||||
end | ||||||
|
||||||
model_def = demo4_100k_dotted | ||||||
data = (); | ||||||
``` | ||||||
|
||||||
```julia; echo=false | ||||||
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS) | ||||||
``` | ||||||
|
||||||
```julia; echo=false | ||||||
if haskey(WEAVE_ARGS, :name_old) | ||||||
display(MIME"text/markdown"(), "## Comparison with $(WEAVE_ARGS[:name_old]) ##") | ||||||
end | ||||||
``` | ||||||
|
||||||
```julia; echo=false | ||||||
if haskey(WEAVE_ARGS, :name_old) | ||||||
DynamicPPLBenchmarks.judgementtable(WEAVE_ARGS[:name], WEAVE_ARGS[:name_old]) | ||||||
end | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶