-
Notifications
You must be signed in to change notification settings - Fork 32
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
Improvements to DynamicPPLBenchmarks #346
base: master
Are you sure you want to change the base?
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
a8541b5
0291c2f
6f255d1
3b5e448
1e61025
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 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using DynamicPPL | ||
using DynamicPPLBenchmarks | ||
using BenchmarkTools | ||
using TuringBenchmarking | ||
using Distributions | ||
using PrettyTables | ||
|
||
# Define models | ||
@model function demo1(x) | ||
m ~ Normal() | ||
x ~ Normal(m, 1) | ||
return (m = m, x = x) | ||
shravanngoswamii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
@model function demo2(y) | ||
p ~ Beta(1, 1) | ||
N = length(y) | ||
for n in 1:N | ||
y[n] ~ Bernoulli(p) | ||
end | ||
return (; p) | ||
end | ||
|
||
demo1_data = randn() | ||
demo2_data = rand(Bool, 10) | ||
|
||
# Create model instances with the data | ||
demo1_instance = demo1(demo1_data) | ||
demo2_instance = demo2(demo2_data) | ||
|
||
# Define available AD backends | ||
available_ad_backends = Dict( | ||
:forwarddiff => :forwarddiff, | ||
:reversediff => :reversediff, | ||
:zygote => :zygote | ||
) | ||
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. This seems unnecessary and unused. |
||
|
||
# Define available VarInfo types. | ||
# Each entry is (Name, function to produce the VarInfo) | ||
available_varinfo_types = Dict( | ||
:untyped => ("UntypedVarInfo", VarInfo), | ||
:typed => ("TypedVarInfo", m -> VarInfo(m)), | ||
:simple_namedtuple => ("SimpleVarInfo (NamedTuple)", m -> SimpleVarInfo{Float64}(m())), | ||
:simple_dict => ("SimpleVarInfo (Dict)", m -> begin | ||
retvals = m() | ||
varnames = map(keys(retvals)) do k | ||
VarName{k}() | ||
end | ||
SimpleVarInfo{Float64}(Dict(zip(varnames, values(retvals)))) | ||
end) | ||
) | ||
Comment on lines
+38
to
+51
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. This seems unnecessary and unused. |
||
|
||
# Specify the combinations to test: | ||
# (Model Name, model instance, VarInfo choice, AD backend) | ||
chosen_combinations = [ | ||
("Demo1", demo1_instance, :typed, :forwarddiff), | ||
("Demo1", demo1_instance, :simple_namedtuple, :zygote), | ||
("Demo2", demo2_instance, :untyped, :reversediff), | ||
("Demo2", demo2_instance, :simple_dict, :forwarddiff) | ||
] | ||
|
||
# Store results as tuples: (Model, AD Backend, VarInfo Type, Eval Time, AD Eval Time) | ||
results_table = Tuple{String, String, String, Float64, Float64}[] | ||
|
||
for (model_name, model, varinfo_choice, adbackend) in chosen_combinations | ||
suite = make_suite(model, varinfo_choice, adbackend) | ||
results = run(suite) | ||
eval_time = median(results["evaluation"]).time | ||
ad_eval_time = median(results["AD_Benchmarking"]["evaluation"]["standard"]).time | ||
Comment on lines
+68
to
+69
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.
|
||
push!(results_table, (model_name, string(adbackend), string(varinfo_choice), eval_time, ad_eval_time)) | ||
end | ||
|
||
# Convert results to a 2D array for PrettyTables | ||
function to_matrix(tuples::Vector{<:NTuple{5,Any}}) | ||
n = length(tuples) | ||
data = Array{Any}(undef, n, 5) | ||
for i in 1:n | ||
for j in 1:5 | ||
data[i, j] = tuples[i][j] | ||
end | ||
end | ||
return data | ||
end | ||
|
||
table_matrix = to_matrix(results_table) | ||
Comment on lines
+73
to
+85
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. I think this could be simplified into table_matrix = hcat(Iterators.map(collect, zip(results_table...))...) You could also skip the |
||
header = ["Model", "AD Backend", "VarInfo Type", "Evaluation Time (ns)", "AD Eval Time (ns)"] | ||
pretty_table(table_matrix; header=header, tf=PrettyTables.tf_markdown) |
This file was deleted.
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.
We are trying to move away from unqualified
using X
statements in TuringLang (see TuringLang/Turing.jl#2288). Could these be replaced with eitherusing X: X
, which then forces to qualify the use of the module later asX.foo
, or withusing X: foo
if only one or two names need to be imported fromX
?