Skip to content

Commit a7337f8

Browse files
authored
Merge pull request #352 from stan-dev/use-touchstone
Use touchstone
2 parents d0aa8b2 + 8af5a81 commit a7337f8

11 files changed

Lines changed: 1784 additions & 0 deletions

File tree

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ vignettes/loo2-non-factorized_cache/*
2424
^release-prep\.R$
2525
^_pkgdown\.yml$
2626
^pkgdown$
27+
^touchstone$
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Continuous Benchmarks (Comment)
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_run:
9+
workflows: ["Continuous Benchmarks (Receive)"]
10+
types:
11+
- completed
12+
13+
jobs:
14+
upload:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
pull-requests: write
19+
statuses: write
20+
if: >
21+
${{ github.event.workflow_run.event == 'pull_request' }}
22+
steps:
23+
- uses: lorenzwalthert/touchstone/actions/comment@main
24+
with:
25+
GITHUB_TOKEN: ${{ github.token }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Continuous Benchmarks (Receive)
2+
3+
permissions:
4+
contents: read
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.head_ref }}
8+
cancel-in-progress: true
9+
10+
on:
11+
pull_request:
12+
13+
jobs:
14+
prepare:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
config: ${{ steps.read_touchstone_config.outputs.config }}
18+
steps:
19+
- name: Checkout repo
20+
uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 0
23+
24+
- id: read_touchstone_config
25+
run: |
26+
echo "config=$(jq -c . ./touchstone/config.json)" >> $GITHUB_OUTPUT
27+
28+
build:
29+
needs: prepare
30+
runs-on: ${{ matrix.config.os }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
config:
35+
- ${{ fromJson(needs.prepare.outputs.config) }}
36+
steps:
37+
- name: Checkout repo
38+
uses: actions/checkout@v6
39+
with:
40+
fetch-depth: 0
41+
- uses: lorenzwalthert/touchstone/actions/receive@main
42+
with:
43+
r-version: ${{ matrix.config.r }}

data-raw/wine_loglik.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library(brms)
2+
library(loo)
3+
options(brms.backend = "cmdstanr")
4+
options(mc.cores = 4)
5+
6+
fitos <- read.delim("data-raw/winequality-red.csv", sep = ";") |>
7+
unique() |>
8+
scale() |>
9+
as.data.frame() |>
10+
brm(
11+
ordered(quality) ~ .,
12+
family = cumulative("logit"),
13+
prior = prior(R2D2(mean_R2 = 1 / 3, prec_R2 = 3)),
14+
data = _,
15+
seed = 1,
16+
silent = 2,
17+
refresh = 0
18+
)
19+
20+
saveRDS(log_lik(fitos), "touchstone/wine.rds")

data-raw/winequality-red.csv

Lines changed: 1600 additions & 0 deletions
Large diffs are not rendered by default.

touchstone/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*
2+
!script.R
3+
!config.json
4+
!.gitignore
5+
!header.R
6+
!footer.R
7+
!wine.rds

touchstone/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"os": "ubuntu-22.04",
3+
"r": "4.4.3",
4+
"rspm": "https://packagemanager.posit.co/cran/__linux__/jammy/latest",
5+
"benchmarking_repo": "",
6+
"benchmarking_ref": "",
7+
"benchmarking_path": ""
8+
}

touchstone/footer.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# You can modify the PR comment footer here. You can use github markdown e.g.
2+
# emojis like :tada:.
3+
# This file will be parsed and evaluate within the context of
4+
# `benchmark_analyze` and should return the comment text as the last value.
5+
# See `?touchstone::pr_comment`
6+
link <- "https://lorenzwalthert.github.io/touchstone/articles/inference.html"
7+
glue::glue(
8+
"\nFurther explanation regarding interpretation and",
9+
" methodology can be found in the [documentation]({link})."
10+
)

touchstone/header.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# You can modify the PR comment header here. You can use github markdown e.g.
2+
# emojis like :tada:.
3+
# This file will be parsed and evaluate within the context of
4+
# `benchmark_analyze` and should return the comment text as the last value.
5+
# Available variables for glue substitution:
6+
# * ci: confidence interval
7+
# * branches: BASE and HEAD branches benchmarked against each other.
8+
# See `?touchstone::pr_comment`
9+
glue::glue(
10+
"This is how benchmark results would change (along with a",
11+
" {100 * ci}% confidence interval in relative change) if ",
12+
"{system2('git', c('rev-parse', 'HEAD'), stdout = TRUE)} is merged into {branches[1]}:\n"
13+
)

touchstone/script.R

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# see `help(run_script, package = 'touchstone')` on how to run this
2+
# interactively
3+
4+
# installs branches to benchmark
5+
touchstone::branch_install()
6+
7+
touchstone::pin_assets("touchstone/wine.rds")
8+
9+
# These synthetic workloads are large enough to expose real slowdowns in the
10+
# core `loo()` paths, but still short enough to keep PR feedback reasonably fast.
11+
touchstone::benchmark_run(
12+
expr_before_benchmark = {
13+
suppressPackageStartupMessages(library(loo))
14+
# benchmark_run() evaluates in a callr subprocess, so load pinned assets here.
15+
wine_log_lik_matrix <- readRDS(touchstone::path_pinned_asset(
16+
"touchstone/wine.rds"
17+
))
18+
matrix_r_eff <- rep(1, ncol(wine_log_lik_matrix))
19+
},
20+
loo_matrix = {
21+
suppressWarnings(
22+
loo(
23+
wine_log_lik_matrix,
24+
r_eff = matrix_r_eff,
25+
cores = 1
26+
)
27+
)
28+
},
29+
n = 10
30+
)
31+
32+
touchstone::benchmark_run(
33+
expr_before_benchmark = {
34+
suppressPackageStartupMessages(library(loo))
35+
wine_log_lik_matrix <- readRDS(touchstone::path_pinned_asset(
36+
"touchstone/wine.rds"
37+
))
38+
function_r_eff <- rep(1, ncol(wine_log_lik_matrix))
39+
wine_data <- data.frame(obs = seq_len(ncol(wine_log_lik_matrix)))
40+
wine_llfun <- function(data_i, draws) draws[, data_i$obs, drop = FALSE]
41+
},
42+
loo_function = {
43+
suppressWarnings(
44+
loo(
45+
wine_llfun,
46+
data = wine_data,
47+
draws = wine_log_lik_matrix,
48+
r_eff = function_r_eff,
49+
cores = 1
50+
)
51+
)
52+
},
53+
n = 10
54+
)
55+
56+
# create artifacts used downstream in the GitHub Action
57+
touchstone::benchmark_analyze()

0 commit comments

Comments
 (0)