Skip to content
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

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
57b5d47
bigboy update to benchmarks
torfjelde Aug 2, 2021
e7c0a76
Merge branch 'master' into tor/benchmark-update
torfjelde Aug 19, 2021
60ec2c8
Merge branch 'master' into tor/benchmark-update
torfjelde Sep 8, 2021
eb1b83c
Merge branch 'master' into tor/benchmark-update
torfjelde Nov 6, 2021
d8afa71
Merge branch 'master' into tor/benchmark-update
torfjelde Nov 6, 2021
5bb48d2
make models return random variables as NamedTuple as it can be useful…
torfjelde Dec 2, 2021
02484cf
add benchmarking of evaluation with SimpleVarInfo with NamedTuple
torfjelde Dec 2, 2021
5c59769
added some information about the execution environment
torfjelde Dec 3, 2021
f1f1381
added judgementtable_single
torfjelde Dec 3, 2021
a48553a
added benchmarking of SimpleVarInfo, if present
torfjelde Dec 3, 2021
f2dc062
Merge branch 'master' into tor/benchmark-update
torfjelde Dec 3, 2021
fa675de
added ComponentArrays benchmarking for SimpleVarInfo
torfjelde Dec 5, 2021
3962da2
Merge branch 'master' into tor/benchmark-update
yebai Aug 29, 2022
53dc571
Merge branch 'master' into tor/benchmark-update
yebai Nov 2, 2022
f5705d5
Merge branch 'master' into tor/benchmark-update
torfjelde Nov 7, 2022
7f569f7
formatting
torfjelde Nov 7, 2022
4a06150
Merge branch 'master' into tor/benchmark-update
yebai Feb 2, 2023
a1cc6bf
Apply suggestions from code review
yebai Feb 2, 2023
3e7e200
Update benchmarks/benchmarks.jmd
yebai Feb 2, 2023
c867ae8
Merge branch 'master' into tor/benchmark-update
yebai Jul 4, 2023
96f120b
merged main into this one
shravanngoswamii Dec 19, 2024
0460b64
Benchmarking CI
shravanngoswamii Dec 19, 2024
a8541b5
Julia script for benchmarking on top of current setup
shravanngoswamii Feb 1, 2025
0291c2f
keep old results for reference
shravanngoswamii Feb 1, 2025
6f255d1
Merge branch 'master' of https://github.com/TuringLang/DynamicPPL.jl …
shravanngoswamii Feb 1, 2025
3b5e448
updated benchmarking setup
shravanngoswamii Feb 20, 2025
1e61025
Merge branch 'master' of https://github.com/TuringLang/DynamicPPL.jl …
shravanngoswamii Feb 20, 2025
640aa45
applied suggested changes
shravanngoswamii Feb 27, 2025
3bdbe40
Merge branch 'master' of https://github.com/TuringLang/DynamicPPL.jl …
shravanngoswamii Feb 27, 2025
d8fd05c
updated benchmarks/README.md
shravanngoswamii Feb 27, 2025
c34e489
setup benchmarking CI
shravanngoswamii Feb 27, 2025
1d1b11e
Merge remote-tracking branch 'origin/main' into tor/benchmark-update
mhauru Mar 3, 2025
ad4175a
Update benchmark models (#826)
mhauru Mar 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/Benchmarking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Benchmarking

on:
pull_request:

jobs:
benchmarks:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- 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
id: run_benchmarks
run: |
# Capture version info into a variable, print it, and set it as an env var for later steps
version_info=$(julia -e 'using InteractiveUtils; versioninfo()')
echo "$version_info"
echo "VERSION_INFO<<EOF" >> $GITHUB_ENV
echo "$version_info" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

# Capture benchmark output into a variable
echo "Running Benchmarks..."
benchmark_output=$(julia --project=benchmarks benchmarks/benchmarks.jl)

# Print benchmark results directly to the workflow log
echo "Benchmark Results:"
echo "$benchmark_output"

# Set the benchmark output as an env var for later steps
echo "BENCHMARK_OUTPUT<<EOF" >> $GITHUB_ENV
echo "$benchmark_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Find Existing Comment
uses: peter-evans/find-comment@v3
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]

- name: Post Benchmark Results as PR Comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
## Computer Information
```
${{ env.VERSION_INFO }}
```
## Benchmark Report
${{ env.BENCHMARK_OUTPUT }}
comment-id: ${{ steps.find_comment.outputs.comment-id }}
edit-mode: replace
8 changes: 3 additions & 5 deletions benchmarks/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ version = "0.1.0"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
DiffUtils = "8294860b-85a6-42f8-8c35-d911f667b5f6"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Weave = "44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
TuringBenchmarking = "0db1332d-5c25-4deb-809f-459bc696f94f"
28 changes: 3 additions & 25 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
To run the benchmarks, simply do:
To run the benchmarks, simply do this from the root directory of the repository:

```sh
julia --project -e 'using DynamicPPLBenchmarks; weave_benchmarks();'
```

```julia
julia> @doc weave_benchmarks
weave_benchmarks(input="benchmarks.jmd"; kwargs...)

Weave benchmarks present in benchmarks.jmd into a single file.

Keyword arguments
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

• benchmarkbody: JMD-file to be rendered for each model.

• include_commit_id=false: specify whether to include commit-id in the default name.

• name: the name of directory in results/ to use as output directory.

• name_old=nothing: if specified, comparisons of current run vs. the run pinted to by name_old will be included in the generated document.

• include_typed_code=false: if true, output of code_typed for the evaluator of the model will be included in the weaved document.

• Rest of the passed kwargs will be passed on to Weave.weave.
```
julia --project=benchmarks benchmarks/benchmarks.jl
```
49 changes: 0 additions & 49 deletions benchmarks/benchmark_body.jmd

This file was deleted.

108 changes: 108 additions & 0 deletions benchmarks/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using DynamicPPLBenchmarks: Models, make_suite
using BenchmarkTools: @benchmark, median, run
using PrettyTables: PrettyTables, ft_printf
using Random: seed!

seed!(23)

# Create DynamicPPL.Model instances to run benchmarks on.
smorgasbord_instance = Models.smorgasbord(randn(100), randn(100))
loop_univariate1k, multivariate1k = begin
data_1k = randn(1_000)
loop = Models.loop_univariate(length(data_1k)) | (; o=data_1k)
multi = Models.multivariate(length(data_1k)) | (; o=data_1k)
loop, multi
end
loop_univariate10k, multivariate10k = begin
data_10k = randn(10_000)
loop = Models.loop_univariate(length(data_10k)) | (; o=data_10k)
multi = Models.multivariate(length(data_10k)) | (; o=data_10k)
loop, multi
end
lda_instance = begin
w = [1, 2, 3, 2, 1, 1]
d = [1, 1, 1, 2, 2, 2]
Models.lda(2, d, w)
end

# Specify the combinations to test:
# (Model Name, model instance, VarInfo choice, AD backend, linked)
chosen_combinations = [
(
"Simple assume observe",
Models.simple_assume_observe(randn()),
:typed,
:forwarddiff,
false,
),
("Smorgasbord", smorgasbord_instance, :typed, :forwarddiff, false),
("Smorgasbord", smorgasbord_instance, :simple_namedtuple, :forwarddiff, true),
("Smorgasbord", smorgasbord_instance, :untyped, :forwarddiff, true),
("Smorgasbord", smorgasbord_instance, :simple_dict, :forwarddiff, true),
("Smorgasbord", smorgasbord_instance, :typed, :reversediff, true),
# TODO(mhauru) Add Mooncake once TuringBenchmarking.jl supports it. Consider changing
# all the below :reversediffs to :mooncakes too.
#("Smorgasbord", smorgasbord_instance, :typed, :mooncake, true),
("Loop univariate 1k", loop_univariate1k, :typed, :reversediff, true),
("Multivariate 1k", multivariate1k, :typed, :reversediff, true),
("Loop univariate 10k", loop_univariate10k, :typed, :reversediff, true),
("Multivariate 10k", multivariate10k, :typed, :reversediff, true),
("Dynamic", Models.dynamic(), :typed, :reversediff, true),
("Submodel", Models.parent(randn()), :typed, :reversediff, true),
("LDA", lda_instance, :typed, :reversediff, true),
]

# Time running a model-like function that does not use DynamicPPL, as a reference point.
# Eval timings will be relative to this.
reference_time = begin
obs = randn()
median(@benchmark Models.simple_assume_observe_non_model(obs)).time
end

results_table = Tuple{String,String,String,Bool,Float64,Float64}[]

for (model_name, model, varinfo_choice, adbackend, islinked) in chosen_combinations
suite = make_suite(model, varinfo_choice, adbackend)
results = run(suite)
result_key = islinked ? "linked" : "standard"

eval_time = median(results["evaluation"][result_key]).time
relative_eval_time = eval_time / reference_time

grad_group = results["gradient"]
if isempty(grad_group)
relative_ad_eval_time = NaN
else
grad_backend_key = first(keys(grad_group))
ad_eval_time = median(grad_group[grad_backend_key][result_key]).time
relative_ad_eval_time = ad_eval_time / eval_time
end

push!(
results_table,
(
model_name,
string(adbackend),
string(varinfo_choice),
islinked,
relative_eval_time,
relative_ad_eval_time,
),
)
end

table_matrix = hcat(Iterators.map(collect, zip(results_table...))...)
header = [
"Model",
"AD Backend",
"VarInfo Type",
"Linked",
"Eval Time / Ref Time",
"AD Time / Eval Time",
]
PrettyTables.pretty_table(
table_matrix;
header=header,
tf=PrettyTables.tf_markdown,
formatters=ft_printf("%.1f", [5, 6]),
)
Loading
Loading