@model function arK_arK(K, T, y)
alpha ~ Normal(0, 10)
beta ~ product_distribution(Fill(Normal(0, 10), K))
sigma ~ truncated(Cauchy(0, 2.5); lower=0)
for t in (K + 1):T
mu = alpha
for k in 1:K
mu += beta[k] * y[t - k]
end
y[t] ~ Normal(mu, sigma)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
305 ns · 580 calls
922 ns · 168 calls
5.04 μs
6.97 μs
20261122T002521Z-565231f-registered-repeat-1
Off
389 ns · 108 calls
1.06 μs · 636 calls
8.41 μs
6.1 μs
20261122T002521Z-565231f
On · no reduction
305 ns · 580 calls
922 ns · 168 calls
5.04 μs
6.97 μs
20261122T002521Z-565231f
Off
389 ns · 108 calls
1.06 μs · 636 calls
8.41 μs
6.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
280 ns · 1052 calls
908 ns · 132 calls
5.1 μs
6.75 μs
20261122T000034Z-565231f-registered-repeat-1
Off
292 ns · 992 calls
900 ns · 560 calls
3.61 μs
7.78 μs
20261122T000034Z-565231f
On · no reduction
280 ns · 1052 calls
908 ns · 132 calls
5.1 μs
6.75 μs
20261122T000034Z-565231f
Off
292 ns · 992 calls
900 ns · 560 calls
3.61 μs
7.78 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
870 ns · 294 calls
4.84 μs
6.67 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
975 ns · 165 calls
3.52 μs
6.74 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
870 ns · 294 calls
4.84 μs
6.67 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
975 ns · 165 calls
3.52 μs
6.74 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.33 μs · value and gradient 12.4 μs
PosteriorDB model arK · dataset arK · SHA-256 8c561dcceb3e74654097f25f07277cd5448fc175f4a2589962bb817a54e4e742
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
360 ns
953 ns
FlatPPL · normal optimizations
5.04 μs · 14.0× Wren
6.97 μs · 7.31× Wren
FlatPPL · equal work
8.41 μs · 23.4× Wren
6.1 μs · 6.4× Wren
Wren definition in this run
@wren function ark_model(y, lags, K)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Normal(0.0, 10.0) size=K
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = alpha .+ lags * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
489 ns
943 ns
FlatPPL · normal optimizations
5.1 μs · 10.4× Wren
6.75 μs · 7.16× Wren
FlatPPL · equal work
3.61 μs · 7.38× Wren
7.78 μs · 8.25× Wren
Wren definition in this run
@wren function ark_model(y, lags, K)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Normal(0.0, 10.0) size=K
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = alpha .+ lags * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
311 ns
580 ns
FlatPPL · normal optimizations
4.84 μs · 15.5× Wren
6.67 μs · 11.5× Wren
FlatPPL · equal work
3.52 μs · 11.3× Wren
6.74 μs · 11.6× Wren
Wren definition in this run
@wren function ark_model(y, lags, K)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Normal(0.0, 10.0) size=K
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = alpha .+ lags * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
end
const ARMA11 = @rkppl begin
mu ~ Normal(0, 10)
phi ~ Normal(0, 2)
theta ~ Normal(0, 2)
sigma ~ HalfCauchy(2.5)
@scan begin
nu[1] = mu + phi * mu
err[1] = y[1] - nu[1]
for t in 2:T
nu[t] = mu + phi * y[t - 1] + theta * err[t - 1]
err[t] = y[t] - nu[t]
end
end
y .~ Normal.(nu, sigma)
end
function arma11_predictions(yobs, mu, phi, theta)
nu = similar(yobs, typeof(mu + phi + theta))
err = similar(nu)
nu[1] = mu + phi * mu
err[1] = yobs[1] - nu[1]
for t in 2:length(yobs)
nu[t] = mu + phi * yobs[t - 1] + theta * err[t - 1]
err[t] = yobs[t] - nu[t]
end
nu
end
const ARMA11 = @model yobs begin
mu ~ Normal(0, 10)
phi ~ Normal(0, 2)
theta ~ Normal(0, 2)
sigma ~ HalfCauchy(2.5)
nu = arma11_predictions(yobs, mu, phi, theta)
y ~ For(nu) do m
Normal(m, sigma)
end
end
@model function arma_arma11(T, y)
mu ~ Normal(0, 10)
phi ~ Normal(0, 2)
theta ~ Normal(0, 2)
sigma ~ truncated(Cauchy(0, 2.5); lower=0)
nu = Vector{typeof(mu)}(undef, T)
err = Vector{typeof(mu)}(undef, T)
nu[1] = mu + phi * mu
err[1] = y[1] - nu[1]
for t in 2:T
nu[t] = mu + phi * y[t - 1] + theta * err[t - 1]
err[t] = y[t] - nu[t]
end
return y ~ product_distribution(map(Normal, nu, Fill(sigma, T)))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.07 μs · 308 calls
1.98 μs · 276 calls
7.14 μs
14.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.05 μs · 380 calls
2.03 μs · 408 calls
5.32 μs
15.5 μs
20261122T002521Z-565231f
On · no reduction
1.07 μs · 308 calls
1.98 μs · 276 calls
7.14 μs
14.5 μs
20261122T002521Z-565231f
Off
1.05 μs · 380 calls
2.03 μs · 408 calls
5.32 μs
15.5 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.03 μs · 460 calls
2.04 μs · 304 calls
5.4 μs
14.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.05 μs · 724 calls
1.99 μs · 388 calls
5.51 μs
12.8 μs
20261122T000034Z-565231f
On · no reduction
1.03 μs · 460 calls
2.04 μs · 304 calls
5.4 μs
14.8 μs
20261122T000034Z-565231f
Off
1.05 μs · 724 calls
1.99 μs · 388 calls
5.51 μs
12.8 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.15 μs · 116 calls
5.04 μs
13.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.95 μs · 247 calls
4.84 μs
15.2 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.15 μs · 116 calls
5.04 μs
13.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.95 μs · 247 calls
4.84 μs
15.2 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 7.01 μs · value and gradient 14.1 μs
PosteriorDB model arma11 · dataset arma · SHA-256 42dae9f7ccca02a5e62f6e89e6e0ffcc15dee5d42638d7540147b0c8b88b8cab
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
379 ns
975 ns
FlatPPL · normal optimizations
7.14 μs · 18.9× Wren
14.5 μs · 14.9× Wren
FlatPPL · equal work
5.32 μs · 14.0× Wren
15.5 μs · 15.9× Wren
Wren definition in this run
@wren function arma11(y)
mu ~ WD.Normal(0.0, 10.0)
phi ~ WD.Normal(0.0, 2.0)
theta ~ WD.Normal(0.0, 2.0)
# Stan's positive Cauchy factor differs by the constant log(2).
sigma ~ WD.HalfCauchy(0.0, 2.5)
prediction = mu + phi * mu
predictions = Vector{typeof(prediction)}(undef, length(y))
predictions[1] = prediction
previous_error = y[1] - prediction
for t in 2:length(y)
prediction = mu + phi * y[t - 1] + theta * previous_error
predictions[t] = prediction
previous_error = y[t] - prediction
end
@batch for t in eachindex(y)
@observe y[t] ~ WD.Normal(predictions[t], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
402 ns
970 ns
FlatPPL · normal optimizations
5.4 μs · 13.4× Wren
14.8 μs · 15.2× Wren
FlatPPL · equal work
5.51 μs · 13.7× Wren
12.8 μs · 13.2× Wren
Wren definition in this run
@wren function arma11(y)
mu ~ WD.Normal(0.0, 10.0)
phi ~ WD.Normal(0.0, 2.0)
theta ~ WD.Normal(0.0, 2.0)
# Stan's positive Cauchy factor differs by the constant log(2).
sigma ~ WD.HalfCauchy(0.0, 2.5)
prediction = mu + phi * mu
predictions = Vector{typeof(prediction)}(undef, length(y))
predictions[1] = prediction
previous_error = y[1] - prediction
for t in 2:length(y)
prediction = mu + phi * y[t - 1] + theta * previous_error
predictions[t] = prediction
previous_error = y[t] - prediction
end
@batch for t in eachindex(y)
@observe y[t] ~ WD.Normal(predictions[t], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
370 ns
895 ns
FlatPPL · normal optimizations
5.04 μs · 13.6× Wren
13.3 μs · 14.8× Wren
FlatPPL · equal work
4.84 μs · 13.1× Wren
15.2 μs · 17.0× Wren
Wren definition in this run
@wren function arma11(y)
mu ~ WD.Normal(0.0, 10.0)
phi ~ WD.Normal(0.0, 2.0)
theta ~ WD.Normal(0.0, 2.0)
# Stan's positive Cauchy factor differs by the constant log(2).
sigma ~ WD.HalfCauchy(0.0, 2.5)
prediction = mu + phi * mu
predictions = Vector{typeof(prediction)}(undef, length(y))
predictions[1] = prediction
previous_error = y[1] - prediction
for t in 2:length(y)
prediction = mu + phi * y[t - 1] + theta * previous_error
predictions[t] = prediction
previous_error = y[t] - prediction
end
@batch for t in eachindex(y)
@observe y[t] ~ WD.Normal(predictions[t], sigma)
end
return nothing
end
%%%
# Basketball drives as a hidden Markov model
PosteriorDB's `bball_drive_event_0-hmm_drive_0`. A hidden two-state chain
separates drives from other play. Each state emits two Exponential
observations: inverse speed u with rate phi and hoop distance v with rate
lambda. A scan over the observed history runs the forward filter. Each
observation pair is a two-component mixture weighted by the predicted state
probabilities. The product of these mixtures is the forward-algorithm
likelihood.
Dirichlet priors with data rows alpha govern the transition rows. Both rate
vectors keep Stan's Normal densities on 0 < x[1] < x[2], without
renormalization. Stan starts the recursion with weight one for each state.
The uniform initial distribution here subtracts log(2) from Stan's target.
%%%
flatppl_compat = "0.1"
N = 416
data = load_data("data.json", cartprod(
u = cartpow(posreals, N), v = cartpow(posreals, N), alpha = cartpow(posreals, [2, 2])))
theta1 ~ Dirichlet(data.alpha[1, :])
theta2 ~ Dirichlet(data.alpha[2, :])
phi = elementof(ordered(2))
lambda = elementof(ordered(2))
rate_prior = truncate(truncate(joint(Normal(0, 1), Normal(3, 1)), ordered(2)), cartpow(posreals, 2))
% Log-likelihood ratio of state 1 against state 2 for each observation pair.
log_ratio = log(phi[1] / phi[2]) - log(lambda[2] / lambda[1]) .-
(phi[1] - phi[2]) .* data.u .- (lambda[1] - lambda[2]) .* data.v
% Filter on the current observation, then predict state 1 for the next one.
predict(q, r, p) = p.theta2[1] + (p.theta1[1] - p.theta2[1]) * invlogit(logit(q) + r)
step(state, r, p) = record(current = state.next, next = predict(state.next, r, p))
states = scan(step, record(current = 0.5, next = 0.5), log_ratio,
record(theta1 = theta1, theta2 = theta2))
state_weight(state) = state.current
weight = state_weight.(states)
emission(w, phi1, phi2, lambda1, lambda2) = normalize(superpose(
weighted(w, joint(Exponential(phi1), Exponential(lambda1))),
weighted(1 - w, joint(Exponential(phi2), Exponential(lambda2)))))
y ~ emission.(weight, phi[1], phi[2], lambda[1], lambda[2])
Pi_prior = joint(lawof(record(theta1 = theta1, theta2 = theta2)),
joint(phi = rate_prior, lambda = rate_prior))
K_model = kernelof(record(y = y), theta1 = theta1, theta2 = theta2, phi = phi, lambda = lambda)
% Each observation is the pair [u, v]: a vector of vectors, as the broadcast variate is.
pair(a, b) = [a, b]
L = likelihoodof(K_model, record(y = pair.(data.u, data.v)))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta1 = stdsimplex(2), theta2 = stdsimplex(2),
phi = ordered(2), lambda = ordered(2))
Pi_post_input = record(theta1 = [0.99, 0.01], theta2 = [0.035, 0.965], phi = [1.8, 6.7], lambda = [0.028, 0.076])
function HiddenMarkovModel(n, initial, transition, emissions, transition_layout)
return HiddenMarkovModel(
n, initial, transition, emissions, transition_layout, Val(:ordinary)
)
end
@model function hmm_drive_0(K, observations, alpha, initial)
theta1 ~ Dirichlet(vec(alpha[1, :]))
theta2 ~ Dirichlet(vec(alpha[2, :]))
phi ~ ordered(
product_distribution([
truncated(Normal(0, 1); lower=0), truncated(Normal(3, 1); lower=0)
]),
)
lambda ~ ordered(
product_distribution([
truncated(Normal(0, 1); lower=0), truncated(Normal(3, 1); lower=0)
]),
)
transition = [i == 1 ? theta1[j] : theta2[j] for i in 1:K, j in 1:K]
emissions = [
product_distribution([Exponential(inv(phi[k])), Exponential(inv(lambda[k]))]) for
k in 1:K
]
return observations ~ HiddenMarkovModel(
size(observations, 1), initial, transition, emissions, Val(:rows)
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
22.5 μs · 28 calls
29.2 μs · 32 calls
34.8 μs
57.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
19.1 μs · 36 calls
28.2 μs · 20 calls
35.3 μs
51.7 μs
20261122T002521Z-565231f
On · no reduction
22.5 μs · 28 calls
29.2 μs · 32 calls
34.8 μs
57.5 μs
20261122T002521Z-565231f
Off
19.1 μs · 36 calls
28.2 μs · 20 calls
35.3 μs
51.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
21.1 μs · 24 calls
27.5 μs · 28 calls
29.8 μs
45.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
20.3 μs · 40 calls
24.4 μs · 24 calls
30.3 μs
51.2 μs
20261122T000034Z-565231f
On · no reduction
21.1 μs · 24 calls
27.5 μs · 28 calls
29.8 μs
45.8 μs
20261122T000034Z-565231f
Off
20.3 μs · 40 calls
24.4 μs · 24 calls
30.3 μs
51.2 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
25.8 μs · 11 calls
30.9 μs
41.2 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
27.4 μs · 4 calls
29.3 μs
50.6 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
25.8 μs · 11 calls
30.9 μs
41.2 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
27.4 μs · 4 calls
29.3 μs
50.6 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 32.8 μs · value and gradient 37.1 μs
PosteriorDB model hmm_drive_0 · dataset bball_drive_event_0 · SHA-256 8f9d94a824c181e13fe939c2e52d2f59ddf61deebe6653fedba2ba1d4477ed8a
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
%%%
# Basketball drives, Normal emissions
PosteriorDB's `bball_drive_event_1-hmm_drive_1`. A hidden two-state chain
separates drives from other play. Each state emits inverse speed u and hoop
distance v as Normals with ordered locations phi and lambda and data scales
tau and rho. A scan over the observed history runs the forward filter. Each
observation pair is a two-component mixture weighted by the predicted state
probabilities. Dirichlet priors with data rows alpha govern the transition
rows. Both location vectors keep Stan's Normal densities on the ordered set,
without renormalization. Stan starts the recursion with weight one for each
state, so the uniform initial distribution subtracts log(2) from Stan's
target.
%%%
flatppl_compat = "0.1"
N = 416
data = load_data("data.json", cartprod(
u = cartpow(reals, N), v = cartpow(reals, N), alpha = cartpow(posreals, [2, 2]),
tau = posreals, rho = posreals))
theta1 ~ Dirichlet(data.alpha[1, :])
theta2 ~ Dirichlet(data.alpha[2, :])
phi = elementof(ordered(2))
lambda = elementof(ordered(2))
location_prior = truncate(joint(Normal(0, 1), Normal(3, 1)), ordered(2))
% Log-likelihood ratio of state 1 against state 2 for each observation pair.
log_ratio = 0.5 .* (((data.u .- phi[2]).^2 .- (data.u .- phi[1]).^2) ./ data.tau^2 .+
((data.v .- lambda[2]).^2 .- (data.v .- lambda[1]).^2) ./ data.rho^2)
% Filter on the current observation, then predict state 1 for the next one.
predict(q, r, p) = p.theta2[1] + (p.theta1[1] - p.theta2[1]) * invlogit(logit(q) + r)
step(state, r, p) = record(current = state.next, next = predict(state.next, r, p))
states = scan(step, record(current = 0.5, next = 0.5), log_ratio,
record(theta1 = theta1, theta2 = theta2))
state_weight(state) = state.current
weight = state_weight.(states)
emission(w, phi1, phi2, lambda1, lambda2) = normalize(superpose(
weighted(w, joint(Normal(phi1, data.tau), Normal(lambda1, data.rho))),
weighted(1 - w, joint(Normal(phi2, data.tau), Normal(lambda2, data.rho)))))
y ~ emission.(weight, phi[1], phi[2], lambda[1], lambda[2])
Pi_prior = joint(lawof(record(theta1 = theta1, theta2 = theta2)),
joint(phi = location_prior, lambda = location_prior))
K_model = kernelof(record(y = y), theta1 = theta1, theta2 = theta2, phi = phi, lambda = lambda)
% Each observation is the pair [u, v]: a vector of vectors, as the broadcast variate is.
pair(a, b) = [a, b]
L = likelihoodof(K_model, record(y = pair.(data.u, data.v)))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta1 = stdsimplex(2), theta2 = stdsimplex(2), phi = ordered(2), lambda = ordered(2))
Pi_post_input = record(theta1 = [0.9, 0.1], theta2 = [0.1, 0.9], phi = [0.2, 0.5], lambda = [0.5, 2.0])
function HiddenMarkovModel(n, initial, transition, emissions, transition_layout)
return HiddenMarkovModel(
n, initial, transition, emissions, transition_layout, Val(:ordinary)
)
end
@model function hmm_drive_1(K, observations, alpha, tau, rho, initial)
theta1 ~ Dirichlet(vec(alpha[1, :]))
theta2 ~ Dirichlet(vec(alpha[2, :]))
phi ~ ordered(product_distribution([Normal(0, 1), Normal(3, 1)]))
lambda ~ ordered(product_distribution([Normal(0, 1), Normal(3, 1)]))
transition = [i == 1 ? theta1[j] : theta2[j] for i in 1:K, j in 1:K]
emissions = [
product_distribution([Normal(phi[k], tau), Normal(lambda[k], rho)]) for k in 1:K
]
return observations ~ HiddenMarkovModel(
size(observations, 1), initial, transition, emissions, Val(:rows)
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
18.9 μs · 44 calls
23 μs · 36 calls
34.8 μs
47.8 μs
20261122T002521Z-565231f-registered-repeat-1
Off
16.1 μs · 52 calls
23.9 μs · 8 calls
34.4 μs
48.4 μs
20261122T002521Z-565231f
On · no reduction
18.9 μs · 44 calls
23 μs · 36 calls
34.8 μs
47.8 μs
20261122T002521Z-565231f
Off
16.1 μs · 52 calls
23.9 μs · 8 calls
34.4 μs
48.4 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
17.2 μs · 8 calls
28.4 μs · 36 calls
33.6 μs
35.5 μs
20261122T000034Z-565231f-registered-repeat-1
Off
16.8 μs · 16 calls
22.4 μs · 16 calls
28.4 μs
35 μs
20261122T000034Z-565231f
On · no reduction
17.2 μs · 8 calls
28.4 μs · 36 calls
33.6 μs
35.5 μs
20261122T000034Z-565231f
Off
16.8 μs · 16 calls
22.4 μs · 16 calls
28.4 μs
35 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
21.4 μs · 29 calls
30 μs
37 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
26.6 μs · 14 calls
30.4 μs
41.4 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
21.4 μs · 29 calls
30 μs
37 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
26.6 μs · 14 calls
30.4 μs
41.4 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 29.4 μs · value and gradient 47.7 μs
PosteriorDB model hmm_drive_1 · dataset bball_drive_event_1 · SHA-256 c283aee9403f0e8aad499cdaf8e501f5473d879839441dc6af7b0a8a7b017dd5
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
const BONES_MODEL = @rkppl begin
theta[1:nchild] .~ Normal.(0, 36)
@plate for j in eachindex(ncat)
grade[j] .~ Ordinal.(Cumulative(), LogitLink(), theta[child[j]],
Ref(cuts[j]), delta[j])
end
end
@model function pdb_bones_model(nChild, nInd, gamma, delta, ncat, grade)
theta ~ product_distribution(Fill(Normal(0.0, 36.0), nChild))
p = zeros(typeof(theta[1]), nChild, nInd, 5)
Q = zeros(typeof(theta[1]), nChild, nInd, 4)
for i in 1:nChild
for j in 1:nInd
for k in 1:(ncat[j] - 1)
Q[i, j, k] = logistic(delta[j] * (theta[i] - gamma[j, k]))
end
p[i, j, 1] = 1 - Q[i, j, 1]
for k in 2:(ncat[j] - 1)
p[i, j, k] = Q[i, j, k - 1] - Q[i, j, k]
end
p[i, j, ncat[j]] = Q[i, j, ncat[j] - 1]
if grade[i, j] != -1
DynamicPPL.@addlogprob! log(p[i, j, grade[i, j]])
end
end
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
6.86 μs · 124 calls
8.72 μs · 112 calls
13.8 μs
16.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
6.44 μs · 120 calls
7.48 μs · 100 calls
13.2 μs
15.6 μs
20261122T002521Z-565231f
On · no reduction
6.86 μs · 124 calls
8.72 μs · 112 calls
13.8 μs
16.6 μs
20261122T002521Z-565231f
Off
6.44 μs · 120 calls
7.48 μs · 100 calls
13.2 μs
15.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
6.47 μs · 28 calls
7.43 μs · 108 calls
14.2 μs
16 μs
20261122T000034Z-565231f-registered-repeat-1
Off
6.51 μs · 128 calls
7.11 μs · 108 calls
13.2 μs
16.1 μs
20261122T000034Z-565231f
On · no reduction
6.47 μs · 28 calls
7.43 μs · 108 calls
14.2 μs
16 μs
20261122T000034Z-565231f
Off
6.51 μs · 128 calls
7.11 μs · 108 calls
13.2 μs
16.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
7.15 μs · 103 calls
13.8 μs
15.1 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
7.62 μs · 71 calls
13.1 μs
15.8 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
7.15 μs · 103 calls
13.8 μs
15.1 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
7.62 μs · 71 calls
13.1 μs
15.8 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 13.7 μs · value and gradient 15.1 μs
PosteriorDB model bones_model · dataset bones_data · SHA-256 1838297b396d0a632ea73f0d5d0fd09c17f6aa39d0b34303a5308245537f85a1
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_multi_occupancy(J, K, n, X, S)
alpha ~ Cauchy(0, 2.5)
beta ~ Cauchy(0, 2.5)
Omega ~ Beta(2, 2)
rho_uv ~ Uniform(-1, 1)
sigma_uv ~ product_distribution(Fill(FlatPos(0), 2))
uv1 ~ product_distribution(Fill(Flat(), S))
uv2 ~ product_distribution(Fill(Flat(), S))
uv = hcat(uv1, uv2)
logit_psi = uv1 .+ alpha
logit_theta = uv2 .+ beta
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Cauchy(0, 2.5), size(sigma_uv))), sigma_uv
)
DynamicPPL.@addlogprob! logpdf(Beta(2, 2), (rho_uv + 1) / 2)
covariance12 = sigma_uv[1] * sigma_uv[2] * rho_uv
covariance = [
sigma_uv[1]^2 covariance12
covariance12 sigma_uv[2]^2
]
uv_distribution = MvNormal(zeros(2), Symmetric(covariance))
DynamicPPL.@addlogprob! loglikelihood(uv_distribution, uv')
for i in 1:n
DynamicPPL.@addlogprob! logpdf(Bernoulli(Omega), 1)
for j in 1:J
occupied =
logpdf(BernoulliLogit(logit_psi[i]), 1) +
logpdf(BinomialLogit(K, logit_theta[i]), X[i, j])
if X[i, j] > 0
DynamicPPL.@addlogprob! occupied
else
DynamicPPL.@addlogprob! logaddexp(
occupied, logpdf(BernoulliLogit(logit_psi[i]), 0)
)
end
end
end
for i in (n + 1):S
unobserved = logaddexp(
logpdf(BernoulliLogit(logit_psi[i]), 1) +
logpdf(BinomialLogit(K, logit_theta[i]), 0),
logpdf(BernoulliLogit(logit_psi[i]), 0),
)
DynamicPPL.@addlogprob! logaddexp(
logpdf(Bernoulli(Omega), 0), logpdf(Bernoulli(Omega), 1) + J * unobserved
)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
18.5 μs · 24 calls
14.3 μs · 44 calls
26.3 μs
29.1 μs
20261122T002521Z-565231f-registered-repeat-1
Off
19.4 μs · 32 calls
14.4 μs · 28 calls
21.7 μs
32.6 μs
20261122T002521Z-565231f
On · no reduction
18.5 μs · 24 calls
14.3 μs · 44 calls
26.3 μs
29.1 μs
20261122T002521Z-565231f
Off
19.4 μs · 32 calls
14.4 μs · 28 calls
21.7 μs
32.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
17.8 μs · 32 calls
18.6 μs · 64 calls
20.8 μs
32.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
19.4 μs · 52 calls
14.2 μs · 48 calls
21.5 μs
33.9 μs
20261122T000034Z-565231f
On · no reduction
17.8 μs · 32 calls
18.6 μs · 64 calls
20.8 μs
32.9 μs
20261122T000034Z-565231f
Off
19.4 μs · 52 calls
14.2 μs · 48 calls
21.5 μs
33.9 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
8.27 μs · 79 calls
20.7 μs
25.1 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
7.82 μs · 80 calls
16.7 μs
29 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
8.27 μs · 79 calls
20.7 μs
25.1 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
7.82 μs · 80 calls
16.7 μs
29 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 20.9 μs · value and gradient 36.2 μs
PosteriorDB model multi_occupancy · dataset butterfly · SHA-256 455d722d60b508fc799ed5e2ab666831b55d905ad219272173491fd8cc132eff
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@wren function diamonds(y, Xc, prior_only)
@iid b ~ WD.Normal(0.0, 1.0) size=size(Xc, 2)
Intercept ~ WD.TDist(3.0, 8.0, 10.0)
sigma ~ WD.HalfTDist(3.0, 0.0, 10.0)
if prior_only == 0
mu = Intercept .+ Xc * b
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
end
return nothing
end
@model function diamonds_model(stats, prior_only)
data = stats.value
b ~ product_distribution(Fill(Normal(), size(data.XtX, 1)))
Intercept ~ LocationScale(8, 10, TDist(3))
sigma ~ truncated(LocationScale(0, 10, TDist(3)); lower=0)
if prior_only == 0
sse =
data.yty - 2dot(b, data.Xty) - 2Intercept * data.ysum +
dot(b, data.XtX * b) +
2Intercept * dot(data.xsum, b) +
data.n * Intercept^2
DynamicPPL.@addlogprob! -0.5data.n * log(2pi) - data.n * log(sigma) -
0.5sse / sigma^2
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
8.52 μs · 60 calls
19.6 μs · 48 calls
15.7 μs
28.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
8.63 μs · 20 calls
18.8 μs · 40 calls
16 μs
29.2 μs
20261122T002521Z-565231f
On · no reduction
8.52 μs · 60 calls
19.6 μs · 48 calls
15.7 μs
28.2 μs
20261122T002521Z-565231f
Off
8.63 μs · 20 calls
18.8 μs · 40 calls
16 μs
29.2 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
8.3 μs · 48 calls
19.3 μs · 44 calls
17.2 μs
30.1 μs
20261122T000034Z-565231f-registered-repeat-1
Off
10 μs · 100 calls
19.4 μs · 48 calls
18.1 μs
28.9 μs
20261122T000034Z-565231f
On · no reduction
8.3 μs · 48 calls
19.3 μs · 44 calls
17.2 μs
30.1 μs
20261122T000034Z-565231f
Off
10 μs · 100 calls
19.4 μs · 48 calls
18.1 μs
28.9 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
18.5 μs · 38 calls
13.9 μs
24.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
16.2 μs · 42 calls
15.6 μs
25.8 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
18.5 μs · 38 calls
13.9 μs
24.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
16.2 μs · 42 calls
15.6 μs
25.8 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 16.6 μs · value and gradient 30.2 μs
PosteriorDB model diamonds · dataset diamonds · SHA-256 681cd95077f24986782f8ad2b52f1a0ca80b337d368d6be155264b6abe3ba21d
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
13.7 μs
35.4 μs
FlatPPL · normal optimizations
15.7 μs · 1.15× Wren
28.2 μs · 0.797× Wren
FlatPPL · equal work
16 μs · 1.17× Wren
29.2 μs · 0.825× Wren
Wren definition in this run
@wren function diamonds(y, Xc, prior_only)
@iid b ~ WD.Normal(0.0, 1.0) size=size(Xc, 2)
Intercept ~ WD.TDist(3.0, 8.0, 10.0)
sigma ~ WD.HalfTDist(3.0, 0.0, 10.0)
if prior_only == 0
mu = Intercept .+ Xc * b
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
13.3 μs
35.6 μs
FlatPPL · normal optimizations
17.2 μs · 1.29× Wren
30.1 μs · 0.848× Wren
FlatPPL · equal work
18.1 μs · 1.37× Wren
28.9 μs · 0.814× Wren
Wren definition in this run
@wren function diamonds(y, Xc, prior_only)
@iid b ~ WD.Normal(0.0, 1.0) size=size(Xc, 2)
Intercept ~ WD.TDist(3.0, 8.0, 10.0)
sigma ~ WD.HalfTDist(3.0, 0.0, 10.0)
if prior_only == 0
mu = Intercept .+ Xc * b
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
13.4 μs
32.2 μs
FlatPPL · normal optimizations
13.9 μs · 1.04× Wren
24.3 μs · 0.754× Wren
FlatPPL · equal work
15.6 μs · 1.17× Wren
25.8 μs · 0.8× Wren
Wren definition in this run
@wren function diamonds(y, Xc, prior_only)
@iid b ~ WD.Normal(0.0, 1.0) size=size(Xc, 2)
Intercept ~ WD.TDist(3.0, 8.0, 10.0)
sigma ~ WD.HalfTDist(3.0, 0.0, 10.0)
if prior_only == 0
mu = Intercept .+ Xc * b
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
end
return nothing
end
@wren function dogs_model(y, shocks, avoids)
@iid beta ~ WD.Normal(0.0, 100.0) size=3
eta = beta[1] .+ beta[2] .* avoids .+ beta[3] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_dogs(n_dogs, n_trials, y, prev_shock, prev_avoid)
beta ~ product_distribution(Fill(Normal(0, 100), 3))
for i in 1:n_dogs
for j in 1:n_trials
p = beta[1] + beta[2] * prev_avoid[i, j] + beta[3] * prev_shock[i, j]
DynamicPPL.@addlogprob! logpdf(BernoulliLogit(p), y[i, j])
end
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
5.41 μs · 80 calls
9.43 μs · 100 calls
10.9 μs
15.8 μs
20261122T002521Z-565231f-registered-repeat-1
Off
6.54 μs · 104 calls
9.67 μs · 92 calls
10.7 μs
15.6 μs
20261122T002521Z-565231f
On · no reduction
5.41 μs · 80 calls
9.43 μs · 100 calls
10.9 μs
15.8 μs
20261122T002521Z-565231f
Off
6.54 μs · 104 calls
9.67 μs · 92 calls
10.7 μs
15.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
6.88 μs · 132 calls
8.88 μs · 96 calls
10.7 μs
15.7 μs
20261122T000034Z-565231f-registered-repeat-1
Off
5.78 μs · 148 calls
8.02 μs · 28 calls
11.3 μs
16 μs
20261122T000034Z-565231f
On · no reduction
6.88 μs · 132 calls
8.88 μs · 96 calls
10.7 μs
15.7 μs
20261122T000034Z-565231f
Off
5.78 μs · 148 calls
8.02 μs · 28 calls
11.3 μs
16 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 16.1 μs · value and gradient 17.5 μs
PosteriorDB model dogs · dataset dogs · SHA-256 a0a846b35922994afb60ed464eecf3e118efe06fa04b917eda5e642668986211
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
2.49 μs
4.43 μs
FlatPPL · normal optimizations
10.9 μs · 4.4× Wren
15.8 μs · 3.57× Wren
FlatPPL · equal work
10.7 μs · 4.31× Wren
15.6 μs · 3.51× Wren
Wren definition in this run
@wren function dogs_model(y, shocks, avoids)
@iid beta ~ WD.Normal(0.0, 100.0) size=3
eta = beta[1] .+ beta[2] .* avoids .+ beta[3] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.54 μs
4.05 μs
FlatPPL · normal optimizations
10.7 μs · 6.91× Wren
15.7 μs · 3.88× Wren
FlatPPL · equal work
11.3 μs · 7.29× Wren
16 μs · 3.96× Wren
Wren definition in this run
@wren function dogs_model(y, shocks, avoids)
@iid beta ~ WD.Normal(0.0, 100.0) size=3
eta = beta[1] .+ beta[2] .* avoids .+ beta[3] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.64 μs
4.34 μs
FlatPPL · normal optimizations
evaluation failed
evaluation failed
FlatPPL · equal work
evaluation failed
evaluation failed
Wren definition in this run
@wren function dogs_model(y, shocks, avoids)
@iid beta ~ WD.Normal(0.0, 100.0) size=3
eta = beta[1] .+ beta[2] .* avoids .+ beta[3] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@wren function dogs_hierarchical(y, shocks, avoids)
a ~ WD.Uniform(0.0, 1.0)
b ~ WD.Uniform(0.0, 1.0)
p = a .^ shocks .* b .^ avoids
@batch for i in eachindex(y)
@observe y[i] ~ WD.Bernoulli(p[i])
end
return nothing
end
%%%
# Learning from shocks and avoidances
PosteriorDB's `dogs-dogs_hierarchical`. Two shared probabilities describe
learning across 25 trials for 30 dogs. Each shock probability depends on the
numbers of shocks and avoidances strictly before that trial.
The likelihood conditions on observed histories. Simulating new trajectories
requires updating those histories from the simulated outcomes.
%%%
flatppl_compat = "0.1"
J = 30
T = 25
data = load_data("data.json", cartprod(y = cartpow(nonnegintegers, [J, T])))
dogs = indicesof(zeros(J))
previous_trials = indicesof(zeros(T - 1))
shock_history(j) = cat([0], scan((total, shock) -> total + shock,
0, data.y[j, previous_trials]))
avoid_history(j) = (indicesof(zeros(T)) .- 1) .- shock_history(j)
previous_shocks = rowstack(shock_history.(dogs))
previous_avoidances = rowstack(avoid_history.(dogs))
a ~ Uniform(unitinterval)
b ~ Uniform(unitinterval)
shock_probability = (a .^ previous_shocks) .* (b .^ previous_avoidances)
y ~ Bernoulli.(shock_probability)
Pi_prior = lawof(record(a = a, b = b))
K_model = kernelof(record(y = y), a = a, b = b)
L = likelihoodof(K_model, record(y = data.y))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(a = unitinterval, b = unitinterval)
Pi_post_input = record(a = 0.8, b = 0.8)
@model function pdb_dogs_hierarchical(n_dogs, n_trials, y, prev_shock, prev_avoid)
J = n_dogs
T = n_trials
a ~ Uniform(0, 1)
b ~ Uniform(0, 1)
DynamicPPL.@addlogprob! logpdf(
product_distribution(map(Bernoulli, a .^ prev_shock .* b .^ prev_avoid)), y
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
30.4 μs · 20 calls
25.7 μs · 12 calls
34.4 μs
31 μs
20261122T002521Z-565231f-registered-repeat-1
Off
33.1 μs · 24 calls
26.6 μs · 40 calls
34.5 μs
32.6 μs
20261122T002521Z-565231f
On · no reduction
30.4 μs · 20 calls
25.7 μs · 12 calls
34.4 μs
31 μs
20261122T002521Z-565231f
Off
33.1 μs · 24 calls
26.6 μs · 40 calls
34.5 μs
32.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
40.8 μs · 4 calls
23.8 μs · 24 calls
35.7 μs
32.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
32.8 μs · 4 calls
29.7 μs · 20 calls
34.9 μs
31.3 μs
20261122T000034Z-565231f
On · no reduction
40.8 μs · 4 calls
23.8 μs · 24 calls
35.7 μs
32.6 μs
20261122T000034Z-565231f
Off
32.8 μs · 4 calls
29.7 μs · 20 calls
34.9 μs
31.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
22.3 μs · 27 calls
33.7 μs
31.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
23.1 μs · 35 calls
33 μs
30.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
22.3 μs · 27 calls
33.7 μs
31.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
23.1 μs · 35 calls
33 μs
30.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 33.8 μs · value and gradient 32.1 μs
PosteriorDB model dogs_hierarchical · dataset dogs · SHA-256 a0a846b35922994afb60ed464eecf3e118efe06fa04b917eda5e642668986211
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.37 μs
15.8 μs
FlatPPL · normal optimizations
34.4 μs · 6.4× Wren
31 μs · 1.97× Wren
FlatPPL · equal work
34.5 μs · 6.43× Wren
32.6 μs · 2.06× Wren
Wren definition in this run
@wren function dogs_hierarchical(y, shocks, avoids)
a ~ WD.Uniform(0.0, 1.0)
b ~ WD.Uniform(0.0, 1.0)
p = a .^ shocks .* b .^ avoids
@batch for i in eachindex(y)
@observe y[i] ~ WD.Bernoulli(p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.06 μs
14.6 μs
FlatPPL · normal optimizations
35.7 μs · 7.05× Wren
32.6 μs · 2.22× Wren
FlatPPL · equal work
34.9 μs · 6.9× Wren
31.3 μs · 2.14× Wren
Wren definition in this run
@wren function dogs_hierarchical(y, shocks, avoids)
a ~ WD.Uniform(0.0, 1.0)
b ~ WD.Uniform(0.0, 1.0)
p = a .^ shocks .* b .^ avoids
@batch for i in eachindex(y)
@observe y[i] ~ WD.Bernoulli(p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.12 μs
16.1 μs
FlatPPL · normal optimizations
33.7 μs · 6.57× Wren
31.8 μs · 1.98× Wren
FlatPPL · equal work
33 μs · 6.44× Wren
30.5 μs · 1.9× Wren
Wren definition in this run
@wren function dogs_hierarchical(y, shocks, avoids)
a ~ WD.Uniform(0.0, 1.0)
b ~ WD.Uniform(0.0, 1.0)
p = a .^ shocks .* b .^ avoids
@batch for i in eachindex(y)
@observe y[i] ~ WD.Bernoulli(p[i])
end
return nothing
end
@wren function dogs_log(y, shocks, avoids)
# Stan declares unconstrained beta and imposes bounded uniform factors in the model block.
@iid beta ~ WD.Flat() size=2
@observe beta[1] ~ WD.Uniform(-100.0, 0.0)
@observe beta[2] ~ WD.Uniform(0.0, 100.0)
eta = beta[1] .* avoids .+ beta[2] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_dogs_log(n_dogs, n_trials, y, prev_shock, prev_avoid)
@assert size(y) == (n_dogs, n_trials)
# Stan declares beta unconstrained and applies bounded priors in the model.
# Keep the same identity parameterisation rather than introducing DynamicPPL's
# bounded transform for a product of Uniform distributions.
beta ~ product_distribution(Fill(Flat(), 2))
DynamicPPL.@addlogprob! logpdf(Uniform(-100, 0), beta[1])
DynamicPPL.@addlogprob! logpdf(Uniform(0, 100), beta[2])
for i in 1:n_dogs
for j in 1:n_trials
p = logistic(beta[1] * prev_avoid[i, j] + beta[2] * prev_shock[i, j])
DynamicPPL.@addlogprob! logpdf(Bernoulli(p), y[i, j])
end
end
end
same(x) = x
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
6.16 μs · 96 calls
8.49 μs · 84 calls
12.7 μs
15.9 μs
20261122T002521Z-565231f-registered-repeat-1
Off
6.31 μs · 116 calls
8.41 μs · 84 calls
12.2 μs
18.9 μs
20261122T002521Z-565231f
On · no reduction
6.16 μs · 96 calls
8.49 μs · 84 calls
12.7 μs
15.9 μs
20261122T002521Z-565231f
Off
6.31 μs · 116 calls
8.41 μs · 84 calls
12.2 μs
18.9 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
6.18 μs · 116 calls
8.3 μs · 88 calls
12.4 μs
15.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
6.67 μs · 120 calls
10.9 μs · 80 calls
11.9 μs
15.2 μs
20261122T000034Z-565231f
On · no reduction
6.18 μs · 116 calls
8.3 μs · 88 calls
12.4 μs
15.6 μs
20261122T000034Z-565231f
Off
6.67 μs · 120 calls
10.9 μs · 80 calls
11.9 μs
15.2 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
6.56 μs · 83 calls
10.6 μs
13.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
6.23 μs · 104 calls
11.4 μs
12.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
6.56 μs · 83 calls
10.6 μs
13.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
6.23 μs · 104 calls
11.4 μs
12.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 12.1 μs · value and gradient 16.7 μs
PosteriorDB model dogs_log · dataset dogs · SHA-256 a0a846b35922994afb60ed464eecf3e118efe06fa04b917eda5e642668986211
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
7.4 μs
11.5 μs
FlatPPL · normal optimizations
12.7 μs · 1.71× Wren
15.9 μs · 1.38× Wren
FlatPPL · equal work
12.2 μs · 1.65× Wren
18.9 μs · 1.64× Wren
Wren definition in this run
@wren function dogs_log(y, shocks, avoids)
# Stan declares unconstrained beta and imposes bounded uniform factors in the model block.
@iid beta ~ WD.Flat() size=2
@observe beta[1] ~ WD.Uniform(-100.0, 0.0)
@observe beta[2] ~ WD.Uniform(0.0, 100.0)
eta = beta[1] .* avoids .+ beta[2] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
7.26 μs
11.7 μs
FlatPPL · normal optimizations
12.4 μs · 1.7× Wren
15.6 μs · 1.33× Wren
FlatPPL · equal work
11.9 μs · 1.64× Wren
15.2 μs · 1.3× Wren
Wren definition in this run
@wren function dogs_log(y, shocks, avoids)
# Stan declares unconstrained beta and imposes bounded uniform factors in the model block.
@iid beta ~ WD.Flat() size=2
@observe beta[1] ~ WD.Uniform(-100.0, 0.0)
@observe beta[2] ~ WD.Uniform(0.0, 100.0)
eta = beta[1] .* avoids .+ beta[2] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
7.02 μs
11.8 μs
FlatPPL · normal optimizations
10.6 μs · 1.51× Wren
13.8 μs · 1.16× Wren
FlatPPL · equal work
11.4 μs · 1.63× Wren
12.9 μs · 1.09× Wren
Wren definition in this run
@wren function dogs_log(y, shocks, avoids)
# Stan declares unconstrained beta and imposes bounded uniform factors in the model block.
@iid beta ~ WD.Flat() size=2
@observe beta[1] ~ WD.Uniform(-100.0, 0.0)
@observe beta[2] ~ WD.Uniform(0.0, 100.0)
eta = beta[1] .* avoids .+ beta[2] .* shocks
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_dogs_nonhierarchical(n_dogs, n_trials, y, prev_shock, prev_avoid)
J = n_dogs
T = n_trials
mu_logit_ab ~ product_distribution(Fill(Logistic(0, 1), 2))
sigma_logit_ab ~ product_distribution(Fill(FlatPos(0), 2))
L_logit_ab ~ LKJCholesky(2, 2.0)
z ~ product_distribution(Fill(Normal(0, 1), J, 2))
logit_ab = ones(J) * mu_logit_ab' + z * (Diagonal(sigma_logit_ab) * L_logit_ab.L)
a = logistic.(logit_ab[:, 1])
b = logistic.(logit_ab[:, 2])
DynamicPPL.@addlogprob! logpdf(
product_distribution(map(Bernoulli, a .^ prev_shock .* b .^ prev_avoid)), y
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, 1), size(sigma_logit_ab))), sigma_logit_ab
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
13.9 μs · 24 calls
31.1 μs · 4 calls
22 μs
35.4 μs
20261122T002521Z-565231f-registered-repeat-1
Off
14.5 μs · 12 calls
25 μs · 8 calls
21.4 μs
33.9 μs
20261122T002521Z-565231f
On · no reduction
13.9 μs · 24 calls
31.1 μs · 4 calls
22 μs
35.4 μs
20261122T002521Z-565231f
Off
14.5 μs · 12 calls
25 μs · 8 calls
21.4 μs
33.9 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
18.3 μs · 52 calls
25.1 μs · 20 calls
20.8 μs
36.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
13.2 μs · 28 calls
23.1 μs · 28 calls
22.8 μs
33.4 μs
20261122T000034Z-565231f
On · no reduction
18.3 μs · 52 calls
25.1 μs · 20 calls
20.8 μs
36.8 μs
20261122T000034Z-565231f
Off
13.2 μs · 28 calls
23.1 μs · 28 calls
22.8 μs
33.4 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 28.6 μs · value and gradient 32.4 μs
PosteriorDB model dogs_nonhierarchical · dataset dogs · SHA-256 a0a846b35922994afb60ed464eecf3e118efe06fa04b917eda5e642668986211
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_dugongs_model(N, x, Y)
x_ = x
alpha ~ Normal(0.0, 1000.0)
beta ~ Normal(0.0, 1000.0)
lambda ~ Uniform(0.5, 1.0)
tau ~ Gamma(0.0001, inv(0.0001))
sigma = 1.0 / sqrt(tau)
U3 = logit(lambda)
for i in 1:N
m = alpha - beta * lambda^x_[i]
DynamicPPL.@addlogprob! logpdf(Normal(m, sigma), Y[i])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
165 ns · 1948 calls
308 ns · 1328 calls
3.53 μs
5.83 μs
20261122T002521Z-565231f-registered-repeat-1
Off
200 ns · 124 calls
315 ns · 1688 calls
3.64 μs
5.5 μs
20261122T002521Z-565231f
On · no reduction
165 ns · 1948 calls
308 ns · 1328 calls
3.53 μs
5.83 μs
20261122T002521Z-565231f
Off
200 ns · 124 calls
315 ns · 1688 calls
3.64 μs
5.5 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
177 ns · 1968 calls
239 ns · 948 calls
3.51 μs
5.48 μs
20261122T000034Z-565231f-registered-repeat-1
Off
246 ns · 68 calls
242 ns · 556 calls
3.63 μs
5.68 μs
20261122T000034Z-565231f
On · no reduction
177 ns · 1968 calls
239 ns · 948 calls
3.51 μs
5.48 μs
20261122T000034Z-565231f
Off
246 ns · 68 calls
242 ns · 556 calls
3.63 μs
5.68 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
238 ns · 502 calls
3.63 μs
5.57 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
248 ns · 560 calls
3.46 μs
5.37 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
238 ns · 502 calls
3.63 μs
5.57 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
248 ns · 560 calls
3.46 μs
5.37 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.55 μs · value and gradient 5.71 μs
PosteriorDB model dugongs_model · dataset dugongs_data · SHA-256 f0334744aca0dc4042b1f8fc890fa06806506b7ab948c408da9af4a2cf8ce13c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
314 ns
1.76 μs
FlatPPL · normal optimizations
3.53 μs · 11.3× Wren
5.83 μs · 3.3× Wren
FlatPPL · equal work
3.64 μs · 11.6× Wren
5.5 μs · 3.12× Wren
Wren definition in this run
@wren function dugongs_model(x, y)
alpha ~ WD.Normal(0.0, 1000.0)
beta ~ WD.Normal(0.0, 1000.0)
lambda ~ WD.Uniform(0.5, 1.0)
# Stan Gamma uses a rate; WrenDists Gamma uses a scale.
tau ~ WD.Gamma(0.0001, 10000.0)
sigma = inv(sqrt(tau))
mu = alpha .- beta .* (lambda .^ x)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
313 ns
1.78 μs
FlatPPL · normal optimizations
3.51 μs · 11.2× Wren
5.48 μs · 3.08× Wren
FlatPPL · equal work
3.63 μs · 11.6× Wren
5.68 μs · 3.19× Wren
Wren definition in this run
@wren function dugongs_model(x, y)
alpha ~ WD.Normal(0.0, 1000.0)
beta ~ WD.Normal(0.0, 1000.0)
lambda ~ WD.Uniform(0.5, 1.0)
# Stan Gamma uses a rate; WrenDists Gamma uses a scale.
tau ~ WD.Gamma(0.0001, 10000.0)
sigma = inv(sqrt(tau))
mu = alpha .- beta .* (lambda .^ x)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
342 ns
1.76 μs
FlatPPL · normal optimizations
3.63 μs · 10.6× Wren
5.57 μs · 3.16× Wren
FlatPPL · equal work
3.46 μs · 10.1× Wren
5.37 μs · 3.05× Wren
Wren definition in this run
@wren function dugongs_model(x, y)
alpha ~ WD.Normal(0.0, 1000.0)
beta ~ WD.Normal(0.0, 1000.0)
lambda ~ WD.Uniform(0.5, 1.0)
# Stan Gamma uses a rate; WrenDists Gamma uses a scale.
tau ~ WD.Gamma(0.0001, 10000.0)
sigma = inv(sqrt(tau))
mu = alpha .- beta .* (lambda .^ x)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
const FLAT_GAUSSIAN = @model X begin
beta ~ Lebesgue(ℝ) ^ size(X, 2)
sigma ~ Half(Lebesgue(ℝ))
mu = X * beta
y ~ For(mu) do m
Normal(m, sigma)
end
end
const FLAT_GAUSSIAN_LEBESGUE_POSITIVE = @model X begin
beta ~ Lebesgue(ℝ) ^ size(X, 2)
sigma ~ Lebesgue(ℝ₊)
mu = X * beta
y ~ For(mu) do m
Normal(m, sigma)
end
end
@model function flat_gaussian(X, y)
beta ~ filldist(Flat(), size(X, 2))
sigma ~ FlatPos(0.0)
y ~ MvNormal(X * beta, sigma^2 * I)
end
@model function flat_gaussian_loop(X, y)
beta ~ filldist(Flat(), size(X, 2))
sigma ~ FlatPos(0.0)
mu = X * beta
for i in eachindex(y)
y[i] ~ Normal(mu[i], sigma)
end
end
@model function earnings_earn_height(earn, height)
beta ~ product_distribution(Fill(Flat(), 2))
sigma ~ FlatPos(0.0)
mu = beta[1] .+ beta[2] .* height
return earn ~ MvNormal(mu, sigma)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.25 μs · 420 calls
1.26 μs · 564 calls
6.71 μs
7.95 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.43 μs · 496 calls
1.47 μs · 96 calls
6.82 μs
12.2 μs
20261122T002521Z-565231f
On · no reduction
1.25 μs · 420 calls
1.26 μs · 564 calls
6.71 μs
7.95 μs
20261122T002521Z-565231f
Off
1.43 μs · 496 calls
1.47 μs · 96 calls
6.82 μs
12.2 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
966 ns · 480 calls
1.17 μs · 112 calls
5.82 μs
7.24 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.07 μs · 540 calls
1.2 μs · 588 calls
5.37 μs
6.55 μs
20261122T000034Z-565231f
On · no reduction
966 ns · 480 calls
1.17 μs · 112 calls
5.82 μs
7.24 μs
20261122T000034Z-565231f
Off
1.07 μs · 540 calls
1.2 μs · 588 calls
5.37 μs
6.55 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.08 μs · 321 calls
4.7 μs
5.86 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.06 μs · 442 calls
4.2 μs
5.49 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.08 μs · 321 calls
4.7 μs
5.86 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.06 μs · 442 calls
4.2 μs
5.49 μs
20261114T233319Z-f022c87
On · reduced
JIT-loop timing not recorded
1.39 μs · 149 calls
120 μs
136 μs
20261114T233319Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
5.29 μs
7.96 μs
20261114T225256Z-f022c87
On · reduced
JIT-loop timing not recorded
1.32 μs · 148 calls
115 μs
136 μs
20261114T225256Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
4.78 μs
8.16 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.47 μs · value and gradient 10.6 μs
PosteriorDB model earn_height · dataset earnings · SHA-256 a3c1192078b1e08b68bed1c075ebb3072c84db7dc031b678ab66293d3691504c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.21 μs
2.59 μs
FlatPPL · normal optimizations
6.71 μs · 5.55× Wren
7.95 μs · 3.07× Wren
FlatPPL · equal work
6.82 μs · 5.64× Wren
12.2 μs · 4.71× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.26 μs
1.93 μs
FlatPPL · normal optimizations
5.82 μs · 4.61× Wren
7.24 μs · 3.75× Wren
FlatPPL · equal work
5.37 μs · 4.25× Wren
6.55 μs · 3.39× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.34 μs
1.94 μs
FlatPPL · normal optimizations
4.7 μs · 3.52× Wren
5.86 μs · 3.01× Wren
FlatPPL · equal work
4.2 μs · 3.14× Wren
5.49 μs · 2.82× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function earnings_log10earn_height(log10_earn, height)
beta ~ product_distribution(Fill(Flat(), 2))
sigma ~ FlatPos(0.0)
mu = beta[1] .+ beta[2] .* height
return log10_earn ~ MvNormal(mu, sigma)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.14 μs · 564 calls
1.21 μs · 112 calls
5.71 μs
9.63 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.22 μs · 608 calls
1.49 μs · 364 calls
7.5 μs
11.7 μs
20261122T002521Z-565231f
On · no reduction
1.14 μs · 564 calls
1.21 μs · 112 calls
5.71 μs
9.63 μs
20261122T002521Z-565231f
Off
1.22 μs · 608 calls
1.49 μs · 364 calls
7.5 μs
11.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.08 μs · 588 calls
1.26 μs · 544 calls
4.98 μs
7.1 μs
20261122T000034Z-565231f-registered-repeat-1
Off
949 ns · 456 calls
1.21 μs · 272 calls
5.95 μs
7.21 μs
20261122T000034Z-565231f
On · no reduction
1.08 μs · 588 calls
1.26 μs · 544 calls
4.98 μs
7.1 μs
20261122T000034Z-565231f
Off
949 ns · 456 calls
1.21 μs · 272 calls
5.95 μs
7.21 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.31 μs · 452 calls
4.86 μs
5.57 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.1 μs · 399 calls
4.2 μs
5.71 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.31 μs · 452 calls
4.86 μs
5.57 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.1 μs · 399 calls
4.2 μs
5.71 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 9.42 μs · value and gradient 9.59 μs
PosteriorDB model log10earn_height · dataset earnings · SHA-256 a3c1192078b1e08b68bed1c075ebb3072c84db7dc031b678ab66293d3691504c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.24 μs
2.01 μs
FlatPPL · normal optimizations
5.71 μs · 4.59× Wren
9.63 μs · 4.79× Wren
FlatPPL · equal work
7.5 μs · 6.03× Wren
11.7 μs · 5.81× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.21 μs
2.23 μs
FlatPPL · normal optimizations
4.98 μs · 4.12× Wren
7.1 μs · 3.18× Wren
FlatPPL · equal work
5.95 μs · 4.93× Wren
7.21 μs · 3.23× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.16 μs
2.35 μs
FlatPPL · normal optimizations
4.86 μs · 4.2× Wren
5.57 μs · 2.37× Wren
FlatPPL · equal work
4.2 μs · 3.63× Wren
5.71 μs · 2.43× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function earnings_logearn_height(log_earn, height)
beta ~ product_distribution(Fill(Flat(), 2))
sigma ~ FlatPos(0.0)
mu = beta[1] .+ beta[2] .* height
return log_earn ~ MvNormal(mu, sigma)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.24 μs · 508 calls
1.14 μs · 536 calls
9.4 μs
14.9 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.34 μs · 572 calls
1.61 μs · 44 calls
7.33 μs
7.12 μs
20261122T002521Z-565231f
On · no reduction
1.24 μs · 508 calls
1.14 μs · 536 calls
9.4 μs
14.9 μs
20261122T002521Z-565231f
Off
1.34 μs · 572 calls
1.61 μs · 44 calls
7.33 μs
7.12 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.01 μs · 596 calls
1.11 μs · 572 calls
5.96 μs
7.51 μs
20261122T000034Z-565231f-registered-repeat-1
Off
995 ns · 520 calls
1.18 μs · 500 calls
9.15 μs
8.96 μs
20261122T000034Z-565231f
On · no reduction
1.01 μs · 596 calls
1.11 μs · 572 calls
5.96 μs
7.51 μs
20261122T000034Z-565231f
Off
995 ns · 520 calls
1.18 μs · 500 calls
9.15 μs
8.96 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.1 μs · 292 calls
4.15 μs
6.17 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.17 μs · 397 calls
5.35 μs
6.23 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.1 μs · 292 calls
4.15 μs
6.17 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.17 μs · 397 calls
5.35 μs
6.23 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.91 μs · value and gradient 7.37 μs
PosteriorDB model logearn_height · dataset earnings · SHA-256 a3c1192078b1e08b68bed1c075ebb3072c84db7dc031b678ab66293d3691504c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.12 μs
2.13 μs
FlatPPL · normal optimizations
9.4 μs · 8.39× Wren
14.9 μs · 6.98× Wren
FlatPPL · equal work
7.33 μs · 6.54× Wren
7.12 μs · 3.34× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.17 μs
2.13 μs
FlatPPL · normal optimizations
5.96 μs · 5.09× Wren
7.51 μs · 3.53× Wren
FlatPPL · equal work
9.15 μs · 7.81× Wren
8.96 μs · 4.21× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.36 μs
1.9 μs
FlatPPL · normal optimizations
4.15 μs · 3.05× Wren
6.17 μs · 3.26× Wren
FlatPPL · equal work
5.35 μs · 3.94× Wren
6.23 μs · 3.29× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function earnings_logearn_height_male(log_earn, height, male)
beta ~ product_distribution(Fill(Flat(), 3))
sigma ~ FlatPos(0.0)
mu = beta[1] .+ beta[2] .* height .+ beta[3] .* male
return log_earn ~ MvNormal(mu, sigma)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.42 μs · 464 calls
1.36 μs · 500 calls
6.11 μs
9.02 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.26 μs · 360 calls
1.27 μs · 316 calls
6.08 μs
8.96 μs
20261122T002521Z-565231f
On · no reduction
1.42 μs · 464 calls
1.36 μs · 500 calls
6.11 μs
9.02 μs
20261122T002521Z-565231f
Off
1.26 μs · 360 calls
1.27 μs · 316 calls
6.08 μs
8.96 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.18 μs · 508 calls
1.21 μs · 496 calls
6.05 μs
7.3 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.21 μs · 472 calls
1.33 μs · 40 calls
5.2 μs
8.35 μs
20261122T000034Z-565231f
On · no reduction
1.18 μs · 508 calls
1.21 μs · 496 calls
6.05 μs
7.3 μs
20261122T000034Z-565231f
Off
1.21 μs · 472 calls
1.33 μs · 40 calls
5.2 μs
8.35 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.15 μs · 511 calls
5.72 μs
7.48 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.18 μs · 274 calls
5.85 μs
6.34 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.15 μs · 511 calls
5.72 μs
7.48 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.18 μs · 274 calls
5.85 μs
6.34 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 7.27 μs · value and gradient 7.03 μs
PosteriorDB model logearn_height_male · dataset earnings · SHA-256 a3c1192078b1e08b68bed1c075ebb3072c84db7dc031b678ab66293d3691504c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.19 μs
2.18 μs
FlatPPL · normal optimizations
6.11 μs · 5.15× Wren
9.02 μs · 4.15× Wren
FlatPPL · equal work
6.08 μs · 5.12× Wren
8.96 μs · 4.12× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.28 μs
2.32 μs
FlatPPL · normal optimizations
6.05 μs · 4.74× Wren
7.3 μs · 3.15× Wren
FlatPPL · equal work
5.2 μs · 4.07× Wren
8.35 μs · 3.6× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.38 μs
2.59 μs
FlatPPL · normal optimizations
5.72 μs · 4.14× Wren
7.48 μs · 2.89× Wren
FlatPPL · equal work
5.85 μs · 4.24× Wren
6.34 μs · 2.45× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function earnings_logearn_interaction(log_earn, height, male, interaction)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ FlatPos(0.0)
mu = beta[1] .+ beta[2] .* height .+ beta[3] .* male .+ beta[4] .* interaction
return log_earn ~ MvNormal(mu, sigma)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.53 μs · 80 calls
1.32 μs · 504 calls
5.22 μs
7.64 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.44 μs · 536 calls
1.3 μs · 440 calls
4.42 μs
7.56 μs
20261122T002521Z-565231f
On · no reduction
1.53 μs · 80 calls
1.32 μs · 504 calls
5.22 μs
7.64 μs
20261122T002521Z-565231f
Off
1.44 μs · 536 calls
1.3 μs · 440 calls
4.42 μs
7.56 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.48 μs · 368 calls
1.3 μs · 532 calls
6.11 μs
7.47 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.72 μs · 412 calls
1.54 μs · 260 calls
5.47 μs
7.57 μs
20261122T000034Z-565231f
On · no reduction
1.48 μs · 368 calls
1.3 μs · 532 calls
6.11 μs
7.47 μs
20261122T000034Z-565231f
Off
1.72 μs · 412 calls
1.54 μs · 260 calls
5.47 μs
7.57 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.24 μs · 307 calls
5.09 μs
6.79 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.23 μs · 396 calls
3.97 μs
6.09 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.24 μs · 307 calls
5.09 μs
6.79 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.23 μs · 396 calls
3.97 μs
6.09 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.64 μs · value and gradient 11.8 μs
PosteriorDB model logearn_interaction · dataset earnings · SHA-256 a3c1192078b1e08b68bed1c075ebb3072c84db7dc031b678ab66293d3691504c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.08 μs
2.59 μs
FlatPPL · normal optimizations
5.22 μs · 4.81× Wren
7.64 μs · 2.95× Wren
FlatPPL · equal work
4.42 μs · 4.07× Wren
7.56 μs · 2.91× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.16 μs
2.47 μs
FlatPPL · normal optimizations
6.11 μs · 5.25× Wren
7.47 μs · 3.03× Wren
FlatPPL · equal work
5.47 μs · 4.7× Wren
7.57 μs · 3.07× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.08 μs
2.52 μs
FlatPPL · normal optimizations
5.09 μs · 4.71× Wren
6.79 μs · 2.69× Wren
FlatPPL · equal work
3.97 μs · 3.68× Wren
6.09 μs · 2.42× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function earnings_logearn_interaction_z(log_earn, z_height, male, interaction)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ FlatPos(0.0)
mu = beta[1] .+ beta[2] .* z_height .+ beta[3] .* male .+ beta[4] .* interaction
return log_earn ~ MvNormal(mu, sigma)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.39 μs · 444 calls
1.67 μs · 532 calls
5.32 μs
7.78 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.44 μs · 416 calls
1.56 μs · 404 calls
4.2 μs
7.67 μs
20261122T002521Z-565231f
On · no reduction
1.39 μs · 444 calls
1.67 μs · 532 calls
5.32 μs
7.78 μs
20261122T002521Z-565231f
Off
1.44 μs · 416 calls
1.56 μs · 404 calls
4.2 μs
7.67 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.65 μs · 392 calls
1.4 μs · 68 calls
5.14 μs
7.53 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.79 μs · 428 calls
1.59 μs · 500 calls
5.23 μs
7.87 μs
20261122T000034Z-565231f
On · no reduction
1.65 μs · 392 calls
1.4 μs · 68 calls
5.14 μs
7.53 μs
20261122T000034Z-565231f
Off
1.79 μs · 428 calls
1.59 μs · 500 calls
5.23 μs
7.87 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.24 μs · 379 calls
4.47 μs
7.48 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.24 μs · 357 calls
4.45 μs
6.44 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.24 μs · 379 calls
4.47 μs
7.48 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.24 μs · 357 calls
4.45 μs
6.44 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.7 μs · value and gradient 9.21 μs
PosteriorDB model logearn_interaction_z · dataset earnings · SHA-256 a3c1192078b1e08b68bed1c075ebb3072c84db7dc031b678ab66293d3691504c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.12 μs
2.01 μs
FlatPPL · normal optimizations
5.32 μs · 4.77× Wren
7.78 μs · 3.88× Wren
FlatPPL · equal work
4.2 μs · 3.77× Wren
7.67 μs · 3.83× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.43 μs
2.03 μs
FlatPPL · normal optimizations
5.14 μs · 3.61× Wren
7.53 μs · 3.71× Wren
FlatPPL · equal work
5.23 μs · 3.67× Wren
7.87 μs · 3.88× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.11 μs
1.76 μs
FlatPPL · normal optimizations
4.47 μs · 4.04× Wren
7.48 μs · 4.25× Wren
FlatPPL · equal work
4.45 μs · 4.02× Wren
6.44 μs · 3.66× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function earnings_logearn_logheight_male(log_earn, log_height, male)
beta ~ product_distribution(Fill(Flat(), 3))
sigma ~ FlatPos(0.0)
mu = beta[1] .+ beta[2] .* log_height .+ beta[3] .* male
return log_earn ~ MvNormal(mu, sigma)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.18 μs · 460 calls
1.19 μs · 528 calls
5.78 μs
7.48 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.17 μs · 356 calls
1.31 μs · 512 calls
5.85 μs
7.42 μs
20261122T002521Z-565231f
On · no reduction
1.18 μs · 460 calls
1.19 μs · 528 calls
5.78 μs
7.48 μs
20261122T002521Z-565231f
Off
1.17 μs · 356 calls
1.31 μs · 512 calls
5.85 μs
7.42 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.25 μs · 508 calls
1.17 μs · 436 calls
9.79 μs
7.33 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.17 μs · 472 calls
1.26 μs · 492 calls
5.99 μs
8.69 μs
20261122T000034Z-565231f
On · no reduction
1.25 μs · 508 calls
1.17 μs · 436 calls
9.79 μs
7.33 μs
20261122T000034Z-565231f
Off
1.17 μs · 472 calls
1.26 μs · 492 calls
5.99 μs
8.69 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.2 μs · 417 calls
5.71 μs
6.92 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.15 μs · 367 calls
4.46 μs
5.71 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.2 μs · 417 calls
5.71 μs
6.92 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.15 μs · 367 calls
4.46 μs
5.71 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.34 μs · value and gradient 7.88 μs
PosteriorDB model logearn_logheight_male · dataset earnings · SHA-256 a3c1192078b1e08b68bed1c075ebb3072c84db7dc031b678ab66293d3691504c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.44 μs
1.96 μs
FlatPPL · normal optimizations
5.78 μs · 4.01× Wren
7.48 μs · 3.83× Wren
FlatPPL · equal work
5.85 μs · 4.06× Wren
7.42 μs · 3.8× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.29 μs
2.49 μs
FlatPPL · normal optimizations
9.79 μs · 7.58× Wren
7.33 μs · 2.94× Wren
FlatPPL · equal work
5.99 μs · 4.64× Wren
8.69 μs · 3.49× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.12 μs
2.06 μs
FlatPPL · normal optimizations
5.71 μs · 5.11× Wren
6.92 μs · 3.35× Wren
FlatPPL · equal work
4.46 μs · 3.99× Wren
5.71 μs · 2.77× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function pdb_covid19imperial_v2(M, P, fixed, observed_deaths)
data = fixed.value
mu ~ product_distribution(Fill(FlatPos(0), M))
alpha_hier ~ product_distribution(Fill(Gamma(0.1667, 1), P))
kappa ~ truncated(Normal(0, 0.5); lower=0)
tau ~ Exponential(inv(0.03))
y ~ product_distribution(Fill(Exponential(tau), M))
phi ~ truncated(Normal(0, 5); lower=0)
ifr_noise ~ product_distribution(Fill(truncated(Normal(1, 0.1); lower=0), M))
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(3.28, kappa), size(mu))), mu
)
death_mean_parts = Vector{Vector{typeof(mu[1])}}(undef, M)
adjusted_alpha = alpha_hier .- log(1.05) / 6
for m in 1:M
prediction = zeros(typeof(mu[1]), data.N2)
prediction[1:(data.N0)] .= y[m]
cumulative = zero(mu[1])
for i in 2:(data.N0)
cumulative += prediction[i]
end
for i in (data.N0 + 1):(data.N2)
infection = dot(data.SI_weights[i], prediction)
cumulative += prediction[i - 1]
reproduction = mu[m] * exp(-dot(view(data.X, m, i, :), adjusted_alpha))
susceptible = (data.pop[m] - cumulative) / data.pop[m]
prediction[i] = reproduction * susceptible * infection
end
expected_deaths = ifr_noise[m] .* (data.death_weights[m] * prediction)
expected_deaths[1] = 1.0e-15 * prediction[1]
death_mean_parts[m] = expected_deaths[data.EpidemicStart[m]:data.N[m]]
end
death_means = reduce(vcat, death_mean_parts)
log_denominator = log.(phi .+ death_means)
DynamicPPL.@addlogprob! sum(loggamma.(observed_deaths .+ phi)) -
length(observed_deaths) * loggamma(phi) -
data.count_logfactorial +
length(observed_deaths) * phi * log(phi) -
phi * sum(log_denominator) +
sum(xlogy.(observed_deaths, death_means)) -
dot(observed_deaths, log_denominator)
end
function _make_covid(data)
f = Float64.(data["f"])
N2 = Int(data["N2"])
SI_rev = reverse(Float64.(data["SI"]))
f_rev = permutedims(mapreduce(reverse, hcat, eachcol(f)))
SI_weights = [zeros(N2) for _ in 1:N2]
for i in 2:N2, j in 1:(i - 1)
SI_weights[i][j] = SI_rev[length(SI_rev) - i + j + 1]
end
death_weights = [zeros(N2, N2) for _ in 1:data["M"]]
for m in 1:data["M"], i in 2:N2, j in 1:(i - 1)
death_weights[m][i, j] = f_rev[m, size(f_rev, 2) - i + j + 1]
end
deaths = Int.(data["deaths"])
epidemic_start = Int.(data["EpidemicStart"])
observation_end = Int.(data["N"])
observed_deaths = [
deaths[i, m] for m in 1:data["M"] for i in epidemic_start[m]:observation_end[m]
]
fixed = _FixedData((
N0=Int(data["N0"]),
N2=N2,
N=observation_end,
EpidemicStart=epidemic_start,
X=Float64.(data["X"]),
pop=Float64.(data["pop"]),
SI_weights=SI_weights,
death_weights=death_weights,
count_logfactorial=sum(loggamma.(observed_deaths .+ 1)),
))
return pdb_covid19imperial_v2(data["M"], data["P"], fixed, observed_deaths)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
197 μs · 4 calls
625 μs · 4 calls
199 μs
400 μs
20261122T002521Z-565231f-registered-repeat-1
Off
251 μs · 4 calls
1.06 ms · 4 calls
205 μs
479 μs
20261122T002521Z-565231f
On · no reduction
197 μs · 4 calls
625 μs · 4 calls
199 μs
400 μs
20261122T002521Z-565231f
Off
251 μs · 4 calls
1.06 ms · 4 calls
205 μs
479 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
221 μs · 4 calls
659 μs · 4 calls
195 μs
385 μs
20261122T000034Z-565231f-registered-repeat-1
Off
268 μs · 4 calls
600 μs · 4 calls
209 μs
548 μs
20261122T000034Z-565231f
On · no reduction
221 μs · 4 calls
659 μs · 4 calls
195 μs
385 μs
20261122T000034Z-565231f
Off
268 μs · 4 calls
600 μs · 4 calls
209 μs
548 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
456 μs · 4 calls
182 μs
364 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
374 μs · 4 calls
168 μs
357 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
456 μs · 4 calls
182 μs
364 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
374 μs · 4 calls
168 μs
357 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 196 μs · value and gradient 407 μs
PosteriorDB model covid19imperial_v2 · dataset ecdc0401 · SHA-256 97389c0f2a24ffe59371abe416d72607471f5d319bae9b4f3495357d0a73544c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_covid19imperial_v2(M, P, fixed, observed_deaths)
data = fixed.value
mu ~ product_distribution(Fill(FlatPos(0), M))
alpha_hier ~ product_distribution(Fill(Gamma(0.1667, 1), P))
kappa ~ truncated(Normal(0, 0.5); lower=0)
tau ~ Exponential(inv(0.03))
y ~ product_distribution(Fill(Exponential(tau), M))
phi ~ truncated(Normal(0, 5); lower=0)
ifr_noise ~ product_distribution(Fill(truncated(Normal(1, 0.1); lower=0), M))
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(3.28, kappa), size(mu))), mu
)
death_mean_parts = Vector{Vector{typeof(mu[1])}}(undef, M)
adjusted_alpha = alpha_hier .- log(1.05) / 6
for m in 1:M
prediction = zeros(typeof(mu[1]), data.N2)
prediction[1:(data.N0)] .= y[m]
cumulative = zero(mu[1])
for i in 2:(data.N0)
cumulative += prediction[i]
end
for i in (data.N0 + 1):(data.N2)
infection = dot(data.SI_weights[i], prediction)
cumulative += prediction[i - 1]
reproduction = mu[m] * exp(-dot(view(data.X, m, i, :), adjusted_alpha))
susceptible = (data.pop[m] - cumulative) / data.pop[m]
prediction[i] = reproduction * susceptible * infection
end
expected_deaths = ifr_noise[m] .* (data.death_weights[m] * prediction)
expected_deaths[1] = 1.0e-15 * prediction[1]
death_mean_parts[m] = expected_deaths[data.EpidemicStart[m]:data.N[m]]
end
death_means = reduce(vcat, death_mean_parts)
log_denominator = log.(phi .+ death_means)
DynamicPPL.@addlogprob! sum(loggamma.(observed_deaths .+ phi)) -
length(observed_deaths) * loggamma(phi) -
data.count_logfactorial +
length(observed_deaths) * phi * log(phi) -
phi * sum(log_denominator) +
sum(xlogy.(observed_deaths, death_means)) -
dot(observed_deaths, log_denominator)
end
function _make_covid(data)
f = Float64.(data["f"])
N2 = Int(data["N2"])
SI_rev = reverse(Float64.(data["SI"]))
f_rev = permutedims(mapreduce(reverse, hcat, eachcol(f)))
SI_weights = [zeros(N2) for _ in 1:N2]
for i in 2:N2, j in 1:(i - 1)
SI_weights[i][j] = SI_rev[length(SI_rev) - i + j + 1]
end
death_weights = [zeros(N2, N2) for _ in 1:data["M"]]
for m in 1:data["M"], i in 2:N2, j in 1:(i - 1)
death_weights[m][i, j] = f_rev[m, size(f_rev, 2) - i + j + 1]
end
deaths = Int.(data["deaths"])
epidemic_start = Int.(data["EpidemicStart"])
observation_end = Int.(data["N"])
observed_deaths = [
deaths[i, m] for m in 1:data["M"] for i in epidemic_start[m]:observation_end[m]
]
fixed = _FixedData((
N0=Int(data["N0"]),
N2=N2,
N=observation_end,
EpidemicStart=epidemic_start,
X=Float64.(data["X"]),
pop=Float64.(data["pop"]),
SI_weights=SI_weights,
death_weights=death_weights,
count_logfactorial=sum(loggamma.(observed_deaths .+ 1)),
))
return pdb_covid19imperial_v2(data["M"], data["P"], fixed, observed_deaths)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
193 μs · 4 calls
477 μs · 4 calls
198 μs
505 μs
20261122T002521Z-565231f-registered-repeat-1
Off
264 μs · 4 calls
658 μs · 4 calls
171 μs
510 μs
20261122T002521Z-565231f
On · no reduction
193 μs · 4 calls
477 μs · 4 calls
198 μs
505 μs
20261122T002521Z-565231f
Off
264 μs · 4 calls
658 μs · 4 calls
171 μs
510 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
270 μs · 4 calls
639 μs · 4 calls
199 μs
402 μs
20261122T000034Z-565231f-registered-repeat-1
Off
335 μs · 4 calls
588 μs · 4 calls
195 μs
616 μs
20261122T000034Z-565231f
On · no reduction
270 μs · 4 calls
639 μs · 4 calls
199 μs
402 μs
20261122T000034Z-565231f
Off
335 μs · 4 calls
588 μs · 4 calls
195 μs
616 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
726 μs · 4 calls
198 μs
530 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
951 μs · 4 calls
196 μs
607 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
726 μs · 4 calls
198 μs
530 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
951 μs · 4 calls
196 μs
607 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 219 μs · value and gradient 387 μs
PosteriorDB model covid19imperial_v3 · dataset ecdc0401 · SHA-256 97389c0f2a24ffe59371abe416d72607471f5d319bae9b4f3495357d0a73544c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_covid19imperial_v2(M, P, fixed, observed_deaths)
data = fixed.value
mu ~ product_distribution(Fill(FlatPos(0), M))
alpha_hier ~ product_distribution(Fill(Gamma(0.1667, 1), P))
kappa ~ truncated(Normal(0, 0.5); lower=0)
tau ~ Exponential(inv(0.03))
y ~ product_distribution(Fill(Exponential(tau), M))
phi ~ truncated(Normal(0, 5); lower=0)
ifr_noise ~ product_distribution(Fill(truncated(Normal(1, 0.1); lower=0), M))
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(3.28, kappa), size(mu))), mu
)
death_mean_parts = Vector{Vector{typeof(mu[1])}}(undef, M)
adjusted_alpha = alpha_hier .- log(1.05) / 6
for m in 1:M
prediction = zeros(typeof(mu[1]), data.N2)
prediction[1:(data.N0)] .= y[m]
cumulative = zero(mu[1])
for i in 2:(data.N0)
cumulative += prediction[i]
end
for i in (data.N0 + 1):(data.N2)
infection = dot(data.SI_weights[i], prediction)
cumulative += prediction[i - 1]
reproduction = mu[m] * exp(-dot(view(data.X, m, i, :), adjusted_alpha))
susceptible = (data.pop[m] - cumulative) / data.pop[m]
prediction[i] = reproduction * susceptible * infection
end
expected_deaths = ifr_noise[m] .* (data.death_weights[m] * prediction)
expected_deaths[1] = 1.0e-15 * prediction[1]
death_mean_parts[m] = expected_deaths[data.EpidemicStart[m]:data.N[m]]
end
death_means = reduce(vcat, death_mean_parts)
log_denominator = log.(phi .+ death_means)
DynamicPPL.@addlogprob! sum(loggamma.(observed_deaths .+ phi)) -
length(observed_deaths) * loggamma(phi) -
data.count_logfactorial +
length(observed_deaths) * phi * log(phi) -
phi * sum(log_denominator) +
sum(xlogy.(observed_deaths, death_means)) -
dot(observed_deaths, log_denominator)
end
function _make_covid(data)
f = Float64.(data["f"])
N2 = Int(data["N2"])
SI_rev = reverse(Float64.(data["SI"]))
f_rev = permutedims(mapreduce(reverse, hcat, eachcol(f)))
SI_weights = [zeros(N2) for _ in 1:N2]
for i in 2:N2, j in 1:(i - 1)
SI_weights[i][j] = SI_rev[length(SI_rev) - i + j + 1]
end
death_weights = [zeros(N2, N2) for _ in 1:data["M"]]
for m in 1:data["M"], i in 2:N2, j in 1:(i - 1)
death_weights[m][i, j] = f_rev[m, size(f_rev, 2) - i + j + 1]
end
deaths = Int.(data["deaths"])
epidemic_start = Int.(data["EpidemicStart"])
observation_end = Int.(data["N"])
observed_deaths = [
deaths[i, m] for m in 1:data["M"] for i in epidemic_start[m]:observation_end[m]
]
fixed = _FixedData((
N0=Int(data["N0"]),
N2=N2,
N=observation_end,
EpidemicStart=epidemic_start,
X=Float64.(data["X"]),
pop=Float64.(data["pop"]),
SI_weights=SI_weights,
death_weights=death_weights,
count_logfactorial=sum(loggamma.(observed_deaths .+ 1)),
))
return pdb_covid19imperial_v2(data["M"], data["P"], fixed, observed_deaths)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
326 μs · 4 calls
394 μs · 4 calls
230 μs
825 μs
20261122T002521Z-565231f-registered-repeat-1
Off
221 μs · 4 calls
416 μs · 4 calls
266 μs
464 μs
20261122T002521Z-565231f
On · no reduction
326 μs · 4 calls
394 μs · 4 calls
230 μs
825 μs
20261122T002521Z-565231f
Off
221 μs · 4 calls
416 μs · 4 calls
266 μs
464 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
302 μs · 4 calls
662 μs · 4 calls
255 μs
515 μs
20261122T000034Z-565231f-registered-repeat-1
Off
263 μs · 4 calls
551 μs · 4 calls
307 μs
676 μs
20261122T000034Z-565231f
On · no reduction
302 μs · 4 calls
662 μs · 4 calls
255 μs
515 μs
20261122T000034Z-565231f
Off
263 μs · 4 calls
551 μs · 4 calls
307 μs
676 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
959 μs · 4 calls
267 μs
550 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
786 μs · 4 calls
248 μs
626 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
959 μs · 4 calls
267 μs
550 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
786 μs · 4 calls
248 μs
626 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 234 μs · value and gradient 487 μs
PosteriorDB model covid19imperial_v2 · dataset ecdc0501 · SHA-256 9fc667dad3dd1519530a6fc17e1374007eece95df310f7ca410953f2af1f3ef6
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_covid19imperial_v2(M, P, fixed, observed_deaths)
data = fixed.value
mu ~ product_distribution(Fill(FlatPos(0), M))
alpha_hier ~ product_distribution(Fill(Gamma(0.1667, 1), P))
kappa ~ truncated(Normal(0, 0.5); lower=0)
tau ~ Exponential(inv(0.03))
y ~ product_distribution(Fill(Exponential(tau), M))
phi ~ truncated(Normal(0, 5); lower=0)
ifr_noise ~ product_distribution(Fill(truncated(Normal(1, 0.1); lower=0), M))
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(3.28, kappa), size(mu))), mu
)
death_mean_parts = Vector{Vector{typeof(mu[1])}}(undef, M)
adjusted_alpha = alpha_hier .- log(1.05) / 6
for m in 1:M
prediction = zeros(typeof(mu[1]), data.N2)
prediction[1:(data.N0)] .= y[m]
cumulative = zero(mu[1])
for i in 2:(data.N0)
cumulative += prediction[i]
end
for i in (data.N0 + 1):(data.N2)
infection = dot(data.SI_weights[i], prediction)
cumulative += prediction[i - 1]
reproduction = mu[m] * exp(-dot(view(data.X, m, i, :), adjusted_alpha))
susceptible = (data.pop[m] - cumulative) / data.pop[m]
prediction[i] = reproduction * susceptible * infection
end
expected_deaths = ifr_noise[m] .* (data.death_weights[m] * prediction)
expected_deaths[1] = 1.0e-15 * prediction[1]
death_mean_parts[m] = expected_deaths[data.EpidemicStart[m]:data.N[m]]
end
death_means = reduce(vcat, death_mean_parts)
log_denominator = log.(phi .+ death_means)
DynamicPPL.@addlogprob! sum(loggamma.(observed_deaths .+ phi)) -
length(observed_deaths) * loggamma(phi) -
data.count_logfactorial +
length(observed_deaths) * phi * log(phi) -
phi * sum(log_denominator) +
sum(xlogy.(observed_deaths, death_means)) -
dot(observed_deaths, log_denominator)
end
function _make_covid(data)
f = Float64.(data["f"])
N2 = Int(data["N2"])
SI_rev = reverse(Float64.(data["SI"]))
f_rev = permutedims(mapreduce(reverse, hcat, eachcol(f)))
SI_weights = [zeros(N2) for _ in 1:N2]
for i in 2:N2, j in 1:(i - 1)
SI_weights[i][j] = SI_rev[length(SI_rev) - i + j + 1]
end
death_weights = [zeros(N2, N2) for _ in 1:data["M"]]
for m in 1:data["M"], i in 2:N2, j in 1:(i - 1)
death_weights[m][i, j] = f_rev[m, size(f_rev, 2) - i + j + 1]
end
deaths = Int.(data["deaths"])
epidemic_start = Int.(data["EpidemicStart"])
observation_end = Int.(data["N"])
observed_deaths = [
deaths[i, m] for m in 1:data["M"] for i in epidemic_start[m]:observation_end[m]
]
fixed = _FixedData((
N0=Int(data["N0"]),
N2=N2,
N=observation_end,
EpidemicStart=epidemic_start,
X=Float64.(data["X"]),
pop=Float64.(data["pop"]),
SI_weights=SI_weights,
death_weights=death_weights,
count_logfactorial=sum(loggamma.(observed_deaths .+ 1)),
))
return pdb_covid19imperial_v2(data["M"], data["P"], fixed, observed_deaths)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
265 μs · 4 calls
811 μs · 4 calls
205 μs
719 μs
20261122T002521Z-565231f-registered-repeat-1
Off
253 μs · 4 calls
1.3 ms · 4 calls
321 μs
773 μs
20261122T002521Z-565231f
On · no reduction
265 μs · 4 calls
811 μs · 4 calls
205 μs
719 μs
20261122T002521Z-565231f
Off
253 μs · 4 calls
1.3 ms · 4 calls
321 μs
773 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
306 μs · 4 calls
846 μs · 4 calls
245 μs
690 μs
20261122T000034Z-565231f-registered-repeat-1
Off
331 μs · 4 calls
805 μs · 4 calls
246 μs
591 μs
20261122T000034Z-565231f
On · no reduction
306 μs · 4 calls
846 μs · 4 calls
245 μs
690 μs
20261122T000034Z-565231f
Off
331 μs · 4 calls
805 μs · 4 calls
246 μs
591 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
866 μs · 4 calls
252 μs
550 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.03 ms · 4 calls
248 μs
479 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
866 μs · 4 calls
252 μs
550 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.03 ms · 4 calls
248 μs
479 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 236 μs · value and gradient 471 μs
PosteriorDB model covid19imperial_v3 · dataset ecdc0501 · SHA-256 9fc667dad3dd1519530a6fc17e1374007eece95df310f7ca410953f2af1f3ef6
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@wren function eight_schools_centered(y, sigma, J)
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
@iid theta ~ WD.Normal(mu, tau) size=J
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
@model function eight_schools_centered(J, y, sigma)
mu ~ Normal(0, 5)
tau ~ truncated(Cauchy(0, 5); lower=0)
theta ~ product_distribution(Fill(Normal(mu, tau), J))
for i in 1:J
y[i] ~ Normal(theta[i], sigma[i])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
28.9 ns · 1956 calls
44.7 ns · 3660 calls
3.53 μs
5.21 μs
20261122T002521Z-565231f-registered-repeat-1
Off
26.9 ns · 6672 calls
44.7 ns · 3876 calls
3.5 μs
4.97 μs
20261122T002521Z-565231f
On · no reduction
28.9 ns · 1956 calls
44.7 ns · 3660 calls
3.53 μs
5.21 μs
20261122T002521Z-565231f
Off
26.9 ns · 6672 calls
44.7 ns · 3876 calls
3.5 μs
4.97 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
27.9 ns · 3420 calls
47.5 ns · 3756 calls
3.62 μs
5.18 μs
20261122T000034Z-565231f-registered-repeat-1
Off
27.8 ns · 4520 calls
45.7 ns · 3844 calls
3.7 μs
5.14 μs
20261122T000034Z-565231f
On · no reduction
27.9 ns · 3420 calls
47.5 ns · 3756 calls
3.62 μs
5.18 μs
20261122T000034Z-565231f
Off
27.8 ns · 4520 calls
45.7 ns · 3844 calls
3.7 μs
5.14 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
51.7 ns · 668 calls
3.54 μs
5.03 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
56.4 ns · 439 calls
3.67 μs
4.85 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
51.7 ns · 668 calls
3.54 μs
5.03 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
56.4 ns · 439 calls
3.67 μs
4.85 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.55 μs · value and gradient 5.21 μs
PosteriorDB model eight_schools_centered · dataset eight_schools · SHA-256 f06889e8cae3755c00a4a44f002d5fc3acf3263ff9ae8ffe5655b1907bcadd80
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
78 ns
134 ns
FlatPPL · normal optimizations
3.53 μs · 45.3× Wren
5.21 μs · 38.9× Wren
FlatPPL · equal work
3.5 μs · 44.9× Wren
4.97 μs · 37.1× Wren
Wren definition in this run
@wren function eight_schools_centered(y, sigma, J)
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
@iid theta ~ WD.Normal(mu, tau) size=J
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
81.3 ns
136 ns
FlatPPL · normal optimizations
3.62 μs · 44.5× Wren
5.18 μs · 38.1× Wren
FlatPPL · equal work
3.7 μs · 45.5× Wren
5.14 μs · 37.8× Wren
Wren definition in this run
@wren function eight_schools_centered(y, sigma, J)
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
@iid theta ~ WD.Normal(mu, tau) size=J
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
77.5 ns
141 ns
FlatPPL · normal optimizations
3.54 μs · 45.7× Wren
5.03 μs · 35.8× Wren
FlatPPL · equal work
3.67 μs · 47.4× Wren
4.85 μs · 34.5× Wren
Wren definition in this run
@wren function eight_schools_centered(y, sigma, J)
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
@iid theta ~ WD.Normal(mu, tau) size=J
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
@wren function eight_schools_noncentered(y, sigma, J)
@iid theta_trans ~ WD.Normal(0.0, 1.0) size=J
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
theta = theta_trans .* tau .+ mu
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
const EIGHT_SCHOOLS_NONCENTERED = @rkppl begin
theta_trans[axes(y, 1)] .~ Normal.(0, 1)
mu ~ Normal(0, 5)
tau ~ HalfCauchy(5)
theta = theta_trans .* tau .+ mu
y .~ Normal.(theta, sigma)
end
@model function eight_schools_noncentered(y, sigma)
theta_trans ~ MvNormal(zeros(length(y)), I)
mu ~ Normal(0, 5)
tau ~ truncated(Cauchy(0, 5); lower = 0)
theta = theta_trans .* tau .+ mu
y .~ Normal.(theta, sigma)
end
const EIGHT_SCHOOLS_NONCENTERED = @model sigma begin
theta_trans ~ Normal() ^ length(sigma)
mu ~ Normal(0, 5)
tau ~ HalfCauchy(5)
theta = mu .+ tau .* theta_trans
y ~ For(eachindex(sigma)) do j
Normal(theta[j], sigma[j])
end
end
@model function eight_schools_noncentered(y, sigma)
theta_trans ~ filldist(Normal(0, 1), length(y))
mu ~ Normal(0, 5)
tau ~ truncated(Cauchy(0, 5); lower = 0)
theta = theta_trans .* tau .+ mu
y ~ MvNormal(theta, Diagonal(sigma .^ 2))
end
@model function eight_schools_noncentered_loop(y, sigma)
theta_trans ~ filldist(Normal(0, 1), length(y))
mu ~ Normal(0, 5)
tau ~ truncated(Cauchy(0, 5); lower = 0)
theta = theta_trans .* tau .+ mu
for i in eachindex(y)
y[i] ~ Normal(theta[i], sigma[i])
end
end
@model function eight_schools_noncentered(J, y, sigma)
mu ~ Normal(0, 5)
tau ~ truncated(Cauchy(0, 5); lower=0)
theta_trans ~ product_distribution(Fill(Normal(), J))
for i in 1:J
y[i] ~ Normal(theta_trans[i] * tau + mu, sigma[i])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
21.2 ns · 4700 calls
37 ns · 3860 calls
3.55 μs
5.02 μs
20261122T002521Z-565231f-registered-repeat-1
Off
21.3 ns · 4384 calls
36.5 ns · 5420 calls
3.68 μs
4.84 μs
20261122T002521Z-565231f
On · no reduction
21.2 ns · 4700 calls
37 ns · 3860 calls
3.55 μs
5.02 μs
20261122T002521Z-565231f
Off
21.3 ns · 4384 calls
36.5 ns · 5420 calls
3.68 μs
4.84 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
21.6 ns · 3160 calls
38.7 ns · 1728 calls
3.68 μs
4.77 μs
20261122T000034Z-565231f-registered-repeat-1
Off
22.6 ns · 1944 calls
36.5 ns · 3756 calls
3.47 μs
4.78 μs
20261122T000034Z-565231f
On · no reduction
21.6 ns · 3160 calls
38.7 ns · 1728 calls
3.68 μs
4.77 μs
20261122T000034Z-565231f
Off
22.6 ns · 1944 calls
36.5 ns · 3756 calls
3.47 μs
4.78 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
46.1 ns · 478 calls
3.51 μs
4.75 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
45.2 ns · 576 calls
3.58 μs
4.72 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
46.1 ns · 478 calls
3.51 μs
4.75 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
45.2 ns · 576 calls
3.58 μs
4.72 μs
20261114T233319Z-f022c87
On · no reduction
JIT-loop timing not recorded
38.5 ns · 2281 calls
3.37 μs
4.99 μs
20261114T233319Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
3.5 μs
4.68 μs
20261114T225256Z-f022c87
On · no reduction
JIT-loop timing not recorded
42.5 ns · 997 calls
3.46 μs
4.79 μs
20261114T225256Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
3.61 μs
4.78 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.58 μs · value and gradient 5.07 μs
PosteriorDB model eight_schools_noncentered · dataset eight_schools · SHA-256 f06889e8cae3755c00a4a44f002d5fc3acf3263ff9ae8ffe5655b1907bcadd80
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
88.6 ns
157 ns
FlatPPL · normal optimizations
3.55 μs · 40.1× Wren
5.02 μs · 32.1× Wren
FlatPPL · equal work
3.68 μs · 41.5× Wren
4.84 μs · 30.9× Wren
Wren definition in this run
@wren function eight_schools_noncentered(y, sigma, J)
@iid theta_trans ~ WD.Normal(0.0, 1.0) size=J
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
theta = theta_trans .* tau .+ mu
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
85 ns
167 ns
FlatPPL · normal optimizations
3.68 μs · 43.3× Wren
4.77 μs · 28.5× Wren
FlatPPL · equal work
3.47 μs · 40.8× Wren
4.78 μs · 28.6× Wren
Wren definition in this run
@wren function eight_schools_noncentered(y, sigma, J)
@iid theta_trans ~ WD.Normal(0.0, 1.0) size=J
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
theta = theta_trans .* tau .+ mu
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
89.3 ns
156 ns
FlatPPL · normal optimizations
3.51 μs · 39.3× Wren
4.75 μs · 30.5× Wren
FlatPPL · equal work
3.58 μs · 40.1× Wren
4.72 μs · 30.3× Wren
Wren definition in this run
@wren function eight_schools_noncentered(y, sigma, J)
@iid theta_trans ~ WD.Normal(0.0, 1.0) size=J
mu ~ WD.Normal(0.0, 5.0)
tau ~ WD.HalfCauchy(0.0, 5.0)
theta = theta_trans .* tau .+ mu
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(theta[i], sigma[i])
end
return nothing
end
@model function pdb_election88_full(
N,
n_age,
n_age_edu,
n_edu,
n_region_full,
n_state,
age,
age_edu,
black,
edu,
female,
region_full,
state,
v_prev_full,
y,
)
a ~ product_distribution(Fill(Flat(), n_age))
b ~ product_distribution(Fill(Flat(), n_edu))
c ~ product_distribution(Fill(Flat(), n_age_edu))
d ~ product_distribution(Fill(Flat(), n_state))
e ~ product_distribution(Fill(Flat(), n_region_full))
beta ~ product_distribution(Fill(Normal(0, 100), 5))
sigma_a ~ Uniform(0, 100)
sigma_b ~ Uniform(0, 100)
sigma_c ~ Uniform(0, 100)
sigma_d ~ Uniform(0, 100)
sigma_e ~ Uniform(0, 100)
y_hat =
beta[1] .+ beta[2] .* black .+ beta[3] .* female .+ beta[5] .* female .* black .+
beta[4] .* v_prev_full .+ a[age] .+ b[edu] .+ c[age_edu] .+ d[state] .+
e[region_full]
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_a), size(a))), a
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_b), size(b))), b
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_c), size(c))), c
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_d), size(d))), d
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_e), size(e))), e
)
DynamicPPL.@addlogprob! logpdf(product_distribution(map(BernoulliLogit, y_hat)), y)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
36.3 μs · 8 calls
100 μs · 4 calls
46.5 μs
95.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
39.9 μs · 12 calls
100 μs · 4 calls
30.6 μs
572 μs
20261122T002521Z-565231f
On · no reduction
36.3 μs · 8 calls
100 μs · 4 calls
46.5 μs
95.2 μs
20261122T002521Z-565231f
Off
39.9 μs · 12 calls
100 μs · 4 calls
30.6 μs
572 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
41.2 μs · 4 calls
101 μs · 4 calls
41.7 μs
102 μs
20261122T000034Z-565231f-registered-repeat-1
Off
36.9 μs · 20 calls
97.6 μs · 4 calls
36.1 μs
105 μs
20261122T000034Z-565231f
On · no reduction
41.2 μs · 4 calls
101 μs · 4 calls
41.7 μs
102 μs
20261122T000034Z-565231f
Off
36.9 μs · 20 calls
97.6 μs · 4 calls
36.1 μs
105 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 33.7 μs · value and gradient 106 μs
PosteriorDB model election88_full · dataset election88 · SHA-256 1780753c5b88f9c4e83a4974a9465b80665d6cfe9a7bf1217b9689afda6b8295
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
124 μs
248 μs
FlatPPL · normal optimizations
46.5 μs · 0.376× Wren
95.2 μs · 0.384× Wren
FlatPPL · equal work
30.6 μs · 0.247× Wren
572 μs · 2.31× Wren
Wren definition in this run
@wren function election88(age, edu, age_edu, state, region, black, female,
v_prev_full, y, n_age, n_edu, n_age_edu, n_state, n_region)
@iid beta ~ WD.Normal(0.0, 100.0) size=5
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_b ~ WD.Uniform(0.0, 100.0)
sigma_c ~ WD.Uniform(0.0, 100.0)
sigma_d ~ WD.Uniform(0.0, 100.0)
sigma_e ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(0.0, sigma_a) size=n_age
@iid b ~ WD.Normal(0.0, sigma_b) size=n_edu
@iid c ~ WD.Normal(0.0, sigma_c) size=n_age_edu
@iid d ~ WD.Normal(0.0, sigma_d) size=n_state
@iid e ~ WD.Normal(0.0, sigma_e) size=n_region
eta = beta[1] .+ beta[2] .* black .+ beta[3] .* female .+
beta[5] .* (female .* black) .+ beta[4] .* v_prev_full .+
a[age] .+ b[edu] .+ c[age_edu] .+ d[state] .+ e[region]
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
124 μs
232 μs
FlatPPL · normal optimizations
41.7 μs · 0.338× Wren
102 μs · 0.44× Wren
FlatPPL · equal work
36.1 μs · 0.292× Wren
105 μs · 0.453× Wren
Wren definition in this run
@wren function election88(age, edu, age_edu, state, region, black, female,
v_prev_full, y, n_age, n_edu, n_age_edu, n_state, n_region)
@iid beta ~ WD.Normal(0.0, 100.0) size=5
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_b ~ WD.Uniform(0.0, 100.0)
sigma_c ~ WD.Uniform(0.0, 100.0)
sigma_d ~ WD.Uniform(0.0, 100.0)
sigma_e ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(0.0, sigma_a) size=n_age
@iid b ~ WD.Normal(0.0, sigma_b) size=n_edu
@iid c ~ WD.Normal(0.0, sigma_c) size=n_age_edu
@iid d ~ WD.Normal(0.0, sigma_d) size=n_state
@iid e ~ WD.Normal(0.0, sigma_e) size=n_region
eta = beta[1] .+ beta[2] .* black .+ beta[3] .* female .+
beta[5] .* (female .* black) .+ beta[4] .* v_prev_full .+
a[age] .+ b[edu] .+ c[age_edu] .+ d[state] .+ e[region]
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
100 μs
302 μs
FlatPPL · normal optimizations
evaluation failed
evaluation failed
FlatPPL · equal work
evaluation failed
evaluation failed
Wren definition in this run
@wren function election88(age, edu, age_edu, state, region, black, female,
v_prev_full, y, n_age, n_edu, n_age_edu, n_state, n_region)
@iid beta ~ WD.Normal(0.0, 100.0) size=5
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_b ~ WD.Uniform(0.0, 100.0)
sigma_c ~ WD.Uniform(0.0, 100.0)
sigma_d ~ WD.Uniform(0.0, 100.0)
sigma_e ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(0.0, sigma_a) size=n_age
@iid b ~ WD.Normal(0.0, sigma_b) size=n_edu
@iid c ~ WD.Normal(0.0, sigma_c) size=n_age_edu
@iid d ~ WD.Normal(0.0, sigma_d) size=n_state
@iid e ~ WD.Normal(0.0, sigma_e) size=n_region
eta = beta[1] .+ beta[2] .* black .+ beta[3] .* female .+
beta[5] .* (female .* black) .+ beta[4] .* v_prev_full .+
a[age] .+ b[edu] .+ c[age_edu] .+ d[state] .+ e[region]
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_2pl_latent_reg_irt(I, J, N, ii, jj, y, W_adj)
K = size(W_adj, 2)
alpha ~ product_distribution(Fill(LogNormal(1, 1), I))
beta_free ~ product_distribution(Fill(Flat(), I - 1))
theta ~ product_distribution(Fill(Flat(), J))
lambda_adj ~ product_distribution(Fill(LocationScale(0, 1, TDist(3)), K))
beta = vcat(beta_free, -(sum(beta_free)))
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, 3), size(beta))), beta
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(), size(theta))), theta .- W_adj * lambda_adj
)
logits = alpha[ii] .* theta[jj] .- beta[ii]
DynamicPPL.@addlogprob! -sum(log1pexp.(y .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
10.9 μs · 48 calls
52.4 μs · 16 calls
17.9 μs
73.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
11.4 μs · 52 calls
55.8 μs · 4 calls
17.8 μs
63.8 μs
20261122T002521Z-565231f
On · no reduction
10.9 μs · 48 calls
52.4 μs · 16 calls
17.9 μs
73.6 μs
20261122T002521Z-565231f
Off
11.4 μs · 52 calls
55.8 μs · 4 calls
17.8 μs
63.8 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
10.9 μs · 68 calls
52.4 μs · 4 calls
17.9 μs
61 μs
20261122T000034Z-565231f-registered-repeat-1
Off
11.1 μs · 72 calls
54.3 μs · 8 calls
18 μs
62.2 μs
20261122T000034Z-565231f
On · no reduction
10.9 μs · 68 calls
52.4 μs · 4 calls
17.9 μs
61 μs
20261122T000034Z-565231f
Off
11.1 μs · 72 calls
54.3 μs · 8 calls
18 μs
62.2 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 18 μs · value and gradient 59.7 μs
PosteriorDB model 2pl_latent_reg_irt · dataset fims_Aus_Jpn_irt · SHA-256 78f1e8b55da0e34b5c02a593acf1bcf76782bfdb696406706de74270bf29f978
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
62.3 μs
138 μs
FlatPPL · normal optimizations
17.9 μs · 0.288× Wren
73.6 μs · 0.535× Wren
FlatPPL · equal work
17.8 μs · 0.285× Wren
63.8 μs · 0.464× Wren
Wren definition in this run
@wren function latent_reg_2pl(y, ii, jj, W_adj, I, J, K)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(I - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood fims_logdensity(y, ii, jj, W_adj,
alpha, beta_free, theta, lambda_adj)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
59.5 μs
133 μs
FlatPPL · normal optimizations
17.9 μs · 0.301× Wren
61 μs · 0.458× Wren
FlatPPL · equal work
18 μs · 0.303× Wren
62.2 μs · 0.467× Wren
Wren definition in this run
@wren function latent_reg_2pl(y, ii, jj, W_adj, I, J, K)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(I - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood fims_logdensity(y, ii, jj, W_adj,
alpha, beta_free, theta, lambda_adj)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
59.2 μs
131 μs
FlatPPL · normal optimizations
evaluation failed
evaluation failed
FlatPPL · equal work
evaluation failed
evaluation failed
Wren definition in this run
@wren function latent_reg_2pl(y, ii, jj, W_adj, I, J, K)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(I - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood fims_logdensity(y, ii, jj, W_adj,
alpha, beta_free, theta, lambda_adj)
return nothing
end
@wren function garch11(y, sigma1)
mu ~ WD.Flat()
log_alpha0 ~ WD.Flat()
alpha0 = exp(log_alpha0)
# Temporary positive-flat alpha0 transform pending #192.
@addloglikelihood log_alpha0
# Stan declares alpha1 on (0, 1) and beta1 on (0, 1 - alpha1) with no prior
# statement: a flat prior on the triangle alpha1 + beta1 < 1. Beta(1, 2)
# times Uniform(0, 1 - alpha1) has the constant density 2 on that triangle,
# so the alpha1 and beta1 lines after this comment give Stan's prior up to
# log(2). Uniform alone would not: its 1/(1 - alpha1) depends on alpha1.
# Equivalent alternatives:
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.Uniform(0.0, 1 - alpha1)
# @addloglikelihood log1p(-alpha1) # cancels Uniform's 1/(1 - alpha1)
# or, the direct translation of Stan's bounds, once a truncated flat
# with parameter-dependent bounds is available (#203, tracked in #207):
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.truncated(WD.Flat(); lower=0.0, upper=1 - alpha1)
alpha1 ~ WD.Beta(1.0, 2.0)
beta1 ~ WD.Uniform(0.0, 1 - alpha1)
sigma = Vector{typeof(alpha0 + mu)}(undef, length(y))
sigma[1] = sigma1
for t in 2:length(y)
sigma[t] = sqrt(alpha0 + alpha1 * (y[t - 1] - mu)^2 +
beta1 * sigma[t - 1]^2)
end
@batch for t in eachindex(y)
@observe y[t] ~ WD.Normal(mu, sigma[t])
end
return nothing
end
@model function garch_garch11(T, y, sigma1)
mu ~ Flat()
alpha0 ~ FlatPos(0.0)
alpha1 ~ Uniform(0, 1)
beta1 ~ Flat()
if !(0 <= beta1 <= 1 - alpha1)
DynamicPPL.@addlogprob! -Inf
return nothing
end
sigma = Vector{typeof(mu)}(undef, T)
sigma[1] = sigma1
for t in 2:T
sigma[t] = sqrt(alpha0 + alpha1 * (y[t - 1] - mu)^2 + beta1 * sigma[t - 1]^2)
end
for t in 1:T
y[t] ~ Normal(mu, sigma[t])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
2.96 μs · 52 calls
4.53 μs · 168 calls
7.73 μs
14.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
2.04 μs · 80 calls
4.24 μs · 144 calls
7.7 μs
15 μs
20261122T002521Z-565231f
On · no reduction
2.96 μs · 52 calls
4.53 μs · 168 calls
7.73 μs
14.5 μs
20261122T002521Z-565231f
Off
2.04 μs · 80 calls
4.24 μs · 144 calls
7.7 μs
15 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
2 μs · 320 calls
4.34 μs · 176 calls
7.54 μs
14.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
2.04 μs · 328 calls
4.23 μs · 92 calls
6.93 μs
16.4 μs
20261122T000034Z-565231f
On · no reduction
2 μs · 320 calls
4.34 μs · 176 calls
7.54 μs
14.8 μs
20261122T000034Z-565231f
Off
2.04 μs · 328 calls
4.23 μs · 92 calls
6.93 μs
16.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
4.57 μs · 68 calls
8.59 μs
20.2 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
4.31 μs · 158 calls
7.25 μs
15.3 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
4.57 μs · 68 calls
8.59 μs
20.2 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
4.31 μs · 158 calls
7.25 μs
15.3 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 7.29 μs · value and gradient 15.7 μs
PosteriorDB model garch11 · dataset garch · SHA-256 6f5dd0d191c8f5f0dd655d1936a78dded65c41807d9c733e18d08a2fb0437ce0
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
2.28 μs
4.83 μs
FlatPPL · normal optimizations
7.73 μs · 3.4× Wren
14.5 μs · 3.0× Wren
FlatPPL · equal work
7.7 μs · 3.38× Wren
15 μs · 3.11× Wren
Wren definition in this run
@wren function garch11(y, sigma1)
mu ~ WD.Flat()
log_alpha0 ~ WD.Flat()
alpha0 = exp(log_alpha0)
# Temporary positive-flat alpha0 transform pending #192.
@addloglikelihood log_alpha0
# Stan declares alpha1 on (0, 1) and beta1 on (0, 1 - alpha1) with no prior
# statement: a flat prior on the triangle alpha1 + beta1 < 1. Beta(1, 2)
# times Uniform(0, 1 - alpha1) has the constant density 2 on that triangle,
# so the alpha1 and beta1 lines after this comment give Stan's prior up to
# log(2). Uniform alone would not: its 1/(1 - alpha1) depends on alpha1.
# Equivalent alternatives:
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.Uniform(0.0, 1 - alpha1)
# @addloglikelihood log1p(-alpha1) # cancels Uniform's 1/(1 - alpha1)
# or, the direct translation of Stan's bounds, once a truncated flat
# with parameter-dependent bounds is available (#203, tracked in #207):
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.truncated(WD.Flat(); lower=0.0, upper=1 - alpha1)
alpha1 ~ WD.Beta(1.0, 2.0)
beta1 ~ WD.Uniform(0.0, 1 - alpha1)
sigma = Vector{typeof(alpha0 + mu)}(undef, length(y))
sigma[1] = sigma1
for t in 2:length(y)
sigma[t] = sqrt(alpha0 + alpha1 * (y[t - 1] - mu)^2 +
beta1 * sigma[t - 1]^2)
end
@batch for t in eachindex(y)
@observe y[t] ~ WD.Normal(mu, sigma[t])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
2.27 μs
4.86 μs
FlatPPL · normal optimizations
7.54 μs · 3.33× Wren
14.8 μs · 3.05× Wren
FlatPPL · equal work
6.93 μs · 3.06× Wren
16.4 μs · 3.38× Wren
Wren definition in this run
@wren function garch11(y, sigma1)
mu ~ WD.Flat()
log_alpha0 ~ WD.Flat()
alpha0 = exp(log_alpha0)
# Temporary positive-flat alpha0 transform pending #192.
@addloglikelihood log_alpha0
# Stan declares alpha1 on (0, 1) and beta1 on (0, 1 - alpha1) with no prior
# statement: a flat prior on the triangle alpha1 + beta1 < 1. Beta(1, 2)
# times Uniform(0, 1 - alpha1) has the constant density 2 on that triangle,
# so the alpha1 and beta1 lines after this comment give Stan's prior up to
# log(2). Uniform alone would not: its 1/(1 - alpha1) depends on alpha1.
# Equivalent alternatives:
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.Uniform(0.0, 1 - alpha1)
# @addloglikelihood log1p(-alpha1) # cancels Uniform's 1/(1 - alpha1)
# or, the direct translation of Stan's bounds, once a truncated flat
# with parameter-dependent bounds is available (#203, tracked in #207):
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.truncated(WD.Flat(); lower=0.0, upper=1 - alpha1)
alpha1 ~ WD.Beta(1.0, 2.0)
beta1 ~ WD.Uniform(0.0, 1 - alpha1)
sigma = Vector{typeof(alpha0 + mu)}(undef, length(y))
sigma[1] = sigma1
for t in 2:length(y)
sigma[t] = sqrt(alpha0 + alpha1 * (y[t - 1] - mu)^2 +
beta1 * sigma[t - 1]^2)
end
@batch for t in eachindex(y)
@observe y[t] ~ WD.Normal(mu, sigma[t])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
2.19 μs
4.76 μs
FlatPPL · normal optimizations
8.59 μs · 3.92× Wren
20.2 μs · 4.24× Wren
FlatPPL · equal work
7.25 μs · 3.31× Wren
15.3 μs · 3.22× Wren
Wren definition in this run
@wren function garch11(y, sigma1)
mu ~ WD.Flat()
log_alpha0 ~ WD.Flat()
alpha0 = exp(log_alpha0)
# Temporary positive-flat alpha0 transform pending #192.
@addloglikelihood log_alpha0
# Stan declares alpha1 on (0, 1) and beta1 on (0, 1 - alpha1) with no prior
# statement: a flat prior on the triangle alpha1 + beta1 < 1. Beta(1, 2)
# times Uniform(0, 1 - alpha1) has the constant density 2 on that triangle,
# so the alpha1 and beta1 lines after this comment give Stan's prior up to
# log(2). Uniform alone would not: its 1/(1 - alpha1) depends on alpha1.
# Equivalent alternatives:
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.Uniform(0.0, 1 - alpha1)
# @addloglikelihood log1p(-alpha1) # cancels Uniform's 1/(1 - alpha1)
# or, the direct translation of Stan's bounds, once a truncated flat
# with parameter-dependent bounds is available (#203, tracked in #207):
# alpha1 ~ WD.Uniform(0.0, 1.0)
# beta1 ~ WD.truncated(WD.Flat(); lower=0.0, upper=1 - alpha1)
alpha1 ~ WD.Beta(1.0, 2.0)
beta1 ~ WD.Uniform(0.0, 1 - alpha1)
sigma = Vector{typeof(alpha0 + mu)}(undef, length(y))
sigma[1] = sigma1
for t in 2:length(y)
sigma[t] = sqrt(alpha0 + alpha1 * (y[t - 1] - mu)^2 +
beta1 * sigma[t - 1]^2)
end
@batch for t in eachindex(y)
@observe y[t] ~ WD.Normal(mu, sigma[t])
end
return nothing
end
@model function pdb_GLM_Binomial_model(nyears, C, N, year, year_squared)
alpha ~ Normal(0, 100)
beta1 ~ Normal(0, 100)
beta2 ~ Normal(0, 100)
logit_p = alpha .+ beta1 .* year .+ beta2 .* year_squared
DynamicPPL.@addlogprob! logpdf(product_distribution(map(BinomialLogit, N, logit_p)), C)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
207 ns · 392 calls
489 ns · 80 calls
4.07 μs
7.25 μs
20261122T002521Z-565231f-registered-repeat-1
Off
206 ns · 2172 calls
375 ns · 892 calls
4.04 μs
10.6 μs
20261122T002521Z-565231f
On · no reduction
207 ns · 392 calls
489 ns · 80 calls
4.07 μs
7.25 μs
20261122T002521Z-565231f
Off
206 ns · 2172 calls
375 ns · 892 calls
4.04 μs
10.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
197 ns · 1560 calls
363 ns · 828 calls
3.93 μs
7.06 μs
20261122T000034Z-565231f-registered-repeat-1
Off
196 ns · 1876 calls
391 ns · 1232 calls
3.79 μs
7.25 μs
20261122T000034Z-565231f
On · no reduction
197 ns · 1560 calls
363 ns · 828 calls
3.93 μs
7.06 μs
20261122T000034Z-565231f
Off
196 ns · 1876 calls
391 ns · 1232 calls
3.79 μs
7.25 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 4.02 μs · value and gradient 8.67 μs
PosteriorDB model GLM_Binomial_model · dataset GLM_Binomial_data · SHA-256 ad0ac3630f9e684b8b5b583258717d19a66bba7b9a5c86b94b0f66b876d49a9c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.26 μs
1.51 μs
FlatPPL · normal optimizations
4.07 μs · 3.24× Wren
7.25 μs · 4.8× Wren
FlatPPL · equal work
4.04 μs · 3.21× Wren
10.6 μs · 7.03× Wren
Wren definition in this run
@wren function glm_binomial_model(counts, trials, year, year_squared)
alpha ~ WD.Normal(0.0, 100.0)
beta1 ~ WD.Normal(0.0, 100.0)
beta2 ~ WD.Normal(0.0, 100.0)
logit_p = alpha .+ beta1 .* year .+ beta2 .* year_squared
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.BinomialLogit(trials[i], logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.14 μs
1.45 μs
FlatPPL · normal optimizations
3.93 μs · 3.43× Wren
7.06 μs · 4.86× Wren
FlatPPL · equal work
3.79 μs · 3.31× Wren
7.25 μs · 4.99× Wren
Wren definition in this run
@wren function glm_binomial_model(counts, trials, year, year_squared)
alpha ~ WD.Normal(0.0, 100.0)
beta1 ~ WD.Normal(0.0, 100.0)
beta2 ~ WD.Normal(0.0, 100.0)
logit_p = alpha .+ beta1 .* year .+ beta2 .* year_squared
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.BinomialLogit(trials[i], logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.13 μs
1.39 μs
FlatPPL · normal optimizations
evaluation failed
evaluation failed
FlatPPL · equal work
evaluation failed
evaluation failed
Wren definition in this run
@wren function glm_binomial_model(counts, trials, year, year_squared)
alpha ~ WD.Normal(0.0, 100.0)
beta1 ~ WD.Normal(0.0, 100.0)
beta2 ~ WD.Normal(0.0, 100.0)
logit_p = alpha .+ beta1 .* year .+ beta2 .* year_squared
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.BinomialLogit(trials[i], logit_p[i])
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
475 ns · 664 calls
514 ns · 848 calls
5.17 μs
9.32 μs
20261122T002521Z-565231f-registered-repeat-1
Off
504 ns · 140 calls
676 ns · 944 calls
6.6 μs
8.71 μs
20261122T002521Z-565231f
On · no reduction
475 ns · 664 calls
514 ns · 848 calls
5.17 μs
9.32 μs
20261122T002521Z-565231f
Off
504 ns · 140 calls
676 ns · 944 calls
6.6 μs
8.71 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
461 ns · 832 calls
525 ns · 760 calls
5.24 μs
8.93 μs
20261122T000034Z-565231f-registered-repeat-1
Off
483 ns · 688 calls
543 ns · 920 calls
5.37 μs
9.95 μs
20261122T000034Z-565231f
On · no reduction
461 ns · 832 calls
525 ns · 760 calls
5.24 μs
8.93 μs
20261122T000034Z-565231f
Off
483 ns · 688 calls
543 ns · 920 calls
5.37 μs
9.95 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
611 ns · 420 calls
3.86 μs
9.58 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
556 ns · 320 calls
3.94 μs
8.75 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
611 ns · 420 calls
3.86 μs
9.58 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
556 ns · 320 calls
3.94 μs
8.75 μs
20261114T233319Z-f022c87
On · no reduction
JIT-loop timing not recorded
513 ns · 700 calls
3.63 μs
6.64 μs
20261114T233319Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
3.63 μs
6.87 μs
20261114T225256Z-f022c87
On · no reduction
JIT-loop timing not recorded
528 ns · 376 calls
3.69 μs
6.79 μs
20261114T225256Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
3.62 μs
6.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 8.76 μs · value and gradient 9.31 μs
PosteriorDB model GLM_Poisson_model · dataset GLM_Poisson_Data · SHA-256 3a0352fad3ddf15cc83e082bccbc4d8c3257d83d0f36481bf1122f440269f7d8
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
617 ns
1.05 μs
FlatPPL · normal optimizations
5.17 μs · 8.37× Wren
9.32 μs · 8.9× Wren
FlatPPL · equal work
6.6 μs · 10.7× Wren
8.71 μs · 8.32× Wren
Wren definition in this run
@wren function glm_poisson_model(counts, year, year_squared, year_cubed)
alpha ~ WD.Uniform(-20.0, 20.0)
beta1 ~ WD.Uniform(-10.0, 10.0)
beta2 ~ WD.Uniform(-10.0, 10.0)
beta3 ~ WD.Uniform(-10.0, 10.0)
log_lambda = alpha .+ beta1 .* year .+ beta2 .* year_squared .+ beta3 .* year_cubed
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(log_lambda[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
635 ns
1.01 μs
FlatPPL · normal optimizations
5.24 μs · 8.25× Wren
8.93 μs · 8.87× Wren
FlatPPL · equal work
5.37 μs · 8.45× Wren
9.95 μs · 9.88× Wren
Wren definition in this run
@wren function glm_poisson_model(counts, year, year_squared, year_cubed)
alpha ~ WD.Uniform(-20.0, 20.0)
beta1 ~ WD.Uniform(-10.0, 10.0)
beta2 ~ WD.Uniform(-10.0, 10.0)
beta3 ~ WD.Uniform(-10.0, 10.0)
log_lambda = alpha .+ beta1 .* year .+ beta2 .* year_squared .+ beta3 .* year_cubed
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(log_lambda[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
614 ns
1.03 μs
FlatPPL · normal optimizations
3.86 μs · 6.29× Wren
9.58 μs · 9.32× Wren
FlatPPL · equal work
3.94 μs · 6.42× Wren
8.75 μs · 8.51× Wren
Wren definition in this run
@wren function glm_poisson_model(counts, year, year_squared, year_cubed)
alpha ~ WD.Uniform(-20.0, 20.0)
beta1 ~ WD.Uniform(-10.0, 10.0)
beta2 ~ WD.Uniform(-10.0, 10.0)
beta3 ~ WD.Uniform(-10.0, 10.0)
log_lambda = alpha .+ beta1 .* year .+ beta2 .* year_squared .+ beta3 .* year_cubed
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(log_lambda[i])
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
22.3 μs · 16 calls
21.5 μs · 24 calls
27.7 μs
38.8 μs
20261122T002521Z-565231f-registered-repeat-1
Off
25.7 μs · 20 calls
21.3 μs · 20 calls
27 μs
32.4 μs
20261122T002521Z-565231f
On · no reduction
22.3 μs · 16 calls
21.5 μs · 24 calls
27.7 μs
38.8 μs
20261122T002521Z-565231f
Off
25.7 μs · 20 calls
21.3 μs · 20 calls
27 μs
32.4 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
22.1 μs · 4 calls
20.9 μs · 28 calls
26.1 μs
39.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
22.3 μs · 20 calls
20.7 μs · 32 calls
26.3 μs
33.6 μs
20261122T000034Z-565231f
On · no reduction
22.1 μs · 4 calls
20.9 μs · 28 calls
26.1 μs
39.9 μs
20261122T000034Z-565231f
Off
22.3 μs · 20 calls
20.7 μs · 32 calls
26.3 μs
33.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
19.7 μs · 41 calls
26.3 μs
30.6 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
22.3 μs · 4 calls
23.8 μs
26.6 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
19.7 μs · 41 calls
26.3 μs
30.6 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
22.3 μs · 4 calls
23.8 μs
26.6 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 25.6 μs · value and gradient 28 μs
PosteriorDB model GLMM1_model · dataset GLMM_data · SHA-256 d1d3d134a096f48c12e1190d454380bfec08855f6dc4de23128baee5f2a32d97
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
30 μs
44.2 μs
FlatPPL · normal optimizations
27.7 μs · 0.923× Wren
38.8 μs · 0.878× Wren
FlatPPL · equal work
27 μs · 0.899× Wren
32.4 μs · 0.733× Wren
Wren definition in this run
@wren function glmm1_model(nsite, obs, obssite)
@iid alpha ~ WD.Flat() size=nsite
mu_alpha ~ WD.Normal(0.0, 10.0)
sd_alpha ~ WD.Uniform(0.0, 5.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sd_alpha) size=nsite
@batch for i in eachindex(obs)
@observe obs[i] ~ WD.PoissonLog(alpha[obssite[i]])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
29.7 μs
43.8 μs
FlatPPL · normal optimizations
26.1 μs · 0.879× Wren
39.9 μs · 0.911× Wren
FlatPPL · equal work
26.3 μs · 0.886× Wren
33.6 μs · 0.769× Wren
Wren definition in this run
@wren function glmm1_model(nsite, obs, obssite)
@iid alpha ~ WD.Flat() size=nsite
mu_alpha ~ WD.Normal(0.0, 10.0)
sd_alpha ~ WD.Uniform(0.0, 5.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sd_alpha) size=nsite
@batch for i in eachindex(obs)
@observe obs[i] ~ WD.PoissonLog(alpha[obssite[i]])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
29.9 μs
44 μs
FlatPPL · normal optimizations
26.3 μs · 0.879× Wren
30.6 μs · 0.695× Wren
FlatPPL · equal work
23.8 μs · 0.798× Wren
26.6 μs · 0.604× Wren
Wren definition in this run
@wren function glmm1_model(nsite, obs, obssite)
@iid alpha ~ WD.Flat() size=nsite
mu_alpha ~ WD.Normal(0.0, 10.0)
sd_alpha ~ WD.Uniform(0.0, 5.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sd_alpha) size=nsite
@batch for i in eachindex(obs)
@observe obs[i] ~ WD.PoissonLog(alpha[obssite[i]])
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
526 ns · 620 calls
848 ns · 56 calls
5.77 μs
12 μs
20261122T002521Z-565231f-registered-repeat-1
Off
514 ns · 884 calls
689 ns · 820 calls
5.46 μs
12.6 μs
20261122T002521Z-565231f
On · no reduction
526 ns · 620 calls
848 ns · 56 calls
5.77 μs
12 μs
20261122T002521Z-565231f
Off
514 ns · 884 calls
689 ns · 820 calls
5.46 μs
12.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
498 ns · 480 calls
603 ns · 756 calls
7.01 μs
8.79 μs
20261122T000034Z-565231f-registered-repeat-1
Off
723 ns · 32 calls
614 ns · 620 calls
6.6 μs
8.68 μs
20261122T000034Z-565231f
On · no reduction
498 ns · 480 calls
603 ns · 756 calls
7.01 μs
8.79 μs
20261122T000034Z-565231f
Off
723 ns · 32 calls
614 ns · 620 calls
6.6 μs
8.68 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
595 ns · 713 calls
4.5 μs
7.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
588 ns · 690 calls
3.91 μs
6.93 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
595 ns · 713 calls
4.5 μs
7.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
588 ns · 690 calls
3.91 μs
6.93 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.3 μs · value and gradient 9.97 μs
PosteriorDB model GLMM_Poisson_model · dataset GLMM_Poisson_data · SHA-256 a5bf224dc224c31653442a0580c8568f4852f4e741aa000e187946b2bea629d2
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
674 ns
1.16 μs
FlatPPL · normal optimizations
5.77 μs · 8.56× Wren
12 μs · 10.4× Wren
FlatPPL · equal work
5.46 μs · 8.1× Wren
12.6 μs · 10.9× Wren
Wren definition in this run
@wren function glmm_poisson_model(counts, year, year_squared, year_cubed, n)
alpha ~ WD.Uniform(-20.0, 20.0)
beta1 ~ WD.Uniform(-10.0, 10.0)
beta2 ~ WD.Uniform(-10.0, 10.0)
beta3 ~ WD.Uniform(-10.0, 10.0)
@iid eps ~ WD.Flat() size=n
sigma ~ WD.Uniform(0.0, 5.0)
log_lambda =
alpha .+ beta1 .* year .+ beta2 .* year_squared .+ beta3 .* year_cubed .+ eps
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(log_lambda[i])
end
@observe @iid eps ~ WD.Normal(0.0, sigma) size=n
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
647 ns
1.14 μs
FlatPPL · normal optimizations
7.01 μs · 10.8× Wren
8.79 μs · 7.71× Wren
FlatPPL · equal work
6.6 μs · 10.2× Wren
8.68 μs · 7.61× Wren
Wren definition in this run
@wren function glmm_poisson_model(counts, year, year_squared, year_cubed, n)
alpha ~ WD.Uniform(-20.0, 20.0)
beta1 ~ WD.Uniform(-10.0, 10.0)
beta2 ~ WD.Uniform(-10.0, 10.0)
beta3 ~ WD.Uniform(-10.0, 10.0)
@iid eps ~ WD.Flat() size=n
sigma ~ WD.Uniform(0.0, 5.0)
log_lambda =
alpha .+ beta1 .* year .+ beta2 .* year_squared .+ beta3 .* year_cubed .+ eps
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(log_lambda[i])
end
@observe @iid eps ~ WD.Normal(0.0, sigma) size=n
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
671 ns
1.21 μs
FlatPPL · normal optimizations
4.5 μs · 6.71× Wren
7.5 μs · 6.19× Wren
FlatPPL · equal work
3.91 μs · 5.83× Wren
6.93 μs · 5.72× Wren
Wren definition in this run
@wren function glmm_poisson_model(counts, year, year_squared, year_cubed, n)
alpha ~ WD.Uniform(-20.0, 20.0)
beta1 ~ WD.Uniform(-10.0, 10.0)
beta2 ~ WD.Uniform(-10.0, 10.0)
beta3 ~ WD.Uniform(-10.0, 10.0)
@iid eps ~ WD.Flat() size=n
sigma ~ WD.Uniform(0.0, 5.0)
log_lambda =
alpha .+ beta1 .* year .+ beta2 .* year_squared .+ beta3 .* year_cubed .+ eps
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(log_lambda[i])
end
@observe @iid eps ~ WD.Normal(0.0, sigma) size=n
return nothing
end
@model function gp_pois_regr(dist_sq, k, N)
dist_sq = dist_sq.value
rho ~ Gamma(25, 1 / 4)
alpha ~ truncated(Normal(0, 2); lower=0)
f_tilde ~ product_distribution(Fill(Normal(), N))
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + 1e-10 * I
factor = cholesky(Symmetric(covariance); check=false)
if !issuccess(factor)
DynamicPPL.@addlogprob! -Inf
return nothing
end
f = factor.L * f_tilde
DynamicPPL.@addlogprob! logpdf(product_distribution(map(x -> Poisson(exp(x)), f)), k)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.85 μs · 416 calls
FlatPPL gradient disagrees with the reference
5.98 μs
Not measured
20261122T002521Z-565231f-registered-repeat-1
Off
1.77 μs · 284 calls
FlatPPL gradient disagrees with the reference
7.15 μs
Not measured
20261122T002521Z-565231f
On · no reduction
1.85 μs · 416 calls
FlatPPL gradient disagrees with the reference
5.98 μs
Not measured
20261122T002521Z-565231f
Off
1.77 μs · 284 calls
FlatPPL gradient disagrees with the reference
7.15 μs
Not measured
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.42 μs · 448 calls
FlatPPL gradient disagrees with the reference
6.14 μs
Not measured
20261122T000034Z-565231f-registered-repeat-1
Off
1.41 μs · 264 calls
FlatPPL gradient disagrees with the reference
6.37 μs
Not measured
20261122T000034Z-565231f
On · no reduction
1.42 μs · 448 calls
FlatPPL gradient disagrees with the reference
6.14 μs
Not measured
20261122T000034Z-565231f
Off
1.41 μs · 264 calls
FlatPPL gradient disagrees with the reference
6.37 μs
Not measured
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
FlatPPL gradient disagrees with the reference
5.71 μs
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
FlatPPL gradient disagrees with the reference
6.16 μs
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
FlatPPL gradient disagrees with the reference
5.71 μs
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
FlatPPL gradient disagrees with the reference
6.16 μs
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.06 μs · value and gradient 10.6 μs
PosteriorDB model gp_pois_regr · dataset gp_pois_regr · SHA-256 9094c25b7653ba5f347178b2614d697fd7b709d4ee16ca33112ffd6266936e12
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.04 μs
4.53 μs
FlatPPL · normal optimizations
5.98 μs · 5.73× Wren
FlatPPL gradient disagrees with the reference
FlatPPL · equal work
7.15 μs · 6.85× Wren
FlatPPL gradient disagrees with the reference
Wren definition in this run
@wren function gp_pois_regr(counts, dist_sq, N)
rho ~ WD.Gamma(25.0, 1 / 4)
# Stan's positive Normal factor differs by the constant log(2).
alpha ~ WD.HalfNormal(0.0, 2.0)
@iid f_tilde ~ WD.Normal(0.0, 1.0) size=N
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + 1e-10I
chol = cholesky(Symmetric(covariance); check=false)
if issuccess(chol)
f = chol.L * f_tilde
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(f[i])
end
else
@addloglikelihood -Inf
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.34 μs
4.35 μs
FlatPPL · normal optimizations
6.14 μs · 4.59× Wren
FlatPPL gradient disagrees with the reference
FlatPPL · equal work
6.37 μs · 4.76× Wren
FlatPPL gradient disagrees with the reference
Wren definition in this run
@wren function gp_pois_regr(counts, dist_sq, N)
rho ~ WD.Gamma(25.0, 1 / 4)
# Stan's positive Normal factor differs by the constant log(2).
alpha ~ WD.HalfNormal(0.0, 2.0)
@iid f_tilde ~ WD.Normal(0.0, 1.0) size=N
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + 1e-10I
chol = cholesky(Symmetric(covariance); check=false)
if issuccess(chol)
f = chol.L * f_tilde
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(f[i])
end
else
@addloglikelihood -Inf
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
851 ns
4.41 μs
FlatPPL · normal optimizations
5.71 μs · 6.71× Wren
FlatPPL gradient disagrees with the reference
FlatPPL · equal work
6.16 μs · 7.24× Wren
FlatPPL gradient disagrees with the reference
Wren definition in this run
@wren function gp_pois_regr(counts, dist_sq, N)
rho ~ WD.Gamma(25.0, 1 / 4)
# Stan's positive Normal factor differs by the constant log(2).
alpha ~ WD.HalfNormal(0.0, 2.0)
@iid f_tilde ~ WD.Normal(0.0, 1.0) size=N
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + 1e-10I
chol = cholesky(Symmetric(covariance); check=false)
if issuccess(chol)
f = chol.L * f_tilde
@batch for i in eachindex(counts)
@observe counts[i] ~ WD.PoissonLog(f[i])
end
else
@addloglikelihood -Inf
end
return nothing
end
@wren function gp_regr(y, dist_sq, N)
rho ~ WD.Gamma(25.0, 1 / 4)
alpha ~ WD.HalfNormal(0.0, 2.0)
sigma ~ WD.HalfNormal(0.0, 1.0)
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + sigma * I
# For extreme parameter values (e.g. large rho and tiny sigma) the covariance matrix
# isn't numerically positive definite. Like Stan, give those values zero density
# instead of throwing an error.
chol = cholesky(Symmetric(covariance); check=false)
if issuccess(chol)
@observe y ~ WD.MvNormalScale(zeros(N), chol.L)
else
@addloglikelihood -Inf
end
return nothing
end
@model function gp_pois_regr(dist_sq, k, N)
dist_sq = dist_sq.value
rho ~ Gamma(25, 1 / 4)
alpha ~ truncated(Normal(0, 2); lower=0)
f_tilde ~ product_distribution(Fill(Normal(), N))
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + 1e-10 * I
factor = cholesky(Symmetric(covariance); check=false)
if !issuccess(factor)
DynamicPPL.@addlogprob! -Inf
return nothing
end
f = factor.L * f_tilde
DynamicPPL.@addlogprob! logpdf(product_distribution(map(x -> Poisson(exp(x)), f)), k)
end
@model function gp_regr(dist_sq, y, N)
dist_sq = dist_sq.value
y = y.value
rho ~ Gamma(25, 1 / 4)
alpha ~ truncated(Normal(0, 2); lower=0)
sigma ~ truncated(Normal(0, 1); lower=0)
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + sigma * I
return y ~ MvNormal(zeros(N), Symmetric(covariance))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.64 μs · 148 calls
3.82 μs · 116 calls
6.21 μs
14.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.67 μs · 304 calls
4.3 μs · 24 calls
7.17 μs
11.7 μs
20261122T002521Z-565231f
On · no reduction
1.64 μs · 148 calls
3.82 μs · 116 calls
6.21 μs
14.7 μs
20261122T002521Z-565231f
Off
1.67 μs · 304 calls
4.3 μs · 24 calls
7.17 μs
11.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.84 μs · 440 calls
3.83 μs · 156 calls
6.28 μs
11.3 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.61 μs · 340 calls
4.96 μs · 176 calls
5.95 μs
11.3 μs
20261122T000034Z-565231f
On · no reduction
1.84 μs · 440 calls
3.83 μs · 156 calls
6.28 μs
11.3 μs
20261122T000034Z-565231f
Off
1.61 μs · 340 calls
4.96 μs · 176 calls
5.95 μs
11.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
3.79 μs · 82 calls
6.31 μs
11.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
3.68 μs · 138 calls
6.23 μs
11.6 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
3.79 μs · 82 calls
6.31 μs
11.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
3.68 μs · 138 calls
6.23 μs
11.6 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.94 μs · value and gradient 11.5 μs
PosteriorDB model gp_regr · dataset gp_pois_regr · SHA-256 9094c25b7653ba5f347178b2614d697fd7b709d4ee16ca33112ffd6266936e12
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.28 μs
4.71 μs
FlatPPL · normal optimizations
6.21 μs · 4.85× Wren
14.7 μs · 3.12× Wren
FlatPPL · equal work
7.17 μs · 5.6× Wren
11.7 μs · 2.49× Wren
Wren definition in this run
@wren function gp_regr(y, dist_sq, N)
rho ~ WD.Gamma(25.0, 1 / 4)
alpha ~ WD.HalfNormal(0.0, 2.0)
sigma ~ WD.HalfNormal(0.0, 1.0)
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + sigma * I
# For extreme parameter values (e.g. large rho and tiny sigma) the covariance matrix
# isn't numerically positive definite. Like Stan, give those values zero density
# instead of throwing an error.
chol = cholesky(Symmetric(covariance); check=false)
if issuccess(chol)
@observe y ~ WD.MvNormalScale(zeros(N), chol.L)
else
@addloglikelihood -Inf
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.31 μs
4.77 μs
FlatPPL · normal optimizations
6.28 μs · 4.79× Wren
11.3 μs · 2.38× Wren
FlatPPL · equal work
5.95 μs · 4.54× Wren
11.3 μs · 2.37× Wren
Wren definition in this run
@wren function gp_regr(y, dist_sq, N)
rho ~ WD.Gamma(25.0, 1 / 4)
alpha ~ WD.HalfNormal(0.0, 2.0)
sigma ~ WD.HalfNormal(0.0, 1.0)
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + sigma * I
# For extreme parameter values (e.g. large rho and tiny sigma) the covariance matrix
# isn't numerically positive definite. Like Stan, give those values zero density
# instead of throwing an error.
chol = cholesky(Symmetric(covariance); check=false)
if issuccess(chol)
@observe y ~ WD.MvNormalScale(zeros(N), chol.L)
else
@addloglikelihood -Inf
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.45 μs
4.27 μs
FlatPPL · normal optimizations
6.31 μs · 4.35× Wren
11.8 μs · 2.76× Wren
FlatPPL · equal work
6.23 μs · 4.3× Wren
11.6 μs · 2.72× Wren
Wren definition in this run
@wren function gp_regr(y, dist_sq, N)
rho ~ WD.Gamma(25.0, 1 / 4)
alpha ~ WD.HalfNormal(0.0, 2.0)
sigma ~ WD.HalfNormal(0.0, 1.0)
covariance = alpha^2 .* exp.(-0.5 .* dist_sq ./ rho^2) + sigma * I
# For extreme parameter values (e.g. large rho and tiny sigma) the covariance matrix
# isn't numerically positive definite. Like Stan, give those values zero density
# instead of throwing an error.
chol = cholesky(Symmetric(covariance); check=false)
if issuccess(chol)
@observe y ~ WD.MvNormalScale(zeros(N), chol.L)
else
@addloglikelihood -Inf
end
return nothing
end
%%%
# Two-state hidden Markov model
PosteriorDB's `hmm_example-hmm_example`. A hidden two-state Markov chain
emits unit-variance Normal observations with state means mu. A scan over the
observed history runs the forward filter. Each observation is a two-component
mixture weighted by the predicted state probabilities. The product of these
mixtures is the forward-algorithm likelihood.
The transition rows are uniform on the simplex. The means keep Stan's
Normal(3, 1) and Normal(10, 1) densities on 0 < mu[1] < mu[2], without
renormalization. Stan starts the recursion with weight one for each state.
The uniform initial distribution here subtracts log(2) from Stan's target.
%%%
flatppl_compat = "0.1"
N = 100
data = load_data("data.json", cartprod(y = cartpow(reals, N)))
theta1 ~ Dirichlet([1.0, 1.0])
theta2 ~ Dirichlet([1.0, 1.0])
mu = elementof(ordered(2))
mu_prior = truncate(truncate(joint(Normal(3, 1), Normal(10, 1)), ordered(2)), cartpow(posreals, 2))
% Log-likelihood ratio of state 1 against state 2 for each observation.
log_ratio = 0.5 .* ((data.y .- mu[2]).^2 .- (data.y .- mu[1]).^2)
% Filter on the current observation, then predict state 1 for the next one.
predict(q, r, p) = p.theta2[1] + (p.theta1[1] - p.theta2[1]) * invlogit(logit(q) + r)
step(state, r, p) = record(current = state.next, next = predict(state.next, r, p))
states = scan(step, record(current = 0.5, next = 0.5), log_ratio,
record(theta1 = theta1, theta2 = theta2))
state_weight(state) = state.current
weight = state_weight.(states)
emission(w, mu1, mu2) = normalize(superpose(
weighted(w, Normal(mu1, 1)), weighted(1 - w, Normal(mu2, 1))))
y ~ emission.(weight, mu[1], mu[2])
Pi_prior = joint(lawof(record(theta1 = theta1, theta2 = theta2)), joint(mu = mu_prior))
K_model = kernelof(record(y = y), theta1 = theta1, theta2 = theta2, mu = mu)
L = likelihoodof(K_model, record(y = data.y))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta1 = stdsimplex(2), theta2 = stdsimplex(2), mu = ordered(2))
Pi_post_input = record(theta1 = [0.67, 0.33], theta2 = [0.07, 0.93], mu = [3.0, 9.0])
function HiddenMarkovModel(n, initial, transition, emissions, transition_layout)
return HiddenMarkovModel(
n, initial, transition, emissions, transition_layout, Val(:ordinary)
)
end
@model function hmm_example_model(N, K, y, initial)
theta1 ~ Dirichlet(ones(K))
theta2 ~ Dirichlet(ones(K))
mu ~ ordered(
product_distribution([
truncated(Normal(3, 1); lower=0), truncated(Normal(10, 1); lower=0)
]),
)
transition = [i == 1 ? theta1[j] : theta2[j] for i in 1:K, j in 1:K]
emissions = NormalEmissions(mu, ones(K))
return y ~ HiddenMarkovModel(N, initial, transition, emissions, Val(:rows))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
6.23 μs · 12 calls
7.2 μs · 20 calls
20 μs
24.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
5.23 μs · 160 calls
8.1 μs · 116 calls
16.3 μs
18.2 μs
20261122T002521Z-565231f
On · no reduction
6.23 μs · 12 calls
7.2 μs · 20 calls
20 μs
24.7 μs
20261122T002521Z-565231f
Off
5.23 μs · 160 calls
8.1 μs · 116 calls
16.3 μs
18.2 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
4.85 μs · 180 calls
5.76 μs · 120 calls
18 μs
19.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
4.62 μs · 160 calls
6.15 μs · 120 calls
16.7 μs
21.6 μs
20261122T000034Z-565231f
On · no reduction
4.85 μs · 180 calls
5.76 μs · 120 calls
18 μs
19.6 μs
20261122T000034Z-565231f
Off
4.62 μs · 160 calls
6.15 μs · 120 calls
16.7 μs
21.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
5.75 μs · 118 calls
13.7 μs
19.7 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
5.87 μs · 102 calls
13.7 μs
15.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
5.75 μs · 118 calls
13.7 μs
19.7 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
5.87 μs · 102 calls
13.7 μs
15.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 14.8 μs · value and gradient 18.5 μs
PosteriorDB model hmm_example · dataset hmm_example · SHA-256 8fe2ad2a4ceb9f006694dced959f4fb8190277cfaadde2a281ebef92b6a36019
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
const HMM_GAUSSIAN = @rkppl begin
init ~ Dirichlet(ones(3))
eachrow(A[1:3, 1:3]) .~ Dirichlet(ones(3))
mu ~ Ordered(Flat(), 3)
sigma[1:3] .~ restricted.(Flat.(), 0, Inf)
# Stan's vectorized first emission adds the same sum of three Normal log
# densities to every initial state. The remaining chain starts one step later.
first_observations .~ Normal.(mu, sigma)
y_tail ~ LogDensity(normal_hmm_logdensity, mu, sigma, A, A' * init)
end
%%%
# Three-state Gaussian hidden Markov model
PosteriorDB's `hmm_gaussian_simulated-hmm_gaussian`. A hidden three-state
Markov chain with initial probabilities pi1 and transition rows A emits
Normal observations with ordered means mu and scales sigma. The posterior
reweights the prior by Stan's forward-algorithm target, written as a scan of
log forward variables. Stan's first forward step adds the vectorized
normal_lpdf, which sums the first observation's log density over all three
states. That target is not a normalized likelihood of y, so the model keeps
it as an explicit log weight. The simplex priors are uniform, which adds
4 log(2) to Stan's flat target. The means and scales have flat priors.
%%%
flatppl_compat = "0.1"
T = 500
K = 3
data = load_data("data.json", cartprod(y = cartpow(reals, T)))
pi1 ~ Dirichlet(ones(K))
A ~ iid(Dirichlet(ones(K)), K)
Pi_proper = lawof(record(pi1 = pi1, A = A))
Pi_improper = Lebesgue(cartprod(mu = ordered(K), sigma = cartpow(posreals, K)))
Pi_prior = joint(Pi_proper, Pi_improper)
normal_lpdf(y, m, s) = -0.5 * ((y - m) / s)^2 - log(s) - 0.5 * log(2 * pi)
forward(la, t, p) = maximum(la) .+ log.(p.A_t * exp.(la .- maximum(la))) .+ p.log_lik[t, :]
log_target(x) = logsumexp(scan(forward,
log.(x.pi1) .+ sum(normal_lpdf.(data.y[1], x.mu, x.sigma)), indicesof(zeros(T - 1)) .+ 1,
record(A_t = transpose(rowstack(x.A)),
log_lik = aggregate(sum, [.t, .k], normal_lpdf(data.y[.t], x.mu[.k], x.sigma[.k]))))[T - 1])
Pi_post = logweighted(log_target, Pi_prior)
Pi_post_domain = cartprod(pi1 = stdsimplex(3), A = cartpow(stdsimplex(3), 3), mu = ordered(3),
sigma = cartpow(posreals, 3))
Pi_post_input = record(pi1 = [0.34, 0.33, 0.33],
A = [[0.2, 0.4, 0.4], [0.4, 0.2, 0.4], [0.4, 0.4, 0.2]],
mu = [9.0, 18.0, 29.0], sigma = [0.3, 3.0, 3.0])
function HiddenMarkovModel(n, initial, transition, emissions, transition_layout)
return HiddenMarkovModel(
n, initial, transition, emissions, transition_layout, Val(:ordinary)
)
end
@model function pdb_hmm_gaussian(T, K, y)
pi1 ~ Dirichlet(ones(K))
A ~ product_distribution(Fill(Dirichlet(ones(K)), K))
mu ~ ordered(product_distribution(Fill(Flat(), K)))
sigma ~ product_distribution(Fill(FlatPos(0), K))
# Stan's first vectorized Normal density is a scalar sum which is then added
# to every initial state. Preserve that model exactly.
emissions = NormalEmissions(mu, sigma)
# ProductDistribution stores transition simplex i in column i.
return y ~ HiddenMarkovModel(T, pi1, A, emissions, Val(:columns), Val(:summed_first))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
27.5 μs · 28 calls
47.7 μs · 16 calls
47.8 μs
79 μs
20261122T002521Z-565231f-registered-repeat-1
Off
38.3 μs · 4 calls
53.8 μs · 20 calls
38.8 μs
67.1 μs
20261122T002521Z-565231f
On · no reduction
27.5 μs · 28 calls
47.7 μs · 16 calls
47.8 μs
79 μs
20261122T002521Z-565231f
Off
38.3 μs · 4 calls
53.8 μs · 20 calls
38.8 μs
67.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
26.4 μs · 12 calls
59 μs · 16 calls
39.6 μs
73.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
22.8 μs · 36 calls
47.4 μs · 16 calls
40.1 μs
74.8 μs
20261122T000034Z-565231f
On · no reduction
26.4 μs · 12 calls
59 μs · 16 calls
39.6 μs
73.6 μs
20261122T000034Z-565231f
Off
22.8 μs · 36 calls
47.4 μs · 16 calls
40.1 μs
74.8 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 45.3 μs · value and gradient 83.1 μs
PosteriorDB model hmm_gaussian · dataset hmm_gaussian_simulated · SHA-256 b3dacb0e6d576fe51a3760310d0f94a42b7b0d150a961a96850a2c4faccada2c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
60.2 μs
122 μs
FlatPPL · normal optimizations
47.8 μs · 0.793× Wren
79 μs · 0.648× Wren
FlatPPL · equal work
38.8 μs · 0.644× Wren
67.1 μs · 0.551× Wren
Wren definition in this run
@wren function hmm_gaussian(y)
pi ~ WD.Dirichlet(fill(1.0, 3))
a1 ~ WD.Dirichlet(fill(1.0, 3))
a2 ~ WD.Dirichlet(fill(1.0, 3))
a3 ~ WD.Dirichlet(fill(1.0, 3))
raw_mu1 ~ WD.Flat()
raw_gap2 ~ WD.Flat()
raw_gap3 ~ WD.Flat()
raw_sigma1 ~ WD.Flat()
raw_sigma2 ~ WD.Flat()
raw_sigma3 ~ WD.Flat()
mu1 = raw_mu1
mu2 = mu1 + exp(raw_gap2)
mu3 = mu2 + exp(raw_gap3)
sigma1 = exp(raw_sigma1)
sigma2 = exp(raw_sigma2)
sigma3 = exp(raw_sigma3)
# Ordered means and positive flat scales still need Jacobians.
# Native ordered priors are tracked in #207; positive-flat scales in #192.
@addloglikelihood raw_gap2 + raw_gap3 + raw_sigma1 + raw_sigma2 + raw_sigma3
# The Stan source starts the forward pass with
# logalpha[1] = log(pi1) + normal_lpdf(y[1] | mu, sigma);
# where the vectorised `normal_lpdf` is one number, the sum over all three
# states. Every state therefore gets the same first emission term. This is the
# PosteriorDB target, not the usual per-state emission.
first_emission = logdensityof(WD.Normal(mu1, sigma1), y[1]) +
logdensityof(WD.Normal(mu2, sigma2), y[1]) +
logdensityof(WD.Normal(mu3, sigma3), y[1])
g1 = log(pi[1]) + first_emission
g2 = log(pi[2]) + first_emission
g3 = log(pi[3]) + first_emission
for t in 2:length(y)
next1 = logdensityof(WD.Normal(mu1, sigma1), y[t]) +
logaddexp(logaddexp(g1 + log(a1[1]), g2 + log(a2[1])),
g3 + log(a3[1]))
next2 = logdensityof(WD.Normal(mu2, sigma2), y[t]) +
logaddexp(logaddexp(g1 + log(a1[2]), g2 + log(a2[2])),
g3 + log(a3[2]))
next3 = logdensityof(WD.Normal(mu3, sigma3), y[t]) +
logaddexp(logaddexp(g1 + log(a1[3]), g2 + log(a2[3])),
g3 + log(a3[3]))
g1, g2, g3 = next1, next2, next3
end
@addloglikelihood logaddexp(logaddexp(g1, g2), g3)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
59.2 μs
130 μs
FlatPPL · normal optimizations
39.6 μs · 0.668× Wren
73.6 μs · 0.565× Wren
FlatPPL · equal work
40.1 μs · 0.678× Wren
74.8 μs · 0.574× Wren
Wren definition in this run
@wren function hmm_gaussian(y)
pi ~ WD.Dirichlet(fill(1.0, 3))
a1 ~ WD.Dirichlet(fill(1.0, 3))
a2 ~ WD.Dirichlet(fill(1.0, 3))
a3 ~ WD.Dirichlet(fill(1.0, 3))
raw_mu1 ~ WD.Flat()
raw_gap2 ~ WD.Flat()
raw_gap3 ~ WD.Flat()
raw_sigma1 ~ WD.Flat()
raw_sigma2 ~ WD.Flat()
raw_sigma3 ~ WD.Flat()
mu1 = raw_mu1
mu2 = mu1 + exp(raw_gap2)
mu3 = mu2 + exp(raw_gap3)
sigma1 = exp(raw_sigma1)
sigma2 = exp(raw_sigma2)
sigma3 = exp(raw_sigma3)
# Ordered means and positive flat scales still need Jacobians.
# Native ordered priors are tracked in #207; positive-flat scales in #192.
@addloglikelihood raw_gap2 + raw_gap3 + raw_sigma1 + raw_sigma2 + raw_sigma3
# The Stan source starts the forward pass with
# logalpha[1] = log(pi1) + normal_lpdf(y[1] | mu, sigma);
# where the vectorised `normal_lpdf` is one number, the sum over all three
# states. Every state therefore gets the same first emission term. This is the
# PosteriorDB target, not the usual per-state emission.
first_emission = logdensityof(WD.Normal(mu1, sigma1), y[1]) +
logdensityof(WD.Normal(mu2, sigma2), y[1]) +
logdensityof(WD.Normal(mu3, sigma3), y[1])
g1 = log(pi[1]) + first_emission
g2 = log(pi[2]) + first_emission
g3 = log(pi[3]) + first_emission
for t in 2:length(y)
next1 = logdensityof(WD.Normal(mu1, sigma1), y[t]) +
logaddexp(logaddexp(g1 + log(a1[1]), g2 + log(a2[1])),
g3 + log(a3[1]))
next2 = logdensityof(WD.Normal(mu2, sigma2), y[t]) +
logaddexp(logaddexp(g1 + log(a1[2]), g2 + log(a2[2])),
g3 + log(a3[2]))
next3 = logdensityof(WD.Normal(mu3, sigma3), y[t]) +
logaddexp(logaddexp(g1 + log(a1[3]), g2 + log(a2[3])),
g3 + log(a3[3]))
g1, g2, g3 = next1, next2, next3
end
@addloglikelihood logaddexp(logaddexp(g1, g2), g3)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
56.9 μs
127 μs
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function hmm_gaussian(y)
pi ~ WD.Dirichlet(fill(1.0, 3))
a1 ~ WD.Dirichlet(fill(1.0, 3))
a2 ~ WD.Dirichlet(fill(1.0, 3))
a3 ~ WD.Dirichlet(fill(1.0, 3))
raw_mu1 ~ WD.Flat()
raw_gap2 ~ WD.Flat()
raw_gap3 ~ WD.Flat()
raw_sigma1 ~ WD.Flat()
raw_sigma2 ~ WD.Flat()
raw_sigma3 ~ WD.Flat()
mu1 = raw_mu1
mu2 = mu1 + exp(raw_gap2)
mu3 = mu2 + exp(raw_gap3)
sigma1 = exp(raw_sigma1)
sigma2 = exp(raw_sigma2)
sigma3 = exp(raw_sigma3)
# Ordered means and positive flat scales still need Jacobians.
# Native ordered priors are tracked in #207; positive-flat scales in #192.
@addloglikelihood raw_gap2 + raw_gap3 + raw_sigma1 + raw_sigma2 + raw_sigma3
# The Stan source starts the forward pass with
# logalpha[1] = log(pi1) + normal_lpdf(y[1] | mu, sigma);
# where the vectorised `normal_lpdf` is one number, the sum over all three
# states. Every state therefore gets the same first emission term. This is the
# PosteriorDB target, not the usual per-state emission.
first_emission = logdensityof(WD.Normal(mu1, sigma1), y[1]) +
logdensityof(WD.Normal(mu2, sigma2), y[1]) +
logdensityof(WD.Normal(mu3, sigma3), y[1])
g1 = log(pi[1]) + first_emission
g2 = log(pi[2]) + first_emission
g3 = log(pi[3]) + first_emission
for t in 2:length(y)
next1 = logdensityof(WD.Normal(mu1, sigma1), y[t]) +
logaddexp(logaddexp(g1 + log(a1[1]), g2 + log(a2[1])),
g3 + log(a3[1]))
next2 = logdensityof(WD.Normal(mu2, sigma2), y[t]) +
logaddexp(logaddexp(g1 + log(a1[2]), g2 + log(a2[2])),
g3 + log(a3[2]))
next3 = logdensityof(WD.Normal(mu3, sigma3), y[t]) +
logaddexp(logaddexp(g1 + log(a1[3]), g2 + log(a2[3])),
g3 + log(a3[3]))
g1, g2, g3 = next1, next2, next3
end
@addloglikelihood logaddexp(logaddexp(g1, g2), g3)
return nothing
end
Standalone FlatPPL single call · sufficient statistics on · log density 10.3 μs · value and gradient Reverse differentiation of the adaptive ODE loop failed
PosteriorDB model lotka_volterra · dataset hudson_lynx_hare · SHA-256 381934bf92c9f86e938da824fda8adcc0b5b43dd3c0eb62c0686006beea0893d
%%%
# Input-output hidden Markov regression
PosteriorDB's `iohmm_reg_simulated-iohmm_reg`. Three hidden states each have
a regression of y on four inputs u with coefficients b and scale sigma.
Stan's forward step weights each source state i by a softmax of u[t] * w
over the source index alone, so the transition weight does not depend on the
destination state. The forward recursion then factorizes into one log-sum-
exp per time step, and the target is not a normalized likelihood of y. The
model keeps it as an explicit log weight on the prior. The uniform simplex
prior on pi1 and the three normalized half-Normal scales add 4 log(2) to
Stan's target.
%%%
flatppl_compat = "0.1"
T = 500
K = 3
M = 4
data = load_data("data.json", cartprod(y = cartpow(reals, T), u = cartpow(reals, [T, M])))
pi1 ~ Dirichlet(ones(K))
w ~ iid(iid(Normal(0, 5), M), K)
b ~ iid(iid(Normal(0, 5), M), K)
sigma ~ iid(normalize(truncate(Normal(0, 3), interval(0, inf))), K)
Pi_prior = lawof(record(pi1 = pi1, w = w, b = b, sigma = sigma))
row_max(X) = aggregate(maximum, [.t], X[.t, .k])
row_logsumexp(X) = row_max(X) .+ log.(aggregate(sum, [.t], exp(X[.t, .k] - row_max(X)[.t])))
log_obs(x) = aggregate(sum, [.t, .k], -0.5 * ((data.y[.t] - (data.u * transpose(rowstack(x.b)))[.t, .k])
/ x.sigma[.k])^2 - log(x.sigma[.k]) - 0.5 * log(2 * pi))
log_trans(x) = (data.u * transpose(rowstack(x.w))) .- addaxes(row_logsumexp(data.u * transpose(rowstack(x.w))), 0, 1)
middle = indicesof(zeros(T - 2)) .+ 1
% Stan's forward recursion, collapsed: one log-sum-exp per step.
log_target(x) = logsumexp(log.(x.pi1) .+ log_obs(x)[1, :] .+ log_trans(x)[2, :]) +
sum(row_logsumexp(log_obs(x)[middle, :] .+ log_trans(x)[middle .+ 1, :])) +
logsumexp(log_obs(x)[T, :])
Pi_post = logweighted(log_target, Pi_prior)
Pi_post_domain = cartprod(pi1 = stdsimplex(3), w = cartpow(cartpow(reals, 4), 3), b = cartpow(cartpow(reals, 4), 3), sigma = cartpow(posreals, 3))
Pi_post_input = record(pi1 = [0.026665, 0.15385, 0.819485], w = [[1.75, 1.58, 1.9, 3.57], [1.63, 1.77, 1.84, 3.28], [1.55, 1.54, 1.85, 3.31]], b = [[4.98, 5.98, 7.03, 0.494], [-0.0888, -1.11, -4.81, 0.0371], [1.01, 4.92, 0.127, -0.606]], sigma = [0.199, 2.56, 1.05])
function HiddenMarkovModel(n, initial, transition, emissions, transition_layout)
return HiddenMarkovModel(
n, initial, transition, emissions, transition_layout, Val(:ordinary)
)
end
@model function pdb_iohmm_reg(T, K, M, y, u)
pi1 ~ Dirichlet(ones(K))
w ~ product_distribution(Fill(Normal(0, 5), K, M))
b ~ product_distribution(Fill(Normal(0, 5), K, M))
sigma ~ product_distribution(Fill(truncated(Normal(0, 3); lower=0), K))
unA = (hcat(pi1, w * (u')[:, 2:end]))'
A = copy(unA)
for t in 2:T
A[t, :] .= softmax(unA[t, :])
end
logA = log.(A)
emission_mu = u * b'
emissions = NormalEmissions(emission_mu, sigma)
return y ~ HiddenMarkovModel(T, pi1, logA, emissions, Val(:source_logprob))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
10.3 μs · 28 calls
13.9 μs · 32 calls
20.1 μs
30.8 μs
20261122T002521Z-565231f-registered-repeat-1
Off
10.6 μs · 84 calls
14.5 μs · 52 calls
23.9 μs
25.4 μs
20261122T002521Z-565231f
On · no reduction
10.3 μs · 28 calls
13.9 μs · 32 calls
20.1 μs
30.8 μs
20261122T002521Z-565231f
Off
10.6 μs · 84 calls
14.5 μs · 52 calls
23.9 μs
25.4 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
12.8 μs · 4 calls
15.8 μs · 44 calls
20.1 μs
27.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
11.8 μs · 68 calls
15.9 μs · 44 calls
19.6 μs
27.3 μs
20261122T000034Z-565231f
On · no reduction
12.8 μs · 4 calls
15.8 μs · 44 calls
20.1 μs
27.8 μs
20261122T000034Z-565231f
Off
11.8 μs · 68 calls
15.9 μs · 44 calls
19.6 μs
27.3 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 18.9 μs · value and gradient 35.5 μs
PosteriorDB model iohmm_reg · dataset iohmm_reg_simulated · SHA-256 5c3bc65361738fdccec5eae4f1fb036c3259ff4bab3a45821997b27e2a9361eb
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
54.1 μs
78 μs
FlatPPL · normal optimizations
20.1 μs · 0.371× Wren
30.8 μs · 0.394× Wren
FlatPPL · equal work
23.9 μs · 0.441× Wren
25.4 μs · 0.326× Wren
Wren definition in this run
@wren function iohmm_reg(y, u)
pi ~ WD.Dirichlet(fill(1.0, 3))
@iid w1 ~ WD.Normal(0.0, 5.0) size=4
@iid w2 ~ WD.Normal(0.0, 5.0) size=4
@iid w3 ~ WD.Normal(0.0, 5.0) size=4
@iid b1 ~ WD.Normal(0.0, 5.0) size=4
@iid b2 ~ WD.Normal(0.0, 5.0) size=4
@iid b3 ~ WD.Normal(0.0, 5.0) size=4
sigma1 ~ WD.HalfNormal(0.0, 3.0)
sigma2 ~ WD.HalfNormal(0.0, 3.0)
sigma3 ~ WD.HalfNormal(0.0, 3.0)
g1 = log(pi[1]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b1), sigma1), y[1])
g2 = log(pi[2]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b2), sigma2), y[1])
g3 = log(pi[3]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b3), sigma3), y[1])
for t in 2:length(y)
r1 = linear_predictor(u, t, w1)
r2 = linear_predictor(u, t, w2)
r3 = linear_predictor(u, t, w3)
normalizer = logaddexp(logaddexp(r1, r2), r3)
# The source Stan program uses logA[t][i] for every destination j.
# Thus this transition factor is shared across all three next states.
shared = logaddexp(logaddexp(g1 + r1 - normalizer,
g2 + r2 - normalizer), g3 + r3 - normalizer)
g1 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b1), sigma1), y[t])
g2 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b2), sigma2), y[t])
g3 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b3), sigma3), y[t])
end
@addloglikelihood logaddexp(logaddexp(g1, g2), g3)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
51.7 μs
81.8 μs
FlatPPL · normal optimizations
20.1 μs · 0.388× Wren
27.8 μs · 0.34× Wren
FlatPPL · equal work
19.6 μs · 0.379× Wren
27.3 μs · 0.334× Wren
Wren definition in this run
@wren function iohmm_reg(y, u)
pi ~ WD.Dirichlet(fill(1.0, 3))
@iid w1 ~ WD.Normal(0.0, 5.0) size=4
@iid w2 ~ WD.Normal(0.0, 5.0) size=4
@iid w3 ~ WD.Normal(0.0, 5.0) size=4
@iid b1 ~ WD.Normal(0.0, 5.0) size=4
@iid b2 ~ WD.Normal(0.0, 5.0) size=4
@iid b3 ~ WD.Normal(0.0, 5.0) size=4
sigma1 ~ WD.HalfNormal(0.0, 3.0)
sigma2 ~ WD.HalfNormal(0.0, 3.0)
sigma3 ~ WD.HalfNormal(0.0, 3.0)
g1 = log(pi[1]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b1), sigma1), y[1])
g2 = log(pi[2]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b2), sigma2), y[1])
g3 = log(pi[3]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b3), sigma3), y[1])
for t in 2:length(y)
r1 = linear_predictor(u, t, w1)
r2 = linear_predictor(u, t, w2)
r3 = linear_predictor(u, t, w3)
normalizer = logaddexp(logaddexp(r1, r2), r3)
# The source Stan program uses logA[t][i] for every destination j.
# Thus this transition factor is shared across all three next states.
shared = logaddexp(logaddexp(g1 + r1 - normalizer,
g2 + r2 - normalizer), g3 + r3 - normalizer)
g1 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b1), sigma1), y[t])
g2 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b2), sigma2), y[t])
g3 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b3), sigma3), y[t])
end
@addloglikelihood logaddexp(logaddexp(g1, g2), g3)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
49.5 μs
79.9 μs
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function iohmm_reg(y, u)
pi ~ WD.Dirichlet(fill(1.0, 3))
@iid w1 ~ WD.Normal(0.0, 5.0) size=4
@iid w2 ~ WD.Normal(0.0, 5.0) size=4
@iid w3 ~ WD.Normal(0.0, 5.0) size=4
@iid b1 ~ WD.Normal(0.0, 5.0) size=4
@iid b2 ~ WD.Normal(0.0, 5.0) size=4
@iid b3 ~ WD.Normal(0.0, 5.0) size=4
sigma1 ~ WD.HalfNormal(0.0, 3.0)
sigma2 ~ WD.HalfNormal(0.0, 3.0)
sigma3 ~ WD.HalfNormal(0.0, 3.0)
g1 = log(pi[1]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b1), sigma1), y[1])
g2 = log(pi[2]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b2), sigma2), y[1])
g3 = log(pi[3]) +
logdensityof(WD.Normal(linear_predictor(u, 1, b3), sigma3), y[1])
for t in 2:length(y)
r1 = linear_predictor(u, t, w1)
r2 = linear_predictor(u, t, w2)
r3 = linear_predictor(u, t, w3)
normalizer = logaddexp(logaddexp(r1, r2), r3)
# The source Stan program uses logA[t][i] for every destination j.
# Thus this transition factor is shared across all three next states.
shared = logaddexp(logaddexp(g1 + r1 - normalizer,
g2 + r2 - normalizer), g3 + r3 - normalizer)
g1 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b1), sigma1), y[t])
g2 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b2), sigma2), y[t])
g3 = shared +
logdensityof(WD.Normal(linear_predictor(u, t, b3), sigma3), y[t])
end
@addloglikelihood logaddexp(logaddexp(g1, g2), g3)
return nothing
end
@model function pdb_irt_2pl(I, J, y)
sigma_theta ~ FlatPos(0)
theta ~ product_distribution(Fill(Flat(), J))
sigma_a ~ FlatPos(0)
a ~ product_distribution(Fill(FlatPos(0), I))
mu_b ~ Normal(0, 5)
sigma_b ~ FlatPos(0)
b ~ product_distribution(Fill(Flat(), I))
DynamicPPL.@addlogprob! logpdf(Cauchy(0, 2), sigma_theta)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_theta), size(theta))), theta
)
DynamicPPL.@addlogprob! logpdf(Cauchy(0, 2), sigma_a)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(LogNormal(0, sigma_a), size(a))), a
)
DynamicPPL.@addlogprob! logpdf(Cauchy(0, 2), sigma_b)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_b, sigma_b), size(b))), b
)
for i in 1:I
logits = a[i] .* (theta .- b[i])
DynamicPPL.@addlogprob! logpdf(
product_distribution(map(BernoulliLogit, logits)), y[i, :]
)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
27.5 μs · 36 calls
27.2 μs · 32 calls
25.6 μs
29.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
26.9 μs · 24 calls
30 μs · 4 calls
29.4 μs
27.3 μs
20261122T002521Z-565231f
On · no reduction
27.5 μs · 36 calls
27.2 μs · 32 calls
25.6 μs
29.5 μs
20261122T002521Z-565231f
Off
26.9 μs · 24 calls
30 μs · 4 calls
29.4 μs
27.3 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
22.5 μs · 36 calls
21.8 μs · 36 calls
27.2 μs
29.5 μs
20261122T000034Z-565231f-registered-repeat-1
Off
23.6 μs · 32 calls
21.9 μs · 28 calls
27 μs
28.3 μs
20261122T000034Z-565231f
On · no reduction
22.5 μs · 36 calls
21.8 μs · 36 calls
27.2 μs
29.5 μs
20261122T000034Z-565231f
Off
23.6 μs · 32 calls
21.9 μs · 28 calls
27 μs
28.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 26.2 μs · value and gradient 28 μs
PosteriorDB model irt_2pl · dataset irt_2pl · SHA-256 2f19672a37352782fefc8936356ea30cd78bdd7a4732641bf1a8151eb9ade1a8
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
19.8 μs
37.4 μs
FlatPPL · normal optimizations
25.6 μs · 1.29× Wren
29.5 μs · 0.788× Wren
FlatPPL · equal work
29.4 μs · 1.49× Wren
27.3 μs · 0.73× Wren
Wren definition in this run
@wren function irt_2pl(y, I, J)
sigma_theta ~ WD.HalfCauchy(0.0, 2.0)
@iid theta ~ WD.Normal(0.0, sigma_theta) size=J
sigma_a ~ WD.HalfCauchy(0.0, 2.0)
@iid a ~ WD.LogNormal(0.0, sigma_a) size=I
mu_b ~ WD.Normal(0.0, 5.0)
sigma_b ~ WD.HalfCauchy(0.0, 2.0)
@iid b ~ WD.Normal(mu_b, sigma_b) size=I
logits = Vector{typeof(a[1] + theta[1] + b[1])}(undef, length(y))
for n in eachindex(y)
i = mod1(n, I)
j = cld(n, I)
logits[n] = a[i] * (theta[j] - b[i])
end
@batch for n in eachindex(y)
@observe y[n] ~ WD.BernoulliLogit(logits[n])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
19.8 μs
38.1 μs
FlatPPL · normal optimizations
27.2 μs · 1.37× Wren
29.5 μs · 0.775× Wren
FlatPPL · equal work
27 μs · 1.36× Wren
28.3 μs · 0.744× Wren
Wren definition in this run
@wren function irt_2pl(y, I, J)
sigma_theta ~ WD.HalfCauchy(0.0, 2.0)
@iid theta ~ WD.Normal(0.0, sigma_theta) size=J
sigma_a ~ WD.HalfCauchy(0.0, 2.0)
@iid a ~ WD.LogNormal(0.0, sigma_a) size=I
mu_b ~ WD.Normal(0.0, 5.0)
sigma_b ~ WD.HalfCauchy(0.0, 2.0)
@iid b ~ WD.Normal(mu_b, sigma_b) size=I
logits = Vector{typeof(a[1] + theta[1] + b[1])}(undef, length(y))
for n in eachindex(y)
i = mod1(n, I)
j = cld(n, I)
logits[n] = a[i] * (theta[j] - b[i])
end
@batch for n in eachindex(y)
@observe y[n] ~ WD.BernoulliLogit(logits[n])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
19 μs
40.1 μs
FlatPPL · normal optimizations
evaluation failed
evaluation failed
FlatPPL · equal work
evaluation failed
evaluation failed
Wren definition in this run
@wren function irt_2pl(y, I, J)
sigma_theta ~ WD.HalfCauchy(0.0, 2.0)
@iid theta ~ WD.Normal(0.0, sigma_theta) size=J
sigma_a ~ WD.HalfCauchy(0.0, 2.0)
@iid a ~ WD.LogNormal(0.0, sigma_a) size=I
mu_b ~ WD.Normal(0.0, 5.0)
sigma_b ~ WD.HalfCauchy(0.0, 2.0)
@iid b ~ WD.Normal(mu_b, sigma_b) size=I
logits = Vector{typeof(a[1] + theta[1] + b[1])}(undef, length(y))
for n in eachindex(y)
i = mod1(n, I)
j = cld(n, I)
logits[n] = a[i] * (theta[j] - b[i])
end
@batch for n in eachindex(y)
@observe y[n] ~ WD.BernoulliLogit(logits[n])
end
return nothing
end
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kidiq_kidscore_interaction(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ truncated(Cauchy(0, 2.5); lower=0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
554 ns · 604 calls
429 ns · 1216 calls
5.08 μs
6.49 μs
20261122T002521Z-565231f-registered-repeat-1
Off
595 ns · 736 calls
567 ns · 68 calls
4.76 μs
6.74 μs
20261122T002521Z-565231f
On · no reduction
554 ns · 604 calls
429 ns · 1216 calls
5.08 μs
6.49 μs
20261122T002521Z-565231f
Off
595 ns · 736 calls
567 ns · 68 calls
4.76 μs
6.74 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
626 ns · 464 calls
415 ns · 920 calls
4.74 μs
6.71 μs
20261122T000034Z-565231f-registered-repeat-1
Off
507 ns · 1068 calls
411 ns · 1000 calls
5.28 μs
9.62 μs
20261122T000034Z-565231f
On · no reduction
626 ns · 464 calls
415 ns · 920 calls
4.74 μs
6.71 μs
20261122T000034Z-565231f
Off
507 ns · 1068 calls
411 ns · 1000 calls
5.28 μs
9.62 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
468 ns · 764 calls
3.54 μs
4.88 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
465 ns · 198 calls
3.26 μs
6.09 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
468 ns · 764 calls
3.54 μs
4.88 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
465 ns · 198 calls
3.26 μs
6.09 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.73 μs · value and gradient 5.06 μs
PosteriorDB model kidscore_interaction · dataset kidiq · SHA-256 8f6026d1d51013be5956cdeec880e4fd522c1a98a8d1c3600f12dd438924f21b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
480 ns
1.03 μs
FlatPPL · normal optimizations
5.08 μs · 10.6× Wren
6.49 μs · 6.3× Wren
FlatPPL · equal work
4.76 μs · 9.92× Wren
6.74 μs · 6.54× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
510 ns
1.07 μs
FlatPPL · normal optimizations
4.74 μs · 9.29× Wren
6.71 μs · 6.29× Wren
FlatPPL · equal work
5.28 μs · 10.4× Wren
9.62 μs · 9.01× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
458 ns
1.07 μs
FlatPPL · normal optimizations
3.54 μs · 7.73× Wren
4.88 μs · 4.58× Wren
FlatPPL · equal work
3.26 μs · 7.12× Wren
6.09 μs · 5.71× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kidiq_kidscore_momhs(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 2))
sigma ~ truncated(Cauchy(0, 2.5); lower=0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
508 ns · 560 calls
425 ns · 1004 calls
8.51 μs
10 μs
20261122T002521Z-565231f-registered-repeat-1
Off
403 ns · 376 calls
419 ns · 600 calls
3.6 μs
10.1 μs
20261122T002521Z-565231f
On · no reduction
508 ns · 560 calls
425 ns · 1004 calls
8.51 μs
10 μs
20261122T002521Z-565231f
Off
403 ns · 376 calls
419 ns · 600 calls
3.6 μs
10.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
359 ns · 956 calls
400 ns · 1528 calls
3.53 μs
5.06 μs
20261122T000034Z-565231f-registered-repeat-1
Off
377 ns · 916 calls
411 ns · 1400 calls
3.72 μs
4.77 μs
20261122T000034Z-565231f
On · no reduction
359 ns · 956 calls
400 ns · 1528 calls
3.53 μs
5.06 μs
20261122T000034Z-565231f
Off
377 ns · 916 calls
411 ns · 1400 calls
3.72 μs
4.77 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
603 ns · 33 calls
4.9 μs
5.21 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
424 ns · 365 calls
4.62 μs
6.49 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
603 ns · 33 calls
4.9 μs
5.21 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
424 ns · 365 calls
4.62 μs
6.49 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 4.03 μs · value and gradient 5.05 μs
PosteriorDB model kidscore_momhs · dataset kidiq · SHA-256 8f6026d1d51013be5956cdeec880e4fd522c1a98a8d1c3600f12dd438924f21b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
440 ns
833 ns
FlatPPL · normal optimizations
8.51 μs · 19.3× Wren
10 μs · 12.0× Wren
FlatPPL · equal work
3.6 μs · 8.18× Wren
10.1 μs · 12.1× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
576 ns
1.24 μs
FlatPPL · normal optimizations
3.53 μs · 6.13× Wren
5.06 μs · 4.08× Wren
FlatPPL · equal work
3.72 μs · 6.46× Wren
4.77 μs · 3.85× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
402 ns
1.24 μs
FlatPPL · normal optimizations
4.9 μs · 12.2× Wren
5.21 μs · 4.19× Wren
FlatPPL · equal work
4.62 μs · 11.5× Wren
6.49 μs · 5.22× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
const KIDSCORE_FLAT = @model X begin
beta ~ Lebesgue(ℝ) ^ size(X, 2)
sigma ~ HalfCauchy(2.5)
mu = X * beta
kid_score ~ For(mu) do m
Normal(m, sigma)
end
end
@model function kidiq_kidscore_momhsiq(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 3))
sigma ~ truncated(Cauchy(0, 2.5); lower=0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
427 ns · 572 calls
420 ns · 1212 calls
5.5 μs
10.3 μs
20261122T002521Z-565231f-registered-repeat-1
Off
453 ns · 736 calls
408 ns · 1092 calls
5.67 μs
6.42 μs
20261122T002521Z-565231f
On · no reduction
427 ns · 572 calls
420 ns · 1212 calls
5.5 μs
10.3 μs
20261122T002521Z-565231f
Off
453 ns · 736 calls
408 ns · 1092 calls
5.67 μs
6.42 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
460 ns · 952 calls
714 ns · 28 calls
5.18 μs
7.01 μs
20261122T000034Z-565231f-registered-repeat-1
Off
438 ns · 1076 calls
445 ns · 1252 calls
5.02 μs
5.29 μs
20261122T000034Z-565231f
On · no reduction
460 ns · 952 calls
714 ns · 28 calls
5.18 μs
7.01 μs
20261122T000034Z-565231f
Off
438 ns · 1076 calls
445 ns · 1252 calls
5.02 μs
5.29 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
389 ns · 555 calls
4.84 μs
5.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
402 ns · 582 calls
4.64 μs
4.74 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
389 ns · 555 calls
4.84 μs
5.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
402 ns · 582 calls
4.64 μs
4.74 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.94 μs · value and gradient 5.03 μs
PosteriorDB model kidscore_momhsiq · dataset kidiq · SHA-256 8f6026d1d51013be5956cdeec880e4fd522c1a98a8d1c3600f12dd438924f21b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
464 ns
955 ns
FlatPPL · normal optimizations
5.5 μs · 11.8× Wren
10.3 μs · 10.8× Wren
FlatPPL · equal work
5.67 μs · 12.2× Wren
6.42 μs · 6.72× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
483 ns
935 ns
FlatPPL · normal optimizations
5.18 μs · 10.7× Wren
7.01 μs · 7.5× Wren
FlatPPL · equal work
5.02 μs · 10.4× Wren
5.29 μs · 5.66× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
480 ns
963 ns
FlatPPL · normal optimizations
4.84 μs · 10.1× Wren
5.5 μs · 5.71× Wren
FlatPPL · equal work
4.64 μs · 9.67× Wren
4.74 μs · 4.92× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kidiq_kidscore_momiq(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 2))
sigma ~ truncated(Cauchy(0, 2.5); lower=0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
349 ns · 936 calls
387 ns · 796 calls
4.78 μs
6.19 μs
20261122T002521Z-565231f-registered-repeat-1
Off
352 ns · 1644 calls
424 ns · 1032 calls
5.08 μs
4.9 μs
20261122T002521Z-565231f
On · no reduction
349 ns · 936 calls
387 ns · 796 calls
4.78 μs
6.19 μs
20261122T002521Z-565231f
Off
352 ns · 1644 calls
424 ns · 1032 calls
5.08 μs
4.9 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
390 ns · 848 calls
404 ns · 1180 calls
5.14 μs
10 μs
20261122T000034Z-565231f-registered-repeat-1
Off
416 ns · 148 calls
389 ns · 740 calls
5.21 μs
6.24 μs
20261122T000034Z-565231f
On · no reduction
390 ns · 848 calls
404 ns · 1180 calls
5.14 μs
10 μs
20261122T000034Z-565231f
Off
416 ns · 148 calls
389 ns · 740 calls
5.21 μs
6.24 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
736 ns · 23 calls
4.88 μs
4.66 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
530 ns · 50 calls
3.33 μs
6.34 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
736 ns · 23 calls
4.88 μs
4.66 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
530 ns · 50 calls
3.33 μs
6.34 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.83 μs · value and gradient 4.76 μs
PosteriorDB model kidscore_momiq · dataset kidiq · SHA-256 8f6026d1d51013be5956cdeec880e4fd522c1a98a8d1c3600f12dd438924f21b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
423 ns
768 ns
FlatPPL · normal optimizations
4.78 μs · 11.3× Wren
6.19 μs · 8.07× Wren
FlatPPL · equal work
5.08 μs · 12.0× Wren
4.9 μs · 6.38× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
358 ns
808 ns
FlatPPL · normal optimizations
5.14 μs · 14.4× Wren
10 μs · 12.4× Wren
FlatPPL · equal work
5.21 μs · 14.6× Wren
6.24 μs · 7.73× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
468 ns
1.03 μs
FlatPPL · normal optimizations
4.88 μs · 10.4× Wren
4.66 μs · 4.54× Wren
FlatPPL · equal work
3.33 μs · 7.11× Wren
6.34 μs · 6.18× Wren
Wren definition in this run
@wren function kidscore_interaction(kid_score, X)
@iid beta ~ WD.Flat() size=size(X, 2)
sigma ~ WD.HalfCauchy(0.0, 2.5)
mu = X * beta
@batch for i in eachindex(kid_score)
@observe kid_score[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kidiq_kidscore_interaction_c(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
592 ns · 372 calls
496 ns · 1052 calls
6.53 μs
9.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
519 ns · 828 calls
415 ns · 1032 calls
5.02 μs
10.1 μs
20261122T002521Z-565231f
On · no reduction
592 ns · 372 calls
496 ns · 1052 calls
6.53 μs
9.5 μs
20261122T002521Z-565231f
Off
519 ns · 828 calls
415 ns · 1032 calls
5.02 μs
10.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
605 ns · 960 calls
448 ns · 1312 calls
8.16 μs
5.26 μs
20261122T000034Z-565231f-registered-repeat-1
Off
578 ns · 1060 calls
444 ns · 1248 calls
5.06 μs
10.3 μs
20261122T000034Z-565231f
On · no reduction
605 ns · 960 calls
448 ns · 1312 calls
8.16 μs
5.26 μs
20261122T000034Z-565231f
Off
578 ns · 1060 calls
444 ns · 1248 calls
5.06 μs
10.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
395 ns · 562 calls
3.3 μs
6.13 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
426 ns · 395 calls
3.44 μs
4.57 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
395 ns · 562 calls
3.3 μs
6.13 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
426 ns · 395 calls
3.44 μs
4.57 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.56 μs · value and gradient 4.98 μs
PosteriorDB model kidscore_interaction_c · dataset kidiq_with_mom_work · SHA-256 dbf64ae3f0960af11dacdbe5e5f37e0cd7808996a248f277cbea04f0c0705369
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
476 ns
940 ns
FlatPPL · normal optimizations
6.53 μs · 13.7× Wren
9.5 μs · 10.1× Wren
FlatPPL · equal work
5.02 μs · 10.6× Wren
10.1 μs · 10.8× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
397 ns
1.18 μs
FlatPPL · normal optimizations
8.16 μs · 20.5× Wren
5.26 μs · 4.46× Wren
FlatPPL · equal work
5.06 μs · 12.7× Wren
10.3 μs · 8.71× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
561 ns
1.25 μs
FlatPPL · normal optimizations
3.3 μs · 5.88× Wren
6.13 μs · 4.9× Wren
FlatPPL · equal work
3.44 μs · 6.13× Wren
4.57 μs · 3.66× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kidiq_kidscore_interaction_c2(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
489 ns · 996 calls
398 ns · 1608 calls
5.12 μs
6.67 μs
20261122T002521Z-565231f-registered-repeat-1
Off
492 ns · 952 calls
438 ns · 616 calls
3.7 μs
4.72 μs
20261122T002521Z-565231f
On · no reduction
489 ns · 996 calls
398 ns · 1608 calls
5.12 μs
6.67 μs
20261122T002521Z-565231f
Off
492 ns · 952 calls
438 ns · 616 calls
3.7 μs
4.72 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
524 ns · 528 calls
413 ns · 504 calls
4.87 μs
8.18 μs
20261122T000034Z-565231f-registered-repeat-1
Off
2.29 μs · 4 calls
426 ns · 556 calls
5.57 μs
10.6 μs
20261122T000034Z-565231f
On · no reduction
524 ns · 528 calls
413 ns · 504 calls
4.87 μs
8.18 μs
20261122T000034Z-565231f
Off
2.29 μs · 4 calls
426 ns · 556 calls
5.57 μs
10.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
755 ns · 23 calls
3.6 μs
4.79 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
603 ns · 47 calls
3.34 μs
6.43 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
755 ns · 23 calls
3.6 μs
4.79 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
603 ns · 47 calls
3.34 μs
6.43 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.58 μs · value and gradient 5 μs
PosteriorDB model kidscore_interaction_c2 · dataset kidiq_with_mom_work · SHA-256 dbf64ae3f0960af11dacdbe5e5f37e0cd7808996a248f277cbea04f0c0705369
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
498 ns
882 ns
FlatPPL · normal optimizations
5.12 μs · 10.3× Wren
6.67 μs · 7.56× Wren
FlatPPL · equal work
3.7 μs · 7.44× Wren
4.72 μs · 5.35× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
640 ns
953 ns
FlatPPL · normal optimizations
4.87 μs · 7.61× Wren
8.18 μs · 8.58× Wren
FlatPPL · equal work
5.57 μs · 8.7× Wren
10.6 μs · 11.1× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
525 ns
1.36 μs
FlatPPL · normal optimizations
3.6 μs · 6.86× Wren
4.79 μs · 3.53× Wren
FlatPPL · equal work
3.34 μs · 6.36× Wren
6.43 μs · 4.74× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kidiq_kidscore_interaction_z(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
489 ns · 904 calls
436 ns · 1048 calls
3.48 μs
5.53 μs
20261122T002521Z-565231f-registered-repeat-1
Off
595 ns · 756 calls
521 ns · 952 calls
3.65 μs
6.04 μs
20261122T002521Z-565231f
On · no reduction
489 ns · 904 calls
436 ns · 1048 calls
3.48 μs
5.53 μs
20261122T002521Z-565231f
Off
595 ns · 756 calls
521 ns · 952 calls
3.65 μs
6.04 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
629 ns · 820 calls
462 ns · 1164 calls
3.73 μs
6.67 μs
20261122T000034Z-565231f-registered-repeat-1
Off
621 ns · 1016 calls
407 ns · 1180 calls
5.2 μs
7.19 μs
20261122T000034Z-565231f
On · no reduction
629 ns · 820 calls
462 ns · 1164 calls
3.73 μs
6.67 μs
20261122T000034Z-565231f
Off
621 ns · 1016 calls
407 ns · 1180 calls
5.2 μs
7.19 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
426 ns · 522 calls
3.42 μs
4.9 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
449 ns · 321 calls
4.71 μs
4.96 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
426 ns · 522 calls
3.42 μs
4.9 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
449 ns · 321 calls
4.71 μs
4.96 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.51 μs · value and gradient 4.95 μs
PosteriorDB model kidscore_interaction_z · dataset kidiq_with_mom_work · SHA-256 dbf64ae3f0960af11dacdbe5e5f37e0cd7808996a248f277cbea04f0c0705369
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
420 ns
913 ns
FlatPPL · normal optimizations
3.48 μs · 8.29× Wren
5.53 μs · 6.05× Wren
FlatPPL · equal work
3.65 μs · 8.69× Wren
6.04 μs · 6.61× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
598 ns
1.24 μs
FlatPPL · normal optimizations
3.73 μs · 6.24× Wren
6.67 μs · 5.37× Wren
FlatPPL · equal work
5.2 μs · 8.69× Wren
7.19 μs · 5.79× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
555 ns
1.09 μs
FlatPPL · normal optimizations
3.42 μs · 6.16× Wren
4.9 μs · 4.5× Wren
FlatPPL · equal work
4.71 μs · 8.49× Wren
4.96 μs · 4.55× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kidiq_kidscore_mom_work(kid_score, X)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(kid_score))), kid_score .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
624 ns · 1028 calls
661 ns · 28 calls
5.26 μs
6.94 μs
20261122T002521Z-565231f-registered-repeat-1
Off
495 ns · 924 calls
445 ns · 1024 calls
8.2 μs
4.71 μs
20261122T002521Z-565231f
On · no reduction
624 ns · 1028 calls
661 ns · 28 calls
5.26 μs
6.94 μs
20261122T002521Z-565231f
Off
495 ns · 924 calls
445 ns · 1024 calls
8.2 μs
4.71 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
638 ns · 1008 calls
425 ns · 984 calls
5.39 μs
10.3 μs
20261122T000034Z-565231f-registered-repeat-1
Off
620 ns · 1036 calls
387 ns · 1292 calls
5.46 μs
6.59 μs
20261122T000034Z-565231f
On · no reduction
638 ns · 1008 calls
425 ns · 984 calls
5.39 μs
10.3 μs
20261122T000034Z-565231f
Off
620 ns · 1036 calls
387 ns · 1292 calls
5.46 μs
6.59 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
447 ns · 264 calls
3.52 μs
4.98 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
412 ns · 402 calls
3.54 μs
5.87 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
447 ns · 264 calls
3.52 μs
4.98 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
412 ns · 402 calls
3.54 μs
5.87 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.72 μs · value and gradient 4.9 μs
PosteriorDB model kidscore_mom_work · dataset kidiq_with_mom_work · SHA-256 dbf64ae3f0960af11dacdbe5e5f37e0cd7808996a248f277cbea04f0c0705369
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
472 ns
956 ns
FlatPPL · normal optimizations
5.26 μs · 11.1× Wren
6.94 μs · 7.26× Wren
FlatPPL · equal work
8.2 μs · 17.4× Wren
4.71 μs · 4.93× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
592 ns
1.47 μs
FlatPPL · normal optimizations
5.39 μs · 9.1× Wren
10.3 μs · 6.99× Wren
FlatPPL · equal work
5.46 μs · 9.22× Wren
6.59 μs · 4.49× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
521 ns
1.05 μs
FlatPPL · normal optimizations
3.52 μs · 6.75× Wren
4.98 μs · 4.73× Wren
FlatPPL · equal work
3.54 μs · 6.79× Wren
5.87 μs · 5.57× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function kilpisjarvi_model(x, y, pmualpha, psalpha, pmubeta, psbeta)
alpha ~ WD.Normal(pmualpha, psalpha)
beta ~ WD.Normal(pmubeta, psbeta)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# Stan's positive, unprioritized sigma is flat in sigma, not log sigma.
# Positive flat scale: the log-coordinate Jacobian is needed (#192).
@addloglikelihood log_sigma
mu = alpha .+ beta .* x
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function kilpisjarvi(x, y, pmualpha, psalpha, pmubeta, psbeta)
alpha ~ Normal(pmualpha, psalpha)
beta ~ Normal(pmubeta, psbeta)
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(y))), y .- (alpha .+ beta .* x)
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
37.8 ns · 3404 calls
75.2 ns · 2208 calls
3.51 μs
5.85 μs
20261122T002521Z-565231f-registered-repeat-1
Off
37 ns · 3828 calls
81.4 ns · 1092 calls
3.71 μs
5.57 μs
20261122T002521Z-565231f
On · no reduction
37.8 ns · 3404 calls
75.2 ns · 2208 calls
3.51 μs
5.85 μs
20261122T002521Z-565231f
Off
37 ns · 3828 calls
81.4 ns · 1092 calls
3.71 μs
5.57 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
37.2 ns · 2788 calls
75.6 ns · 1836 calls
3.51 μs
5.62 μs
20261122T000034Z-565231f-registered-repeat-1
Off
35.3 ns · 6268 calls
200 ns · 60 calls
3.52 μs
5.86 μs
20261122T000034Z-565231f
On · no reduction
37.2 ns · 2788 calls
75.6 ns · 1836 calls
3.51 μs
5.62 μs
20261122T000034Z-565231f
Off
35.3 ns · 6268 calls
200 ns · 60 calls
3.52 μs
5.86 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
83.6 ns · 631 calls
3.5 μs
5.62 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
89.2 ns · 504 calls
3.47 μs
5.62 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
83.6 ns · 631 calls
3.5 μs
5.62 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
89.2 ns · 504 calls
3.47 μs
5.62 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.66 μs · value and gradient 5.57 μs
PosteriorDB model kilpisjarvi · dataset kilpisjarvi_mod · SHA-256 d967c8eec8059f9784feb9bf425c2a6730dc7573da3f0b9ec8007fcdcaa85baa
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
68.6 ns
181 ns
FlatPPL · normal optimizations
3.51 μs · 51.2× Wren
5.85 μs · 32.4× Wren
FlatPPL · equal work
3.71 μs · 54.1× Wren
5.57 μs · 30.8× Wren
Wren definition in this run
@wren function kilpisjarvi_model(x, y, pmualpha, psalpha, pmubeta, psbeta)
alpha ~ WD.Normal(pmualpha, psalpha)
beta ~ WD.Normal(pmubeta, psbeta)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# Stan's positive, unprioritized sigma is flat in sigma, not log sigma.
# Positive flat scale: the log-coordinate Jacobian is needed (#192).
@addloglikelihood log_sigma
mu = alpha .+ beta .* x
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
109 ns
274 ns
FlatPPL · normal optimizations
3.51 μs · 32.1× Wren
5.62 μs · 20.5× Wren
FlatPPL · equal work
3.52 μs · 32.2× Wren
5.86 μs · 21.4× Wren
Wren definition in this run
@wren function kilpisjarvi_model(x, y, pmualpha, psalpha, pmubeta, psbeta)
alpha ~ WD.Normal(pmualpha, psalpha)
beta ~ WD.Normal(pmubeta, psbeta)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# Stan's positive, unprioritized sigma is flat in sigma, not log sigma.
# Positive flat scale: the log-coordinate Jacobian is needed (#192).
@addloglikelihood log_sigma
mu = alpha .+ beta .* x
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
121 ns
173 ns
FlatPPL · normal optimizations
3.5 μs · 28.8× Wren
5.62 μs · 32.5× Wren
FlatPPL · equal work
3.47 μs · 28.6× Wren
5.62 μs · 32.5× Wren
Wren definition in this run
@wren function kilpisjarvi_model(x, y, pmualpha, psalpha, pmubeta, psbeta)
alpha ~ WD.Normal(pmualpha, psalpha)
beta ~ WD.Normal(pmubeta, psbeta)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# Stan's positive, unprioritized sigma is flat in sigma, not log sigma.
# Positive flat scale: the log-coordinate Jacobian is needed (#192).
@addloglikelihood log_sigma
mu = alpha .+ beta .* x
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
843 ns · 920 calls
1.14 μs · 496 calls
5.92 μs
12 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.27 μs · 540 calls
1.06 μs · 492 calls
5.27 μs
8.52 μs
20261122T002521Z-565231f
On · no reduction
843 ns · 920 calls
1.14 μs · 496 calls
5.92 μs
12 μs
20261122T002521Z-565231f
Off
1.27 μs · 540 calls
1.06 μs · 492 calls
5.27 μs
8.52 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
866 ns · 452 calls
1.07 μs · 308 calls
6.21 μs
9.13 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.07 μs · 840 calls
1.05 μs · 356 calls
6.51 μs
9.52 μs
20261122T000034Z-565231f
On · no reduction
866 ns · 452 calls
1.07 μs · 308 calls
6.21 μs
9.13 μs
20261122T000034Z-565231f
Off
1.07 μs · 840 calls
1.05 μs · 356 calls
6.51 μs
9.52 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.03 μs · 242 calls
6.01 μs
9.73 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.05 μs · 218 calls
6.75 μs
9.13 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.03 μs · 242 calls
6.01 μs
9.73 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.05 μs · 218 calls
6.75 μs
9.13 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.17 μs · value and gradient 8.89 μs
PosteriorDB model losscurve_sislob · dataset loss_curves · SHA-256 800b40c561a61f75411031e04398967ab094f443808b7b11403679dca7c96757
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.32 μs
5.4 μs
FlatPPL · normal optimizations
5.92 μs · 4.5× Wren
12 μs · 2.22× Wren
FlatPPL · equal work
5.27 μs · 4.0× Wren
8.52 μs · 1.58× Wren
Wren definition in this run
@wren function losscurve_sislob(loss, cohort_id, t_idx, t_value, premium,
growthmodel_id, n_cohort)
omega ~ WD.LogNormal(0.0, 0.5)
theta ~ WD.LogNormal(0.0, 0.5)
# Wren evaluates these before LR, whose conditional prior needs their values.
mu_LR ~ WD.Normal(0.0, 0.5)
sd_LR ~ WD.LogNormal(0.0, 0.5)
@iid LR ~ WD.LogNormal(mu_LR, sd_LR) size=n_cohort
loss_sd ~ WD.LogNormal(0.0, 0.7)
mu = Vector{typeof(omega + theta + LR[1] + loss_sd)}(undef, length(loss))
sigma = similar(mu)
for i in eachindex(loss)
t = t_value[t_idx[i]]
growth = if growthmodel_id == 1
1 - exp(-(t / theta)^omega)
else
t^omega / (t^omega + theta^omega)
end
cohort = cohort_id[i]
mu[i] = LR[cohort] * premium[cohort] * growth
sigma[i] = loss_sd * premium[cohort]
end
@batch for i in eachindex(loss)
@observe loss[i] ~ WD.Normal(mu[i], sigma[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.3 μs
5.48 μs
FlatPPL · normal optimizations
6.21 μs · 4.77× Wren
9.13 μs · 1.67× Wren
FlatPPL · equal work
6.51 μs · 5.0× Wren
9.52 μs · 1.74× Wren
Wren definition in this run
@wren function losscurve_sislob(loss, cohort_id, t_idx, t_value, premium,
growthmodel_id, n_cohort)
omega ~ WD.LogNormal(0.0, 0.5)
theta ~ WD.LogNormal(0.0, 0.5)
# Wren evaluates these before LR, whose conditional prior needs their values.
mu_LR ~ WD.Normal(0.0, 0.5)
sd_LR ~ WD.LogNormal(0.0, 0.5)
@iid LR ~ WD.LogNormal(mu_LR, sd_LR) size=n_cohort
loss_sd ~ WD.LogNormal(0.0, 0.7)
mu = Vector{typeof(omega + theta + LR[1] + loss_sd)}(undef, length(loss))
sigma = similar(mu)
for i in eachindex(loss)
t = t_value[t_idx[i]]
growth = if growthmodel_id == 1
1 - exp(-(t / theta)^omega)
else
t^omega / (t^omega + theta^omega)
end
cohort = cohort_id[i]
mu[i] = LR[cohort] * premium[cohort] * growth
sigma[i] = loss_sd * premium[cohort]
end
@batch for i in eachindex(loss)
@observe loss[i] ~ WD.Normal(mu[i], sigma[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.29 μs
5.4 μs
FlatPPL · normal optimizations
6.01 μs · 4.68× Wren
9.73 μs · 1.8× Wren
FlatPPL · equal work
6.75 μs · 5.25× Wren
9.13 μs · 1.69× Wren
Wren definition in this run
@wren function losscurve_sislob(loss, cohort_id, t_idx, t_value, premium,
growthmodel_id, n_cohort)
omega ~ WD.LogNormal(0.0, 0.5)
theta ~ WD.LogNormal(0.0, 0.5)
# Wren evaluates these before LR, whose conditional prior needs their values.
mu_LR ~ WD.Normal(0.0, 0.5)
sd_LR ~ WD.LogNormal(0.0, 0.5)
@iid LR ~ WD.LogNormal(mu_LR, sd_LR) size=n_cohort
loss_sd ~ WD.LogNormal(0.0, 0.7)
mu = Vector{typeof(omega + theta + LR[1] + loss_sd)}(undef, length(loss))
sigma = similar(mu)
for i in eachindex(loss)
t = t_value[t_idx[i]]
growth = if growthmodel_id == 1
1 - exp(-(t / theta)^omega)
else
t^omega / (t^omega + theta^omega)
end
cohort = cohort_id[i]
mu[i] = LR[cohort] * premium[cohort] * growth
sigma[i] = loss_sd * premium[cohort]
end
@batch for i in eachindex(loss)
@observe loss[i] ~ WD.Normal(mu[i], sigma[i])
end
return nothing
end
@model function low_dim_gauss_mix(y, N)
mu ~ ordered(product_distribution(Fill(Normal(0, 2), 2)))
sigma ~ product_distribution(Fill(truncated(Normal(0, 2); lower=0), 2))
theta ~ Beta(5, 5)
for n in 1:N
component1 = log(theta) + logpdf(Normal(mu[1], sigma[1]), y[n])
component2 = log1p(-theta) + logpdf(Normal(mu[2], sigma[2]), y[n])
DynamicPPL.@addlogprob! logaddexp(component1, component2)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
7.4 μs · 36 calls
7.69 μs · 76 calls
19.1 μs
16.9 μs
20261122T002521Z-565231f-registered-repeat-1
Off
9.16 μs · 92 calls
7.2 μs · 96 calls
14.6 μs
17 μs
20261122T002521Z-565231f
On · no reduction
7.4 μs · 36 calls
7.69 μs · 76 calls
19.1 μs
16.9 μs
20261122T002521Z-565231f
Off
9.16 μs · 92 calls
7.2 μs · 96 calls
14.6 μs
17 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
7.86 μs · 52 calls
8.3 μs · 84 calls
15.3 μs
16.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
6.79 μs · 96 calls
10.6 μs · 44 calls
15.5 μs
16.6 μs
20261122T000034Z-565231f
On · no reduction
7.86 μs · 52 calls
8.3 μs · 84 calls
15.3 μs
16.8 μs
20261122T000034Z-565231f
Off
6.79 μs · 96 calls
10.6 μs · 44 calls
15.5 μs
16.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
8.06 μs · 14 calls
15.2 μs
16.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
7.42 μs · 82 calls
14.2 μs
14.8 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
8.06 μs · 14 calls
15.2 μs
16.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
7.42 μs · 82 calls
14.2 μs
14.8 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 14.2 μs · value and gradient 15.1 μs
PosteriorDB model low_dim_gauss_mix · dataset low_dim_gauss_mix · SHA-256 9adb76f51fed5426f26090ce18c2bf732aef7695aadb57fa12e11efc5f0d9efb
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
24.7 μs
33.6 μs
FlatPPL · normal optimizations
19.1 μs · 0.773× Wren
16.9 μs · 0.503× Wren
FlatPPL · equal work
14.6 μs · 0.593× Wren
17 μs · 0.508× Wren
Wren definition in this run
@wren function low_dim_gauss_mix(y)
mu1 ~ WD.Normal(0.0, 2.0)
log_mu_gap ~ WD.Flat()
mu2 = mu1 + exp(log_mu_gap)
# Stan's ordered[2] mapping is (mu1, log(mu2-mu1)); include its Jacobian.
# Native ordered prior support is tracked in #207.
@addloglikelihood (logdensityof(WD.Normal(0.0, 2.0), mu2) + log_mu_gap)
@iid sigma ~ WD.HalfNormal(0.0, 2.0) size=2
theta ~ WD.Beta(5.0, 5.0)
@addloglikelihood low_dim_mixture_logp([mu1, mu2], sigma, theta, y)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
24.9 μs
33.6 μs
FlatPPL · normal optimizations
15.3 μs · 0.613× Wren
16.8 μs · 0.499× Wren
FlatPPL · equal work
15.5 μs · 0.622× Wren
16.6 μs · 0.494× Wren
Wren definition in this run
@wren function low_dim_gauss_mix(y)
mu1 ~ WD.Normal(0.0, 2.0)
log_mu_gap ~ WD.Flat()
mu2 = mu1 + exp(log_mu_gap)
# Stan's ordered[2] mapping is (mu1, log(mu2-mu1)); include its Jacobian.
# Native ordered prior support is tracked in #207.
@addloglikelihood (logdensityof(WD.Normal(0.0, 2.0), mu2) + log_mu_gap)
@iid sigma ~ WD.HalfNormal(0.0, 2.0) size=2
theta ~ WD.Beta(5.0, 5.0)
@addloglikelihood low_dim_mixture_logp([mu1, mu2], sigma, theta, y)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
24.9 μs
33.9 μs
FlatPPL · normal optimizations
15.2 μs · 0.612× Wren
16.5 μs · 0.487× Wren
FlatPPL · equal work
14.2 μs · 0.573× Wren
14.8 μs · 0.437× Wren
Wren definition in this run
@wren function low_dim_gauss_mix(y)
mu1 ~ WD.Normal(0.0, 2.0)
log_mu_gap ~ WD.Flat()
mu2 = mu1 + exp(log_mu_gap)
# Stan's ordered[2] mapping is (mu1, log(mu2-mu1)); include its Jacobian.
# Native ordered prior support is tracked in #207.
@addloglikelihood (logdensityof(WD.Normal(0.0, 2.0), mu2) + log_mu_gap)
@iid sigma ~ WD.HalfNormal(0.0, 2.0) size=2
theta ~ WD.Beta(5.0, 5.0)
@addloglikelihood low_dim_mixture_logp([mu1, mu2], sigma, theta, y)
return nothing
end
@model function pdb_low_dim_gauss_mix_collapse(N, y)
mu ~ product_distribution(Fill(Normal(0, 2), 2))
sigma ~ product_distribution(Fill(FlatPos(0), 2))
theta ~ Beta(5, 5)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, 2), size(sigma))), sigma
)
for n in 1:N
DynamicPPL.@addlogprob! logaddexp(
log(theta) + logpdf(Normal(mu[1], sigma[1]), y[n]),
log1p(-theta) + logpdf(Normal(mu[2], sigma[2]), y[n]),
)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
8.89 μs · 20 calls
12.7 μs · 48 calls
15 μs
20.1 μs
20261122T002521Z-565231f-registered-repeat-1
Off
8.34 μs · 92 calls
12.1 μs · 56 calls
13.9 μs
18.1 μs
20261122T002521Z-565231f
On · no reduction
8.89 μs · 20 calls
12.7 μs · 48 calls
15 μs
20.1 μs
20261122T002521Z-565231f
Off
8.34 μs · 92 calls
12.1 μs · 56 calls
13.9 μs
18.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
10.2 μs · 100 calls
13.2 μs · 16 calls
15 μs
22.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
10.2 μs · 88 calls
12.9 μs · 24 calls
16.8 μs
21.5 μs
20261122T000034Z-565231f
On · no reduction
10.2 μs · 100 calls
13.2 μs · 16 calls
15 μs
22.8 μs
20261122T000034Z-565231f
Off
10.2 μs · 88 calls
12.9 μs · 24 calls
16.8 μs
21.5 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
12.1 μs · 66 calls
14.3 μs
18.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
12.5 μs · 56 calls
14.9 μs
18.3 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
12.1 μs · 66 calls
14.3 μs
18.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
12.5 μs · 56 calls
14.9 μs
18.3 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 14.3 μs · value and gradient 17.2 μs
PosteriorDB model low_dim_gauss_mix_collapse · dataset low_dim_gauss_mix_collapse · SHA-256 f4768c88e6b0a4f7bc0cf9ca65bc38d89cc7c4288a33a0f00153761c90b27263
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
25.7 μs
33.2 μs
FlatPPL · normal optimizations
15 μs · 0.583× Wren
20.1 μs · 0.607× Wren
FlatPPL · equal work
13.9 μs · 0.542× Wren
18.1 μs · 0.545× Wren
Wren definition in this run
@wren function low_dim_gauss_mix_collapse(y)
@iid mu ~ WD.Normal(0.0, 2.0) size=2
@iid sigma ~ WD.HalfNormal(0.0, 2.0) size=2
theta ~ WD.Beta(5.0, 5.0)
@addloglikelihood low_dim_mixture_logp(mu, sigma, theta, y)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
25.4 μs
32.9 μs
FlatPPL · normal optimizations
15 μs · 0.59× Wren
22.8 μs · 0.694× Wren
FlatPPL · equal work
16.8 μs · 0.66× Wren
21.5 μs · 0.654× Wren
Wren definition in this run
@wren function low_dim_gauss_mix_collapse(y)
@iid mu ~ WD.Normal(0.0, 2.0) size=2
@iid sigma ~ WD.HalfNormal(0.0, 2.0) size=2
theta ~ WD.Beta(5.0, 5.0)
@addloglikelihood low_dim_mixture_logp(mu, sigma, theta, y)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
25.9 μs
33.6 μs
FlatPPL · normal optimizations
14.3 μs · 0.552× Wren
18.8 μs · 0.559× Wren
FlatPPL · equal work
14.9 μs · 0.573× Wren
18.3 μs · 0.546× Wren
Wren definition in this run
@wren function low_dim_gauss_mix_collapse(y)
@iid mu ~ WD.Normal(0.0, 2.0) size=2
@iid sigma ~ WD.HalfNormal(0.0, 2.0) size=2
theta ~ WD.Beta(5.0, 5.0)
@addloglikelihood low_dim_mixture_logp(mu, sigma, theta, y)
return nothing
end
@model function pdb_lsat_model(N, T, r)
alpha ~ product_distribution(Fill(Normal(0, 100.0), T))
theta ~ product_distribution(Fill(Normal(0, 1), N))
beta ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0.0, 100.0), beta)
for k in 1:T
logits = beta .* theta .- alpha[k]
DynamicPPL.@addlogprob! logpdf(
product_distribution(map(BernoulliLogit, logits)), r[k, :]
)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
97.2 μs · 8 calls
89.1 μs · 4 calls
45.4 μs
44.9 μs
20261122T002521Z-565231f-registered-repeat-1
Off
117 μs · 8 calls
148 μs · 4 calls
41.8 μs
47.6 μs
20261122T002521Z-565231f
On · no reduction
97.2 μs · 8 calls
89.1 μs · 4 calls
45.4 μs
44.9 μs
20261122T002521Z-565231f
Off
117 μs · 8 calls
148 μs · 4 calls
41.8 μs
47.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
133 μs · 4 calls
94.9 μs · 4 calls
44.4 μs
47.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
111 μs · 4 calls
97.5 μs · 4 calls
46.6 μs
50.4 μs
20261122T000034Z-565231f
On · no reduction
133 μs · 4 calls
94.9 μs · 4 calls
44.4 μs
47.8 μs
20261122T000034Z-565231f
Off
111 μs · 4 calls
97.5 μs · 4 calls
46.6 μs
50.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 47.7 μs · value and gradient 43 μs
PosteriorDB model lsat_model · dataset lsat_data · SHA-256 eb36bced252d0acfeb1ea195c2c3c932602c884e9af1dacfdc6fefacaabe1a03
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
27.6 μs
62.4 μs
FlatPPL · normal optimizations
45.4 μs · 1.64× Wren
44.9 μs · 0.719× Wren
FlatPPL · equal work
41.8 μs · 1.51× Wren
47.6 μs · 0.764× Wren
Wren definition in this run
@wren function lsat(r, T, N)
@iid alpha ~ WD.Normal(0.0, 100.0) size=T
@iid theta ~ WD.Normal(0.0, 1.0) size=N
# Stan's positive Normal factor differs by the constant log(2).
beta ~ WD.HalfNormal(0.0, 100.0)
logits = Vector{typeof(beta + theta[1] + alpha[1])}(undef, length(r))
for n in eachindex(r)
logits[n] = beta * theta[cld(n, T)] - alpha[mod1(n, T)]
end
@batch for n in eachindex(r)
@observe r[n] ~ WD.BernoulliLogit(logits[n])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
26.3 μs
63.7 μs
FlatPPL · normal optimizations
44.4 μs · 1.69× Wren
47.8 μs · 0.75× Wren
FlatPPL · equal work
46.6 μs · 1.77× Wren
50.4 μs · 0.792× Wren
Wren definition in this run
@wren function lsat(r, T, N)
@iid alpha ~ WD.Normal(0.0, 100.0) size=T
@iid theta ~ WD.Normal(0.0, 1.0) size=N
# Stan's positive Normal factor differs by the constant log(2).
beta ~ WD.HalfNormal(0.0, 100.0)
logits = Vector{typeof(beta + theta[1] + alpha[1])}(undef, length(r))
for n in eachindex(r)
logits[n] = beta * theta[cld(n, T)] - alpha[mod1(n, T)]
end
@batch for n in eachindex(r)
@observe r[n] ~ WD.BernoulliLogit(logits[n])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
26.6 μs
65.9 μs
FlatPPL · normal optimizations
evaluation failed
evaluation failed
FlatPPL · equal work
evaluation failed
evaluation failed
Wren definition in this run
@wren function lsat(r, T, N)
@iid alpha ~ WD.Normal(0.0, 100.0) size=T
@iid theta ~ WD.Normal(0.0, 1.0) size=N
# Stan's positive Normal factor differs by the constant log(2).
beta ~ WD.HalfNormal(0.0, 100.0)
logits = Vector{typeof(beta + theta[1] + alpha[1])}(undef, length(r))
for n in eachindex(r)
logits[n] = beta * theta[cld(n, T)] - alpha[mod1(n, T)]
end
@batch for n in eachindex(r)
@observe r[n] ~ WD.BernoulliLogit(logits[n])
end
return nothing
end
@model function capture_m0(s, T)
omega ~ Uniform(0, 1)
p ~ Uniform(0, 1)
for i in eachindex(s)
if s[i] > 0
@addlogprob! logpdf(Bernoulli(omega), 1) + logpdf(Binomial(T, p), s[i])
else
@addlogprob! logsumexp([logpdf(Bernoulli(omega), 1) + logpdf(Binomial(T, p), 0),
logpdf(Bernoulli(omega), 0)])
end
end
end
%%%
# Capture-recapture with unobserved animals
PosteriorDB's `M0_data-M0_model`. Each augmented animal belongs to the
population with probability omega. Present animals have a Binomial capture
total, while absent animals have zero captures. The mixture marginalizes
population membership separately for each animal.
%%%
flatppl_compat = "0.1"
M = 237
T = 3
data = load_data("data.json", cartprod(y = cartpow(nonnegintegers, [M, T])))
capture_totals = aggregate(sum, [.i], data.y[.i, .j])
omega ~ Uniform(unitinterval)
p ~ Uniform(unitinterval)
capture_total = normalize(superpose(
weighted(omega, Binomial(T, p)), weighted(1 - omega, Dirac(0))))
y ~ iid(capture_total, M)
Pi_prior = lawof(record(omega = omega, p = p))
K_model = kernelof(record(y = y), omega = omega, p = p)
L = likelihoodof(K_model, record(y = capture_totals))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(omega = unitinterval, p = unitinterval)
Pi_post_input = record(omega = 0.5, p = 0.5)
@model function pdb_M0_model(M, T, y, s)
@assert size(y) == (M, T)
@assert size(s) == (M,)
omega ~ Uniform(0, 1)
p ~ Uniform(0, 1)
for i in 1:M
if s[i] > 0
DynamicPPL.@addlogprob! logpdf(Bernoulli(omega), 1) +
logpdf(Binomial(T, p), s[i])
else
DynamicPPL.@addlogprob! logaddexp(
logpdf(Bernoulli(omega), 1) + logpdf(Binomial(T, p), 0),
logpdf(Bernoulli(omega), 0),
)
end
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
4.7 μs · 4 calls
2.72 μs · 32 calls
8.21 μs
9.78 μs
20261122T002521Z-565231f-registered-repeat-1
Off
2.94 μs · 32 calls
3.7 μs · 8 calls
7.81 μs
9.89 μs
20261122T002521Z-565231f
On · no reduction
4.7 μs · 4 calls
2.72 μs · 32 calls
8.21 μs
9.78 μs
20261122T002521Z-565231f
Off
2.94 μs · 32 calls
3.7 μs · 8 calls
7.81 μs
9.89 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
2.92 μs · 32 calls
2.43 μs · 244 calls
7.53 μs
9.37 μs
20261122T000034Z-565231f-registered-repeat-1
Off
2.82 μs · 232 calls
2.29 μs · 248 calls
7.47 μs
9.88 μs
20261122T000034Z-565231f
On · no reduction
2.92 μs · 32 calls
2.43 μs · 244 calls
7.53 μs
9.37 μs
20261122T000034Z-565231f
Off
2.82 μs · 232 calls
2.29 μs · 248 calls
7.47 μs
9.88 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.33 μs · 156 calls
7.75 μs
9.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.42 μs · 181 calls
8.03 μs
9.63 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.33 μs · 156 calls
7.75 μs
9.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.42 μs · 181 calls
8.03 μs
9.63 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 8.58 μs · value and gradient 9.86 μs
PosteriorDB model M0_model · dataset M0_data · SHA-256 4a6ce969573049c11bad3e5ea4970826431e3b21158fb423a4617f2237268ee6
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.34 μs
18 μs
FlatPPL · normal optimizations
8.21 μs · 0.879× Wren
9.78 μs · 0.543× Wren
FlatPPL · equal work
7.81 μs · 0.836× Wren
9.89 μs · 0.549× Wren
Wren definition in this run
@wren function capture_m0(s, T)
omega ~ WD.Uniform(0.0, 1.0)
p ~ WD.Uniform(0.0, 1.0)
@addloglikelihood capture_m0_logp(omega, p, s, T)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.28 μs
18.8 μs
FlatPPL · normal optimizations
7.53 μs · 0.811× Wren
9.37 μs · 0.499× Wren
FlatPPL · equal work
7.47 μs · 0.805× Wren
9.88 μs · 0.526× Wren
Wren definition in this run
@wren function capture_m0(s, T)
omega ~ WD.Uniform(0.0, 1.0)
p ~ WD.Uniform(0.0, 1.0)
@addloglikelihood capture_m0_logp(omega, p, s, T)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.22 μs
17.8 μs
FlatPPL · normal optimizations
7.75 μs · 0.841× Wren
9.5 μs · 0.535× Wren
FlatPPL · equal work
8.03 μs · 0.871× Wren
9.63 μs · 0.543× Wren
Wren definition in this run
@wren function capture_m0(s, T)
omega ~ WD.Uniform(0.0, 1.0)
p ~ WD.Uniform(0.0, 1.0)
@addloglikelihood capture_m0_logp(omega, p, s, T)
return nothing
end
@wren function capture_mb(y, seen)
omega ~ WD.Uniform(0.0, 1.0)
p ~ WD.Uniform(0.0, 1.0)
c ~ WD.Uniform(0.0, 1.0)
@addloglikelihood capture_mb_logp(omega, p, c, y, seen)
return nothing
end
const CAPTURE_MB_WHOLE_EVENT = @rkppl begin
omega ~ Uniform(0, 1)
p ~ Uniform(0, 1)
c ~ Uniform(0, 1)
@plate for i in eachindex(histories)
present = p .+ (c - p) .* previous[i]
histories[i] ~ LogDensity(bernoulli_product_mixture_logdensity,
hcat(present, absent), [omega, 1 - omega])
end
end
function capture_history(history_logp, omega, y)
lp = zero(omega)
for i in axes(y, 1)
if any(view(y, i, :))
lp += logpdf(Bernoulli(omega), 1) + history_logp(i)
else
lp += logsumexp([logpdf(Bernoulli(omega), 1) + history_logp(i), logpdf(Bernoulli(omega), 0)])
end
end
lp
end
@model function capture_mb(y, previous)
omega ~ Uniform(0, 1)
p ~ Uniform(0, 1)
c ~ Uniform(0, 1)
present = p .+ (c - p) .* previous
@addlogprob! capture_history(i -> sum(logpdf.(Bernoulli.(view(present, i, :)), view(y, i, :))), omega, y)
end
%%%
# Capture-recapture with a response to the previous capture
PosteriorDB's `Mb_data-Mb_model`. Present animals have capture probability c
after a capture on the immediately preceding occasion, and p otherwise.
The first occasion uses p. A mixture with an all-zero history marginalizes
population membership separately for each animal.
%%%
flatppl_compat = "0.1"
M = 318
T = 5
data = load_data("data.json", cartprod(y = cartpow(nonnegintegers, [M, T])))
history(i) = data.y[i, :]
histories = history.(indicesof(zeros(M)))
omega ~ Uniform(unitinterval)
p ~ Uniform(unitinterval)
c ~ Uniform(unitinterval)
capture_step(previous, q) = Bernoulli(ifelse(previous == 1, q.c, q.p))
capture_history = normalize(superpose(
weighted(omega, markovchain(capture_step, 0, T, (p = p, c = c))),
weighted(1 - omega, Dirac(fill(0, T)))))
y ~ iid(capture_history, M)
Pi_prior = lawof(record(omega = omega, p = p, c = c))
K_model = kernelof(record(y = y), omega = omega, p = p, c = c)
L = likelihoodof(K_model, record(y = histories))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(omega = unitinterval, p = unitinterval, c = unitinterval)
Pi_post_input = record(omega = 0.5, p = 0.5, c = 0.5)
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
11.5 μs · 76 calls
12.5 μs · 76 calls
17.6 μs
19.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
12.6 μs · 72 calls
9.77 μs · 32 calls
20.7 μs
19.7 μs
20261122T002521Z-565231f
On · no reduction
11.5 μs · 76 calls
12.5 μs · 76 calls
17.6 μs
19.5 μs
20261122T002521Z-565231f
Off
12.6 μs · 72 calls
9.77 μs · 32 calls
20.7 μs
19.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
10.5 μs · 68 calls
9.88 μs · 76 calls
17.2 μs
19.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
10.4 μs · 76 calls
9.85 μs · 88 calls
17.4 μs
18.4 μs
20261122T000034Z-565231f
On · no reduction
10.5 μs · 68 calls
9.88 μs · 76 calls
17.2 μs
19.6 μs
20261122T000034Z-565231f
Off
10.4 μs · 76 calls
9.85 μs · 88 calls
17.4 μs
18.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
10.4 μs · 72 calls
16.8 μs
18.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
9.51 μs · 70 calls
16.6 μs
18 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
10.4 μs · 72 calls
16.8 μs
18.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
9.51 μs · 70 calls
16.6 μs
18 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 16.4 μs · value and gradient 19.6 μs
PosteriorDB model Mb_model · dataset Mb_data · SHA-256 56ae0ae7e9e2893fdc942fe944c5557b1de59fb6bb2833848050358cba8d5b47
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.2 μs
13.9 μs
FlatPPL · normal optimizations
17.6 μs · 1.91× Wren
19.5 μs · 1.4× Wren
FlatPPL · equal work
20.7 μs · 2.25× Wren
19.7 μs · 1.42× Wren
Wren definition in this run
@wren function capture_mb(y, seen)
omega ~ WD.Uniform(0.0, 1.0)
p ~ WD.Uniform(0.0, 1.0)
c ~ WD.Uniform(0.0, 1.0)
@addloglikelihood capture_mb_logp(omega, p, c, y, seen)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.55 μs
13.1 μs
FlatPPL · normal optimizations
17.2 μs · 1.8× Wren
19.6 μs · 1.49× Wren
FlatPPL · equal work
17.4 μs · 1.83× Wren
18.4 μs · 1.4× Wren
Wren definition in this run
@wren function capture_mb(y, seen)
omega ~ WD.Uniform(0.0, 1.0)
p ~ WD.Uniform(0.0, 1.0)
c ~ WD.Uniform(0.0, 1.0)
@addloglikelihood capture_mb_logp(omega, p, c, y, seen)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
8.94 μs
13 μs
FlatPPL · normal optimizations
16.8 μs · 1.88× Wren
18.3 μs · 1.41× Wren
FlatPPL · equal work
16.6 μs · 1.86× Wren
18 μs · 1.39× Wren
Wren definition in this run
@wren function capture_mb(y, seen)
omega ~ WD.Uniform(0.0, 1.0)
p ~ WD.Uniform(0.0, 1.0)
c ~ WD.Uniform(0.0, 1.0)
@addloglikelihood capture_mb_logp(omega, p, c, y, seen)
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.36 μs · 328 calls
1.71 μs · 56 calls
7.68 μs
11.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.48 μs · 288 calls
1.72 μs · 412 calls
8.02 μs
10.7 μs
20261122T002521Z-565231f
On · no reduction
1.36 μs · 328 calls
1.71 μs · 56 calls
7.68 μs
11.6 μs
20261122T002521Z-565231f
Off
1.48 μs · 288 calls
1.72 μs · 412 calls
8.02 μs
10.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.67 μs · 32 calls
2.27 μs · 24 calls
6.98 μs
14.2 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.69 μs · 36 calls
1.65 μs · 364 calls
6.77 μs
15.1 μs
20261122T000034Z-565231f
On · no reduction
1.67 μs · 32 calls
2.27 μs · 24 calls
6.98 μs
14.2 μs
20261122T000034Z-565231f
Off
1.69 μs · 36 calls
1.65 μs · 364 calls
6.77 μs
15.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.05 μs · 20 calls
5.7 μs
10.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.58 μs · 235 calls
7.11 μs
11 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.05 μs · 20 calls
5.7 μs
10.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.58 μs · 235 calls
7.11 μs
11 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.23 μs · value and gradient 9.79 μs
PosteriorDB model accel_gp · dataset mcycle_gp · SHA-256 e0c31958c493d78c921cd3795901e0197f5e532d851ec1a8a2e413813d3c1046
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.84 μs
17.9 μs
FlatPPL · normal optimizations
7.68 μs · 4.17× Wren
11.6 μs · 0.647× Wren
FlatPPL · equal work
8.02 μs · 4.36× Wren
10.7 μs · 0.6× Wren
Wren definition in this run
@wren function accel_gp(Y, Xgp, slambda, Xgp_sigma, slambda_sigma, prior_only)
Intercept ~ WD.TDist(3.0, -13.0, 36.0)
sdgp ~ WD.HalfTDist(3.0, 0.0, 36.0)
lscale ~ WD.InverseGamma(1.124909, 0.0177)
@iid zgp ~ WD.Normal(0.0, 1.0) size=size(Xgp, 2)
Intercept_sigma ~ WD.TDist(3.0, 0.0, 10.0)
sdgp_sigma ~ WD.HalfTDist(3.0, 0.0, 36.0)
lscale_sigma ~ WD.InverseGamma(1.124909, 0.0177)
@iid zgp_sigma ~ WD.Normal(0.0, 1.0) size=size(Xgp_sigma, 2)
if prior_only == 0
mu = Intercept .+ approximate_gp(Xgp, slambda, sdgp, lscale, zgp)
sigma = exp.(Intercept_sigma .+ approximate_gp(Xgp_sigma, slambda_sigma,
sdgp_sigma, lscale_sigma, zgp_sigma))
@batch for i in eachindex(Y)
@observe Y[i] ~ WD.Normal(mu[i], sigma[i])
end
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
2.46 μs
25.4 μs
FlatPPL · normal optimizations
6.98 μs · 2.84× Wren
14.2 μs · 0.561× Wren
FlatPPL · equal work
6.77 μs · 2.75× Wren
15.1 μs · 0.595× Wren
Wren definition in this run
@wren function accel_gp(Y, Xgp, slambda, Xgp_sigma, slambda_sigma, prior_only)
Intercept ~ WD.TDist(3.0, -13.0, 36.0)
sdgp ~ WD.HalfTDist(3.0, 0.0, 36.0)
lscale ~ WD.InverseGamma(1.124909, 0.0177)
@iid zgp ~ WD.Normal(0.0, 1.0) size=size(Xgp, 2)
Intercept_sigma ~ WD.TDist(3.0, 0.0, 10.0)
sdgp_sigma ~ WD.HalfTDist(3.0, 0.0, 36.0)
lscale_sigma ~ WD.InverseGamma(1.124909, 0.0177)
@iid zgp_sigma ~ WD.Normal(0.0, 1.0) size=size(Xgp_sigma, 2)
if prior_only == 0
mu = Intercept .+ approximate_gp(Xgp, slambda, sdgp, lscale, zgp)
sigma = exp.(Intercept_sigma .+ approximate_gp(Xgp_sigma, slambda_sigma,
sdgp_sigma, lscale_sigma, zgp_sigma))
@batch for i in eachindex(Y)
@observe Y[i] ~ WD.Normal(mu[i], sigma[i])
end
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
2.01 μs
19.8 μs
FlatPPL · normal optimizations
5.7 μs · 2.83× Wren
10.8 μs · 0.546× Wren
FlatPPL · equal work
7.11 μs · 3.53× Wren
11 μs · 0.554× Wren
Wren definition in this run
@wren function accel_gp(Y, Xgp, slambda, Xgp_sigma, slambda_sigma, prior_only)
Intercept ~ WD.TDist(3.0, -13.0, 36.0)
sdgp ~ WD.HalfTDist(3.0, 0.0, 36.0)
lscale ~ WD.InverseGamma(1.124909, 0.0177)
@iid zgp ~ WD.Normal(0.0, 1.0) size=size(Xgp, 2)
Intercept_sigma ~ WD.TDist(3.0, 0.0, 10.0)
sdgp_sigma ~ WD.HalfTDist(3.0, 0.0, 36.0)
lscale_sigma ~ WD.InverseGamma(1.124909, 0.0177)
@iid zgp_sigma ~ WD.Normal(0.0, 1.0) size=size(Xgp_sigma, 2)
if prior_only == 0
mu = Intercept .+ approximate_gp(Xgp, slambda, sdgp, lscale, zgp)
sigma = exp.(Intercept_sigma .+ approximate_gp(Xgp_sigma, slambda_sigma,
sdgp_sigma, lscale_sigma, zgp_sigma))
@batch for i in eachindex(Y)
@observe Y[i] ~ WD.Normal(mu[i], sigma[i])
end
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.58 μs · 84 calls
2.58 μs · 300 calls
7.81 μs
11.3 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.61 μs · 352 calls
2.37 μs · 308 calls
10.1 μs
14.3 μs
20261122T002521Z-565231f
On · no reduction
1.58 μs · 84 calls
2.58 μs · 300 calls
7.81 μs
11.3 μs
20261122T002521Z-565231f
Off
1.61 μs · 352 calls
2.37 μs · 308 calls
10.1 μs
14.3 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.57 μs · 324 calls
2.68 μs · 36 calls
7.69 μs
14.7 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.61 μs · 356 calls
2.26 μs · 68 calls
6.84 μs
14.1 μs
20261122T000034Z-565231f
On · no reduction
1.57 μs · 324 calls
2.68 μs · 36 calls
7.69 μs
14.7 μs
20261122T000034Z-565231f
Off
1.61 μs · 356 calls
2.26 μs · 68 calls
6.84 μs
14.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.11 μs · 149 calls
6.56 μs
10.1 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.03 μs · 226 calls
6.03 μs
11.1 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.11 μs · 149 calls
6.56 μs
10.1 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.03 μs · 226 calls
6.03 μs
11.1 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.42 μs · value and gradient 10.4 μs
PosteriorDB model accel_splines · dataset mcycle_splines · SHA-256 ef8260893b04ac52d43c71fb2819b5e187c7112f9ccc2ccb3640c375516818e9
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function mesquite_logmesquite(log_weight, X)
beta ~ product_distribution(Fill(Flat(), 7))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(log_weight))),
log_weight .- X * beta,
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
103 ns · 724 calls
85.1 ns · 2140 calls
3.73 μs
6.71 μs
20261122T002521Z-565231f-registered-repeat-1
Off
102 ns · 3584 calls
91.8 ns · 1360 calls
3.92 μs
6.47 μs
20261122T002521Z-565231f
On · no reduction
103 ns · 724 calls
85.1 ns · 2140 calls
3.73 μs
6.71 μs
20261122T002521Z-565231f
Off
102 ns · 3584 calls
91.8 ns · 1360 calls
3.92 μs
6.47 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
108 ns · 824 calls
90.4 ns · 2028 calls
3.96 μs
6.96 μs
20261122T000034Z-565231f-registered-repeat-1
Off
107 ns · 1984 calls
166 ns · 120 calls
3.97 μs
6.69 μs
20261122T000034Z-565231f
On · no reduction
108 ns · 824 calls
90.4 ns · 2028 calls
3.96 μs
6.96 μs
20261122T000034Z-565231f
Off
107 ns · 1984 calls
166 ns · 120 calls
3.97 μs
6.69 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
101 ns · 429 calls
3.65 μs
4.52 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
94.3 ns · 633 calls
3.86 μs
4.56 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
101 ns · 429 calls
3.65 μs
4.52 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
94.3 ns · 633 calls
3.86 μs
4.56 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.78 μs · value and gradient 6.41 μs
PosteriorDB model logmesquite · dataset mesquite · SHA-256 32002e710ee5228e3d7d96109932de86f4e6490cdf0840f472f648b17ff3fb92
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
107 ns
187 ns
FlatPPL · normal optimizations
3.73 μs · 34.8× Wren
6.71 μs · 35.9× Wren
FlatPPL · equal work
3.92 μs · 36.6× Wren
6.47 μs · 34.6× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
110 ns
310 ns
FlatPPL · normal optimizations
3.96 μs · 36.1× Wren
6.96 μs · 22.4× Wren
FlatPPL · equal work
3.97 μs · 36.2× Wren
6.69 μs · 21.6× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
109 ns
313 ns
FlatPPL · normal optimizations
3.65 μs · 33.6× Wren
4.52 μs · 14.4× Wren
FlatPPL · equal work
3.86 μs · 35.5× Wren
4.56 μs · 14.6× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function mesquite_logmesquite_logva(log_weight, X)
beta ~ product_distribution(Fill(Flat(), 4))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(log_weight))),
log_weight .- X * beta,
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
65.7 ns · 740 calls
312 ns · 32 calls
3.74 μs
6.66 μs
20261122T002521Z-565231f-registered-repeat-1
Off
63.4 ns · 2320 calls
105 ns · 396 calls
3.73 μs
6.16 μs
20261122T002521Z-565231f
On · no reduction
65.7 ns · 740 calls
312 ns · 32 calls
3.74 μs
6.66 μs
20261122T002521Z-565231f
Off
63.4 ns · 2320 calls
105 ns · 396 calls
3.73 μs
6.16 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
61 ns · 1200 calls
66.1 ns · 3508 calls
3.73 μs
6.89 μs
20261122T000034Z-565231f-registered-repeat-1
Off
60.9 ns · 2696 calls
70.1 ns · 2476 calls
3.72 μs
6.34 μs
20261122T000034Z-565231f
On · no reduction
61 ns · 1200 calls
66.1 ns · 3508 calls
3.73 μs
6.89 μs
20261122T000034Z-565231f
Off
60.9 ns · 2696 calls
70.1 ns · 2476 calls
3.72 μs
6.34 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
81.5 ns · 461 calls
3.86 μs
5.37 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
73.5 ns · 919 calls
3.81 μs
4.63 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
81.5 ns · 461 calls
3.86 μs
5.37 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
73.5 ns · 919 calls
3.81 μs
4.63 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.81 μs · value and gradient 8.12 μs
PosteriorDB model logmesquite_logva · dataset mesquite · SHA-256 32002e710ee5228e3d7d96109932de86f4e6490cdf0840f472f648b17ff3fb92
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
97.5 ns
241 ns
FlatPPL · normal optimizations
3.74 μs · 38.4× Wren
6.66 μs · 27.6× Wren
FlatPPL · equal work
3.73 μs · 38.3× Wren
6.16 μs · 25.6× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
116 ns
262 ns
FlatPPL · normal optimizations
3.73 μs · 32.2× Wren
6.89 μs · 26.3× Wren
FlatPPL · equal work
3.72 μs · 32.1× Wren
6.34 μs · 24.2× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
72.5 ns
207 ns
FlatPPL · normal optimizations
3.86 μs · 53.3× Wren
5.37 μs · 26.0× Wren
FlatPPL · equal work
3.81 μs · 52.6× Wren
4.63 μs · 22.4× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function mesquite_logmesquite_logvas(log_weight, X)
beta ~ product_distribution(Fill(Flat(), 7))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(log_weight))),
log_weight .- X * beta,
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
230 ns · 64 calls
84.1 ns · 2408 calls
3.55 μs
5.46 μs
20261122T002521Z-565231f-registered-repeat-1
Off
101 ns · 1620 calls
82.9 ns · 2264 calls
3.7 μs
6.61 μs
20261122T002521Z-565231f
On · no reduction
230 ns · 64 calls
84.1 ns · 2408 calls
3.55 μs
5.46 μs
20261122T002521Z-565231f
Off
101 ns · 1620 calls
82.9 ns · 2264 calls
3.7 μs
6.61 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
140 ns · 184 calls
95.2 ns · 576 calls
3.82 μs
6.75 μs
20261122T000034Z-565231f-registered-repeat-1
Off
105 ns · 1888 calls
88.9 ns · 1468 calls
3.98 μs
7.06 μs
20261122T000034Z-565231f
On · no reduction
140 ns · 184 calls
95.2 ns · 576 calls
3.82 μs
6.75 μs
20261122T000034Z-565231f
Off
105 ns · 1888 calls
88.9 ns · 1468 calls
3.98 μs
7.06 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
129 ns · 180 calls
3.9 μs
4.48 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
103 ns · 536 calls
3.69 μs
4.3 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
129 ns · 180 calls
3.9 μs
4.48 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
103 ns · 536 calls
3.69 μs
4.3 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.79 μs · value and gradient 7.87 μs
PosteriorDB model logmesquite_logvas · dataset mesquite · SHA-256 32002e710ee5228e3d7d96109932de86f4e6490cdf0840f472f648b17ff3fb92
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
80.3 ns
164 ns
FlatPPL · normal optimizations
3.55 μs · 44.2× Wren
5.46 μs · 33.2× Wren
FlatPPL · equal work
3.7 μs · 46.1× Wren
6.61 μs · 40.2× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
88.7 ns
262 ns
FlatPPL · normal optimizations
3.82 μs · 43.1× Wren
6.75 μs · 25.8× Wren
FlatPPL · equal work
3.98 μs · 44.9× Wren
7.06 μs · 27.0× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
199 ns
250 ns
FlatPPL · normal optimizations
3.9 μs · 19.6× Wren
4.48 μs · 18.0× Wren
FlatPPL · equal work
3.69 μs · 18.5× Wren
4.3 μs · 17.2× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function mesquite_logmesquite_logvash(log_weight, X)
beta ~ product_distribution(Fill(Flat(), 6))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(log_weight))),
log_weight .- X * beta,
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
101 ns · 2824 calls
84.5 ns · 2756 calls
3.86 μs
7.48 μs
20261122T002521Z-565231f-registered-repeat-1
Off
81.9 ns · 3104 calls
368 ns · 28 calls
3.93 μs
4.88 μs
20261122T002521Z-565231f
On · no reduction
101 ns · 2824 calls
84.5 ns · 2756 calls
3.86 μs
7.48 μs
20261122T002521Z-565231f
Off
81.9 ns · 3104 calls
368 ns · 28 calls
3.93 μs
4.88 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
82.5 ns · 2184 calls
86 ns · 896 calls
3.93 μs
7.14 μs
20261122T000034Z-565231f-registered-repeat-1
Off
88.3 ns · 2512 calls
85.3 ns · 1548 calls
3.89 μs
6.85 μs
20261122T000034Z-565231f
On · no reduction
82.5 ns · 2184 calls
86 ns · 896 calls
3.93 μs
7.14 μs
20261122T000034Z-565231f
Off
88.3 ns · 2512 calls
85.3 ns · 1548 calls
3.89 μs
6.85 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
85.7 ns · 889 calls
3.85 μs
4.45 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
98.8 ns · 290 calls
3.68 μs
4.38 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
85.7 ns · 889 calls
3.85 μs
4.45 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
98.8 ns · 290 calls
3.68 μs
4.38 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.96 μs · value and gradient 4.95 μs
PosteriorDB model logmesquite_logvash · dataset mesquite · SHA-256 32002e710ee5228e3d7d96109932de86f4e6490cdf0840f472f648b17ff3fb92
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
81.3 ns
148 ns
FlatPPL · normal optimizations
3.86 μs · 47.5× Wren
7.48 μs · 50.6× Wren
FlatPPL · equal work
3.93 μs · 48.4× Wren
4.88 μs · 33.0× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
75 ns
214 ns
FlatPPL · normal optimizations
3.93 μs · 52.4× Wren
7.14 μs · 33.4× Wren
FlatPPL · equal work
3.89 μs · 51.9× Wren
6.85 μs · 32.0× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
104 ns
153 ns
FlatPPL · normal optimizations
3.85 μs · 37.1× Wren
4.45 μs · 29.1× Wren
FlatPPL · equal work
3.68 μs · 35.4× Wren
4.38 μs · 28.7× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function mesquite_logmesquite_logvolume(log_weight, X)
beta ~ product_distribution(Fill(Flat(), 2))
sigma ~ FlatPos(0.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(log_weight))),
log_weight .- X * beta,
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
48.6 ns · 3812 calls
58.9 ns · 4256 calls
3.92 μs
5.37 μs
20261122T002521Z-565231f-registered-repeat-1
Off
47.4 ns · 2952 calls
66.6 ns · 448 calls
3.63 μs
5.59 μs
20261122T002521Z-565231f
On · no reduction
48.6 ns · 3812 calls
58.9 ns · 4256 calls
3.92 μs
5.37 μs
20261122T002521Z-565231f
Off
47.4 ns · 2952 calls
66.6 ns · 448 calls
3.63 μs
5.59 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
49.4 ns · 3808 calls
56.1 ns · 5532 calls
3.92 μs
5.64 μs
20261122T000034Z-565231f-registered-repeat-1
Off
49.3 ns · 4144 calls
56.2 ns · 6992 calls
3.91 μs
5.42 μs
20261122T000034Z-565231f
On · no reduction
49.4 ns · 3808 calls
56.1 ns · 5532 calls
3.92 μs
5.64 μs
20261122T000034Z-565231f
Off
49.3 ns · 4144 calls
56.2 ns · 6992 calls
3.91 μs
5.42 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
61.1 ns · 733 calls
3.68 μs
5.27 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
66.3 ns · 548 calls
3.59 μs
5.18 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
61.1 ns · 733 calls
3.68 μs
5.27 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
66.3 ns · 548 calls
3.59 μs
5.18 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.81 μs · value and gradient 5.52 μs
PosteriorDB model logmesquite_logvolume · dataset mesquite · SHA-256 32002e710ee5228e3d7d96109932de86f4e6490cdf0840f472f648b17ff3fb92
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
94.8 ns
184 ns
FlatPPL · normal optimizations
3.92 μs · 41.3× Wren
5.37 μs · 29.2× Wren
FlatPPL · equal work
3.63 μs · 38.3× Wren
5.59 μs · 30.4× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
64.5 ns
196 ns
FlatPPL · normal optimizations
3.92 μs · 60.8× Wren
5.64 μs · 28.8× Wren
FlatPPL · equal work
3.91 μs · 60.6× Wren
5.42 μs · 27.7× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
98.8 ns
185 ns
FlatPPL · normal optimizations
3.68 μs · 37.3× Wren
5.27 μs · 28.5× Wren
FlatPPL · equal work
3.59 μs · 36.3× Wren
5.18 μs · 28.0× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function mesquite_mesquite(
weight, diam1, diam2, canopy_height, total_height, density, group
)
beta ~ product_distribution(Fill(Flat(), 7))
sigma ~ FlatPos(0.0)
mu =
beta[1] .+ beta[2] .* diam1 .+ beta[3] .* diam2 .+ beta[4] .* canopy_height .+
beta[5] .* total_height .+ beta[6] .* density .+ beta[7] .* group
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(weight))), weight .- mu
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
108 ns · 1280 calls
83.4 ns · 1860 calls
3.92 μs
6.54 μs
20261122T002521Z-565231f-registered-repeat-1
Off
145 ns · 140 calls
89.2 ns · 1228 calls
3.76 μs
6.33 μs
20261122T002521Z-565231f
On · no reduction
108 ns · 1280 calls
83.4 ns · 1860 calls
3.92 μs
6.54 μs
20261122T002521Z-565231f
Off
145 ns · 140 calls
89.2 ns · 1228 calls
3.76 μs
6.33 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
108 ns · 1332 calls
96.9 ns · 1832 calls
5.35 μs
7.14 μs
20261122T000034Z-565231f-registered-repeat-1
Off
107 ns · 1788 calls
87.7 ns · 1144 calls
3.81 μs
7.67 μs
20261122T000034Z-565231f
On · no reduction
108 ns · 1332 calls
96.9 ns · 1832 calls
5.35 μs
7.14 μs
20261122T000034Z-565231f
Off
107 ns · 1788 calls
87.7 ns · 1144 calls
3.81 μs
7.67 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
94.6 ns · 479 calls
3.9 μs
4.84 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
107 ns · 342 calls
3.81 μs
4.49 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
94.6 ns · 479 calls
3.9 μs
4.84 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
107 ns · 342 calls
3.81 μs
4.49 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.95 μs · value and gradient 9.35 μs
PosteriorDB model mesquite · dataset mesquite · SHA-256 32002e710ee5228e3d7d96109932de86f4e6490cdf0840f472f648b17ff3fb92
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
83.2 ns
158 ns
FlatPPL · normal optimizations
3.92 μs · 47.1× Wren
6.54 μs · 41.5× Wren
FlatPPL · equal work
3.76 μs · 45.2× Wren
6.33 μs · 40.2× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
132 ns
238 ns
FlatPPL · normal optimizations
5.35 μs · 40.7× Wren
7.14 μs · 30.0× Wren
FlatPPL · equal work
3.81 μs · 29.0× Wren
7.67 μs · 32.3× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
116 ns
221 ns
FlatPPL · normal optimizations
3.9 μs · 33.5× Wren
4.84 μs · 21.9× Wren
FlatPPL · equal work
3.81 μs · 32.7× Wren
4.49 μs · 20.3× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function pdb_Mh_model(M, T, y)
@assert size(y) == (M,)
omega ~ Uniform(0, 1)
mean_p ~ Uniform(0, 1)
sigma ~ Uniform(0, 5)
eps_raw ~ product_distribution(Fill(Normal(0, 1), M))
eps = logit(mean_p) .+ sigma .* eps_raw
for i in 1:M
if y[i] > 0
DynamicPPL.@addlogprob! logpdf(Bernoulli(omega), 1) +
logpdf(BinomialLogit(T, eps[i]), y[i])
else
DynamicPPL.@addlogprob! logaddexp(
logpdf(Bernoulli(omega), 1) + logpdf(BinomialLogit(T, eps[i]), 0),
logpdf(Bernoulli(omega), 0),
)
end
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
10.8 μs · 68 calls
10.1 μs · 92 calls
20.1 μs
16.4 μs
20261122T002521Z-565231f-registered-repeat-1
Off
11 μs · 24 calls
7.94 μs · 20 calls
17.2 μs
16.3 μs
20261122T002521Z-565231f
On · no reduction
10.8 μs · 68 calls
10.1 μs · 92 calls
20.1 μs
16.4 μs
20261122T002521Z-565231f
Off
11 μs · 24 calls
7.94 μs · 20 calls
17.2 μs
16.3 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
11.6 μs · 4 calls
7.05 μs · 72 calls
16.7 μs
16.2 μs
20261122T000034Z-565231f-registered-repeat-1
Off
11.5 μs · 48 calls
7.58 μs · 80 calls
16.8 μs
16.8 μs
20261122T000034Z-565231f
On · no reduction
11.6 μs · 4 calls
7.05 μs · 72 calls
16.7 μs
16.2 μs
20261122T000034Z-565231f
Off
11.5 μs · 48 calls
7.58 μs · 80 calls
16.8 μs
16.8 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
8.7 μs · 79 calls
13.7 μs
13.4 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
6.89 μs · 74 calls
14 μs
13 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
8.7 μs · 79 calls
13.7 μs
13.4 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
6.89 μs · 74 calls
14 μs
13 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 15.8 μs · value and gradient 16.1 μs
PosteriorDB model Mh_model · dataset Mh_data · SHA-256 a75163d6278df2e8e63fc6da1556eea2c8bbe2439ab1532be18548aa77ab0c99
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.24 μs
16.6 μs
FlatPPL · normal optimizations
20.1 μs · 2.18× Wren
16.4 μs · 0.987× Wren
FlatPPL · equal work
17.2 μs · 1.86× Wren
16.3 μs · 0.985× Wren
Wren definition in this run
@wren function mh_model(captures, detected, undetected, trials, M)
omega ~ WD.Uniform(0.0, 1.0)
mean_p ~ WD.Uniform(0.0, 1.0)
sigma ~ WD.Uniform(0.0, 5.0)
@iid eps_raw ~ WD.Normal(0.0, 1.0) size=M
logit_p = logit(mean_p) .+ sigma .* eps_raw
logit_p_detected = logit_p[detected]
@batch for i in eachindex(captures)
@observe captures[i] ~ WD.BinomialLogit(trials, logit_p_detected[i])
end
@addloglikelihood length(detected) * log(omega) + sum(
logaddexp.(log(omega) .- trials .* log1pexp.(logit_p[undetected]), log1p(-omega)),
)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.8 μs
15.7 μs
FlatPPL · normal optimizations
16.7 μs · 1.7× Wren
16.2 μs · 1.03× Wren
FlatPPL · equal work
16.8 μs · 1.71× Wren
16.8 μs · 1.07× Wren
Wren definition in this run
@wren function mh_model(captures, detected, undetected, trials, M)
omega ~ WD.Uniform(0.0, 1.0)
mean_p ~ WD.Uniform(0.0, 1.0)
sigma ~ WD.Uniform(0.0, 5.0)
@iid eps_raw ~ WD.Normal(0.0, 1.0) size=M
logit_p = logit(mean_p) .+ sigma .* eps_raw
logit_p_detected = logit_p[detected]
@batch for i in eachindex(captures)
@observe captures[i] ~ WD.BinomialLogit(trials, logit_p_detected[i])
end
@addloglikelihood length(detected) * log(omega) + sum(
logaddexp.(log(omega) .- trials .* log1pexp.(logit_p[undetected]), log1p(-omega)),
)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.21 μs
16.5 μs
FlatPPL · normal optimizations
13.7 μs · 1.49× Wren
13.4 μs · 0.812× Wren
FlatPPL · equal work
14 μs · 1.52× Wren
13 μs · 0.786× Wren
Wren definition in this run
@wren function mh_model(captures, detected, undetected, trials, M)
omega ~ WD.Uniform(0.0, 1.0)
mean_p ~ WD.Uniform(0.0, 1.0)
sigma ~ WD.Uniform(0.0, 5.0)
@iid eps_raw ~ WD.Normal(0.0, 1.0) size=M
logit_p = logit(mean_p) .+ sigma .* eps_raw
logit_p_detected = logit_p[detected]
@batch for i in eachindex(captures)
@observe captures[i] ~ WD.BinomialLogit(trials, logit_p_detected[i])
end
@addloglikelihood length(detected) * log(omega) + sum(
logaddexp.(log(omega) .- trials .* log1pexp.(logit_p[undetected]), log1p(-omega)),
)
return nothing
end
@model function pdb_nn_rbm1bJ10(N, M, x, K, y)
x = x.value
J = 10
nu_alpha = 0.5
s2_0_alpha = (0.05 / M^(1 / nu_alpha))^2
nu_beta = 0.5
s2_0_beta = (0.05 / J^(1 / nu_beta))^2
sigma2_alpha ~ InverseGamma(nu_alpha / 2, (nu_alpha * s2_0_alpha) / 2)
sigma2_beta ~ InverseGamma(nu_beta / 2, (nu_beta * s2_0_beta) / 2)
alpha ~ product_distribution(Fill(Normal(0, sqrt(sigma2_alpha)), M * J))
beta ~ product_distribution(Fill(Normal(0, sqrt(sigma2_beta)), J * (K - 1)))
alpha1 ~ product_distribution(Fill(Normal(0, 1), J))
beta1 ~ product_distribution(Fill(Normal(0, 1), K - 1))
hidden = tanh.(x * reshape(alpha, M, J) .+ alpha1')
logits = hidden * reshape(beta, J, K - 1) .+ beta1'
return y ~ product_distribution(
map(axes(logits, 1)) do i
Categorical(softmax(vcat(1.0, collect(view(logits, i, :)))))
end,
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
313 μs · 4 calls
107 μs · 4 calls
320 μs
112 μs
20261122T002521Z-565231f-registered-repeat-1
Off
359 μs · 4 calls
102 μs · 4 calls
310 μs
120 μs
20261122T002521Z-565231f
On · no reduction
313 μs · 4 calls
107 μs · 4 calls
320 μs
112 μs
20261122T002521Z-565231f
Off
359 μs · 4 calls
102 μs · 4 calls
310 μs
120 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
333 μs · 4 calls
114 μs · 4 calls
333 μs
127 μs
20261122T000034Z-565231f-registered-repeat-1
Off
339 μs · 4 calls
115 μs · 8 calls
325 μs
119 μs
20261122T000034Z-565231f
On · no reduction
333 μs · 4 calls
114 μs · 4 calls
333 μs
127 μs
20261122T000034Z-565231f
Off
339 μs · 4 calls
115 μs · 8 calls
325 μs
119 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
108 μs · 4 calls
314 μs
118 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
107 μs · 7 calls
320 μs
117 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
108 μs · 4 calls
314 μs
118 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
107 μs · 7 calls
320 μs
117 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 305 μs · value and gradient 109 μs
PosteriorDB model nn_rbm1bJ10 · dataset mnist_100 · SHA-256 74f4b1d65197593acbb903ec0c13583f5262d4bd3d894df5950e01c253906661
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
const CAPTURE_MT_WHOLE_EVENT = @rkppl begin
omega ~ Uniform(0, 1)
p[1:T] .~ Uniform.(0, 1)
@plate for i in eachindex(histories)
histories[i] ~ LogDensity(bernoulli_product_mixture_logdensity,
hcat(p, absent), [omega, 1 - omega])
end
end
function capture_history(history_logp, omega, y)
lp = zero(omega)
for i in axes(y, 1)
if any(view(y, i, :))
lp += logpdf(Bernoulli(omega), 1) + history_logp(i)
else
lp += logsumexp([logpdf(Bernoulli(omega), 1) + history_logp(i), logpdf(Bernoulli(omega), 0)])
end
end
lp
end
@model function capture_mt(y)
omega ~ Uniform(0, 1)
p ~ filldist(Uniform(0, 1), size(y, 2))
@addlogprob! capture_history(i -> sum(logpdf.(Bernoulli.(p), view(y, i, :))), omega, y)
end
%%%
# Capture-recapture with occasion effects
PosteriorDB's `Mt_data-Mt_model`. Each augmented animal belongs to the
population with probability omega. Present animals are captured on occasion
t with probability p[t]; absent animals are never captured. The mixture
marginalizes membership for each capture history.
%%%
flatppl_compat = "0.1"
M = 237
T = 3
data = load_data("data.json", cartprod(y = cartpow(nonnegintegers, [M, T])))
history(i) = data.y[i, :]
histories = history.(indicesof(zeros(M)))
omega ~ Uniform(unitinterval)
p ~ iid(Uniform(unitinterval), T)
capture_history = normalize(superpose(
weighted(omega, Bernoulli.(p)), weighted(1 - omega, Dirac(fill(false, T)))))
y ~ iid(capture_history, M)
Pi_prior = lawof(record(omega = omega, p = p))
K_model = kernelof(record(y = y), omega = omega, p = p)
L = likelihoodof(K_model, record(y = histories))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(omega = interval(0.0, 1.0), p = cartpow(interval(0.0, 1.0), 3))
Pi_post_input = record(omega = 0.401, p = [0.129, 0.6, 0.602])
@model function pdb_Mt_model(M, T, y, s)
@assert size(y) == (M, T)
@assert size(s) == (M,)
omega ~ Uniform(0, 1)
p ~ product_distribution(Fill(Uniform(0, 1), T))
for i in 1:M
if s[i] > 0
DynamicPPL.@addlogprob! logpdf(Bernoulli(omega), 1) +
logpdf(product_distribution(map(Bernoulli, p)), y[i, :])
else
DynamicPPL.@addlogprob! logaddexp(
logpdf(Bernoulli(omega), 1) +
logpdf(product_distribution(map(Bernoulli, p)), y[i, :]),
logpdf(Bernoulli(omega), 0),
)
end
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
5.24 μs · 152 calls
3.81 μs · 180 calls
10.6 μs
13.3 μs
20261122T002521Z-565231f-registered-repeat-1
Off
4.06 μs · 180 calls
3.57 μs · 192 calls
10.9 μs
12.6 μs
20261122T002521Z-565231f
On · no reduction
5.24 μs · 152 calls
3.81 μs · 180 calls
10.6 μs
13.3 μs
20261122T002521Z-565231f
Off
4.06 μs · 180 calls
3.57 μs · 192 calls
10.9 μs
12.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
3.91 μs · 108 calls
4.8 μs · 168 calls
10.7 μs
11.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
3.84 μs · 88 calls
3.47 μs · 120 calls
10.1 μs
11.8 μs
20261122T000034Z-565231f
On · no reduction
3.91 μs · 108 calls
4.8 μs · 168 calls
10.7 μs
11.9 μs
20261122T000034Z-565231f
Off
3.84 μs · 88 calls
3.47 μs · 120 calls
10.1 μs
11.8 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
4.74 μs · 142 calls
9.49 μs
12.4 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
3.42 μs · 113 calls
9.62 μs
14.2 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
4.74 μs · 142 calls
9.49 μs
12.4 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
3.42 μs · 113 calls
9.62 μs
14.2 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 10.3 μs · value and gradient 12.4 μs
PosteriorDB model Mt_model · dataset Mt_data · SHA-256 cd6048568fd7c455a41cf6632138046396809cc3841ccbd4799607aa1a2f5445
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.05 μs
7.16 μs
FlatPPL · normal optimizations
10.6 μs · 2.09× Wren
13.3 μs · 1.86× Wren
FlatPPL · equal work
10.9 μs · 2.16× Wren
12.6 μs · 1.76× Wren
Wren definition in this run
@wren function capture_mt(y, seen)
omega ~ WD.Uniform(0.0, 1.0)
@iid p ~ WD.Uniform(0.0, 1.0) size=size(y, 2)
@addloglikelihood capture_mt_logp(omega, p, y, seen)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
4.66 μs
7.12 μs
FlatPPL · normal optimizations
10.7 μs · 2.3× Wren
11.9 μs · 1.67× Wren
FlatPPL · equal work
10.1 μs · 2.17× Wren
11.8 μs · 1.65× Wren
Wren definition in this run
@wren function capture_mt(y, seen)
omega ~ WD.Uniform(0.0, 1.0)
@iid p ~ WD.Uniform(0.0, 1.0) size=size(y, 2)
@addloglikelihood capture_mt_logp(omega, p, y, seen)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
4.39 μs
6.81 μs
FlatPPL · normal optimizations
9.49 μs · 2.16× Wren
12.4 μs · 1.83× Wren
FlatPPL · equal work
9.62 μs · 2.19× Wren
14.2 μs · 2.09× Wren
Wren definition in this run
@wren function capture_mt(y, seen)
omega ~ WD.Uniform(0.0, 1.0)
@iid p ~ WD.Uniform(0.0, 1.0) size=size(y, 2)
@addloglikelihood capture_mt_logp(omega, p, y, seen)
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
10.7 μs · 68 calls
7.9 μs · 32 calls
16.2 μs
17.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
8.63 μs · 44 calls
7.23 μs · 48 calls
16 μs
17 μs
20261122T002521Z-565231f
On · no reduction
10.7 μs · 68 calls
7.9 μs · 32 calls
16.2 μs
17.6 μs
20261122T002521Z-565231f
Off
8.63 μs · 44 calls
7.23 μs · 48 calls
16 μs
17 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
8.64 μs · 80 calls
7.18 μs · 104 calls
15.4 μs
17.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
9.97 μs · 88 calls
7.08 μs · 100 calls
15.6 μs
18.4 μs
20261122T000034Z-565231f
On · no reduction
8.64 μs · 80 calls
7.18 μs · 104 calls
15.4 μs
17.4 μs
20261122T000034Z-565231f
Off
9.97 μs · 88 calls
7.08 μs · 100 calls
15.6 μs
18.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
6.16 μs · 94 calls
11.8 μs
14.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
9.44 μs · 4 calls
12.8 μs
16.1 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
6.16 μs · 94 calls
11.8 μs
14.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
9.44 μs · 4 calls
12.8 μs
16.1 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 16 μs · value and gradient 16.6 μs
PosteriorDB model Mtbh_model · dataset Mtbh_data · SHA-256 138b4cc8ad5338d22e0d113e809f0f43f04e1ce1d68d498f06b62418304ee515
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_Mth_model(M, T, y, s)
@assert size(y) == (M, T)
@assert size(s) == (M,)
omega ~ Uniform(0.0, 1.0)
mean_p ~ product_distribution(Fill(Uniform(0.0, 1.0), T))
sigma ~ Uniform(0.0, 5.0)
eps_raw ~ product_distribution(Fill(Normal(0.0, 1.0), M))
logit_p = logit.(mean_p)' .+ sigma .* eps_raw
for i in 1:M
if s[i] > 0
DynamicPPL.@addlogprob! logpdf(Bernoulli(omega), 1) + logpdf(
product_distribution(map(BernoulliLogit, logit_p[i, :])), y[i, :]
)
else
DynamicPPL.@addlogprob! logaddexp(
logpdf(Bernoulli(omega), 1) +
logpdf(product_distribution(map(BernoulliLogit, logit_p[i, :])), y[i, :]),
logpdf(Bernoulli(omega), 0),
)
end
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
25.2 μs · 36 calls
17.2 μs · 44 calls
29.1 μs
26.9 μs
20261122T002521Z-565231f-registered-repeat-1
Off
23.3 μs · 4 calls
17.4 μs · 40 calls
29.2 μs
26.8 μs
20261122T002521Z-565231f
On · no reduction
25.2 μs · 36 calls
17.2 μs · 44 calls
29.1 μs
26.9 μs
20261122T002521Z-565231f
Off
23.3 μs · 4 calls
17.4 μs · 40 calls
29.2 μs
26.8 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
21.3 μs · 36 calls
17.8 μs · 40 calls
27.6 μs
28 μs
20261122T000034Z-565231f-registered-repeat-1
Off
26 μs · 44 calls
17.5 μs · 40 calls
29.6 μs
27.5 μs
20261122T000034Z-565231f
On · no reduction
21.3 μs · 36 calls
17.8 μs · 40 calls
27.6 μs
28 μs
20261122T000034Z-565231f
Off
26 μs · 44 calls
17.5 μs · 40 calls
29.6 μs
27.5 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
23.5 μs · 38 calls
21.2 μs
31.1 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
23.2 μs · 27 calls
21.2 μs
32.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
23.5 μs · 38 calls
21.2 μs
31.1 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
23.2 μs · 27 calls
21.2 μs
32.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 27.3 μs · value and gradient 25.5 μs
PosteriorDB model Mth_model · dataset Mth_data · SHA-256 1e0e16d9dcfda9dc40431fc043c94dc1f1472b8277ecd7056e9ca03de09c4b27
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
3.14 μs · 4 calls
2.16 μs · 372 calls
5.39 μs
8.62 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.37 μs · 64 calls
2.33 μs · 28 calls
6.3 μs
8.63 μs
20261122T002521Z-565231f
On · no reduction
3.14 μs · 4 calls
2.16 μs · 372 calls
5.39 μs
8.62 μs
20261122T002521Z-565231f
Off
1.37 μs · 64 calls
2.33 μs · 28 calls
6.3 μs
8.63 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.53 μs · 44 calls
2.3 μs · 260 calls
7.35 μs
10.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.51 μs · 52 calls
2.33 μs · 112 calls
6.5 μs
10.8 μs
20261122T000034Z-565231f
On · no reduction
1.53 μs · 44 calls
2.3 μs · 260 calls
7.35 μs
10.6 μs
20261122T000034Z-565231f
Off
1.51 μs · 52 calls
2.33 μs · 112 calls
6.5 μs
10.8 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.1 μs · 39 calls
5.82 μs
8.66 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.95 μs · 281 calls
5.63 μs
7.97 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.1 μs · 39 calls
5.82 μs
8.66 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.95 μs · 281 calls
5.63 μs
7.97 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 7.05 μs · value and gradient 11.2 μs
PosteriorDB model nes · dataset nes1972 · SHA-256 adafcabd097476afd9bc9c6c9a0c567615ada6c141714f37c473f478888f040f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.72 μs
3.14 μs
FlatPPL · normal optimizations
5.39 μs · 3.14× Wren
8.62 μs · 2.75× Wren
FlatPPL · equal work
6.3 μs · 3.67× Wren
8.63 μs · 2.75× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
2.15 μs
3.05 μs
FlatPPL · normal optimizations
7.35 μs · 3.43× Wren
10.6 μs · 3.49× Wren
FlatPPL · equal work
6.5 μs · 3.03× Wren
10.8 μs · 3.54× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.8 μs
2.98 μs
FlatPPL · normal optimizations
5.82 μs · 3.24× Wren
8.66 μs · 2.91× Wren
FlatPPL · equal work
5.63 μs · 3.14× Wren
7.97 μs · 2.67× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.12 μs · 616 calls
1.84 μs · 436 calls
6.02 μs
8.43 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.11 μs · 612 calls
1.99 μs · 400 calls
5.82 μs
8.57 μs
20261122T002521Z-565231f
On · no reduction
1.12 μs · 616 calls
1.84 μs · 436 calls
6.02 μs
8.43 μs
20261122T002521Z-565231f
Off
1.11 μs · 612 calls
1.99 μs · 400 calls
5.82 μs
8.57 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.26 μs · 576 calls
1.98 μs · 428 calls
5.83 μs
9.47 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.21 μs · 496 calls
1.96 μs · 408 calls
5.91 μs
8.24 μs
20261122T000034Z-565231f
On · no reduction
1.26 μs · 576 calls
1.98 μs · 428 calls
5.83 μs
9.47 μs
20261122T000034Z-565231f
Off
1.21 μs · 496 calls
1.96 μs · 408 calls
5.91 μs
8.24 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.76 μs · 214 calls
5.82 μs
7.63 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.87 μs · 44 calls
5.7 μs
6.61 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.76 μs · 214 calls
5.82 μs
7.63 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.87 μs · 44 calls
5.7 μs
6.61 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.23 μs · value and gradient 8.08 μs
PosteriorDB model nes · dataset nes1976 · SHA-256 4f67161bbf8a510f888296f2c73f6d6816e8c7ae59d0d5a12780824d03f0018a
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.51 μs
2.66 μs
FlatPPL · normal optimizations
6.02 μs · 3.98× Wren
8.43 μs · 3.18× Wren
FlatPPL · equal work
5.82 μs · 3.85× Wren
8.57 μs · 3.23× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.64 μs
2.84 μs
FlatPPL · normal optimizations
5.83 μs · 3.55× Wren
9.47 μs · 3.34× Wren
FlatPPL · equal work
5.91 μs · 3.6× Wren
8.24 μs · 2.91× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.72 μs
2.72 μs
FlatPPL · normal optimizations
5.82 μs · 3.38× Wren
7.63 μs · 2.8× Wren
FlatPPL · equal work
5.7 μs · 3.31× Wren
6.61 μs · 2.43× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
679 ns · 752 calls
1.14 μs · 632 calls
4.78 μs
7.22 μs
20261122T002521Z-565231f-registered-repeat-1
Off
704 ns · 240 calls
1.07 μs · 620 calls
5.23 μs
7.87 μs
20261122T002521Z-565231f
On · no reduction
679 ns · 752 calls
1.14 μs · 632 calls
4.78 μs
7.22 μs
20261122T002521Z-565231f
Off
704 ns · 240 calls
1.07 μs · 620 calls
5.23 μs
7.87 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
740 ns · 852 calls
1.63 μs · 24 calls
5.95 μs
12.1 μs
20261122T000034Z-565231f-registered-repeat-1
Off
743 ns · 492 calls
1.2 μs · 568 calls
6.69 μs
11 μs
20261122T000034Z-565231f
On · no reduction
740 ns · 852 calls
1.63 μs · 24 calls
5.95 μs
12.1 μs
20261122T000034Z-565231f
Off
743 ns · 492 calls
1.2 μs · 568 calls
6.69 μs
11 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.1 μs · 383 calls
4.02 μs
6.82 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.88 μs · 4 calls
4.01 μs
5.56 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.1 μs · 383 calls
4.02 μs
6.82 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.88 μs · 4 calls
4.01 μs
5.56 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.41 μs · value and gradient 6.57 μs
PosteriorDB model nes · dataset nes1980 · SHA-256 01648fa28d7ba698e1e05b03a2b23a3b2ccbfa11d16bdcdb004c92b42c618766
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.02 μs
2 μs
FlatPPL · normal optimizations
4.78 μs · 4.7× Wren
7.22 μs · 3.62× Wren
FlatPPL · equal work
5.23 μs · 5.14× Wren
7.87 μs · 3.94× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.2 μs
1.85 μs
FlatPPL · normal optimizations
5.95 μs · 4.97× Wren
12.1 μs · 6.53× Wren
FlatPPL · equal work
6.69 μs · 5.58× Wren
11 μs · 5.92× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.14 μs
2.42 μs
FlatPPL · normal optimizations
4.02 μs · 3.53× Wren
6.82 μs · 2.81× Wren
FlatPPL · equal work
4.01 μs · 3.52× Wren
5.56 μs · 2.29× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
const FLAT_GAUSSIAN = @model X begin
beta ~ Lebesgue(ℝ) ^ size(X, 2)
sigma ~ Half(Lebesgue(ℝ))
mu = X * beta
y ~ For(mu) do m
Normal(m, sigma)
end
end
const FLAT_GAUSSIAN_LEBESGUE_POSITIVE = @model X begin
beta ~ Lebesgue(ℝ) ^ size(X, 2)
sigma ~ Lebesgue(ℝ₊)
mu = X * beta
y ~ For(mu) do m
Normal(m, sigma)
end
end
@model function flat_gaussian(X, y)
beta ~ filldist(Flat(), size(X, 2))
sigma ~ FlatPos(0.0)
y ~ MvNormal(X * beta, sigma^2 * I)
end
@model function flat_gaussian_loop(X, y)
beta ~ filldist(Flat(), size(X, 2))
sigma ~ FlatPos(0.0)
mu = X * beta
for i in eachindex(y)
y[i] ~ Normal(mu[i], sigma)
end
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.23 μs · 544 calls
2.05 μs · 264 calls
6.65 μs
8.92 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.15 μs · 448 calls
1.98 μs · 360 calls
4.93 μs
8.47 μs
20261122T002521Z-565231f
On · no reduction
1.23 μs · 544 calls
2.05 μs · 264 calls
6.65 μs
8.92 μs
20261122T002521Z-565231f
Off
1.15 μs · 448 calls
1.98 μs · 360 calls
4.93 μs
8.47 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.33 μs · 604 calls
2.2 μs · 292 calls
7.89 μs
10.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.15 μs · 336 calls
2.24 μs · 328 calls
10 μs
10.4 μs
20261122T000034Z-565231f
On · no reduction
1.33 μs · 604 calls
2.2 μs · 292 calls
7.89 μs
10.9 μs
20261122T000034Z-565231f
Off
1.15 μs · 336 calls
2.24 μs · 328 calls
10 μs
10.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.81 μs · 217 calls
4.33 μs
8.21 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.99 μs · 262 calls
5.6 μs
8.48 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.81 μs · 217 calls
4.33 μs
8.21 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.99 μs · 262 calls
5.6 μs
8.48 μs
20261114T233319Z-f022c87
On · reduced
JIT-loop timing not recorded
6.07 μs · 91 calls
465 μs
497 μs
20261114T233319Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
4.23 μs
7.43 μs
20261114T225256Z-f022c87
On · reduced
JIT-loop timing not recorded
5.31 μs · 106 calls
468 μs
496 μs
20261114T225256Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
4.16 μs
8.58 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.11 μs · value and gradient 9.36 μs
PosteriorDB model nes · dataset nes1984 · SHA-256 2dd85833051b7b086231fbf92c47420d97a2f651838fd368a1800228d44a57a6
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.73 μs
3.14 μs
FlatPPL · normal optimizations
6.65 μs · 3.84× Wren
8.92 μs · 2.85× Wren
FlatPPL · equal work
4.93 μs · 2.85× Wren
8.47 μs · 2.7× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.72 μs
3.35 μs
FlatPPL · normal optimizations
7.89 μs · 4.6× Wren
10.9 μs · 3.25× Wren
FlatPPL · equal work
10 μs · 5.85× Wren
10.4 μs · 3.11× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.7 μs
3.08 μs
FlatPPL · normal optimizations
4.33 μs · 2.55× Wren
8.21 μs · 2.67× Wren
FlatPPL · equal work
5.6 μs · 3.3× Wren
8.48 μs · 2.75× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.05 μs · 628 calls
1.74 μs · 372 calls
5.62 μs
7.98 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.11 μs · 416 calls
1.67 μs · 480 calls
4.39 μs
8.43 μs
20261122T002521Z-565231f
On · no reduction
1.05 μs · 628 calls
1.74 μs · 372 calls
5.62 μs
7.98 μs
20261122T002521Z-565231f
Off
1.11 μs · 416 calls
1.67 μs · 480 calls
4.39 μs
8.43 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.13 μs · 620 calls
2.08 μs · 448 calls
6.98 μs
9.97 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.04 μs · 556 calls
1.87 μs · 64 calls
6.15 μs
9.96 μs
20261122T000034Z-565231f
On · no reduction
1.13 μs · 620 calls
2.08 μs · 448 calls
6.98 μs
9.97 μs
20261122T000034Z-565231f
Off
1.04 μs · 556 calls
1.87 μs · 64 calls
6.15 μs
9.96 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.64 μs · 346 calls
5.2 μs
7.85 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.67 μs · 365 calls
4.73 μs
7.86 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.64 μs · 346 calls
5.2 μs
7.85 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.67 μs · 365 calls
4.73 μs
7.86 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.95 μs · value and gradient 7.98 μs
PosteriorDB model nes · dataset nes1988 · SHA-256 4b8eaca3870c2cfcfdd64c931132182eb959042fe8975f76b72f17f06bb35092
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.61 μs
3.24 μs
FlatPPL · normal optimizations
5.62 μs · 3.48× Wren
7.98 μs · 2.46× Wren
FlatPPL · equal work
4.39 μs · 2.72× Wren
8.43 μs · 2.6× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.63 μs
3.02 μs
FlatPPL · normal optimizations
6.98 μs · 4.28× Wren
9.97 μs · 3.3× Wren
FlatPPL · equal work
6.15 μs · 3.78× Wren
9.96 μs · 3.29× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.8 μs
3.02 μs
FlatPPL · normal optimizations
5.2 μs · 2.89× Wren
7.85 μs · 2.6× Wren
FlatPPL · equal work
4.73 μs · 2.63× Wren
7.86 μs · 2.6× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.35 μs · 512 calls
2.12 μs · 312 calls
5.94 μs
8.89 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.3 μs · 452 calls
2.32 μs · 308 calls
4.52 μs
9.01 μs
20261122T002521Z-565231f
On · no reduction
1.35 μs · 512 calls
2.12 μs · 312 calls
5.94 μs
8.89 μs
20261122T002521Z-565231f
Off
1.3 μs · 452 calls
2.32 μs · 308 calls
4.52 μs
9.01 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.36 μs · 496 calls
2.12 μs · 272 calls
5.89 μs
10.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.33 μs · 480 calls
2.25 μs · 60 calls
6.15 μs
9.92 μs
20261122T000034Z-565231f
On · no reduction
1.36 μs · 496 calls
2.12 μs · 272 calls
5.89 μs
10.4 μs
20261122T000034Z-565231f
Off
1.33 μs · 480 calls
2.25 μs · 60 calls
6.15 μs
9.92 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.1 μs · 179 calls
4.97 μs
8.31 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.07 μs · 229 calls
5.71 μs
8.88 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.1 μs · 179 calls
4.97 μs
8.31 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.07 μs · 229 calls
5.71 μs
8.88 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 7.05 μs · value and gradient 9.28 μs
PosteriorDB model nes · dataset nes1992 · SHA-256 7274bb21b2858381e106405965138e19beee5b10e2a97ad1a51d36b53f3eba61
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.86 μs
3.34 μs
FlatPPL · normal optimizations
5.94 μs · 3.19× Wren
8.89 μs · 2.67× Wren
FlatPPL · equal work
4.52 μs · 2.43× Wren
9.01 μs · 2.7× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.84 μs
3.24 μs
FlatPPL · normal optimizations
5.89 μs · 3.19× Wren
10.4 μs · 3.2× Wren
FlatPPL · equal work
6.15 μs · 3.33× Wren
9.92 μs · 3.06× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.74 μs
3.04 μs
FlatPPL · normal optimizations
4.97 μs · 2.86× Wren
8.31 μs · 2.73× Wren
FlatPPL · equal work
5.71 μs · 3.29× Wren
8.88 μs · 2.92× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
1.05 μs · 608 calls
1.69 μs · 436 calls
5.43 μs
7.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
1.05 μs · 680 calls
1.63 μs · 396 calls
5.68 μs
8.72 μs
20261122T002521Z-565231f
On · no reduction
1.05 μs · 608 calls
1.69 μs · 436 calls
5.43 μs
7.5 μs
20261122T002521Z-565231f
Off
1.05 μs · 680 calls
1.63 μs · 396 calls
5.68 μs
8.72 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.14 μs · 608 calls
2.02 μs · 452 calls
5.75 μs
9.78 μs
20261122T000034Z-565231f-registered-repeat-1
Off
970 ns · 616 calls
1.72 μs · 524 calls
5.49 μs
9.58 μs
20261122T000034Z-565231f
On · no reduction
1.14 μs · 608 calls
2.02 μs · 452 calls
5.75 μs
9.78 μs
20261122T000034Z-565231f
Off
970 ns · 616 calls
1.72 μs · 524 calls
5.49 μs
9.58 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
1.61 μs · 259 calls
4.4 μs
8.38 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.57 μs · 260 calls
5.56 μs
7.84 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
1.61 μs · 259 calls
4.4 μs
8.38 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.57 μs · 260 calls
5.56 μs
7.84 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 7.47 μs · value and gradient 9.66 μs
PosteriorDB model nes · dataset nes1996 · SHA-256 38cfd1fd41039870448ee851bf6ba1517933475875307f1c04aa66ec1f44c768
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.62 μs
2.9 μs
FlatPPL · normal optimizations
5.43 μs · 3.35× Wren
7.5 μs · 2.58× Wren
FlatPPL · equal work
5.68 μs · 3.51× Wren
8.72 μs · 3.0× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.47 μs
2.64 μs
FlatPPL · normal optimizations
5.75 μs · 3.9× Wren
9.78 μs · 3.71× Wren
FlatPPL · equal work
5.49 μs · 3.73× Wren
9.58 μs · 3.64× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.57 μs
2.55 μs
FlatPPL · normal optimizations
4.4 μs · 2.8× Wren
8.38 μs · 3.29× Wren
FlatPPL · equal work
5.56 μs · 3.54× Wren
7.84 μs · 3.07× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
458 ns · 1140 calls
605 ns · 1316 calls
5.16 μs
6.64 μs
20261122T002521Z-565231f-registered-repeat-1
Off
465 ns · 1200 calls
607 ns · 324 calls
3.63 μs
5.29 μs
20261122T002521Z-565231f
On · no reduction
458 ns · 1140 calls
605 ns · 1316 calls
5.16 μs
6.64 μs
20261122T002521Z-565231f
Off
465 ns · 1200 calls
607 ns · 324 calls
3.63 μs
5.29 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
462 ns · 940 calls
652 ns · 832 calls
5.14 μs
11.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
473 ns · 1108 calls
633 ns · 844 calls
4.52 μs
6.74 μs
20261122T000034Z-565231f
On · no reduction
462 ns · 940 calls
652 ns · 832 calls
5.14 μs
11.6 μs
20261122T000034Z-565231f
Off
473 ns · 1108 calls
633 ns · 844 calls
4.52 μs
6.74 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
661 ns · 524 calls
4.72 μs
6.31 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
763 ns · 98 calls
3.39 μs
6.66 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
661 ns · 524 calls
4.72 μs
6.31 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
763 ns · 98 calls
3.39 μs
6.66 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.52 μs · value and gradient 11 μs
PosteriorDB model nes · dataset nes2000 · SHA-256 336edc63ad7d647a5a0d6532bad705383517a7fd95e178b0056617267442e95b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
741 ns
1.52 μs
FlatPPL · normal optimizations
5.16 μs · 6.97× Wren
6.64 μs · 4.38× Wren
FlatPPL · equal work
3.63 μs · 4.9× Wren
5.29 μs · 3.49× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
782 ns
1.48 μs
FlatPPL · normal optimizations
5.14 μs · 6.57× Wren
11.6 μs · 7.84× Wren
FlatPPL · equal work
4.52 μs · 5.78× Wren
6.74 μs · 4.54× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
728 ns
1.34 μs
FlatPPL · normal optimizations
4.72 μs · 6.48× Wren
6.31 μs · 4.7× Wren
FlatPPL · equal work
3.39 μs · 4.66× Wren
6.66 μs · 4.96× Wren
Wren definition in this run
@wren function flat_gaussian(y, X)
@iid beta ~ WD.Flat() size=size(X, 2)
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# A flat density in positive sigma induces this Jacobian in log sigma.
# Temporary until the constrained Flat API in #192 is available here.
@addloglikelihood log_sigma
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function nes_logit(income, vote)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=1
eta = alpha .+ beta[1] .* income
@batch for i in eachindex(vote)
@observe vote[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_nes_logit_model(X, vote)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), size(X, 2)))
logits = alpha .+ X * beta
return vote ~ product_distribution(map(BernoulliLogit, logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
8.98 μs · 88 calls
8.15 μs · 116 calls
13.5 μs
13.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
9.48 μs · 96 calls
6.9 μs · 120 calls
12.8 μs
12.7 μs
20261122T002521Z-565231f
On · no reduction
8.98 μs · 88 calls
8.15 μs · 116 calls
13.5 μs
13.2 μs
20261122T002521Z-565231f
Off
9.48 μs · 96 calls
6.9 μs · 120 calls
12.8 μs
12.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
9.82 μs · 92 calls
8.76 μs · 108 calls
13 μs
13.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
9.18 μs · 84 calls
6.53 μs · 112 calls
13.4 μs
13 μs
20261122T000034Z-565231f
On · no reduction
9.82 μs · 92 calls
8.76 μs · 108 calls
13 μs
13.4 μs
20261122T000034Z-565231f
Off
9.18 μs · 84 calls
6.53 μs · 112 calls
13.4 μs
13 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
5.65 μs · 29 calls
13.5 μs
12.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
7.24 μs · 4 calls
13.9 μs
12.4 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
5.65 μs · 29 calls
13.5 μs
12.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
7.24 μs · 4 calls
13.9 μs
12.4 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 12.8 μs · value and gradient 12.7 μs
PosteriorDB model nes_logit_model · dataset nes_logit_data · SHA-256 f941606e061dcf47eaf86d45511b22dad0e05e68399f148ee93a6e2af14e4a75
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
8.82 μs
18.3 μs
FlatPPL · normal optimizations
13.5 μs · 1.54× Wren
13.2 μs · 0.722× Wren
FlatPPL · equal work
12.8 μs · 1.45× Wren
12.7 μs · 0.696× Wren
Wren definition in this run
@wren function nes_logit(income, vote)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=1
eta = alpha .+ beta[1] .* income
@batch for i in eachindex(vote)
@observe vote[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
8.76 μs
17 μs
FlatPPL · normal optimizations
13 μs · 1.48× Wren
13.4 μs · 0.789× Wren
FlatPPL · equal work
13.4 μs · 1.53× Wren
13 μs · 0.761× Wren
Wren definition in this run
@wren function nes_logit(income, vote)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=1
eta = alpha .+ beta[1] .* income
@batch for i in eachindex(vote)
@observe vote[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
8.99 μs
16.6 μs
FlatPPL · normal optimizations
13.5 μs · 1.5× Wren
12.8 μs · 0.77× Wren
FlatPPL · equal work
13.9 μs · 1.54× Wren
12.4 μs · 0.745× Wren
Wren definition in this run
@wren function nes_logit(income, vote)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=1
eta = alpha .+ beta[1] .* income
@batch for i in eachindex(vote)
@observe vote[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_normal_mixture(N, y)
theta ~ Uniform(0, 1)
mu ~ product_distribution(Fill(Normal(0, 10), 2))
for n in 1:N
DynamicPPL.@addlogprob! logaddexp(
log(theta) + logpdf(Normal(mu[1], 1.0), y[n]),
log1p(-theta) + logpdf(Normal(mu[2], 1.0), y[n]),
)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
5.57 μs · 72 calls
20.4 μs · 4 calls
9.12 μs
16.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
5.33 μs · 100 calls
19.2 μs · 52 calls
9.23 μs
15.1 μs
20261122T002521Z-565231f
On · no reduction
5.57 μs · 72 calls
20.4 μs · 4 calls
9.12 μs
16.2 μs
20261122T002521Z-565231f
Off
5.33 μs · 100 calls
19.2 μs · 52 calls
9.23 μs
15.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
6.53 μs · 72 calls
19.2 μs · 16 calls
9.36 μs
15.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
6.45 μs · 128 calls
19.8 μs · 36 calls
8.89 μs
16.9 μs
20261122T000034Z-565231f
On · no reduction
6.53 μs · 72 calls
19.2 μs · 16 calls
9.36 μs
15.4 μs
20261122T000034Z-565231f
Off
6.45 μs · 128 calls
19.8 μs · 36 calls
8.89 μs
16.9 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
18.3 μs · 32 calls
8.45 μs
15.2 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
19.7 μs · 35 calls
9.49 μs
15.2 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
18.3 μs · 32 calls
8.45 μs
15.2 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
19.7 μs · 35 calls
9.49 μs
15.2 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 9.12 μs · value and gradient 15.5 μs
PosteriorDB model normal_mixture · dataset normal_2 · SHA-256 936eba745a34b361d60a34728fb5a9ab18c84815da704644497b715ac029bd3b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.59 μs
19.8 μs
FlatPPL · normal optimizations
9.12 μs · 1.63× Wren
16.2 μs · 0.818× Wren
FlatPPL · equal work
9.23 μs · 1.65× Wren
15.1 μs · 0.76× Wren
Wren definition in this run
@wren function normal_mixture(y)
theta ~ WD.Uniform(0.0, 1.0)
@iid mu ~ WD.Normal(0.0, 10.0) size=2
@addloglikelihood mixture_logp(theta, mu, y)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.34 μs
19.2 μs
FlatPPL · normal optimizations
9.36 μs · 1.75× Wren
15.4 μs · 0.805× Wren
FlatPPL · equal work
8.89 μs · 1.66× Wren
16.9 μs · 0.88× Wren
Wren definition in this run
@wren function normal_mixture(y)
theta ~ WD.Uniform(0.0, 1.0)
@iid mu ~ WD.Normal(0.0, 10.0) size=2
@addloglikelihood mixture_logp(theta, mu, y)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.57 μs
28.9 μs
FlatPPL · normal optimizations
8.45 μs · 1.52× Wren
15.2 μs · 0.526× Wren
FlatPPL · equal work
9.49 μs · 1.7× Wren
15.2 μs · 0.527× Wren
Wren definition in this run
@wren function normal_mixture(y)
theta ~ WD.Uniform(0.0, 1.0)
@iid mu ~ WD.Normal(0.0, 10.0) size=2
@addloglikelihood mixture_logp(theta, mu, y)
return nothing
end
@model function normal_mixture_k(y, K)
theta ~ Dirichlet(K, 1.0)
mu ~ filldist(Normal(0, 10), K)
sigma ~ filldist(Uniform(0, 10), K)
y .~ MixtureModel([Normal(mu[k], sigma[k]) for k in 1:K], theta)
end
@model function pdb_normal_mixture_k(K, N, y)
theta ~ Dirichlet(ones(K))
mu ~ product_distribution(Fill(Normal(0.0, 10.0), K))
sigma ~ product_distribution(Fill(Uniform(0.0, 10.0), K))
for n in 1:N
ps = map(
(weight, location, scale) ->
log(weight) + logpdf(Normal(location, scale), y[n]),
theta,
mu,
sigma,
)
DynamicPPL.@addlogprob! logsumexp(ps)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
16.1 μs · 40 calls
29 μs · 24 calls
25.2 μs
39.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
15.5 μs · 52 calls
29.3 μs · 32 calls
23.6 μs
40 μs
20261122T002521Z-565231f
On · no reduction
16.1 μs · 40 calls
29 μs · 24 calls
25.2 μs
39.6 μs
20261122T002521Z-565231f
Off
15.5 μs · 52 calls
29.3 μs · 32 calls
23.6 μs
40 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
16.6 μs · 40 calls
31.2 μs · 12 calls
26.3 μs
42.1 μs
20261122T000034Z-565231f-registered-repeat-1
Off
18.1 μs · 40 calls
32.7 μs · 4 calls
23.5 μs
42.5 μs
20261122T000034Z-565231f
On · no reduction
16.6 μs · 40 calls
31.2 μs · 12 calls
26.3 μs
42.1 μs
20261122T000034Z-565231f
Off
18.1 μs · 40 calls
32.7 μs · 4 calls
23.5 μs
42.5 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
33.5 μs · 4 calls
24 μs
41.9 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
38 μs · 17 calls
23.8 μs
38.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
33.5 μs · 4 calls
24 μs
41.9 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
38 μs · 17 calls
23.8 μs
38.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 23.8 μs · value and gradient 54.4 μs
PosteriorDB model normal_mixture_k · dataset normal_5 · SHA-256 bad076a1f089d0ca5dec8ba070c0cc4629e02509858e5b100b34188c7333c91c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
177 μs
331 μs
FlatPPL · normal optimizations
25.2 μs · 0.142× Wren
39.6 μs · 0.12× Wren
FlatPPL · equal work
23.6 μs · 0.133× Wren
40 μs · 0.121× Wren
Wren definition in this run
@wren function normal_mixture_k(y, K)
# Stan's implicit flat simplex factor differs only by a constant.
theta ~ WD.Dirichlet(ones(K))
@iid mu ~ WD.Normal(0.0, 10.0) size=K
@iid sigma ~ WD.Uniform(0.0, 10.0) size=K
@addloglikelihood mixture_k_logp(theta, mu, sigma, y)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
177 μs
332 μs
FlatPPL · normal optimizations
26.3 μs · 0.148× Wren
42.1 μs · 0.127× Wren
FlatPPL · equal work
23.5 μs · 0.132× Wren
42.5 μs · 0.128× Wren
Wren definition in this run
@wren function normal_mixture_k(y, K)
# Stan's implicit flat simplex factor differs only by a constant.
theta ~ WD.Dirichlet(ones(K))
@iid mu ~ WD.Normal(0.0, 10.0) size=K
@iid sigma ~ WD.Uniform(0.0, 10.0) size=K
@addloglikelihood mixture_k_logp(theta, mu, sigma, y)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
212 μs
387 μs
FlatPPL · normal optimizations
24 μs · 0.113× Wren
41.9 μs · 0.108× Wren
FlatPPL · equal work
23.8 μs · 0.113× Wren
38.9 μs · 0.1× Wren
Wren definition in this run
@wren function normal_mixture_k(y, K)
# Stan's implicit flat simplex factor differs only by a constant.
theta ~ WD.Dirichlet(ones(K))
@iid mu ~ WD.Normal(0.0, 10.0) size=K
@iid sigma ~ WD.Uniform(0.0, 10.0) size=K
@addloglikelihood mixture_k_logp(theta, mu, sigma, y)
return nothing
end
Standalone FlatPPL single call · sufficient statistics on · log density 11.4 μs · value and gradient Reverse differentiation of the adaptive ODE loop failed
PosteriorDB model one_comp_mm_elim_abs · dataset one_comp_mm_elim_abs · SHA-256 8df0f4206783394f97241d81f8ba53680dd559f1bc9ad3a721ee438c9151093e
@model function pdb_logistic_regression_rhs(
n, d, y, x, scale_icept, scale_global, nu_global, nu_local, slab_scale, slab_df
)
x = x.value
beta0 ~ Normal(0.0, scale_icept)
z ~ product_distribution(Fill(Normal(), d))
tau ~ truncated(LocationScale(0.0, 2.0scale_global, TDist(nu_global)); lower=0.0)
lambda ~ product_distribution(
Fill(truncated(LocationScale(0.0, 1.0, TDist(nu_local)); lower=0.0), d)
)
caux ~ InverseGamma(0.5slab_df, 0.5slab_df)
c2 = slab_scale^2 * caux
tau2 = tau^2
beta = tau .* z .* lambda .* sqrt.(c2 ./ (c2 .+ tau2 .* abs2.(lambda)))
logits = beta0 .+ x * beta
DynamicPPL.@addlogprob! dot(y, logits) - sum(log1pexp.(logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
11.6 μs · 76 calls
18.7 μs · 24 calls
20.2 μs
32.1 μs
20261122T002521Z-565231f-registered-repeat-1
Off
12.3 μs · 68 calls
19 μs · 20 calls
19.8 μs
27 μs
20261122T002521Z-565231f
On · no reduction
11.6 μs · 76 calls
18.7 μs · 24 calls
20.2 μs
32.1 μs
20261122T002521Z-565231f
Off
12.3 μs · 68 calls
19 μs · 20 calls
19.8 μs
27 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
15.4 μs · 56 calls
21.5 μs · 12 calls
24.6 μs
35.2 μs
20261122T000034Z-565231f-registered-repeat-1
Off
15.7 μs · 60 calls
22.5 μs · 24 calls
21.9 μs
33.8 μs
20261122T000034Z-565231f
On · no reduction
15.4 μs · 56 calls
21.5 μs · 12 calls
24.6 μs
35.2 μs
20261122T000034Z-565231f
Off
15.7 μs · 60 calls
22.5 μs · 24 calls
21.9 μs
33.8 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
18.9 μs · 38 calls
16.9 μs
30 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
18 μs · 47 calls
20.4 μs
31.4 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
18.9 μs · 38 calls
16.9 μs
30 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
18 μs · 47 calls
20.4 μs
31.4 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 26.4 μs · value and gradient 39.8 μs
PosteriorDB model logistic_regression_rhs · dataset ovarian · SHA-256 640e60012a432ac5e430f6d2552ff66ac07d86508fd0df65d78b63736ba6f1c9
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
23.7 μs
73.5 μs
FlatPPL · normal optimizations
20.2 μs · 0.853× Wren
32.1 μs · 0.437× Wren
FlatPPL · equal work
19.8 μs · 0.837× Wren
27 μs · 0.368× Wren
Wren definition in this run
@wren function logistic_rhs(y, x, n, d, scale_icept, scale_global,
nu_global, nu_local, slab_scale, slab_df)
beta0 ~ WD.Normal(0.0, scale_icept)
@iid z ~ WD.Normal(0.0, 1.0) size=d
tau ~ WD.HalfTDist(nu_global, 0.0, 2 * scale_global)
@iid lambda ~ WD.HalfTDist(nu_local, 0.0, 1.0) size=d
caux ~ WD.InverseGamma(0.5 * slab_df, 0.5 * slab_df)
c2 = slab_scale^2 * caux
beta = Vector{typeof(beta0 + tau + caux + z[1] + lambda[1])}(undef, d)
for j in eachindex(z)
lambda_j = lambda[j]
beta[j] = z[j] * tau * sqrt(c2 * lambda_j^2 /
(c2 + tau^2 * lambda_j^2))
end
eta = beta0 .+ x * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
23.1 μs
73.6 μs
FlatPPL · normal optimizations
24.6 μs · 1.07× Wren
35.2 μs · 0.478× Wren
FlatPPL · equal work
21.9 μs · 0.948× Wren
33.8 μs · 0.46× Wren
Wren definition in this run
@wren function logistic_rhs(y, x, n, d, scale_icept, scale_global,
nu_global, nu_local, slab_scale, slab_df)
beta0 ~ WD.Normal(0.0, scale_icept)
@iid z ~ WD.Normal(0.0, 1.0) size=d
tau ~ WD.HalfTDist(nu_global, 0.0, 2 * scale_global)
@iid lambda ~ WD.HalfTDist(nu_local, 0.0, 1.0) size=d
caux ~ WD.InverseGamma(0.5 * slab_df, 0.5 * slab_df)
c2 = slab_scale^2 * caux
beta = Vector{typeof(beta0 + tau + caux + z[1] + lambda[1])}(undef, d)
for j in eachindex(z)
lambda_j = lambda[j]
beta[j] = z[j] * tau * sqrt(c2 * lambda_j^2 /
(c2 + tau^2 * lambda_j^2))
end
eta = beta0 .+ x * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
23.5 μs
91.2 μs
FlatPPL · normal optimizations
16.9 μs · 0.719× Wren
30 μs · 0.329× Wren
FlatPPL · equal work
20.4 μs · 0.87× Wren
31.4 μs · 0.344× Wren
Wren definition in this run
@wren function logistic_rhs(y, x, n, d, scale_icept, scale_global,
nu_global, nu_local, slab_scale, slab_df)
beta0 ~ WD.Normal(0.0, scale_icept)
@iid z ~ WD.Normal(0.0, 1.0) size=d
tau ~ WD.HalfTDist(nu_global, 0.0, 2 * scale_global)
@iid lambda ~ WD.HalfTDist(nu_local, 0.0, 1.0) size=d
caux ~ WD.InverseGamma(0.5 * slab_df, 0.5 * slab_df)
c2 = slab_scale^2 * caux
beta = Vector{typeof(beta0 + tau + caux + z[1] + lambda[1])}(undef, d)
for j in eachindex(z)
lambda_j = lambda[j]
beta[j] = z[j] * tau * sqrt(c2 * lambda_j^2 /
(c2 + tau^2 * lambda_j^2))
end
eta = beta0 .+ x * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_pilots(N, n_groups, n_scenarios, group_id, scenario_id, y)
a ~ product_distribution(Fill(Flat(), n_groups))
b ~ product_distribution(Fill(Flat(), n_scenarios))
mu_a ~ Normal(0, 1)
mu_b ~ Normal(0, 1)
sigma_a ~ Uniform(0, 100)
sigma_b ~ Uniform(0, 100)
sigma_y ~ Uniform(0, 100)
y_hat = a[group_id] .+ b[scenario_id]
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(10mu_a, sigma_a), size(a))), a
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(10mu_b, sigma_b), size(b))), b
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_y), N)), y .- y_hat
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
104 ns · 2392 calls
483 ns · 1476 calls
3.98 μs
6.45 μs
20261122T002521Z-565231f-registered-repeat-1
Off
102 ns · 3500 calls
491 ns · 992 calls
3.98 μs
6.03 μs
20261122T002521Z-565231f
On · no reduction
104 ns · 2392 calls
483 ns · 1476 calls
3.98 μs
6.45 μs
20261122T002521Z-565231f
Off
102 ns · 3500 calls
491 ns · 992 calls
3.98 μs
6.03 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
110 ns · 1132 calls
565 ns · 860 calls
5.83 μs
11.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
105 ns · 1896 calls
521 ns · 644 calls
4.29 μs
10.6 μs
20261122T000034Z-565231f
On · no reduction
110 ns · 1132 calls
565 ns · 860 calls
5.83 μs
11.8 μs
20261122T000034Z-565231f
Off
105 ns · 1896 calls
521 ns · 644 calls
4.29 μs
10.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
504 ns · 388 calls
4.03 μs
6.16 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
499 ns · 408 calls
4.1 μs
5.82 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
504 ns · 388 calls
4.03 μs
6.16 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
499 ns · 408 calls
4.1 μs
5.82 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 4.08 μs · value and gradient 11 μs
PosteriorDB model pilots · dataset pilots · SHA-256 bc35ce1446523f76a8e76eb9aafd504fe80ff4ad9952c4d7587af5a1fe03f810
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
253 ns
665 ns
FlatPPL · normal optimizations
3.98 μs · 15.7× Wren
6.45 μs · 9.7× Wren
FlatPPL · equal work
3.98 μs · 15.7× Wren
6.03 μs · 9.07× Wren
Wren definition in this run
@wren function pilots_model(group_id, scenario_id, y, n_groups, n_scenarios)
mu_a ~ WD.Normal(0.0, 1.0)
mu_b ~ WD.Normal(0.0, 1.0)
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_b ~ WD.Uniform(0.0, 100.0)
sigma_y ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(10 * mu_a, sigma_a) size=n_groups
@iid b ~ WD.Normal(10 * mu_b, sigma_b) size=n_scenarios
y_hat = a[group_id] .+ b[scenario_id]
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(y_hat[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
158 ns
375 ns
FlatPPL · normal optimizations
5.83 μs · 37.0× Wren
11.8 μs · 31.4× Wren
FlatPPL · equal work
4.29 μs · 27.2× Wren
10.6 μs · 28.2× Wren
Wren definition in this run
@wren function pilots_model(group_id, scenario_id, y, n_groups, n_scenarios)
mu_a ~ WD.Normal(0.0, 1.0)
mu_b ~ WD.Normal(0.0, 1.0)
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_b ~ WD.Uniform(0.0, 100.0)
sigma_y ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(10 * mu_a, sigma_a) size=n_groups
@iid b ~ WD.Normal(10 * mu_b, sigma_b) size=n_scenarios
y_hat = a[group_id] .+ b[scenario_id]
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(y_hat[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
184 ns
600 ns
FlatPPL · normal optimizations
4.03 μs · 21.9× Wren
6.16 μs · 10.3× Wren
FlatPPL · equal work
4.1 μs · 22.3× Wren
5.82 μs · 9.7× Wren
Wren definition in this run
@wren function pilots_model(group_id, scenario_id, y, n_groups, n_scenarios)
mu_a ~ WD.Normal(0.0, 1.0)
mu_b ~ WD.Normal(0.0, 1.0)
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_b ~ WD.Uniform(0.0, 100.0)
sigma_y ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(10 * mu_a, sigma_a) size=n_groups
@iid b ~ WD.Normal(10 * mu_b, sigma_b) size=n_scenarios
y_hat = a[group_id] .+ b[scenario_id]
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(y_hat[i], sigma_y)
end
return nothing
end
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
const LDA_K5_DOCUMENT_CATEGORICAL = @rkppl begin
eachcol(theta[1:K, 1:M]) .~ Dirichlet(alpha)
eachcol(phi[1:V, 1:K]) .~ Dirichlet(beta)
@plate for m in eachindex(words)
words[m] .~ Categorical(phi * theta[:, m])
end
end
const LDA_K5_WORD_CATEGORICAL = @rkppl begin
eachcol(theta[1:K, 1:M]) .~ Dirichlet(alpha)
eachcol(phi[1:V, 1:K]) .~ Dirichlet(beta)
@plate for i in eachindex(w)
w[i] ~ Categorical(phi * theta[:, doc[i]])
end
end
%%%
# Latent Dirichlet allocation with five topics
PosteriorDB's `prideprejudice_chapter-ldaK5`. Pride and Prejudice split into
61 chapters holds 32877 word instances over a vocabulary of 1495 words. Each
chapter mixes five topics with weights theta, and each topic draws words
with probabilities phi. Summing over the topic of each word gives the word
probabilities theta * phi, as Stan's log_sum_exp over topics does. The
Dirichlet parameters alpha and beta come from the data.
%%%
flatppl_compat = "0.1"
V = 1495
M = 61
N = 32877
K = 5
data = load_data("data.json", cartprod(
w = cartpow(posintegers, N), doc = cartpow(posintegers, N),
alpha = cartpow(posreals, K), beta = cartpow(posreals, V)))
theta ~ iid(Dirichlet(data.alpha), M)
phi ~ iid(Dirichlet(data.beta), K)
% The word probabilities of a document are its topic weights mixed over the topics' rows.
mix(t, P) = transpose(P) * t
document_words = mix.(theta, fill(rowstack(phi), M))
w ~ Categorical.(document_words[data.doc])
Pi_prior = lawof(record(theta = theta, phi = phi))
K_model = kernelof(record(w = w), theta = theta, phi = phi)
L = likelihoodof(K_model, record(w = data.w))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta = cartpow(stdsimplex(K), M), phi = cartpow(stdsimplex(V), K))
Pi_post_input = record(theta = fill(fill(1 / K, K), M), phi = fill(fill(1 / V, V), K))
@model function pdb_ldaK5(V, M, N, w, doc, alpha, beta)
theta ~ product_distribution(Fill(Dirichlet(alpha), M))
phi ~ product_distribution(Fill(Dirichlet(beta), 5))
logits = permutedims(log.(view(theta, :, doc))) .+ log.(view(phi, w, :))
DynamicPPL.@addlogprob! sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T031115Z-565231f-registered-repeat-1
On · no reduction
1.07 ms · 4 calls
876 μs · 4 calls
1.07 ms
803 μs
20261122T031115Z-565231f-registered-repeat-1
Off
982 μs · 4 calls
858 μs · 4 calls
958 μs
872 μs
20261122T031115Z-565231f
On · no reduction
1.07 ms · 4 calls
876 μs · 4 calls
1.07 ms
803 μs
20261122T031115Z-565231f
Off
982 μs · 4 calls
858 μs · 4 calls
958 μs
872 μs
20261122T025805Z-565231f-registered-repeat-1
On · no reduction
965 μs · 4 calls
721 μs · 4 calls
875 μs
676 μs
20261122T025805Z-565231f-registered-repeat-1
Off
823 μs · 4 calls
705 μs · 4 calls
885 μs
719 μs
20261122T025805Z-565231f
On · no reduction
965 μs · 4 calls
721 μs · 4 calls
875 μs
676 μs
20261122T025805Z-565231f
Off
823 μs · 4 calls
705 μs · 4 calls
885 μs
719 μs
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
944 μs · 4 calls
751 μs · 4 calls
824 μs
849 μs
20261122T002521Z-565231f-registered-repeat-1
Off
901 μs · 4 calls
888 μs · 4 calls
850 μs
780 μs
20261122T002521Z-565231f
On · no reduction
944 μs · 4 calls
751 μs · 4 calls
824 μs
849 μs
20261122T002521Z-565231f
Off
901 μs · 4 calls
888 μs · 4 calls
850 μs
780 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
1.16 ms · 4 calls
719 μs · 4 calls
1.26 ms
856 μs
20261122T000034Z-565231f-registered-repeat-1
Off
1.06 ms · 4 calls
958 μs · 4 calls
972 μs
957 μs
20261122T000034Z-565231f
On · no reduction
1.16 ms · 4 calls
719 μs · 4 calls
1.26 ms
856 μs
20261122T000034Z-565231f
Off
1.06 ms · 4 calls
958 μs · 4 calls
972 μs
957 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 1.08 ms · value and gradient 823 μs
PosteriorDB model ldaK5 · dataset prideprejudice_chapter · SHA-256 7bbd590c960952956a9efd90ac0e5cb2e9d7ad75dba26c0b36cd5fb9a1374c69
Paired Wren run · 20261122T031115Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
3.85 ms
13.9 ms
FlatPPL · normal optimizations
1.07 ms · 0.278× Wren
803 μs · 0.0578× Wren
FlatPPL · equal work
958 μs · 0.249× Wren
872 μs · 0.0628× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261122T025805Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
3.99 ms
14 ms
FlatPPL · normal optimizations
875 μs · 0.219× Wren
676 μs · 0.0482× Wren
FlatPPL · equal work
885 μs · 0.222× Wren
719 μs · 0.0513× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.07 ms
18 ms
FlatPPL · normal optimizations
824 μs · 0.163× Wren
849 μs · 0.0471× Wren
FlatPPL · equal work
850 μs · 0.168× Wren
780 μs · 0.0433× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
4.5 ms
16 ms
FlatPPL · normal optimizations
1.26 ms · 0.28× Wren
856 μs · 0.0537× Wren
FlatPPL · equal work
972 μs · 0.216× Wren
957 μs · 0.06× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.11 ms
23.2 ms
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Gradient reference · BridgeStan 2.9.0 · log simplex, from original Stan unconstrained gradient at the frozen points · simplex-oracles/prideprejudice_chapter-ldaK5.json · SHA-256 c85b58ddc822bf1ea580318c4db4967484bba4cfc071ba49634e6d64610dcbda
FlatPPL model-space gradient value versus density · maximum absolute difference 2.91038e-11
FlatPPL unconstrained gradient value versus density · maximum absolute difference 0.0
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
const LDA_K5_DOCUMENT_CATEGORICAL = @rkppl begin
eachcol(theta[1:K, 1:M]) .~ Dirichlet(alpha)
eachcol(phi[1:V, 1:K]) .~ Dirichlet(beta)
@plate for m in eachindex(words)
words[m] .~ Categorical(phi * theta[:, m])
end
end
const LDA_K5_WORD_CATEGORICAL = @rkppl begin
eachcol(theta[1:K, 1:M]) .~ Dirichlet(alpha)
eachcol(phi[1:V, 1:K]) .~ Dirichlet(beta)
@plate for i in eachindex(w)
w[i] ~ Categorical(phi * theta[:, doc[i]])
end
end
%%%
# Latent Dirichlet allocation with five topics
PosteriorDB's `prideprejudice_paragraph-ldaK5`. Pride and Prejudice split
into 2025 paragraphs holds 32877 word instances over a vocabulary of 1495
words. Each paragraph mixes five topics with weights theta, and each topic
draws words with probabilities phi. Summing over the topic of each word
gives the word probabilities theta * phi, as Stan's log_sum_exp over topics
does. The Dirichlet parameters alpha and beta come from the data.
%%%
flatppl_compat = "0.1"
V = 1495
M = 2025
N = 32877
K = 5
data = load_data("data.json", cartprod(
w = cartpow(posintegers, N), doc = cartpow(posintegers, N),
alpha = cartpow(posreals, K), beta = cartpow(posreals, V)))
theta ~ iid(Dirichlet(data.alpha), M)
phi ~ iid(Dirichlet(data.beta), K)
% The word probabilities of a document are its topic weights mixed over the topics' rows.
mix(t, P) = transpose(P) * t
document_words = mix.(theta, fill(rowstack(phi), M))
w ~ Categorical.(document_words[data.doc])
Pi_prior = lawof(record(theta = theta, phi = phi))
K_model = kernelof(record(w = w), theta = theta, phi = phi)
L = likelihoodof(K_model, record(w = data.w))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta = cartpow(stdsimplex(K), M), phi = cartpow(stdsimplex(V), K))
Pi_post_input = record(theta = fill(fill(1 / K, K), M), phi = fill(fill(1 / V, V), K))
@model function pdb_ldaK5(V, M, N, w, doc, alpha, beta)
theta ~ product_distribution(Fill(Dirichlet(alpha), M))
phi ~ product_distribution(Fill(Dirichlet(beta), 5))
logits = permutedims(log.(view(theta, :, doc))) .+ log.(view(phi, w, :))
DynamicPPL.@addlogprob! sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T031115Z-565231f-registered-repeat-1
On · no reduction
83.1 ms · 4 calls
31.9 ms · 4 calls
117 ms
24.6 ms
20261122T031115Z-565231f-registered-repeat-1
Off
53.2 ms · 4 calls
32.2 ms · 4 calls
120 ms
21.5 ms
20261122T031115Z-565231f
On · no reduction
83.1 ms · 4 calls
31.9 ms · 4 calls
117 ms
24.6 ms
20261122T031115Z-565231f
Off
53.2 ms · 4 calls
32.2 ms · 4 calls
120 ms
21.5 ms
20261122T025805Z-565231f-registered-repeat-1
On · no reduction
78.1 ms · 4 calls
33.7 ms · 4 calls
119 ms
26.9 ms
20261122T025805Z-565231f-registered-repeat-1
Off
61.3 ms · 4 calls
29.7 ms · 4 calls
111 ms
22 ms
20261122T025805Z-565231f
On · no reduction
78.1 ms · 4 calls
33.7 ms · 4 calls
119 ms
26.9 ms
20261122T025805Z-565231f
Off
61.3 ms · 4 calls
29.7 ms · 4 calls
111 ms
22 ms
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
72.3 ms · 4 calls
28.6 ms · 4 calls
124 ms
22.4 ms
20261122T002521Z-565231f-registered-repeat-1
Off
34.8 ms · 4 calls
29 ms · 4 calls
114 ms
25.2 ms
20261122T002521Z-565231f
On · no reduction
72.3 ms · 4 calls
28.6 ms · 4 calls
124 ms
22.4 ms
20261122T002521Z-565231f
Off
34.8 ms · 4 calls
29 ms · 4 calls
114 ms
25.2 ms
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
78.7 ms · 4 calls
40.6 ms · 4 calls
120 ms
35.5 ms
20261122T000034Z-565231f-registered-repeat-1
Off
75 ms · 4 calls
36.7 ms · 4 calls
193 ms
34.9 ms
20261122T000034Z-565231f
On · no reduction
78.7 ms · 4 calls
40.6 ms · 4 calls
120 ms
35.5 ms
20261122T000034Z-565231f
Off
75 ms · 4 calls
36.7 ms · 4 calls
193 ms
34.9 ms
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 97.7 ms · value and gradient 40 ms
PosteriorDB model ldaK5 · dataset prideprejudice_paragraph · SHA-256 6705bb2cdbb8adcccf91f18d10b10bc3cee51e0859070e1fa6c5cd0b53fdfc84
Paired Wren run · 20261122T031115Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
12.1 ms
29.5 ms
FlatPPL · normal optimizations
117 ms · 9.68× Wren
24.6 ms · 0.834× Wren
FlatPPL · equal work
120 ms · 9.91× Wren
21.5 ms · 0.73× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261122T025805Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
8.35 ms
34.2 ms
FlatPPL · normal optimizations
119 ms · 14.3× Wren
26.9 ms · 0.787× Wren
FlatPPL · equal work
111 ms · 13.3× Wren
22 ms · 0.643× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
15.4 ms
49.2 ms
FlatPPL · normal optimizations
124 ms · 8.07× Wren
22.4 ms · 0.456× Wren
FlatPPL · equal work
114 ms · 7.42× Wren
25.2 ms · 0.513× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
10.4 ms
28.9 ms
FlatPPL · normal optimizations
120 ms · 11.5× Wren
35.5 ms · 1.23× Wren
FlatPPL · equal work
193 ms · 18.6× Wren
34.9 ms · 1.21× Wren
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
16.2 ms
70.4 ms
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function lda_k5(w, doc, M, alpha, beta)
theta = zeros(5, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(alpha)
end
# Named sites allow callers to provide an explicit unconstrained start for
# the 1495-word simplices; a sparse prior draw can fail Plaice's inverse
# simplex transform after floating-point rounding.
phi1 ~ WD.Dirichlet(beta)
phi2 ~ WD.Dirichlet(beta)
phi3 ~ WD.Dirichlet(beta)
phi4 ~ WD.Dirichlet(beta)
phi5 ~ WD.Dirichlet(beta)
@addloglikelihood lda_logdensity(w, doc, theta,
(phi1, phi2, phi3, phi4, phi5))
return nothing
end
Gradient reference · BridgeStan 2.9.0 · log simplex, from original Stan unconstrained gradient at the frozen points · simplex-oracles/prideprejudice_paragraph-ldaK5.json · SHA-256 23c0b0bfafca53f24cb819d57c91b6307dbbec3726e77c44b8b64e80f0499613
FlatPPL model-space gradient value versus density · maximum absolute difference 0.0
FlatPPL unconstrained gradient value versus density · maximum absolute difference 0.0
@model function pdb_logistic_regression_rhs(
n, d, y, x, scale_icept, scale_global, nu_global, nu_local, slab_scale, slab_df
)
x = x.value
beta0 ~ Normal(0.0, scale_icept)
z ~ product_distribution(Fill(Normal(), d))
tau ~ truncated(LocationScale(0.0, 2.0scale_global, TDist(nu_global)); lower=0.0)
lambda ~ product_distribution(
Fill(truncated(LocationScale(0.0, 1.0, TDist(nu_local)); lower=0.0), d)
)
caux ~ InverseGamma(0.5slab_df, 0.5slab_df)
c2 = slab_scale^2 * caux
tau2 = tau^2
beta = tau .* z .* lambda .* sqrt.(c2 ./ (c2 .+ tau2 .* abs2.(lambda)))
logits = beta0 .+ x * beta
DynamicPPL.@addlogprob! dot(y, logits) - sum(log1pexp.(logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
70.2 μs · 8 calls
130 μs · 4 calls
76.9 μs
123 μs
20261122T002521Z-565231f-registered-repeat-1
Off
71.5 μs · 8 calls
141 μs · 4 calls
76.3 μs
131 μs
20261122T002521Z-565231f
On · no reduction
70.2 μs · 8 calls
130 μs · 4 calls
76.9 μs
123 μs
20261122T002521Z-565231f
Off
71.5 μs · 8 calls
141 μs · 4 calls
76.3 μs
131 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
82.3 μs · 4 calls
146 μs · 4 calls
88 μs
129 μs
20261122T000034Z-565231f-registered-repeat-1
Off
83.8 μs · 4 calls
186 μs · 4 calls
79 μs
121 μs
20261122T000034Z-565231f
On · no reduction
82.3 μs · 4 calls
146 μs · 4 calls
88 μs
129 μs
20261122T000034Z-565231f
Off
83.8 μs · 4 calls
186 μs · 4 calls
79 μs
121 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
158 μs · 5 calls
72.2 μs
124 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
129 μs · 4 calls
74.9 μs
125 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
158 μs · 5 calls
72.2 μs
124 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
129 μs · 4 calls
74.9 μs
125 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 73.2 μs · value and gradient 135 μs
PosteriorDB model logistic_regression_rhs · dataset prostate · SHA-256 f07fc94620e5fd651774915f14d97175395cef112dc3d5f83837f5ed2491ddfc
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
116 μs
414 μs
FlatPPL · normal optimizations
76.9 μs · 0.66× Wren
123 μs · 0.297× Wren
FlatPPL · equal work
76.3 μs · 0.655× Wren
131 μs · 0.317× Wren
Wren definition in this run
@wren function logistic_rhs(y, x, n, d, scale_icept, scale_global,
nu_global, nu_local, slab_scale, slab_df)
beta0 ~ WD.Normal(0.0, scale_icept)
@iid z ~ WD.Normal(0.0, 1.0) size=d
tau ~ WD.HalfTDist(nu_global, 0.0, 2 * scale_global)
@iid lambda ~ WD.HalfTDist(nu_local, 0.0, 1.0) size=d
caux ~ WD.InverseGamma(0.5 * slab_df, 0.5 * slab_df)
c2 = slab_scale^2 * caux
beta = Vector{typeof(beta0 + tau + caux + z[1] + lambda[1])}(undef, d)
for j in eachindex(z)
lambda_j = lambda[j]
beta[j] = z[j] * tau * sqrt(c2 * lambda_j^2 /
(c2 + tau^2 * lambda_j^2))
end
eta = beta0 .+ x * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
117 μs
331 μs
FlatPPL · normal optimizations
88 μs · 0.753× Wren
129 μs · 0.39× Wren
FlatPPL · equal work
79 μs · 0.676× Wren
121 μs · 0.365× Wren
Wren definition in this run
@wren function logistic_rhs(y, x, n, d, scale_icept, scale_global,
nu_global, nu_local, slab_scale, slab_df)
beta0 ~ WD.Normal(0.0, scale_icept)
@iid z ~ WD.Normal(0.0, 1.0) size=d
tau ~ WD.HalfTDist(nu_global, 0.0, 2 * scale_global)
@iid lambda ~ WD.HalfTDist(nu_local, 0.0, 1.0) size=d
caux ~ WD.InverseGamma(0.5 * slab_df, 0.5 * slab_df)
c2 = slab_scale^2 * caux
beta = Vector{typeof(beta0 + tau + caux + z[1] + lambda[1])}(undef, d)
for j in eachindex(z)
lambda_j = lambda[j]
beta[j] = z[j] * tau * sqrt(c2 * lambda_j^2 /
(c2 + tau^2 * lambda_j^2))
end
eta = beta0 .+ x * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
120 μs
414 μs
FlatPPL · normal optimizations
72.2 μs · 0.6× Wren
124 μs · 0.298× Wren
FlatPPL · equal work
74.9 μs · 0.622× Wren
125 μs · 0.301× Wren
Wren definition in this run
@wren function logistic_rhs(y, x, n, d, scale_icept, scale_global,
nu_global, nu_local, slab_scale, slab_df)
beta0 ~ WD.Normal(0.0, scale_icept)
@iid z ~ WD.Normal(0.0, 1.0) size=d
tau ~ WD.HalfTDist(nu_global, 0.0, 2 * scale_global)
@iid lambda ~ WD.HalfTDist(nu_local, 0.0, 1.0) size=d
caux ~ WD.InverseGamma(0.5 * slab_df, 0.5 * slab_df)
c2 = slab_scale^2 * caux
beta = Vector{typeof(beta0 + tau + caux + z[1] + lambda[1])}(undef, d)
for j in eachindex(z)
lambda_j = lambda[j]
beta[j] = z[j] * tau * sqrt(c2 * lambda_j^2 /
(c2 + tau^2 * lambda_j^2))
end
eta = beta0 .+ x * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.BernoulliLogit(eta[i])
end
return nothing
end
@model function pdb_radon_county_intercept(N, J, county_idx, floor_measure, log_radon)
alpha ~ product_distribution(Fill(Normal(0, 10), J))
beta ~ Normal(0, 10)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
for n in 1:N
mu = alpha[county_idx[n]] + beta * floor_measure[n]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
7.97 μs · 116 calls
40.9 μs · 4 calls
12.9 μs
36.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
8.27 μs · 80 calls
37.2 μs · 20 calls
13.3 μs
38.4 μs
20261122T002521Z-565231f
On · no reduction
7.97 μs · 116 calls
40.9 μs · 4 calls
12.9 μs
36.6 μs
20261122T002521Z-565231f
Off
8.27 μs · 80 calls
37.2 μs · 20 calls
13.3 μs
38.4 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
8.88 μs · 92 calls
46.4 μs · 4 calls
15.5 μs
39.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
8.91 μs · 16 calls
54 μs · 4 calls
12.7 μs
54.4 μs
20261122T000034Z-565231f
On · no reduction
8.88 μs · 92 calls
46.4 μs · 4 calls
15.5 μs
39.6 μs
20261122T000034Z-565231f
Off
8.91 μs · 16 calls
54 μs · 4 calls
12.7 μs
54.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
34.5 μs · 22 calls
11.4 μs
33.7 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
34.1 μs · 24 calls
11.8 μs
33.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
34.5 μs · 22 calls
11.4 μs
33.7 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
34.1 μs · 24 calls
11.8 μs
33.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 16.6 μs · value and gradient 41.1 μs
PosteriorDB model radon_county_intercept · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
18.4 μs
50.7 μs
FlatPPL · normal optimizations
12.9 μs · 0.701× Wren
36.6 μs · 0.722× Wren
FlatPPL · equal work
13.3 μs · 0.723× Wren
38.4 μs · 0.756× Wren
Wren definition in this run
@wren function radon_county_intercept(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Normal(0.0, 10.0) size=J
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
12.8 μs
42.7 μs
FlatPPL · normal optimizations
15.5 μs · 1.21× Wren
39.6 μs · 0.928× Wren
FlatPPL · equal work
12.7 μs · 0.996× Wren
54.4 μs · 1.27× Wren
Wren definition in this run
@wren function radon_county_intercept(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Normal(0.0, 10.0) size=J
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
19.2 μs
55.6 μs
FlatPPL · normal optimizations
11.4 μs · 0.59× Wren
33.7 μs · 0.605× Wren
FlatPPL · equal work
11.8 μs · 0.613× Wren
33.5 μs · 0.603× Wren
Wren definition in this run
@wren function radon_county_intercept(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Normal(0.0, 10.0) size=J
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_hierarchical_intercept_centered(
J, N, county_idx, log_uppm, floor_measure, log_radon
)
alpha ~ product_distribution(Fill(Flat(), J))
beta ~ product_distribution(Fill(Normal(0, 10), 2))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
for n in 1:N
muj = alpha[county_idx[n]] + log_uppm[n] * beta[1]
mu = muj + floor_measure[n] * beta[2]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
9.08 μs · 72 calls
37 μs · 24 calls
16.8 μs
38.9 μs
20261122T002521Z-565231f-registered-repeat-1
Off
8.94 μs · 104 calls
39.3 μs · 24 calls
16.7 μs
43.2 μs
20261122T002521Z-565231f
On · no reduction
9.08 μs · 72 calls
37 μs · 24 calls
16.8 μs
38.9 μs
20261122T002521Z-565231f
Off
8.94 μs · 104 calls
39.3 μs · 24 calls
16.7 μs
43.2 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
11.9 μs · 4 calls
38.5 μs · 16 calls
18.5 μs
52.1 μs
20261122T000034Z-565231f-registered-repeat-1
Off
12.2 μs · 64 calls
48.8 μs · 8 calls
17.1 μs
44.1 μs
20261122T000034Z-565231f
On · no reduction
11.9 μs · 4 calls
38.5 μs · 16 calls
18.5 μs
52.1 μs
20261122T000034Z-565231f
Off
12.2 μs · 64 calls
48.8 μs · 8 calls
17.1 μs
44.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
37.6 μs · 4 calls
13.4 μs
35 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
35.9 μs · 27 calls
12.9 μs
34.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
37.6 μs · 4 calls
13.4 μs
35 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
35.9 μs · 27 calls
12.9 μs
34.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 17.6 μs · value and gradient 49.4 μs
PosteriorDB model radon_hierarchical_intercept_centered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
17.6 μs
63.6 μs
FlatPPL · normal optimizations
16.8 μs · 0.954× Wren
38.9 μs · 0.612× Wren
FlatPPL · equal work
16.7 μs · 0.945× Wren
43.2 μs · 0.68× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_centered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha ~ WD.Flat() size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
14.3 μs
51.9 μs
FlatPPL · normal optimizations
18.5 μs · 1.3× Wren
52.1 μs · 1.0× Wren
FlatPPL · equal work
17.1 μs · 1.2× Wren
44.1 μs · 0.85× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_centered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha ~ WD.Flat() size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
20.9 μs
68.9 μs
FlatPPL · normal optimizations
13.4 μs · 0.641× Wren
35 μs · 0.508× Wren
FlatPPL · equal work
12.9 μs · 0.618× Wren
34.9 μs · 0.507× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_centered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha ~ WD.Flat() size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_hierarchical_intercept_noncentered(
J, N, county_idx, log_uppm, floor_measure, log_radon
)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
beta ~ product_distribution(Fill(Normal(0, 10), 2))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
for n in 1:N
muj = alpha[county_idx[n]] + log_uppm[n] * beta[1]
mu = muj + floor_measure[n] * beta[2]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
13.9 μs · 44 calls
36.4 μs · 24 calls
15.5 μs
39.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
16.9 μs · 4 calls
39.3 μs · 16 calls
13.1 μs
36.9 μs
20261122T002521Z-565231f
On · no reduction
13.9 μs · 44 calls
36.4 μs · 24 calls
15.5 μs
39.5 μs
20261122T002521Z-565231f
Off
16.9 μs · 4 calls
39.3 μs · 16 calls
13.1 μs
36.9 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
13.8 μs · 68 calls
47.6 μs · 16 calls
14.4 μs
38 μs
20261122T000034Z-565231f-registered-repeat-1
Off
17.9 μs · 4 calls
55.4 μs · 4 calls
13.5 μs
36 μs
20261122T000034Z-565231f
On · no reduction
13.8 μs · 68 calls
47.6 μs · 16 calls
14.4 μs
38 μs
20261122T000034Z-565231f
Off
17.9 μs · 4 calls
55.4 μs · 4 calls
13.5 μs
36 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
39.7 μs · 17 calls
12.8 μs
36.9 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
39.8 μs · 15 calls
14.2 μs
35.1 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
39.7 μs · 17 calls
12.8 μs
36.9 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
39.8 μs · 15 calls
14.2 μs
35.1 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 16.8 μs · value and gradient 44.5 μs
PosteriorDB model radon_hierarchical_intercept_noncentered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
20 μs
63.8 μs
FlatPPL · normal optimizations
15.5 μs · 0.776× Wren
39.5 μs · 0.619× Wren
FlatPPL · equal work
13.1 μs · 0.656× Wren
36.9 μs · 0.578× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_noncentered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
13.7 μs
58.7 μs
FlatPPL · normal optimizations
14.4 μs · 1.05× Wren
38 μs · 0.647× Wren
FlatPPL · equal work
13.5 μs · 0.985× Wren
36 μs · 0.613× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_noncentered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
23.5 μs
74.2 μs
FlatPPL · normal optimizations
12.8 μs · 0.545× Wren
36.9 μs · 0.497× Wren
FlatPPL · equal work
14.2 μs · 0.605× Wren
35.1 μs · 0.473× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_noncentered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_partially_pooled_centered(N, J, county_idx, log_radon)
alpha ~ product_distribution(Fill(Flat(), J))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
for n in 1:N
mu = alpha[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
216 μs · 4 calls
27.8 μs · 28 calls
221 μs
38.1 μs
20261122T002521Z-565231f-registered-repeat-1
Off
212 μs · 4 calls
28.5 μs · 28 calls
217 μs
33.6 μs
20261122T002521Z-565231f
On · no reduction
216 μs · 4 calls
27.8 μs · 28 calls
221 μs
38.1 μs
20261122T002521Z-565231f
Off
212 μs · 4 calls
28.5 μs · 28 calls
217 μs
33.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
216 μs · 4 calls
33.5 μs · 28 calls
228 μs
40.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
212 μs · 4 calls
32.8 μs · 4 calls
219 μs
40.5 μs
20261122T000034Z-565231f
On · no reduction
216 μs · 4 calls
33.5 μs · 28 calls
228 μs
40.4 μs
20261122T000034Z-565231f
Off
212 μs · 4 calls
32.8 μs · 4 calls
219 μs
40.5 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
30.9 μs · 28 calls
232 μs
36.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
28.6 μs · 25 calls
224 μs
39 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
30.9 μs · 28 calls
232 μs
36.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
28.6 μs · 25 calls
224 μs
39 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 224 μs · value and gradient 38.1 μs
PosteriorDB model radon_partially_pooled_centered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
11.1 μs
36.4 μs
FlatPPL · normal optimizations
221 μs · 19.9× Wren
38.1 μs · 1.05× Wren
FlatPPL · equal work
217 μs · 19.6× Wren
33.6 μs · 0.924× Wren
Wren definition in this run
@wren function radon_partially_pooled_centered(J, county_idx, log_radon)
@iid alpha ~ WD.Flat() size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.57 μs
30.7 μs
FlatPPL · normal optimizations
228 μs · 23.8× Wren
40.4 μs · 1.31× Wren
FlatPPL · equal work
219 μs · 22.8× Wren
40.5 μs · 1.32× Wren
Wren definition in this run
@wren function radon_partially_pooled_centered(J, county_idx, log_radon)
@iid alpha ~ WD.Flat() size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
11.8 μs
39.7 μs
FlatPPL · normal optimizations
232 μs · 19.7× Wren
36.5 μs · 0.92× Wren
FlatPPL · equal work
224 μs · 19.0× Wren
39 μs · 0.984× Wren
Wren definition in this run
@wren function radon_partially_pooled_centered(J, county_idx, log_radon)
@iid alpha ~ WD.Flat() size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_partially_pooled_noncentered(N, J, county_idx, log_radon)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
for n in 1:N
mu = alpha[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
220 μs · 4 calls
36.1 μs · 20 calls
225 μs
36.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
218 μs · 4 calls
34.1 μs · 20 calls
214 μs
33.9 μs
20261122T002521Z-565231f
On · no reduction
220 μs · 4 calls
36.1 μs · 20 calls
225 μs
36.7 μs
20261122T002521Z-565231f
Off
218 μs · 4 calls
34.1 μs · 20 calls
214 μs
33.9 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
242 μs · 4 calls
39.6 μs · 4 calls
223 μs
39.3 μs
20261122T000034Z-565231f-registered-repeat-1
Off
230 μs · 4 calls
34.2 μs · 24 calls
214 μs
40.3 μs
20261122T000034Z-565231f
On · no reduction
242 μs · 4 calls
39.6 μs · 4 calls
223 μs
39.3 μs
20261122T000034Z-565231f
Off
230 μs · 4 calls
34.2 μs · 24 calls
214 μs
40.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
33.8 μs · 20 calls
215 μs
31.6 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
32.9 μs · 26 calls
210 μs
35.8 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
33.8 μs · 20 calls
215 μs
31.6 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
32.9 μs · 26 calls
210 μs
35.8 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 224 μs · value and gradient 39.5 μs
PosteriorDB model radon_partially_pooled_noncentered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
12.3 μs
36.1 μs
FlatPPL · normal optimizations
225 μs · 18.3× Wren
36.7 μs · 1.02× Wren
FlatPPL · equal work
214 μs · 17.4× Wren
33.9 μs · 0.938× Wren
Wren definition in this run
@wren function radon_partially_pooled_noncentered(J, county_idx, log_radon)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
11.3 μs
34.1 μs
FlatPPL · normal optimizations
223 μs · 19.8× Wren
39.3 μs · 1.15× Wren
FlatPPL · equal work
214 μs · 19.0× Wren
40.3 μs · 1.18× Wren
Wren definition in this run
@wren function radon_partially_pooled_noncentered(J, county_idx, log_radon)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
12.4 μs
37.2 μs
FlatPPL · normal optimizations
215 μs · 17.3× Wren
31.6 μs · 0.848× Wren
FlatPPL · equal work
210 μs · 16.9× Wren
35.8 μs · 0.961× Wren
Wren definition in this run
@wren function radon_partially_pooled_noncentered(J, county_idx, log_radon)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
4.85 μs · 152 calls
10.1 μs · 76 calls
10.6 μs
16.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
4.8 μs · 132 calls
10.3 μs · 80 calls
7.96 μs
15 μs
20261122T002521Z-565231f
On · no reduction
4.85 μs · 152 calls
10.1 μs · 76 calls
10.6 μs
16.7 μs
20261122T002521Z-565231f
Off
4.8 μs · 132 calls
10.3 μs · 80 calls
7.96 μs
15 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
4.44 μs · 168 calls
11.3 μs · 28 calls
10.7 μs
18.5 μs
20261122T000034Z-565231f-registered-repeat-1
Off
5.47 μs · 168 calls
12.2 μs · 20 calls
9.9 μs
17.3 μs
20261122T000034Z-565231f
On · no reduction
4.44 μs · 168 calls
11.3 μs · 28 calls
10.7 μs
18.5 μs
20261122T000034Z-565231f
Off
5.47 μs · 168 calls
12.2 μs · 20 calls
9.9 μs
17.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
9.63 μs · 71 calls
9.03 μs
15.1 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
9.4 μs · 86 calls
8.09 μs
14.6 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
9.63 μs · 71 calls
9.03 μs
15.1 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
9.4 μs · 86 calls
8.09 μs
14.6 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 10.4 μs · value and gradient 20.1 μs
PosteriorDB model radon_pooled · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
8.83 μs
16.8 μs
FlatPPL · normal optimizations
10.6 μs · 1.2× Wren
16.7 μs · 0.991× Wren
FlatPPL · equal work
7.96 μs · 0.901× Wren
15 μs · 0.891× Wren
Wren definition in this run
@wren function radon_pooled_model(log_radon, floor_measure)
alpha ~ WD.Normal(0.0, 10.0)
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
7.65 μs
14 μs
FlatPPL · normal optimizations
10.7 μs · 1.4× Wren
18.5 μs · 1.33× Wren
FlatPPL · equal work
9.9 μs · 1.29× Wren
17.3 μs · 1.24× Wren
Wren definition in this run
@wren function radon_pooled_model(log_radon, floor_measure)
alpha ~ WD.Normal(0.0, 10.0)
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
10.4 μs
18.3 μs
FlatPPL · normal optimizations
9.03 μs · 0.867× Wren
15.1 μs · 0.824× Wren
FlatPPL · equal work
8.09 μs · 0.776× Wren
14.6 μs · 0.796× Wren
Wren definition in this run
@wren function radon_pooled_model(log_radon, floor_measure)
alpha ~ WD.Normal(0.0, 10.0)
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_intercept_centered(
J, N, county_idx, floor_measure, log_radon
)
alpha ~ product_distribution(Fill(Flat(), J))
beta ~ Normal(0, 10)
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
8.88 μs · 80 calls
36.6 μs · 16 calls
13.7 μs
44.1 μs
20261122T002521Z-565231f-registered-repeat-1
Off
8.25 μs · 88 calls
36.7 μs · 16 calls
16.2 μs
40.3 μs
20261122T002521Z-565231f
On · no reduction
8.88 μs · 80 calls
36.6 μs · 16 calls
13.7 μs
44.1 μs
20261122T002521Z-565231f
Off
8.25 μs · 88 calls
36.7 μs · 16 calls
16.2 μs
40.3 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
8.54 μs · 40 calls
38.4 μs · 16 calls
15.8 μs
55.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
8.74 μs · 72 calls
37.2 μs · 12 calls
16.9 μs
55.6 μs
20261122T000034Z-565231f
On · no reduction
8.54 μs · 40 calls
38.4 μs · 16 calls
15.8 μs
55.9 μs
20261122T000034Z-565231f
Off
8.74 μs · 72 calls
37.2 μs · 12 calls
16.9 μs
55.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
38.9 μs · 18 calls
15.5 μs
41.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
41.5 μs · 8 calls
16.3 μs
43.1 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
38.9 μs · 18 calls
15.5 μs
41.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
41.5 μs · 8 calls
16.3 μs
43.1 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 16.1 μs · value and gradient 43.2 μs
PosteriorDB model radon_variable_intercept_centered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
18.3 μs
46.7 μs
FlatPPL · normal optimizations
13.7 μs · 0.745× Wren
44.1 μs · 0.945× Wren
FlatPPL · equal work
16.2 μs · 0.883× Wren
40.3 μs · 0.862× Wren
Wren definition in this run
@wren function radon_variable_intercept_centered(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Flat() size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
16.2 μs
46.7 μs
FlatPPL · normal optimizations
15.8 μs · 0.979× Wren
55.9 μs · 1.2× Wren
FlatPPL · equal work
16.9 μs · 1.05× Wren
55.6 μs · 1.19× Wren
Wren definition in this run
@wren function radon_variable_intercept_centered(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Flat() size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
21.1 μs
55.8 μs
FlatPPL · normal optimizations
15.5 μs · 0.736× Wren
41.8 μs · 0.749× Wren
FlatPPL · equal work
16.3 μs · 0.772× Wren
43.1 μs · 0.772× Wren
Wren definition in this run
@wren function radon_variable_intercept_centered(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Flat() size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_intercept_noncentered(
J, N, county_idx, floor_measure, log_radon
)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
beta ~ Normal(0, 10)
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
13.5 μs · 44 calls
35.9 μs · 20 calls
12.4 μs
34.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
14.2 μs · 72 calls
36.2 μs · 16 calls
11.9 μs
41.2 μs
20261122T002521Z-565231f
On · no reduction
13.5 μs · 44 calls
35.9 μs · 20 calls
12.4 μs
34.2 μs
20261122T002521Z-565231f
Off
14.2 μs · 72 calls
36.2 μs · 16 calls
11.9 μs
41.2 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
15.9 μs · 24 calls
38.4 μs · 24 calls
16.4 μs
45.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
15.3 μs · 60 calls
52 μs · 16 calls
16.4 μs
52.1 μs
20261122T000034Z-565231f
On · no reduction
15.9 μs · 24 calls
38.4 μs · 24 calls
16.4 μs
45.8 μs
20261122T000034Z-565231f
Off
15.3 μs · 60 calls
52 μs · 16 calls
16.4 μs
52.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
42.1 μs · 4 calls
12.3 μs
37.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
41 μs · 4 calls
12.7 μs
40 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
42.1 μs · 4 calls
12.3 μs
37.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
41 μs · 4 calls
12.7 μs
40 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 15.2 μs · value and gradient 53.5 μs
PosteriorDB model radon_variable_intercept_noncentered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
18.8 μs
48.9 μs
FlatPPL · normal optimizations
12.4 μs · 0.656× Wren
34.2 μs · 0.701× Wren
FlatPPL · equal work
11.9 μs · 0.632× Wren
41.2 μs · 0.842× Wren
Wren definition in this run
@wren function radon_variable_intercept_noncentered(
J, county_idx, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ floor_measure .* beta
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
16.4 μs
48.3 μs
FlatPPL · normal optimizations
16.4 μs · 1.0× Wren
45.8 μs · 0.948× Wren
FlatPPL · equal work
16.4 μs · 1.0× Wren
52.1 μs · 1.08× Wren
Wren definition in this run
@wren function radon_variable_intercept_noncentered(
J, county_idx, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ floor_measure .* beta
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
21.1 μs
62.2 μs
FlatPPL · normal optimizations
12.3 μs · 0.585× Wren
37.5 μs · 0.604× Wren
FlatPPL · equal work
12.7 μs · 0.604× Wren
40 μs · 0.643× Wren
Wren definition in this run
@wren function radon_variable_intercept_noncentered(
J, county_idx, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ floor_measure .* beta
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_intercept_slope_centered(
J, N, county_idx, floor_measure, log_radon
)
sigma_y ~ FlatPos(0)
sigma_alpha ~ FlatPos(0)
sigma_beta ~ FlatPos(0)
alpha ~ product_distribution(Fill(Flat(), J))
beta ~ product_distribution(Fill(Flat(), J))
mu_alpha ~ Normal(0, 10)
mu_beta ~ Normal(0, 10)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_beta, sigma_beta), size(beta))), beta
)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
262 μs · 4 calls
58.9 μs · 12 calls
280 μs
55.3 μs
20261122T002521Z-565231f-registered-repeat-1
Off
298 μs · 4 calls
61.6 μs · 12 calls
260 μs
56.2 μs
20261122T002521Z-565231f
On · no reduction
262 μs · 4 calls
58.9 μs · 12 calls
280 μs
55.3 μs
20261122T002521Z-565231f
Off
298 μs · 4 calls
61.6 μs · 12 calls
260 μs
56.2 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
348 μs · 4 calls
71.7 μs · 8 calls
275 μs
60.5 μs
20261122T000034Z-565231f-registered-repeat-1
Off
285 μs · 4 calls
76.8 μs · 4 calls
273 μs
64 μs
20261122T000034Z-565231f
On · no reduction
348 μs · 4 calls
71.7 μs · 8 calls
275 μs
60.5 μs
20261122T000034Z-565231f
Off
285 μs · 4 calls
76.8 μs · 4 calls
273 μs
64 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
60.8 μs · 10 calls
268 μs
62.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
55.7 μs · 13 calls
272 μs
62.6 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
60.8 μs · 10 calls
268 μs
62.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
55.7 μs · 13 calls
272 μs
62.6 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 285 μs · value and gradient 60.1 μs
PosteriorDB model radon_variable_intercept_slope_centered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_radon_variable_intercept_slope_noncentered(
J, N, county_idx, floor_measure, log_radon
)
sigma_y ~ FlatPos(0)
sigma_alpha ~ FlatPos(0)
sigma_beta ~ FlatPos(0)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
beta_raw ~ product_distribution(Fill(Normal(0, 1), J))
mu_alpha ~ Normal(0, 10)
mu_beta ~ Normal(0, 10)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
beta = mu_beta .+ sigma_beta .* beta_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
304 μs · 4 calls
56.1 μs · 8 calls
274 μs
65.4 μs
20261122T002521Z-565231f-registered-repeat-1
Off
286 μs · 4 calls
73.6 μs · 12 calls
270 μs
65.8 μs
20261122T002521Z-565231f
On · no reduction
304 μs · 4 calls
56.1 μs · 8 calls
274 μs
65.4 μs
20261122T002521Z-565231f
Off
286 μs · 4 calls
73.6 μs · 12 calls
270 μs
65.8 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
325 μs · 4 calls
77.6 μs · 4 calls
284 μs
63.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
335 μs · 4 calls
56.7 μs · 8 calls
282 μs
63.6 μs
20261122T000034Z-565231f
On · no reduction
325 μs · 4 calls
77.6 μs · 4 calls
284 μs
63.9 μs
20261122T000034Z-565231f
Off
335 μs · 4 calls
56.7 μs · 8 calls
282 μs
63.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
60.9 μs · 10 calls
270 μs
58.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
57.9 μs · 8 calls
286 μs
60.7 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
60.9 μs · 10 calls
270 μs
58.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
57.9 μs · 8 calls
286 μs
60.7 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 280 μs · value and gradient 58.4 μs
PosteriorDB model radon_variable_intercept_slope_noncentered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_radon_variable_slope_centered(
J, N, county_idx, floor_measure, log_radon
)
alpha ~ Normal(0, 10)
beta ~ product_distribution(Fill(Flat(), J))
mu_beta ~ Normal(0, 10)
sigma_beta ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_beta, sigma_beta), size(beta))), beta
)
for n in 1:N
mu = alpha + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
283 μs · 4 calls
39.5 μs · 4 calls
278 μs
36.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
285 μs · 4 calls
38.7 μs · 4 calls
271 μs
40.5 μs
20261122T002521Z-565231f
On · no reduction
283 μs · 4 calls
39.5 μs · 4 calls
278 μs
36.7 μs
20261122T002521Z-565231f
Off
285 μs · 4 calls
38.7 μs · 4 calls
271 μs
40.5 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
314 μs · 4 calls
52.3 μs · 16 calls
280 μs
56.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
290 μs · 4 calls
52.5 μs · 4 calls
291 μs
50.3 μs
20261122T000034Z-565231f
On · no reduction
314 μs · 4 calls
52.3 μs · 16 calls
280 μs
56.4 μs
20261122T000034Z-565231f
Off
290 μs · 4 calls
52.5 μs · 4 calls
291 μs
50.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
40.7 μs · 4 calls
266 μs
38.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
38.8 μs · 25 calls
272 μs
42.1 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
40.7 μs · 4 calls
266 μs
38.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
38.8 μs · 25 calls
272 μs
42.1 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 262 μs · value and gradient 39 μs
PosteriorDB model radon_variable_slope_centered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
16 μs
44.2 μs
FlatPPL · normal optimizations
278 μs · 17.3× Wren
36.7 μs · 0.83× Wren
FlatPPL · equal work
271 μs · 16.9× Wren
40.5 μs · 0.916× Wren
Wren definition in this run
@wren function radon_variable_slope_centered(J, county_idx, floor_measure, log_radon)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Flat() size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid beta ~ WD.Normal(mu_beta, sigma_beta) size=J
mu = alpha .+ beta[county_idx] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
13.1 μs
39.5 μs
FlatPPL · normal optimizations
280 μs · 21.4× Wren
56.4 μs · 1.43× Wren
FlatPPL · equal work
291 μs · 22.2× Wren
50.3 μs · 1.27× Wren
Wren definition in this run
@wren function radon_variable_slope_centered(J, county_idx, floor_measure, log_radon)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Flat() size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid beta ~ WD.Normal(mu_beta, sigma_beta) size=J
mu = alpha .+ beta[county_idx] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
22.3 μs
59.6 μs
FlatPPL · normal optimizations
266 μs · 11.9× Wren
38.8 μs · 0.65× Wren
FlatPPL · equal work
272 μs · 12.2× Wren
42.1 μs · 0.706× Wren
Wren definition in this run
@wren function radon_variable_slope_centered(J, county_idx, floor_measure, log_radon)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Flat() size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid beta ~ WD.Normal(mu_beta, sigma_beta) size=J
mu = alpha .+ beta[county_idx] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_slope_noncentered(
J, N, county_idx, floor_measure, log_radon
)
alpha ~ Normal(0, 10)
beta_raw ~ product_distribution(Fill(Normal(0, 1), J))
mu_beta ~ Normal(0, 10)
sigma_beta ~ FlatPos(0)
sigma_y ~ FlatPos(0)
beta = mu_beta .+ sigma_beta .* beta_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
for n in 1:N
mu = alpha + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
305 μs · 4 calls
35.4 μs · 12 calls
290 μs
41.4 μs
20261122T002521Z-565231f-registered-repeat-1
Off
272 μs · 4 calls
34.6 μs · 20 calls
277 μs
45.1 μs
20261122T002521Z-565231f
On · no reduction
305 μs · 4 calls
35.4 μs · 12 calls
290 μs
41.4 μs
20261122T002521Z-565231f
Off
272 μs · 4 calls
34.6 μs · 20 calls
277 μs
45.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
289 μs · 4 calls
38.4 μs · 4 calls
280 μs
48.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
297 μs · 4 calls
51.4 μs · 16 calls
290 μs
41.2 μs
20261122T000034Z-565231f
On · no reduction
289 μs · 4 calls
38.4 μs · 4 calls
280 μs
48.8 μs
20261122T000034Z-565231f
Off
297 μs · 4 calls
51.4 μs · 16 calls
290 μs
41.2 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
37.9 μs · 13 calls
270 μs
35.6 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
34.8 μs · 16 calls
273 μs
41.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
37.9 μs · 13 calls
270 μs
35.6 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
34.8 μs · 16 calls
273 μs
41.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 265 μs · value and gradient 39.1 μs
PosteriorDB model radon_variable_slope_noncentered · dataset radon_all · SHA-256 05cac39913090df5430e3f769d8eb8d2ee4e6f0a3c5286c9e767f37926d51ffd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
18.7 μs
47.8 μs
FlatPPL · normal optimizations
290 μs · 15.5× Wren
41.4 μs · 0.864× Wren
FlatPPL · equal work
277 μs · 14.8× Wren
45.1 μs · 0.943× Wren
Wren definition in this run
@wren function radon_variable_slope_noncentered(
J, county_idx, floor_measure, log_radon,
)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta_raw ~ WD.Normal(0.0, 1.0) size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
beta = mu_beta .+ sigma_beta .* beta_raw
mu = alpha .+ floor_measure .* beta[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
14.5 μs
44.1 μs
FlatPPL · normal optimizations
280 μs · 19.3× Wren
48.8 μs · 1.11× Wren
FlatPPL · equal work
290 μs · 20.0× Wren
41.2 μs · 0.935× Wren
Wren definition in this run
@wren function radon_variable_slope_noncentered(
J, county_idx, floor_measure, log_radon,
)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta_raw ~ WD.Normal(0.0, 1.0) size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
beta = mu_beta .+ sigma_beta .* beta_raw
mu = alpha .+ floor_measure .* beta[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
20.8 μs
61 μs
FlatPPL · normal optimizations
270 μs · 13.0× Wren
35.6 μs · 0.584× Wren
FlatPPL · equal work
273 μs · 13.2× Wren
41.5 μs · 0.68× Wren
Wren definition in this run
@wren function radon_variable_slope_noncentered(
J, county_idx, floor_measure, log_radon,
)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta_raw ~ WD.Normal(0.0, 1.0) size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
beta = mu_beta .+ sigma_beta .* beta_raw
mu = alpha .+ floor_measure .* beta[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_county_intercept(N, J, county_idx, floor_measure, log_radon)
alpha ~ product_distribution(Fill(Normal(0, 10), J))
beta ~ Normal(0, 10)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
for n in 1:N
mu = alpha[county_idx[n]] + beta * floor_measure[n]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
356 ns · 1140 calls
2.49 μs · 248 calls
4.98 μs
8.09 μs
20261122T002521Z-565231f-registered-repeat-1
Off
353 ns · 1380 calls
2.55 μs · 220 calls
3.49 μs
7.55 μs
20261122T002521Z-565231f
On · no reduction
356 ns · 1140 calls
2.49 μs · 248 calls
4.98 μs
8.09 μs
20261122T002521Z-565231f
Off
353 ns · 1380 calls
2.55 μs · 220 calls
3.49 μs
7.55 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
379 ns · 472 calls
3.62 μs · 240 calls
5.17 μs
9.59 μs
20261122T000034Z-565231f-registered-repeat-1
Off
363 ns · 1124 calls
2.64 μs · 240 calls
8.33 μs
10.4 μs
20261122T000034Z-565231f
On · no reduction
379 ns · 472 calls
3.62 μs · 240 calls
5.17 μs
9.59 μs
20261122T000034Z-565231f
Off
363 ns · 1124 calls
2.64 μs · 240 calls
8.33 μs
10.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
3.04 μs · 27 calls
4.77 μs
7.59 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
3.45 μs · 159 calls
3.49 μs
8.54 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
3.04 μs · 27 calls
4.77 μs
7.59 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
3.45 μs · 159 calls
3.49 μs
8.54 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.49 μs · value and gradient 9.88 μs
PosteriorDB model radon_county_intercept · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.09 μs
3.08 μs
FlatPPL · normal optimizations
4.98 μs · 4.57× Wren
8.09 μs · 2.63× Wren
FlatPPL · equal work
3.49 μs · 3.2× Wren
7.55 μs · 2.45× Wren
Wren definition in this run
@wren function radon_county_intercept(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Normal(0.0, 10.0) size=J
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.3 μs
2.78 μs
FlatPPL · normal optimizations
5.17 μs · 3.99× Wren
9.59 μs · 3.45× Wren
FlatPPL · equal work
8.33 μs · 6.43× Wren
10.4 μs · 3.75× Wren
Wren definition in this run
@wren function radon_county_intercept(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Normal(0.0, 10.0) size=J
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.59 μs
3.89 μs
FlatPPL · normal optimizations
4.77 μs · 3.0× Wren
7.59 μs · 1.95× Wren
FlatPPL · equal work
3.49 μs · 2.19× Wren
8.54 μs · 2.2× Wren
Wren definition in this run
@wren function radon_county_intercept(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Normal(0.0, 10.0) size=J
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_hierarchical_intercept_centered(
J, N, county_idx, log_uppm, floor_measure, log_radon
)
alpha ~ product_distribution(Fill(Flat(), J))
beta ~ product_distribution(Fill(Normal(0, 10), 2))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
for n in 1:N
muj = alpha[county_idx[n]] + log_uppm[n] * beta[1]
mu = muj + floor_measure[n] * beta[2]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
422 ns · 1064 calls
2.97 μs · 212 calls
5.45 μs
10.4 μs
20261122T002521Z-565231f-registered-repeat-1
Off
433 ns · 1188 calls
2.84 μs · 260 calls
4.98 μs
9.7 μs
20261122T002521Z-565231f
On · no reduction
422 ns · 1064 calls
2.97 μs · 212 calls
5.45 μs
10.4 μs
20261122T002521Z-565231f
Off
433 ns · 1188 calls
2.84 μs · 260 calls
4.98 μs
9.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
405 ns · 880 calls
3.15 μs · 220 calls
8.46 μs
11.5 μs
20261122T000034Z-565231f-registered-repeat-1
Off
417 ns · 876 calls
4.38 μs · 192 calls
4.82 μs
10.7 μs
20261122T000034Z-565231f
On · no reduction
405 ns · 880 calls
3.15 μs · 220 calls
8.46 μs
11.5 μs
20261122T000034Z-565231f
Off
417 ns · 876 calls
4.38 μs · 192 calls
4.82 μs
10.7 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
5.71 μs · 4 calls
4.59 μs
9.95 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
3.07 μs · 163 calls
4.56 μs
10.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
5.71 μs · 4 calls
4.59 μs
9.95 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
3.07 μs · 163 calls
4.56 μs
10.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.78 μs · value and gradient 10.4 μs
PosteriorDB model radon_hierarchical_intercept_centered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.3 μs
3.91 μs
FlatPPL · normal optimizations
5.45 μs · 4.19× Wren
10.4 μs · 2.66× Wren
FlatPPL · equal work
4.98 μs · 3.83× Wren
9.7 μs · 2.48× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_centered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha ~ WD.Flat() size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.06 μs
3.96 μs
FlatPPL · normal optimizations
8.46 μs · 8.01× Wren
11.5 μs · 2.9× Wren
FlatPPL · equal work
4.82 μs · 4.56× Wren
10.7 μs · 2.69× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_centered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha ~ WD.Flat() size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.33 μs
3.94 μs
FlatPPL · normal optimizations
4.59 μs · 3.45× Wren
9.95 μs · 2.52× Wren
FlatPPL · equal work
4.56 μs · 3.43× Wren
10.9 μs · 2.77× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_centered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha ~ WD.Flat() size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_hierarchical_intercept_noncentered(
J, N, county_idx, log_uppm, floor_measure, log_radon
)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
beta ~ product_distribution(Fill(Normal(0, 10), 2))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
for n in 1:N
muj = alpha[county_idx[n]] + log_uppm[n] * beta[1]
mu = muj + floor_measure[n] * beta[2]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
427 ns · 1084 calls
2.75 μs · 156 calls
4.51 μs
8.41 μs
20261122T002521Z-565231f-registered-repeat-1
Off
460 ns · 1188 calls
2.96 μs · 328 calls
4.55 μs
10 μs
20261122T002521Z-565231f
On · no reduction
427 ns · 1084 calls
2.75 μs · 156 calls
4.51 μs
8.41 μs
20261122T002521Z-565231f
Off
460 ns · 1188 calls
2.96 μs · 328 calls
4.55 μs
10 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
419 ns · 920 calls
2.86 μs · 208 calls
9.19 μs
12.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
458 ns · 1344 calls
3.82 μs · 232 calls
8.94 μs
10.7 μs
20261122T000034Z-565231f
On · no reduction
419 ns · 920 calls
2.86 μs · 208 calls
9.19 μs
12.8 μs
20261122T000034Z-565231f
Off
458 ns · 1344 calls
3.82 μs · 232 calls
8.94 μs
10.7 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
3.09 μs · 219 calls
5.17 μs
10.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.8 μs · 170 calls
4.05 μs
9.25 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
3.09 μs · 219 calls
5.17 μs
10.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.8 μs · 170 calls
4.05 μs
9.25 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 9.99 μs · value and gradient 10.7 μs
PosteriorDB model radon_hierarchical_intercept_noncentered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.4 μs
4.28 μs
FlatPPL · normal optimizations
4.51 μs · 3.23× Wren
8.41 μs · 1.97× Wren
FlatPPL · equal work
4.55 μs · 3.26× Wren
10 μs · 2.34× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_noncentered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.24 μs
4.04 μs
FlatPPL · normal optimizations
9.19 μs · 7.42× Wren
12.8 μs · 3.16× Wren
FlatPPL · equal work
8.94 μs · 7.22× Wren
10.7 μs · 2.65× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_noncentered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.59 μs
5.61 μs
FlatPPL · normal optimizations
5.17 μs · 3.25× Wren
10.3 μs · 1.84× Wren
FlatPPL · equal work
4.05 μs · 2.55× Wren
9.25 μs · 1.65× Wren
Wren definition in this run
@wren function radon_hierarchical_intercept_noncentered(
J, county_idx, log_uppm, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
@iid beta ~ WD.Normal(0.0, 10.0) size=2
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ beta[1] .* log_uppm .+ beta[2] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_partially_pooled_centered(N, J, county_idx, log_radon)
alpha ~ product_distribution(Fill(Flat(), J))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
for n in 1:N
mu = alpha[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
357 ns · 1040 calls
2.21 μs · 340 calls
5.13 μs
9.02 μs
20261122T002521Z-565231f-registered-repeat-1
Off
351 ns · 1396 calls
2.17 μs · 420 calls
3.72 μs
8.7 μs
20261122T002521Z-565231f
On · no reduction
357 ns · 1040 calls
2.21 μs · 340 calls
5.13 μs
9.02 μs
20261122T002521Z-565231f
Off
351 ns · 1396 calls
2.17 μs · 420 calls
3.72 μs
8.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
374 ns · 764 calls
2.48 μs · 292 calls
9.37 μs
10.7 μs
20261122T000034Z-565231f-registered-repeat-1
Off
382 ns · 1164 calls
2.87 μs · 240 calls
9.05 μs
9.86 μs
20261122T000034Z-565231f
On · no reduction
374 ns · 764 calls
2.48 μs · 292 calls
9.37 μs
10.7 μs
20261122T000034Z-565231f
Off
382 ns · 1164 calls
2.87 μs · 240 calls
9.05 μs
9.86 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.18 μs · 247 calls
3.74 μs
8.53 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.18 μs · 226 calls
3.6 μs
8.35 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.18 μs · 247 calls
3.74 μs
8.53 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.18 μs · 226 calls
3.6 μs
8.35 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.83 μs · value and gradient 10.1 μs
PosteriorDB model radon_partially_pooled_centered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
811 ns
2.3 μs
FlatPPL · normal optimizations
5.13 μs · 6.32× Wren
9.02 μs · 3.92× Wren
FlatPPL · equal work
3.72 μs · 4.59× Wren
8.7 μs · 3.78× Wren
Wren definition in this run
@wren function radon_partially_pooled_centered(J, county_idx, log_radon)
@iid alpha ~ WD.Flat() size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
800 ns
2.35 μs
FlatPPL · normal optimizations
9.37 μs · 11.7× Wren
10.7 μs · 4.54× Wren
FlatPPL · equal work
9.05 μs · 11.3× Wren
9.86 μs · 4.2× Wren
Wren definition in this run
@wren function radon_partially_pooled_centered(J, county_idx, log_radon)
@iid alpha ~ WD.Flat() size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.15 μs
2.92 μs
FlatPPL · normal optimizations
3.74 μs · 3.25× Wren
8.53 μs · 2.92× Wren
FlatPPL · equal work
3.6 μs · 3.13× Wren
8.35 μs · 2.86× Wren
Wren definition in this run
@wren function radon_partially_pooled_centered(J, county_idx, log_radon)
@iid alpha ~ WD.Flat() size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_partially_pooled_noncentered(N, J, county_idx, log_radon)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
for n in 1:N
mu = alpha[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
364 ns · 776 calls
2.55 μs · 272 calls
3.72 μs
7.87 μs
20261122T002521Z-565231f-registered-repeat-1
Off
358 ns · 1140 calls
2.52 μs · 368 calls
3.6 μs
7.98 μs
20261122T002521Z-565231f
On · no reduction
364 ns · 776 calls
2.55 μs · 272 calls
3.72 μs
7.87 μs
20261122T002521Z-565231f
Off
358 ns · 1140 calls
2.52 μs · 368 calls
3.6 μs
7.98 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
378 ns · 988 calls
2.78 μs · 220 calls
6.22 μs
13.1 μs
20261122T000034Z-565231f-registered-repeat-1
Off
469 ns · 968 calls
3.45 μs · 256 calls
5.25 μs
8.18 μs
20261122T000034Z-565231f
On · no reduction
378 ns · 988 calls
2.78 μs · 220 calls
6.22 μs
13.1 μs
20261122T000034Z-565231f
Off
469 ns · 968 calls
3.45 μs · 256 calls
5.25 μs
8.18 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.74 μs · 197 calls
3.65 μs
8.99 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.75 μs · 160 calls
3.78 μs
9.45 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.74 μs · 197 calls
3.65 μs
8.99 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.75 μs · 160 calls
3.78 μs
9.45 μs
20261114T233319Z-f022c87
On · reduced
JIT-loop timing not recorded
581 ns · 475 calls
9.59 μs
25.8 μs
20261114T233319Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
3.51 μs
6.67 μs
20261114T225256Z-f022c87
On · reduced
JIT-loop timing not recorded
592 ns · 432 calls
10 μs
28.8 μs
20261114T225256Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
3.71 μs
7.81 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.79 μs · value and gradient 10.3 μs
PosteriorDB model radon_partially_pooled_noncentered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
771 ns
2.9 μs
FlatPPL · normal optimizations
3.72 μs · 4.82× Wren
7.87 μs · 2.71× Wren
FlatPPL · equal work
3.6 μs · 4.67× Wren
7.98 μs · 2.75× Wren
Wren definition in this run
@wren function radon_partially_pooled_noncentered(J, county_idx, log_radon)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
767 ns
2.61 μs
FlatPPL · normal optimizations
6.22 μs · 8.11× Wren
13.1 μs · 5.01× Wren
FlatPPL · equal work
5.25 μs · 6.85× Wren
8.18 μs · 3.13× Wren
Wren definition in this run
@wren function radon_partially_pooled_noncentered(J, county_idx, log_radon)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
834 ns
3.02 μs
FlatPPL · normal optimizations
3.65 μs · 4.38× Wren
8.99 μs · 2.98× Wren
FlatPPL · equal work
3.78 μs · 4.53× Wren
9.45 μs · 3.13× Wren
Wren definition in this run
@wren function radon_partially_pooled_noncentered(J, county_idx, log_radon)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
294 ns · 1800 calls
902 ns · 720 calls
4.23 μs
5.88 μs
20261122T002521Z-565231f-registered-repeat-1
Off
317 ns · 2296 calls
943 ns · 616 calls
3.22 μs
5.51 μs
20261122T002521Z-565231f
On · no reduction
294 ns · 1800 calls
902 ns · 720 calls
4.23 μs
5.88 μs
20261122T002521Z-565231f
Off
317 ns · 2296 calls
943 ns · 616 calls
3.22 μs
5.51 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
323 ns · 560 calls
1.03 μs · 304 calls
4.93 μs
7.14 μs
20261122T000034Z-565231f-registered-repeat-1
Off
312 ns · 1240 calls
934 ns · 640 calls
6.42 μs
6.18 μs
20261122T000034Z-565231f
On · no reduction
323 ns · 560 calls
1.03 μs · 304 calls
4.93 μs
7.14 μs
20261122T000034Z-565231f
Off
312 ns · 1240 calls
934 ns · 640 calls
6.42 μs
6.18 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
913 ns · 427 calls
3.21 μs
6 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
947 ns · 282 calls
3.28 μs
5.68 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
913 ns · 427 calls
3.21 μs
6 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
947 ns · 282 calls
3.28 μs
5.68 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.21 μs · value and gradient 8.35 μs
PosteriorDB model radon_pooled · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
630 ns
1.26 μs
FlatPPL · normal optimizations
4.23 μs · 6.71× Wren
5.88 μs · 4.67× Wren
FlatPPL · equal work
3.22 μs · 5.11× Wren
5.51 μs · 4.38× Wren
Wren definition in this run
@wren function radon_pooled_model(log_radon, floor_measure)
alpha ~ WD.Normal(0.0, 10.0)
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
612 ns
1.76 μs
FlatPPL · normal optimizations
4.93 μs · 8.05× Wren
7.14 μs · 4.06× Wren
FlatPPL · equal work
6.42 μs · 10.5× Wren
6.18 μs · 3.51× Wren
Wren definition in this run
@wren function radon_pooled_model(log_radon, floor_measure)
alpha ~ WD.Normal(0.0, 10.0)
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
627 ns
1.16 μs
FlatPPL · normal optimizations
3.21 μs · 5.12× Wren
6 μs · 5.15× Wren
FlatPPL · equal work
3.28 μs · 5.23× Wren
5.68 μs · 4.88× Wren
Wren definition in this run
@wren function radon_pooled_model(log_radon, floor_measure)
alpha ~ WD.Normal(0.0, 10.0)
beta ~ WD.Normal(0.0, 10.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
mu = alpha .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_intercept_centered(
J, N, county_idx, floor_measure, log_radon
)
alpha ~ product_distribution(Fill(Flat(), J))
beta ~ Normal(0, 10)
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
396 ns · 584 calls
3.1 μs · 216 calls
5.04 μs
14.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
401 ns · 1104 calls
3.21 μs · 188 calls
4.44 μs
14 μs
20261122T002521Z-565231f
On · no reduction
396 ns · 584 calls
3.1 μs · 216 calls
5.04 μs
14.5 μs
20261122T002521Z-565231f
Off
401 ns · 1104 calls
3.21 μs · 188 calls
4.44 μs
14 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
384 ns · 680 calls
3.2 μs · 44 calls
5.19 μs
9.91 μs
20261122T000034Z-565231f-registered-repeat-1
Off
388 ns · 744 calls
5.56 μs · 4 calls
3.98 μs
11.1 μs
20261122T000034Z-565231f
On · no reduction
384 ns · 680 calls
3.2 μs · 44 calls
5.19 μs
9.91 μs
20261122T000034Z-565231f
Off
388 ns · 744 calls
5.56 μs · 4 calls
3.98 μs
11.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
3.04 μs · 142 calls
5.33 μs
10.4 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.99 μs · 151 calls
4.1 μs
9.51 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
3.04 μs · 142 calls
5.33 μs
10.4 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.99 μs · 151 calls
4.1 μs
9.51 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 9.02 μs · value and gradient 15.2 μs
PosteriorDB model radon_variable_intercept_centered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.56 μs
3.88 μs
FlatPPL · normal optimizations
5.04 μs · 3.24× Wren
14.5 μs · 3.74× Wren
FlatPPL · equal work
4.44 μs · 2.86× Wren
14 μs · 3.6× Wren
Wren definition in this run
@wren function radon_variable_intercept_centered(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Flat() size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.28 μs
3.15 μs
FlatPPL · normal optimizations
5.19 μs · 4.05× Wren
9.91 μs · 3.15× Wren
FlatPPL · equal work
3.98 μs · 3.1× Wren
11.1 μs · 3.51× Wren
Wren definition in this run
@wren function radon_variable_intercept_centered(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Flat() size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.64 μs
4.13 μs
FlatPPL · normal optimizations
5.33 μs · 3.25× Wren
10.4 μs · 2.53× Wren
FlatPPL · equal work
4.1 μs · 2.5× Wren
9.51 μs · 2.3× Wren
Wren definition in this run
@wren function radon_variable_intercept_centered(J, county_idx, floor_measure, log_radon)
@iid alpha ~ WD.Flat() size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=J
mu = alpha[county_idx] .+ beta .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_intercept_noncentered(
J, N, county_idx, floor_measure, log_radon
)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
beta ~ Normal(0, 10)
mu_alpha ~ Normal(0, 10)
sigma_alpha ~ FlatPos(0)
sigma_y ~ FlatPos(0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
388 ns · 1576 calls
2.64 μs · 316 calls
5.17 μs
10.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
375 ns · 1768 calls
2.58 μs · 284 calls
4.67 μs
10.1 μs
20261122T002521Z-565231f
On · no reduction
388 ns · 1576 calls
2.64 μs · 316 calls
5.17 μs
10.7 μs
20261122T002521Z-565231f
Off
375 ns · 1768 calls
2.58 μs · 284 calls
4.67 μs
10.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
415 ns · 580 calls
2.89 μs · 52 calls
6.6 μs
13.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
493 ns · 928 calls
2.71 μs · 208 calls
5.03 μs
10.4 μs
20261122T000034Z-565231f
On · no reduction
415 ns · 580 calls
2.89 μs · 52 calls
6.6 μs
13.6 μs
20261122T000034Z-565231f
Off
493 ns · 928 calls
2.71 μs · 208 calls
5.03 μs
10.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.71 μs · 150 calls
3.74 μs
9.43 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.66 μs · 320 calls
3.86 μs
8.59 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.71 μs · 150 calls
3.74 μs
9.43 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.66 μs · 320 calls
3.86 μs
8.59 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.82 μs · value and gradient 13.1 μs
PosteriorDB model radon_variable_intercept_noncentered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.52 μs
3.64 μs
FlatPPL · normal optimizations
5.17 μs · 3.41× Wren
10.7 μs · 2.93× Wren
FlatPPL · equal work
4.67 μs · 3.08× Wren
10.1 μs · 2.79× Wren
Wren definition in this run
@wren function radon_variable_intercept_noncentered(
J, county_idx, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ floor_measure .* beta
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.24 μs
3.03 μs
FlatPPL · normal optimizations
6.6 μs · 5.34× Wren
13.6 μs · 4.48× Wren
FlatPPL · equal work
5.03 μs · 4.07× Wren
10.4 μs · 3.42× Wren
Wren definition in this run
@wren function radon_variable_intercept_noncentered(
J, county_idx, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ floor_measure .* beta
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.59 μs
3.11 μs
FlatPPL · normal optimizations
3.74 μs · 2.35× Wren
9.43 μs · 3.03× Wren
FlatPPL · equal work
3.86 μs · 2.43× Wren
8.59 μs · 2.76× Wren
Wren definition in this run
@wren function radon_variable_intercept_noncentered(
J, county_idx, floor_measure, log_radon,
)
@iid alpha_raw ~ WD.Normal(0.0, 1.0) size=J
beta ~ WD.Normal(0.0, 10.0)
mu_alpha ~ WD.Normal(0.0, 10.0)
sigma_alpha ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
mu = alpha[county_idx] .+ floor_measure .* beta
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_intercept_slope_centered(
J, N, county_idx, floor_measure, log_radon
)
sigma_y ~ FlatPos(0)
sigma_alpha ~ FlatPos(0)
sigma_beta ~ FlatPos(0)
alpha ~ product_distribution(Fill(Flat(), J))
beta ~ product_distribution(Fill(Flat(), J))
mu_alpha ~ Normal(0, 10)
mu_beta ~ Normal(0, 10)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_beta, sigma_beta), size(beta))), beta
)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
489 ns · 1392 calls
4.15 μs · 196 calls
4.99 μs
13.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
484 ns · 1492 calls
4.13 μs · 180 calls
4.32 μs
12.1 μs
20261122T002521Z-565231f
On · no reduction
489 ns · 1392 calls
4.15 μs · 196 calls
4.99 μs
13.2 μs
20261122T002521Z-565231f
Off
484 ns · 1492 calls
4.13 μs · 180 calls
4.32 μs
12.1 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
545 ns · 576 calls
4.26 μs · 96 calls
9.7 μs
12.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
530 ns · 988 calls
4.52 μs · 148 calls
4.55 μs
14.6 μs
20261122T000034Z-565231f
On · no reduction
545 ns · 576 calls
4.26 μs · 96 calls
9.7 μs
12.8 μs
20261122T000034Z-565231f
Off
530 ns · 988 calls
4.52 μs · 148 calls
4.55 μs
14.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
4.25 μs · 149 calls
4.63 μs
12.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
4.13 μs · 155 calls
4.25 μs
11.6 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
4.25 μs · 149 calls
4.63 μs
12.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
4.13 μs · 155 calls
4.25 μs
11.6 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 6.88 μs · value and gradient 12.8 μs
PosteriorDB model radon_variable_intercept_slope_centered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_radon_variable_intercept_slope_noncentered(
J, N, county_idx, floor_measure, log_radon
)
sigma_y ~ FlatPos(0)
sigma_alpha ~ FlatPos(0)
sigma_beta ~ FlatPos(0)
alpha_raw ~ product_distribution(Fill(Normal(0, 1), J))
beta_raw ~ product_distribution(Fill(Normal(0, 1), J))
mu_alpha ~ Normal(0, 10)
mu_beta ~ Normal(0, 10)
alpha = mu_alpha .+ sigma_alpha .* alpha_raw
beta = mu_beta .+ sigma_beta .* beta_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_alpha)
for n in 1:N
mu = alpha[county_idx[n]] + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
512 ns · 1212 calls
3.83 μs · 240 calls
5.66 μs
10.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
496 ns · 1212 calls
3.94 μs · 172 calls
4.35 μs
11 μs
20261122T002521Z-565231f
On · no reduction
512 ns · 1212 calls
3.83 μs · 240 calls
5.66 μs
10.6 μs
20261122T002521Z-565231f
Off
496 ns · 1212 calls
3.94 μs · 172 calls
4.35 μs
11 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
594 ns · 112 calls
4.01 μs · 168 calls
7.34 μs
12.2 μs
20261122T000034Z-565231f-registered-repeat-1
Off
633 ns · 956 calls
5.87 μs · 36 calls
7.05 μs
15 μs
20261122T000034Z-565231f
On · no reduction
594 ns · 112 calls
4.01 μs · 168 calls
7.34 μs
12.2 μs
20261122T000034Z-565231f
Off
633 ns · 956 calls
5.87 μs · 36 calls
7.05 μs
15 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
4 μs · 162 calls
4.69 μs
11.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
4.12 μs · 134 calls
4.26 μs
10.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
4 μs · 162 calls
4.69 μs
11.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
4.12 μs · 134 calls
4.26 μs
10.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 7.05 μs · value and gradient 12.3 μs
PosteriorDB model radon_variable_intercept_slope_noncentered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_radon_variable_slope_centered(
J, N, county_idx, floor_measure, log_radon
)
alpha ~ Normal(0, 10)
beta ~ product_distribution(Fill(Flat(), J))
mu_beta ~ Normal(0, 10)
sigma_beta ~ FlatPos(0)
sigma_y ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_beta, sigma_beta), size(beta))), beta
)
for n in 1:N
mu = alpha + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
378 ns · 1240 calls
3.13 μs · 232 calls
5.18 μs
10.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
400 ns · 712 calls
3.05 μs · 200 calls
4.44 μs
9.46 μs
20261122T002521Z-565231f
On · no reduction
378 ns · 1240 calls
3.13 μs · 232 calls
5.18 μs
10.5 μs
20261122T002521Z-565231f
Off
400 ns · 712 calls
3.05 μs · 200 calls
4.44 μs
9.46 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
476 ns · 1144 calls
3.48 μs · 24 calls
8.87 μs
9.23 μs
20261122T000034Z-565231f-registered-repeat-1
Off
480 ns · 1164 calls
4.17 μs · 216 calls
3.92 μs
11.1 μs
20261122T000034Z-565231f
On · no reduction
476 ns · 1144 calls
3.48 μs · 24 calls
8.87 μs
9.23 μs
20261122T000034Z-565231f
Off
480 ns · 1164 calls
4.17 μs · 216 calls
3.92 μs
11.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
3.33 μs · 26 calls
3.66 μs
8.66 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.98 μs · 96 calls
3.55 μs
8.77 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
3.33 μs · 26 calls
3.66 μs
8.66 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.98 μs · 96 calls
3.55 μs
8.77 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.55 μs · value and gradient 10.7 μs
PosteriorDB model radon_variable_slope_centered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.41 μs
3.5 μs
FlatPPL · normal optimizations
5.18 μs · 3.66× Wren
10.5 μs · 2.99× Wren
FlatPPL · equal work
4.44 μs · 3.14× Wren
9.46 μs · 2.7× Wren
Wren definition in this run
@wren function radon_variable_slope_centered(J, county_idx, floor_measure, log_radon)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Flat() size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid beta ~ WD.Normal(mu_beta, sigma_beta) size=J
mu = alpha .+ beta[county_idx] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.41 μs
3.28 μs
FlatPPL · normal optimizations
8.87 μs · 6.29× Wren
9.23 μs · 2.81× Wren
FlatPPL · equal work
3.92 μs · 2.78× Wren
11.1 μs · 3.38× Wren
Wren definition in this run
@wren function radon_variable_slope_centered(J, county_idx, floor_measure, log_radon)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Flat() size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid beta ~ WD.Normal(mu_beta, sigma_beta) size=J
mu = alpha .+ beta[county_idx] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.42 μs
3.73 μs
FlatPPL · normal optimizations
3.66 μs · 2.59× Wren
8.66 μs · 2.32× Wren
FlatPPL · equal work
3.55 μs · 2.51× Wren
8.77 μs · 2.35× Wren
Wren definition in this run
@wren function radon_variable_slope_centered(J, county_idx, floor_measure, log_radon)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta ~ WD.Flat() size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
@observe @iid beta ~ WD.Normal(mu_beta, sigma_beta) size=J
mu = alpha .+ beta[county_idx] .* floor_measure
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_radon_variable_slope_noncentered(
J, N, county_idx, floor_measure, log_radon
)
alpha ~ Normal(0, 10)
beta_raw ~ product_distribution(Fill(Normal(0, 1), J))
mu_beta ~ Normal(0, 10)
sigma_beta ~ FlatPos(0)
sigma_y ~ FlatPos(0)
beta = mu_beta .+ sigma_beta .* beta_raw
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_y)
DynamicPPL.@addlogprob! logpdf(Normal(0, 1), sigma_beta)
for n in 1:N
mu = alpha + floor_measure[n] * beta[county_idx[n]]
DynamicPPL.@addlogprob! logpdf(Normal(mu, sigma_y), log_radon[n])
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
406 ns · 1112 calls
2.86 μs · 232 calls
5.13 μs
10.8 μs
20261122T002521Z-565231f-registered-repeat-1
Off
408 ns · 1104 calls
2.86 μs · 228 calls
4.42 μs
8.23 μs
20261122T002521Z-565231f
On · no reduction
406 ns · 1112 calls
2.86 μs · 232 calls
5.13 μs
10.8 μs
20261122T002521Z-565231f
Off
408 ns · 1104 calls
2.86 μs · 228 calls
4.42 μs
8.23 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
419 ns · 1164 calls
3.03 μs · 216 calls
5.25 μs
8.71 μs
20261122T000034Z-565231f-registered-repeat-1
Off
392 ns · 716 calls
3.18 μs · 212 calls
3.62 μs
8.78 μs
20261122T000034Z-565231f
On · no reduction
419 ns · 1164 calls
3.03 μs · 216 calls
5.25 μs
8.71 μs
20261122T000034Z-565231f
Off
392 ns · 716 calls
3.18 μs · 212 calls
3.62 μs
8.78 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
2.84 μs · 110 calls
3.66 μs
8.74 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
2.74 μs · 164 calls
3.69 μs
8.21 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
2.84 μs · 110 calls
3.66 μs
8.74 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
2.74 μs · 164 calls
3.69 μs
8.21 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 9.12 μs · value and gradient 11.6 μs
PosteriorDB model radon_variable_slope_noncentered · dataset radon_mn · SHA-256 99c607bdd4e11d2693b27f8fd71d7e79adb6426caf013993b267983fdf598d4f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.46 μs
3.48 μs
FlatPPL · normal optimizations
5.13 μs · 3.53× Wren
10.8 μs · 3.1× Wren
FlatPPL · equal work
4.42 μs · 3.04× Wren
8.23 μs · 2.36× Wren
Wren definition in this run
@wren function radon_variable_slope_noncentered(
J, county_idx, floor_measure, log_radon,
)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta_raw ~ WD.Normal(0.0, 1.0) size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
beta = mu_beta .+ sigma_beta .* beta_raw
mu = alpha .+ floor_measure .* beta[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.27 μs
3.02 μs
FlatPPL · normal optimizations
5.25 μs · 4.13× Wren
8.71 μs · 2.88× Wren
FlatPPL · equal work
3.62 μs · 2.84× Wren
8.78 μs · 2.91× Wren
Wren definition in this run
@wren function radon_variable_slope_noncentered(
J, county_idx, floor_measure, log_radon,
)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta_raw ~ WD.Normal(0.0, 1.0) size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
beta = mu_beta .+ sigma_beta .* beta_raw
mu = alpha .+ floor_measure .* beta[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
1.36 μs
3.71 μs
FlatPPL · normal optimizations
3.66 μs · 2.68× Wren
8.74 μs · 2.36× Wren
FlatPPL · equal work
3.69 μs · 2.7× Wren
8.21 μs · 2.21× Wren
Wren definition in this run
@wren function radon_variable_slope_noncentered(
J, county_idx, floor_measure, log_radon,
)
alpha ~ WD.Normal(0.0, 10.0)
@iid beta_raw ~ WD.Normal(0.0, 1.0) size=J
mu_beta ~ WD.Normal(0.0, 10.0)
sigma_beta ~ WD.HalfNormal(0.0, 1.0)
sigma_y ~ WD.HalfNormal(0.0, 1.0)
beta = mu_beta .+ sigma_beta .* beta_raw
mu = alpha .+ floor_measure .* beta[county_idx]
@batch for i in eachindex(log_radon)
@observe log_radon[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@wren function radon_county(county, y, J)
mu_a ~ WD.Normal(0.0, 1.0)
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_y ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(mu_a, sigma_a) size=J
y_hat = a[county]
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(y_hat[i], sigma_y)
end
return nothing
end
%%%
# Radon by county, national data
PosteriorDB's `radon_mod-radon_county`. Log radon in 12573 homes is Normal
around one mean per county. The 386 county means are Normal around mu_a.
Both scales are uniform on (0, 100). Normalizing those priors adds -2
log(100) to Stan's target.
%%%
flatppl_compat = "0.1"
N = 12573
J = 386
data = load_data("data.json", cartprod(
county = cartpow(posintegers, N), y = cartpow(reals, N)))
mu_a ~ Normal(0, 1)
sigma_a ~ Uniform(interval(0, 100))
sigma_y ~ Uniform(interval(0, 100))
a ~ iid(Normal(mu_a, sigma_a), J)
y ~ Normal.(a[data.county], sigma_y)
Pi_prior = lawof(record(a = a, mu_a = mu_a, sigma_a = sigma_a, sigma_y = sigma_y))
K_model = kernelof(record(y = y), a = a, mu_a = mu_a, sigma_a = sigma_a, sigma_y = sigma_y)
L = likelihoodof(K_model, record(y = data.y))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(a = cartpow(reals, J), mu_a = reals, sigma_a = interval(0, 100),
sigma_y = interval(0, 100))
Pi_post_input = record(a = fill(1.3, J), mu_a = 1.3, sigma_a = 0.5, sigma_y = 0.8)
@model function pdb_radon_county(J, county_design, y)
a ~ product_distribution(Fill(Flat(), J))
mu_a ~ Normal(0.0, 1.0)
sigma_a ~ Uniform(0.0, 100.0)
sigma_y ~ Uniform(0.0, 100.0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_a, sigma_a), size(a))), a
)
prediction = county_design.value * a
return y ~ MvNormal(prediction, sigma_y)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
234 μs · 4 calls
29.7 μs · 12 calls
218 μs
40.1 μs
20261122T002521Z-565231f-registered-repeat-1
Off
229 μs · 4 calls
30.9 μs · 24 calls
217 μs
51.7 μs
20261122T002521Z-565231f
On · no reduction
234 μs · 4 calls
29.7 μs · 12 calls
218 μs
40.1 μs
20261122T002521Z-565231f
Off
229 μs · 4 calls
30.9 μs · 24 calls
217 μs
51.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
244 μs · 4 calls
39.2 μs · 4 calls
225 μs
35 μs
20261122T000034Z-565231f-registered-repeat-1
Off
222 μs · 4 calls
34.6 μs · 24 calls
221 μs
36.2 μs
20261122T000034Z-565231f
On · no reduction
244 μs · 4 calls
39.2 μs · 4 calls
225 μs
35 μs
20261122T000034Z-565231f
Off
222 μs · 4 calls
34.6 μs · 24 calls
221 μs
36.2 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
30 μs · 4 calls
219 μs
37 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
29.3 μs · 4 calls
211 μs
37.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
30 μs · 4 calls
219 μs
37 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
29.3 μs · 4 calls
211 μs
37.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 212 μs · value and gradient 37.4 μs
PosteriorDB model radon_county · dataset radon_mod · SHA-256 9da56b96a78b48d42635173f313a2dd812b613a4231aa4a31f452d0875dcda28
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
11.4 μs
35.5 μs
FlatPPL · normal optimizations
218 μs · 19.1× Wren
40.1 μs · 1.13× Wren
FlatPPL · equal work
217 μs · 19.0× Wren
51.7 μs · 1.46× Wren
Wren definition in this run
@wren function radon_county(county, y, J)
mu_a ~ WD.Normal(0.0, 1.0)
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_y ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(mu_a, sigma_a) size=J
y_hat = a[county]
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(y_hat[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
11.5 μs
34.7 μs
FlatPPL · normal optimizations
225 μs · 19.6× Wren
35 μs · 1.01× Wren
FlatPPL · equal work
221 μs · 19.3× Wren
36.2 μs · 1.04× Wren
Wren definition in this run
@wren function radon_county(county, y, J)
mu_a ~ WD.Normal(0.0, 1.0)
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_y ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(mu_a, sigma_a) size=J
y_hat = a[county]
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(y_hat[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.55 μs
33.7 μs
FlatPPL · normal optimizations
219 μs · 22.9× Wren
37 μs · 1.1× Wren
FlatPPL · equal work
211 μs · 22.1× Wren
37.9 μs · 1.12× Wren
Wren definition in this run
@wren function radon_county(county, y, J)
mu_a ~ WD.Normal(0.0, 1.0)
sigma_a ~ WD.Uniform(0.0, 100.0)
sigma_y ~ WD.Uniform(0.0, 100.0)
@iid a ~ WD.Normal(mu_a, sigma_a) size=J
y_hat = a[county]
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(y_hat[i], sigma_y)
end
return nothing
end
@model function pdb_Rate_1_model(n, k)
theta ~ Beta(1, 1)
return k ~ Binomial(n, theta)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
40 ns · 4592 calls
45 ns · 3600 calls
3.1 μs
4.16 μs
20261122T002521Z-565231f-registered-repeat-1
Off
41 ns · 2968 calls
44.5 ns · 3768 calls
3.07 μs
4.21 μs
20261122T002521Z-565231f
On · no reduction
40 ns · 4592 calls
45 ns · 3600 calls
3.1 μs
4.16 μs
20261122T002521Z-565231f
Off
41 ns · 2968 calls
44.5 ns · 3768 calls
3.07 μs
4.21 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
40.7 ns · 1408 calls
44.2 ns · 3028 calls
2.98 μs
4.08 μs
20261122T000034Z-565231f-registered-repeat-1
Off
38.9 ns · 3972 calls
42.9 ns · 2220 calls
2.91 μs
4.22 μs
20261122T000034Z-565231f
On · no reduction
40.7 ns · 1408 calls
44.2 ns · 3028 calls
2.98 μs
4.08 μs
20261122T000034Z-565231f
Off
38.9 ns · 3972 calls
42.9 ns · 2220 calls
2.91 μs
4.22 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
49.5 ns · 629 calls
2.94 μs
4.15 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
47.9 ns · 880 calls
2.93 μs
4.28 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
49.5 ns · 629 calls
2.94 μs
4.15 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
47.9 ns · 880 calls
2.93 μs
4.28 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.22 μs · value and gradient 4.26 μs
PosteriorDB model Rate_1_model · dataset Rate_1_data · SHA-256 db6733824bf259ffabb002afd0f83aabef29194bb87c465163e6db36e6000a19
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
60.4 ns
128 ns
FlatPPL · normal optimizations
3.1 μs · 51.3× Wren
4.16 μs · 32.5× Wren
FlatPPL · equal work
3.07 μs · 50.8× Wren
4.21 μs · 32.9× Wren
Wren definition in this run
@wren function rate_1_model(k, n)
theta ~ WD.Uniform(0.0, 1.0)
@observe k ~ WD.Binomial(n, theta)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
57.3 ns
123 ns
FlatPPL · normal optimizations
2.98 μs · 52.0× Wren
4.08 μs · 33.3× Wren
FlatPPL · equal work
2.91 μs · 50.8× Wren
4.22 μs · 34.4× Wren
Wren definition in this run
@wren function rate_1_model(k, n)
theta ~ WD.Uniform(0.0, 1.0)
@observe k ~ WD.Binomial(n, theta)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
57.1 ns
121 ns
FlatPPL · normal optimizations
2.94 μs · 51.5× Wren
4.15 μs · 34.2× Wren
FlatPPL · equal work
2.93 μs · 51.3× Wren
4.28 μs · 35.2× Wren
Wren definition in this run
@wren function rate_1_model(k, n)
theta ~ WD.Uniform(0.0, 1.0)
@observe k ~ WD.Binomial(n, theta)
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
70.4 ns · 2108 calls
74.3 ns · 3992 calls
3.11 μs
4.22 μs
20261122T002521Z-565231f-registered-repeat-1
Off
70.7 ns · 2608 calls
72.4 ns · 2648 calls
3 μs
4.38 μs
20261122T002521Z-565231f
On · no reduction
70.4 ns · 2108 calls
74.3 ns · 3992 calls
3.11 μs
4.22 μs
20261122T002521Z-565231f
Off
70.7 ns · 2608 calls
72.4 ns · 2648 calls
3 μs
4.38 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
69.9 ns · 3140 calls
70.5 ns · 4216 calls
2.96 μs
4.21 μs
20261122T000034Z-565231f-registered-repeat-1
Off
67 ns · 6056 calls
71.2 ns · 3860 calls
2.95 μs
4.37 μs
20261122T000034Z-565231f
On · no reduction
69.9 ns · 3140 calls
70.5 ns · 4216 calls
2.96 μs
4.21 μs
20261122T000034Z-565231f
Off
67 ns · 6056 calls
71.2 ns · 3860 calls
2.95 μs
4.37 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
76.1 ns · 659 calls
2.95 μs
4.21 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
85.3 ns · 338 calls
2.97 μs
4.05 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
76.1 ns · 659 calls
2.95 μs
4.21 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
85.3 ns · 338 calls
2.97 μs
4.05 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.06 μs · value and gradient 4.22 μs
PosteriorDB model Rate_2_model · dataset Rate_2_data · SHA-256 22b534aa0ddd926802784b4659ead5a5eb080d2c5de9526ff49a34791900c637
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_Rate_3_model(n1, n2, k1, k2)
theta ~ Beta(1, 1)
k1 ~ Binomial(n1, theta)
return k2 ~ Binomial(n2, theta)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
40.2 ns · 1324 calls
43.3 ns · 5288 calls
2.99 μs
4.26 μs
20261122T002521Z-565231f-registered-repeat-1
Off
38.3 ns · 4664 calls
40.8 ns · 4392 calls
3.05 μs
4.12 μs
20261122T002521Z-565231f
On · no reduction
40.2 ns · 1324 calls
43.3 ns · 5288 calls
2.99 μs
4.26 μs
20261122T002521Z-565231f
Off
38.3 ns · 4664 calls
40.8 ns · 4392 calls
3.05 μs
4.12 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
38.5 ns · 3080 calls
40.8 ns · 5424 calls
3.03 μs
4.08 μs
20261122T000034Z-565231f-registered-repeat-1
Off
40.1 ns · 3124 calls
42.9 ns · 4500 calls
2.95 μs
4.19 μs
20261122T000034Z-565231f
On · no reduction
38.5 ns · 3080 calls
40.8 ns · 5424 calls
3.03 μs
4.08 μs
20261122T000034Z-565231f
Off
40.1 ns · 3124 calls
42.9 ns · 4500 calls
2.95 μs
4.19 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
47.7 ns · 515 calls
2.88 μs
4.16 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
45.8 ns · 668 calls
2.93 μs
4.3 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
47.7 ns · 515 calls
2.88 μs
4.16 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
45.8 ns · 668 calls
2.93 μs
4.3 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.04 μs · value and gradient 4.23 μs
PosteriorDB model Rate_3_model · dataset Rate_3_data · SHA-256 22b534aa0ddd926802784b4659ead5a5eb080d2c5de9526ff49a34791900c637
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_Rate_4_model(n, k)
theta ~ Beta(1, 1)
thetaprior ~ Beta(1, 1)
return k ~ Binomial(n, theta)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
78.6 ns · 5408 calls
80.6 ns · 2332 calls
2.98 μs
4.29 μs
20261122T002521Z-565231f-registered-repeat-1
Off
79.8 ns · 1816 calls
83 ns · 2464 calls
3.1 μs
4.27 μs
20261122T002521Z-565231f
On · no reduction
78.6 ns · 5408 calls
80.6 ns · 2332 calls
2.98 μs
4.29 μs
20261122T002521Z-565231f
Off
79.8 ns · 1816 calls
83 ns · 2464 calls
3.1 μs
4.27 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
73.8 ns · 3024 calls
82.9 ns · 5276 calls
3.01 μs
4.29 μs
20261122T000034Z-565231f-registered-repeat-1
Off
72.9 ns · 4332 calls
78.5 ns · 2220 calls
2.86 μs
4.08 μs
20261122T000034Z-565231f
On · no reduction
73.8 ns · 3024 calls
82.9 ns · 5276 calls
3.01 μs
4.29 μs
20261122T000034Z-565231f
Off
72.9 ns · 4332 calls
78.5 ns · 2220 calls
2.86 μs
4.08 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
89 ns · 335 calls
2.94 μs
4.24 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
83.6 ns · 509 calls
2.95 μs
4.33 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
89 ns · 335 calls
2.94 μs
4.24 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
83.6 ns · 509 calls
2.95 μs
4.33 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 2.96 μs · value and gradient 4.2 μs
PosteriorDB model Rate_4_model · dataset Rate_4_data · SHA-256 b7206d79a0067943533b9a7c5fbe481fa057b850e74067313fc56e4403d49838
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
137 ns
1.64 μs
FlatPPL · normal optimizations
2.98 μs · 21.7× Wren
4.29 μs · 2.62× Wren
FlatPPL · equal work
3.1 μs · 22.6× Wren
4.27 μs · 2.61× Wren
Wren definition in this run
@wren function rate_4_model(k, n)
theta ~ WD.Beta(1.0, 1.0)
thetaprior ~ WD.Beta(1.0, 1.0)
@observe k ~ WD.Binomial(n, theta)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
136 ns
1.54 μs
FlatPPL · normal optimizations
3.01 μs · 22.1× Wren
4.29 μs · 2.79× Wren
FlatPPL · equal work
2.86 μs · 21.0× Wren
4.08 μs · 2.66× Wren
Wren definition in this run
@wren function rate_4_model(k, n)
theta ~ WD.Beta(1.0, 1.0)
thetaprior ~ WD.Beta(1.0, 1.0)
@observe k ~ WD.Binomial(n, theta)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
136 ns
1.54 μs
FlatPPL · normal optimizations
2.94 μs · 21.6× Wren
4.24 μs · 2.74× Wren
FlatPPL · equal work
2.95 μs · 21.7× Wren
4.33 μs · 2.8× Wren
Wren definition in this run
@wren function rate_4_model(k, n)
theta ~ WD.Beta(1.0, 1.0)
thetaprior ~ WD.Beta(1.0, 1.0)
@observe k ~ WD.Binomial(n, theta)
return nothing
end
@model function pdb_Rate_5_model(n1, n2, k1, k2)
theta ~ Beta(1, 1)
k1 ~ Binomial(n1, theta)
return k2 ~ Binomial(n2, theta)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
37.6 ns · 3556 calls
42.6 ns · 5428 calls
3.02 μs
4.22 μs
20261122T002521Z-565231f-registered-repeat-1
Off
39.3 ns · 4280 calls
42.3 ns · 3764 calls
4.1 μs
4.07 μs
20261122T002521Z-565231f
On · no reduction
37.6 ns · 3556 calls
42.6 ns · 5428 calls
3.02 μs
4.22 μs
20261122T002521Z-565231f
Off
39.3 ns · 4280 calls
42.3 ns · 3764 calls
4.1 μs
4.07 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
41.5 ns · 816 calls
43 ns · 3060 calls
3 μs
4.17 μs
20261122T000034Z-565231f-registered-repeat-1
Off
37.7 ns · 2976 calls
41.1 ns · 3788 calls
2.94 μs
4.18 μs
20261122T000034Z-565231f
On · no reduction
41.5 ns · 816 calls
43 ns · 3060 calls
3 μs
4.17 μs
20261122T000034Z-565231f
Off
37.7 ns · 2976 calls
41.1 ns · 3788 calls
2.94 μs
4.18 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
47.4 ns · 528 calls
4.19 μs
4.24 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
44 ns · 845 calls
2.91 μs
3.99 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
47.4 ns · 528 calls
4.19 μs
4.24 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
44 ns · 845 calls
2.91 μs
3.99 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 2.96 μs · value and gradient 5.59 μs
PosteriorDB model Rate_5_model · dataset Rate_5_data · SHA-256 34ab09c4669a9d7fcecfd89809b4ec40163036b67b5ac04ad75e189dbb90fe7f
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_rats_model(N, Npts, rat, x, y, xbar)
x_ = x
alpha ~ product_distribution(Fill(Flat(), N))
beta ~ product_distribution(Fill(Flat(), N))
mu_alpha ~ Normal(0, 100)
mu_beta ~ Normal(0, 100)
sigma_y ~ FlatPos(0)
sigma_alpha ~ FlatPos(0)
sigma_beta ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_alpha, sigma_alpha), size(alpha))), alpha
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu_beta, sigma_beta), size(beta))), beta
)
for n in 1:Npts
irat = rat[n]
DynamicPPL.@addlogprob! logpdf(
Normal(alpha[irat] + beta[irat] * (x_[n] - xbar), sigma_y), y[n]
)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
153 ns · 1708 calls
381 ns · 1212 calls
5.22 μs
8.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
164 ns · 1288 calls
435 ns · 116 calls
5.15 μs
7.33 μs
20261122T002521Z-565231f
On · no reduction
153 ns · 1708 calls
381 ns · 1212 calls
5.22 μs
8.2 μs
20261122T002521Z-565231f
Off
164 ns · 1288 calls
435 ns · 116 calls
5.15 μs
7.33 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
157 ns · 1312 calls
379 ns · 892 calls
5.39 μs
8.34 μs
20261122T000034Z-565231f-registered-repeat-1
Off
193 ns · 1460 calls
366 ns · 1428 calls
5.62 μs
8.26 μs
20261122T000034Z-565231f
On · no reduction
157 ns · 1312 calls
379 ns · 892 calls
5.39 μs
8.34 μs
20261122T000034Z-565231f
Off
193 ns · 1460 calls
366 ns · 1428 calls
5.62 μs
8.26 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
354 ns · 520 calls
3.53 μs
6.5 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
357 ns · 1136 calls
3.49 μs
5.55 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
354 ns · 520 calls
3.53 μs
6.5 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
357 ns · 1136 calls
3.49 μs
5.55 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.32 μs · value and gradient 8.35 μs
PosteriorDB model rats_model · dataset rats_data · SHA-256 7690a263d33c458f2888a5cb809ac957e01cd17324891443c6b02685e6360bad
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
382 ns
1.19 μs
FlatPPL · normal optimizations
5.22 μs · 13.7× Wren
8.2 μs · 6.87× Wren
FlatPPL · equal work
5.15 μs · 13.5× Wren
7.33 μs · 6.14× Wren
Wren definition in this run
@wren function rats_model(rat, x, y, xbar, N)
mu_alpha ~ WD.Normal(0.0, 100.0)
mu_beta ~ WD.Normal(0.0, 100.0)
log_sigma_y ~ WD.Flat()
log_sigma_alpha ~ WD.Flat()
log_sigma_beta ~ WD.Flat()
sigma_y = exp(log_sigma_y)
sigma_alpha = exp(log_sigma_alpha)
sigma_beta = exp(log_sigma_beta)
# The three unprioritized positive scales are flat on their original scales.
# Positive flat scales: each log-coordinate Jacobian is needed (#192).
@addloglikelihood log_sigma_y + log_sigma_alpha + log_sigma_beta
@iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=N
@iid beta ~ WD.Normal(mu_beta, sigma_beta) size=N
mu = alpha[rat] .+ beta[rat] .* (x .- xbar)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
390 ns
1.02 μs
FlatPPL · normal optimizations
5.39 μs · 13.8× Wren
8.34 μs · 8.22× Wren
FlatPPL · equal work
5.62 μs · 14.4× Wren
8.26 μs · 8.14× Wren
Wren definition in this run
@wren function rats_model(rat, x, y, xbar, N)
mu_alpha ~ WD.Normal(0.0, 100.0)
mu_beta ~ WD.Normal(0.0, 100.0)
log_sigma_y ~ WD.Flat()
log_sigma_alpha ~ WD.Flat()
log_sigma_beta ~ WD.Flat()
sigma_y = exp(log_sigma_y)
sigma_alpha = exp(log_sigma_alpha)
sigma_beta = exp(log_sigma_beta)
# The three unprioritized positive scales are flat on their original scales.
# Positive flat scales: each log-coordinate Jacobian is needed (#192).
@addloglikelihood log_sigma_y + log_sigma_alpha + log_sigma_beta
@iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=N
@iid beta ~ WD.Normal(mu_beta, sigma_beta) size=N
mu = alpha[rat] .+ beta[rat] .* (x .- xbar)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
275 ns
1.62 μs
FlatPPL · normal optimizations
3.53 μs · 12.9× Wren
6.5 μs · 4.01× Wren
FlatPPL · equal work
3.49 μs · 12.7× Wren
5.55 μs · 3.43× Wren
Wren definition in this run
@wren function rats_model(rat, x, y, xbar, N)
mu_alpha ~ WD.Normal(0.0, 100.0)
mu_beta ~ WD.Normal(0.0, 100.0)
log_sigma_y ~ WD.Flat()
log_sigma_alpha ~ WD.Flat()
log_sigma_beta ~ WD.Flat()
sigma_y = exp(log_sigma_y)
sigma_alpha = exp(log_sigma_alpha)
sigma_beta = exp(log_sigma_beta)
# The three unprioritized positive scales are flat on their original scales.
# Positive flat scales: each log-coordinate Jacobian is needed (#192).
@addloglikelihood log_sigma_y + log_sigma_alpha + log_sigma_beta
@iid alpha ~ WD.Normal(mu_alpha, sigma_alpha) size=N
@iid beta ~ WD.Normal(mu_beta, sigma_beta) size=N
mu = alpha[rat] .+ beta[rat] .* (x .- xbar)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma_y)
end
return nothing
end
@model function pdb_prophet(
T, K, t, cap, y, S, t_change, A, A_tchange, X_a, X_m, sigmas, tau, trend_indicator
)
k ~ Normal(0, 5)
m ~ Normal(0, 5)
delta ~ product_distribution(Fill(Laplace(0, tau), S))
sigma_obs ~ FlatPos(0)
beta ~ product_distribution(map(sigma -> Normal(0, sigma), sigmas))
DynamicPPL.@addlogprob! logpdf(Normal(0, 0.5), sigma_obs)
if trend_indicator == 0
trend = (k .+ A * delta) .* t .+ (m .- A_tchange * delta)
prediction = trend .* (1 .+ X_m * beta) + X_a * beta
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_obs), T)), y .- prediction
)
elseif trend_indicator == 1
gamma = zeros(S)
segment_rate = vcat(k, k + cumsum(delta))
shifted_offset = m
for i in 1:S
gamma[i] =
(t_change[i] - shifted_offset) * (1 - segment_rate[i] / segment_rate[i + 1])
shifted_offset += gamma[i]
end
trend = cap .* logistic.((k .+ A * delta) .* ((t .- m) .- A * gamma),)
prediction = trend .* (1 .+ X_m * beta) + X_a * beta
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_obs), T)), y .- prediction
)
end
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
7.54 μs · 40 calls
14.3 μs · 56 calls
20 μs
30.3 μs
20261122T002521Z-565231f-registered-repeat-1
Off
7.59 μs · 56 calls
13.4 μs · 56 calls
26.3 μs
29.7 μs
20261122T002521Z-565231f
On · no reduction
7.54 μs · 40 calls
14.3 μs · 56 calls
20 μs
30.3 μs
20261122T002521Z-565231f
Off
7.59 μs · 56 calls
13.4 μs · 56 calls
26.3 μs
29.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
7.55 μs · 72 calls
13 μs · 60 calls
21.9 μs
30.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
7.32 μs · 92 calls
12.8 μs · 56 calls
22.5 μs
33.6 μs
20261122T000034Z-565231f
On · no reduction
7.55 μs · 72 calls
13 μs · 60 calls
21.9 μs
30.9 μs
20261122T000034Z-565231f
Off
7.32 μs · 92 calls
12.8 μs · 56 calls
22.5 μs
33.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
11.8 μs · 66 calls
17.5 μs
24.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
12.4 μs · 63 calls
16.5 μs
29 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
11.8 μs · 66 calls
17.5 μs
24.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
12.4 μs · 63 calls
16.5 μs
29 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 19.9 μs · value and gradient 29.2 μs
PosteriorDB model prophet · dataset rstan_downloads · SHA-256 b324915b127de06696f11af45cd6a763d277fc23cbc822a1b3d1b04e387ec73c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
13.7 μs
43.6 μs
FlatPPL · normal optimizations
20 μs · 1.46× Wren
30.3 μs · 0.695× Wren
FlatPPL · equal work
26.3 μs · 1.92× Wren
29.7 μs · 0.681× Wren
Wren definition in this run
@wren function prophet_linear(y, t, t_change, A, X, sigmas, tau, s_a, s_m)
k ~ WD.Normal(0.0, 5.0)
m ~ WD.Normal(0.0, 5.0)
@iid delta ~ WD.Laplace(0.0, tau) size=length(t_change)
sigma_obs ~ WD.HalfNormal(0.0, 0.5)
@iid beta ~ WD.Normal(0.0, sigmas[1]) size=length(sigmas)
trend = (k .+ A * delta) .* t .+ m .- A * (t_change .* delta)
mu = trend .* (1 .+ X * (beta .* s_m)) .+ X * (beta .* s_a)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma_obs)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
13.8 μs
46.4 μs
FlatPPL · normal optimizations
21.9 μs · 1.58× Wren
30.9 μs · 0.666× Wren
FlatPPL · equal work
22.5 μs · 1.63× Wren
33.6 μs · 0.724× Wren
Wren definition in this run
@wren function prophet_linear(y, t, t_change, A, X, sigmas, tau, s_a, s_m)
k ~ WD.Normal(0.0, 5.0)
m ~ WD.Normal(0.0, 5.0)
@iid delta ~ WD.Laplace(0.0, tau) size=length(t_change)
sigma_obs ~ WD.HalfNormal(0.0, 0.5)
@iid beta ~ WD.Normal(0.0, sigmas[1]) size=length(sigmas)
trend = (k .+ A * delta) .* t .+ m .- A * (t_change .* delta)
mu = trend .* (1 .+ X * (beta .* s_m)) .+ X * (beta .* s_a)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma_obs)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
12.1 μs
48.2 μs
FlatPPL · normal optimizations
17.5 μs · 1.44× Wren
24.8 μs · 0.514× Wren
FlatPPL · equal work
16.5 μs · 1.36× Wren
29 μs · 0.602× Wren
Wren definition in this run
@wren function prophet_linear(y, t, t_change, A, X, sigmas, tau, s_a, s_m)
k ~ WD.Normal(0.0, 5.0)
m ~ WD.Normal(0.0, 5.0)
@iid delta ~ WD.Laplace(0.0, tau) size=length(t_change)
sigma_obs ~ WD.HalfNormal(0.0, 0.5)
@iid beta ~ WD.Normal(0.0, sigmas[1]) size=length(sigmas)
trend = (k .+ A * delta) .* t .+ m .- A * (t_change .* delta)
mu = trend .* (1 .+ X * (beta .* s_m)) .+ X * (beta .* s_a)
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma_obs)
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
93.1 μs · 4 calls
170 μs · 4 calls
70.1 μs
165 μs
20261122T002521Z-565231f-registered-repeat-1
Off
126 μs · 4 calls
158 μs · 4 calls
78 μs
163 μs
20261122T002521Z-565231f
On · no reduction
93.1 μs · 4 calls
170 μs · 4 calls
70.1 μs
165 μs
20261122T002521Z-565231f
Off
126 μs · 4 calls
158 μs · 4 calls
78 μs
163 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
93.6 μs · 4 calls
160 μs · 4 calls
74 μs
184 μs
20261122T000034Z-565231f-registered-repeat-1
Off
101 μs · 4 calls
180 μs · 4 calls
66.3 μs
176 μs
20261122T000034Z-565231f
On · no reduction
93.6 μs · 4 calls
160 μs · 4 calls
74 μs
184 μs
20261122T000034Z-565231f
Off
101 μs · 4 calls
180 μs · 4 calls
66.3 μs
176 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 66.1 μs · value and gradient 167 μs
PosteriorDB model hier_2pl · dataset sat · SHA-256 1b06fd37b0cde2e167615beea91009faf11a395481d6d7c819d54335f1a14d1c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function sblrc_blr(X, y, D)
X = X.value
y = y.value
beta ~ product_distribution(Fill(Normal(0, 10), D))
sigma ~ truncated(Normal(0, 10); lower=0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(y))), y .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
156 ns · 1444 calls
464 ns · 472 calls
3.39 μs
6.57 μs
20261122T002521Z-565231f-registered-repeat-1
Off
152 ns · 1520 calls
444 ns · 1036 calls
5.26 μs
7.48 μs
20261122T002521Z-565231f
On · no reduction
156 ns · 1444 calls
464 ns · 472 calls
3.39 μs
6.57 μs
20261122T002521Z-565231f
Off
152 ns · 1520 calls
444 ns · 1036 calls
5.26 μs
7.48 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
198 ns · 140 calls
421 ns · 896 calls
5.23 μs
9.49 μs
20261122T000034Z-565231f-registered-repeat-1
Off
148 ns · 1536 calls
453 ns · 896 calls
3.48 μs
6.83 μs
20261122T000034Z-565231f
On · no reduction
198 ns · 140 calls
421 ns · 896 calls
5.23 μs
9.49 μs
20261122T000034Z-565231f
Off
148 ns · 1536 calls
453 ns · 896 calls
3.48 μs
6.83 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
420 ns · 594 calls
3.31 μs
4.37 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
416 ns · 726 calls
3.25 μs
4.4 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
420 ns · 594 calls
3.31 μs
4.37 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
416 ns · 726 calls
3.25 μs
4.4 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 5.02 μs · value and gradient 6.62 μs
PosteriorDB model blr · dataset sblrc · SHA-256 d78239c2ff72fb578461d3ed4494f8c5d46e9089c61b4275d7c2f530452e3e9e
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
164 ns
394 ns
FlatPPL · normal optimizations
3.39 μs · 20.7× Wren
6.57 μs · 16.7× Wren
FlatPPL · equal work
5.26 μs · 32.2× Wren
7.48 μs · 19.0× Wren
Wren definition in this run
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
130 ns
357 ns
FlatPPL · normal optimizations
5.23 μs · 40.1× Wren
9.49 μs · 26.6× Wren
FlatPPL · equal work
3.48 μs · 26.7× Wren
6.83 μs · 19.1× Wren
Wren definition in this run
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
265 ns
449 ns
FlatPPL · normal optimizations
3.31 μs · 12.5× Wren
4.37 μs · 9.73× Wren
FlatPPL · equal work
3.25 μs · 12.3× Wren
4.4 μs · 9.79× Wren
Wren definition in this run
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function sblri_blr(X, y, D)
X = X.value
y = y.value
beta ~ product_distribution(Fill(Normal(0, 10), D))
sigma ~ truncated(Normal(0, 10); lower=0)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma), size(y))), y .- X * beta
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
148 ns · 1408 calls
441 ns · 516 calls
5.19 μs
6.43 μs
20261122T002521Z-565231f-registered-repeat-1
Off
181 ns · 1576 calls
450 ns · 1076 calls
4.28 μs
6.14 μs
20261122T002521Z-565231f
On · no reduction
148 ns · 1408 calls
441 ns · 516 calls
5.19 μs
6.43 μs
20261122T002521Z-565231f
Off
181 ns · 1576 calls
450 ns · 1076 calls
4.28 μs
6.14 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
165 ns · 1208 calls
426 ns · 844 calls
8.92 μs
10.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
145 ns · 1628 calls
449 ns · 976 calls
4.96 μs
7.06 μs
20261122T000034Z-565231f
On · no reduction
165 ns · 1208 calls
426 ns · 844 calls
8.92 μs
10.4 μs
20261122T000034Z-565231f
Off
145 ns · 1628 calls
449 ns · 976 calls
4.96 μs
7.06 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
426 ns · 483 calls
3.19 μs
6.7 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
433 ns · 654 calls
8.39 μs
4.56 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
426 ns · 483 calls
3.19 μs
6.7 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
433 ns · 654 calls
8.39 μs
4.56 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 8.18 μs · value and gradient 9.34 μs
PosteriorDB model blr · dataset sblri · SHA-256 5a0a7eec0d478e0aa194a2e7b1597f6589d3c5862abebf440f4c32c2dd4b814c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
130 ns
336 ns
FlatPPL · normal optimizations
5.19 μs · 40.0× Wren
6.43 μs · 19.2× Wren
FlatPPL · equal work
4.28 μs · 33.0× Wren
6.14 μs · 18.3× Wren
Wren definition in this run
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
176 ns
376 ns
FlatPPL · normal optimizations
8.92 μs · 50.8× Wren
10.4 μs · 27.6× Wren
FlatPPL · equal work
4.96 μs · 28.2× Wren
7.06 μs · 18.8× Wren
Wren definition in this run
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
220 ns
434 ns
FlatPPL · normal optimizations
3.19 μs · 14.5× Wren
6.7 μs · 15.4× Wren
FlatPPL · equal work
8.39 μs · 38.1× Wren
4.56 μs · 10.5× Wren
Wren definition in this run
@wren function sblri_blr(y, X, D)
@iid beta ~ WD.Normal(0.0, 10.0) size=D
sigma ~ WD.HalfNormal(0.0, 10.0)
mu = X * beta
@batch for i in eachindex(y)
@observe y[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
@model function pdb_grsm_latent_reg_irt(
I, J, N, ii, jj, response, max_category, W_adj, levels, response_indices
)
m = first(max_category)
K = size(W_adj, 2)
alpha ~ product_distribution(Fill(LogNormal(1, 1), I))
beta_free ~ product_distribution(Fill(Flat(), I - 1))
kappa_free ~ product_distribution(Fill(Flat(), m - 1))
lambda_adj ~ product_distribution(Fill(LocationScale(0, 1, TDist(3)), K))
theta ~ MvNormal(W_adj * lambda_adj, 1.0)
beta = vcat(beta_free, -(sum(beta_free)))
kappa = vcat(kappa_free, -(sum(kappa_free)))
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, 3), size(beta))), beta
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, 3), size(kappa))), kappa
)
ability = alpha[ii] .* theta[jj] .- beta[ii]
cumulative_kappa = vcat(zero(kappa[1]), cumsum(kappa))
logits = reshape(ability, N, 1) .* levels .- reshape(cumulative_kappa, 1, :)
DynamicPPL.@addlogprob! sum(logits[response_indices]) - sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
35.2 μs · 4 calls
103 μs · 4 calls
42.9 μs
155 μs
20261122T002521Z-565231f-registered-repeat-1
Off
34.3 μs · 20 calls
107 μs · 4 calls
42.7 μs
150 μs
20261122T002521Z-565231f
On · no reduction
35.2 μs · 4 calls
103 μs · 4 calls
42.9 μs
155 μs
20261122T002521Z-565231f
Off
34.3 μs · 20 calls
107 μs · 4 calls
42.7 μs
150 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
46.9 μs · 16 calls
115 μs · 4 calls
41.7 μs
110 μs
20261122T000034Z-565231f-registered-repeat-1
Off
36.1 μs · 8 calls
107 μs · 4 calls
49.2 μs
121 μs
20261122T000034Z-565231f
On · no reduction
46.9 μs · 16 calls
115 μs · 4 calls
41.7 μs
110 μs
20261122T000034Z-565231f
Off
36.1 μs · 8 calls
107 μs · 4 calls
49.2 μs
121 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
106 μs · 4 calls
38 μs
114 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
94.2 μs · 4 calls
42.1 μs
119 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
106 μs · 4 calls
38 μs
114 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
94.2 μs · 4 calls
42.1 μs
119 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 41.1 μs · value and gradient 119 μs
PosteriorDB model grsm_latent_reg_irt · dataset science_irt · SHA-256 1d74560ecc4f26c6c00e916dd05fb12e8769189345a13e7c4ce1bbbbe33c3c57
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
119 μs
372 μs
FlatPPL · normal optimizations
42.9 μs · 0.36× Wren
155 μs · 0.416× Wren
FlatPPL · equal work
42.7 μs · 0.359× Wren
150 μs · 0.403× Wren
Wren definition in this run
@wren function latent_reg_grsm(y, ii, jj, W_adj, I, J, K, m)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(I - 1)
@iid kappa_free ~ WD.Flat() size=(m - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood science_logdensity(y, ii, jj, W_adj,
alpha, beta_free, kappa_free, theta, lambda_adj)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
123 μs
468 μs
FlatPPL · normal optimizations
41.7 μs · 0.339× Wren
110 μs · 0.236× Wren
FlatPPL · equal work
49.2 μs · 0.4× Wren
121 μs · 0.258× Wren
Wren definition in this run
@wren function latent_reg_grsm(y, ii, jj, W_adj, I, J, K, m)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(I - 1)
@iid kappa_free ~ WD.Flat() size=(m - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood science_logdensity(y, ii, jj, W_adj,
alpha, beta_free, kappa_free, theta, lambda_adj)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
124 μs
348 μs
FlatPPL · normal optimizations
38 μs · 0.306× Wren
114 μs · 0.328× Wren
FlatPPL · equal work
42.1 μs · 0.339× Wren
119 μs · 0.341× Wren
Wren definition in this run
@wren function latent_reg_grsm(y, ii, jj, W_adj, I, J, K, m)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(I - 1)
@iid kappa_free ~ WD.Flat() size=(m - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood science_logdensity(y, ii, jj, W_adj,
alpha, beta_free, kappa_free, theta, lambda_adj)
return nothing
end
@model function pdb_seeds_centered_model(I, n, N, x1, x2, x1x2)
alpha0 ~ Normal(0.0, 1.0)
alpha1 ~ Normal(0.0, 1.0)
alpha12 ~ Normal(0.0, 1.0)
alpha2 ~ Normal(0.0, 1.0)
c ~ product_distribution(Fill(Flat(), I))
sigma ~ FlatPos(0)
b = c .- mean(c)
DynamicPPL.@addlogprob! logpdf(Cauchy(0, 1), sigma)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0.0, sigma), size(c))), c
)
logits = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+ alpha12 .* x1x2 .+ b
DynamicPPL.@addlogprob! logpdf(product_distribution(map(BinomialLogit, N, logits)), n)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
316 ns · 1504 calls
353 ns · 1008 calls
4.35 μs
7.42 μs
20261122T002521Z-565231f-registered-repeat-1
Off
346 ns · 1020 calls
346 ns · 1120 calls
4.17 μs
7.32 μs
20261122T002521Z-565231f
On · no reduction
316 ns · 1504 calls
353 ns · 1008 calls
4.35 μs
7.42 μs
20261122T002521Z-565231f
Off
346 ns · 1020 calls
346 ns · 1120 calls
4.17 μs
7.32 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
339 ns · 720 calls
343 ns · 1280 calls
4.35 μs
13.7 μs
20261122T000034Z-565231f-registered-repeat-1
Off
314 ns · 1508 calls
349 ns · 336 calls
4.07 μs
11.2 μs
20261122T000034Z-565231f
On · no reduction
339 ns · 720 calls
343 ns · 1280 calls
4.35 μs
13.7 μs
20261122T000034Z-565231f
Off
314 ns · 1508 calls
349 ns · 336 calls
4.07 μs
11.2 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
316 ns · 123 calls
3.84 μs
7.03 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
250 ns · 560 calls
4.03 μs
7.35 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
316 ns · 123 calls
3.84 μs
7.03 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
250 ns · 560 calls
4.03 μs
7.35 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 4.1 μs · value and gradient 7.21 μs
PosteriorDB model seeds_centered_model · dataset seeds_data · SHA-256 d68b8b94a93c03f121ce428000bb59e265b4817fefc0681bdc748524422fe865
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
949 ns
1.08 μs
FlatPPL · normal optimizations
4.35 μs · 4.58× Wren
7.42 μs · 6.85× Wren
FlatPPL · equal work
4.17 μs · 4.39× Wren
7.32 μs · 6.75× Wren
Wren definition in this run
@wren function seeds_centered(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1.0)
alpha1 ~ WD.Normal(0.0, 1.0)
alpha12 ~ WD.Normal(0.0, 1.0)
alpha2 ~ WD.Normal(0.0, 1.0)
@iid c ~ WD.Flat() size=length(n)
sigma ~ WD.HalfCauchy(0.0, 1.0)
@observe @iid c ~ WD.Normal(0.0, sigma) size=length(n)
b = c .- mean(c)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
908 ns
975 ns
FlatPPL · normal optimizations
4.35 μs · 4.79× Wren
13.7 μs · 14.1× Wren
FlatPPL · equal work
4.07 μs · 4.48× Wren
11.2 μs · 11.5× Wren
Wren definition in this run
@wren function seeds_centered(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1.0)
alpha1 ~ WD.Normal(0.0, 1.0)
alpha12 ~ WD.Normal(0.0, 1.0)
alpha2 ~ WD.Normal(0.0, 1.0)
@iid c ~ WD.Flat() size=length(n)
sigma ~ WD.HalfCauchy(0.0, 1.0)
@observe @iid c ~ WD.Normal(0.0, sigma) size=length(n)
b = c .- mean(c)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
908 ns
1.04 μs
FlatPPL · normal optimizations
3.84 μs · 4.23× Wren
7.03 μs · 6.76× Wren
FlatPPL · equal work
4.03 μs · 4.44× Wren
7.35 μs · 7.07× Wren
Wren definition in this run
@wren function seeds_centered(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1.0)
alpha1 ~ WD.Normal(0.0, 1.0)
alpha12 ~ WD.Normal(0.0, 1.0)
alpha2 ~ WD.Normal(0.0, 1.0)
@iid c ~ WD.Flat() size=length(n)
sigma ~ WD.HalfCauchy(0.0, 1.0)
@observe @iid c ~ WD.Normal(0.0, sigma) size=length(n)
b = c .- mean(c)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
@model function pdb_seeds_model(I, n, N, x1, x2, x1x2)
alpha0 ~ Normal(0.0, 1000.0)
alpha1 ~ Normal(0.0, 1000.0)
alpha12 ~ Normal(0.0, 1000.0)
alpha2 ~ Normal(0.0, 1000.0)
tau ~ Gamma(0.001, inv(0.001))
b ~ product_distribution(Fill(Flat(), I))
sigma = 1.0 / sqrt(tau)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0.0, sigma), size(b))), b
)
logits = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+ alpha12 .* x1x2 .+ b
DynamicPPL.@addlogprob! logpdf(product_distribution(map(BinomialLogit, N, logits)), n)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
161 ns · 1140 calls
470 ns · 904 calls
3.98 μs
5.45 μs
20261122T002521Z-565231f-registered-repeat-1
Off
163 ns · 2308 calls
364 ns · 420 calls
4.16 μs
10.4 μs
20261122T002521Z-565231f
On · no reduction
161 ns · 1140 calls
470 ns · 904 calls
3.98 μs
5.45 μs
20261122T002521Z-565231f
Off
163 ns · 2308 calls
364 ns · 420 calls
4.16 μs
10.4 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
161 ns · 1612 calls
420 ns · 864 calls
3.95 μs
7.03 μs
20261122T000034Z-565231f-registered-repeat-1
Off
158 ns · 2156 calls
362 ns · 1268 calls
3.73 μs
6.19 μs
20261122T000034Z-565231f
On · no reduction
161 ns · 1612 calls
420 ns · 864 calls
3.95 μs
7.03 μs
20261122T000034Z-565231f
Off
158 ns · 2156 calls
362 ns · 1268 calls
3.73 μs
6.19 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
254 ns · 411 calls
3.8 μs
5.07 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
258 ns · 468 calls
3.79 μs
5.06 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
254 ns · 411 calls
3.8 μs
5.07 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
258 ns · 468 calls
3.79 μs
5.06 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 4.2 μs · value and gradient 7.36 μs
PosteriorDB model seeds_model · dataset seeds_data · SHA-256 d68b8b94a93c03f121ce428000bb59e265b4817fefc0681bdc748524422fe865
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
904 ns
1.63 μs
FlatPPL · normal optimizations
3.98 μs · 4.4× Wren
5.45 μs · 3.35× Wren
FlatPPL · equal work
4.16 μs · 4.6× Wren
10.4 μs · 6.39× Wren
Wren definition in this run
@wren function seeds_model(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1000.0)
alpha1 ~ WD.Normal(0.0, 1000.0)
alpha12 ~ WD.Normal(0.0, 1000.0)
alpha2 ~ WD.Normal(0.0, 1000.0)
# Stan Gamma uses a rate; WrenDists Gamma uses a scale.
tau ~ WD.Gamma(0.001, 1000.0)
sigma = inv(sqrt(tau))
@iid b ~ WD.Normal(0.0, sigma) size=length(n)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
902 ns
1.59 μs
FlatPPL · normal optimizations
3.95 μs · 4.38× Wren
7.03 μs · 4.41× Wren
FlatPPL · equal work
3.73 μs · 4.13× Wren
6.19 μs · 3.88× Wren
Wren definition in this run
@wren function seeds_model(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1000.0)
alpha1 ~ WD.Normal(0.0, 1000.0)
alpha12 ~ WD.Normal(0.0, 1000.0)
alpha2 ~ WD.Normal(0.0, 1000.0)
# Stan Gamma uses a rate; WrenDists Gamma uses a scale.
tau ~ WD.Gamma(0.001, 1000.0)
sigma = inv(sqrt(tau))
@iid b ~ WD.Normal(0.0, sigma) size=length(n)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
933 ns
1.59 μs
FlatPPL · normal optimizations
3.8 μs · 4.08× Wren
5.07 μs · 3.19× Wren
FlatPPL · equal work
3.79 μs · 4.06× Wren
5.06 μs · 3.18× Wren
Wren definition in this run
@wren function seeds_model(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1000.0)
alpha1 ~ WD.Normal(0.0, 1000.0)
alpha12 ~ WD.Normal(0.0, 1000.0)
alpha2 ~ WD.Normal(0.0, 1000.0)
# Stan Gamma uses a rate; WrenDists Gamma uses a scale.
tau ~ WD.Gamma(0.001, 1000.0)
sigma = inv(sqrt(tau))
@iid b ~ WD.Normal(0.0, sigma) size=length(n)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
@model function pdb_seeds_stanified_model(I, n, N, x1, x2, x1x2)
alpha0 ~ Normal(0.0, 1.0)
alpha1 ~ Normal(0.0, 1.0)
alpha12 ~ Normal(0.0, 1.0)
alpha2 ~ Normal(0.0, 1.0)
b ~ product_distribution(Fill(Flat(), I))
sigma ~ FlatPos(0)
DynamicPPL.@addlogprob! logpdf(Cauchy(0, 1), sigma)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0.0, sigma), size(b))), b
)
logits = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+ alpha12 .* x1x2 .+ b
DynamicPPL.@addlogprob! logpdf(product_distribution(map(BinomialLogit, N, logits)), n)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
154 ns · 2292 calls
437 ns · 1224 calls
3.74 μs
5.33 μs
20261122T002521Z-565231f-registered-repeat-1
Off
167 ns · 2340 calls
346 ns · 840 calls
4.02 μs
7.08 μs
20261122T002521Z-565231f
On · no reduction
154 ns · 2292 calls
437 ns · 1224 calls
3.74 μs
5.33 μs
20261122T002521Z-565231f
Off
167 ns · 2340 calls
346 ns · 840 calls
4.02 μs
7.08 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
154 ns · 1836 calls
331 ns · 1208 calls
3.87 μs
7.11 μs
20261122T000034Z-565231f-registered-repeat-1
Off
154 ns · 2156 calls
395 ns · 1112 calls
4.06 μs
7.71 μs
20261122T000034Z-565231f
On · no reduction
154 ns · 1836 calls
331 ns · 1208 calls
3.87 μs
7.11 μs
20261122T000034Z-565231f
Off
154 ns · 2156 calls
395 ns · 1112 calls
4.06 μs
7.71 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
247 ns · 762 calls
4.12 μs
5.35 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
242 ns · 424 calls
3.87 μs
5.32 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
247 ns · 762 calls
4.12 μs
5.35 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
242 ns · 424 calls
3.87 μs
5.32 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 4.09 μs · value and gradient 7.41 μs
PosteriorDB model seeds_stanified_model · dataset seeds_data · SHA-256 d68b8b94a93c03f121ce428000bb59e265b4817fefc0681bdc748524422fe865
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
898 ns
951 ns
FlatPPL · normal optimizations
3.74 μs · 4.16× Wren
5.33 μs · 5.6× Wren
FlatPPL · equal work
4.02 μs · 4.47× Wren
7.08 μs · 7.44× Wren
Wren definition in this run
@wren function seeds_stanified(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1.0)
alpha1 ~ WD.Normal(0.0, 1.0)
alpha12 ~ WD.Normal(0.0, 1.0)
alpha2 ~ WD.Normal(0.0, 1.0)
@iid b ~ WD.Flat() size=length(n)
sigma ~ WD.HalfCauchy(0.0, 1.0)
@observe @iid b ~ WD.Normal(0.0, sigma) size=length(n)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
941 ns
953 ns
FlatPPL · normal optimizations
3.87 μs · 4.11× Wren
7.11 μs · 7.46× Wren
FlatPPL · equal work
4.06 μs · 4.31× Wren
7.71 μs · 8.09× Wren
Wren definition in this run
@wren function seeds_stanified(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1.0)
alpha1 ~ WD.Normal(0.0, 1.0)
alpha12 ~ WD.Normal(0.0, 1.0)
alpha2 ~ WD.Normal(0.0, 1.0)
@iid b ~ WD.Flat() size=length(n)
sigma ~ WD.HalfCauchy(0.0, 1.0)
@observe @iid b ~ WD.Normal(0.0, sigma) size=length(n)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
940 ns
991 ns
FlatPPL · normal optimizations
4.12 μs · 4.38× Wren
5.35 μs · 5.4× Wren
FlatPPL · equal work
3.87 μs · 4.12× Wren
5.32 μs · 5.37× Wren
Wren definition in this run
@wren function seeds_stanified(n, N, x1, x2)
alpha0 ~ WD.Normal(0.0, 1.0)
alpha1 ~ WD.Normal(0.0, 1.0)
alpha12 ~ WD.Normal(0.0, 1.0)
alpha2 ~ WD.Normal(0.0, 1.0)
@iid b ~ WD.Flat() size=length(n)
sigma ~ WD.HalfCauchy(0.0, 1.0)
@observe @iid b ~ WD.Normal(0.0, sigma) size=length(n)
eta = alpha0 .+ alpha1 .* x1 .+ alpha2 .* x2 .+
alpha12 .* (x1 .* x2) .+ b
@batch for i in eachindex(n)
@observe n[i] ~ WD.BinomialLogit(N[i], eta[i])
end
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
205 ns · 1380 calls
203 ns · 1308 calls
4.51 μs
6.63 μs
20261122T002521Z-565231f-registered-repeat-1
Off
229 ns · 1356 calls
217 ns · 1404 calls
5.14 μs
4.7 μs
20261122T002521Z-565231f
On · no reduction
205 ns · 1380 calls
203 ns · 1308 calls
4.51 μs
6.63 μs
20261122T002521Z-565231f
Off
229 ns · 1356 calls
217 ns · 1404 calls
5.14 μs
4.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
277 ns · 1208 calls
230 ns · 884 calls
5.25 μs
4.79 μs
20261122T000034Z-565231f-registered-repeat-1
Off
272 ns · 1108 calls
236 ns · 1560 calls
3.66 μs
6.95 μs
20261122T000034Z-565231f
On · no reduction
277 ns · 1208 calls
230 ns · 884 calls
5.25 μs
4.79 μs
20261122T000034Z-565231f
Off
272 ns · 1108 calls
236 ns · 1560 calls
3.66 μs
6.95 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
218 ns · 498 calls
3.28 μs
4.49 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
1.5 μs · 4 calls
3.32 μs
4.96 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
218 ns · 498 calls
3.28 μs
4.49 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
1.5 μs · 4 calls
3.32 μs
4.96 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 3.83 μs · value and gradient 6.65 μs
PosteriorDB model sesame_one_pred_a · dataset sesame_data · SHA-256 66f163f15d329a745161bc12b50c0c92964436de01f87a786e6e7a6bb6366262
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
187 ns
438 ns
FlatPPL · normal optimizations
4.51 μs · 24.2× Wren
6.63 μs · 15.2× Wren
FlatPPL · equal work
5.14 μs · 27.6× Wren
4.7 μs · 10.7× Wren
Wren definition in this run
@wren function sesame_one_pred(encouraged, watched)
@iid beta ~ WD.Flat() size=2
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# Temporary positive-flat scale transform pending #192.
@addloglikelihood log_sigma
mu = beta[1] .+ beta[2] .* encouraged
@batch for i in eachindex(watched)
@observe watched[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
183 ns
434 ns
FlatPPL · normal optimizations
5.25 μs · 28.7× Wren
4.79 μs · 11.0× Wren
FlatPPL · equal work
3.66 μs · 20.0× Wren
6.95 μs · 16.0× Wren
Wren definition in this run
@wren function sesame_one_pred(encouraged, watched)
@iid beta ~ WD.Flat() size=2
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# Temporary positive-flat scale transform pending #192.
@addloglikelihood log_sigma
mu = beta[1] .+ beta[2] .* encouraged
@batch for i in eachindex(watched)
@observe watched[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
191 ns
395 ns
FlatPPL · normal optimizations
3.28 μs · 17.2× Wren
4.49 μs · 11.4× Wren
FlatPPL · equal work
3.32 μs · 17.4× Wren
4.96 μs · 12.6× Wren
Wren definition in this run
@wren function sesame_one_pred(encouraged, watched)
@iid beta ~ WD.Flat() size=2
log_sigma ~ WD.Flat()
sigma = exp(log_sigma)
# Temporary positive-flat scale transform pending #192.
@addloglikelihood log_sigma
mu = beta[1] .+ beta[2] .* encouraged
@batch for i in eachindex(watched)
@observe watched[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Standalone FlatPPL single call · sufficient statistics on · log density Excluded from execution in this delivery · value and gradient Excluded from execution in this delivery
PosteriorDB model sir · dataset sir · SHA-256 fb673baf165532b8a46ee5ca12c6203ef79df7dfe6a46bacc0e37e01374b10b6
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
157 ns · 2564 calls
401 ns · 1072 calls
3.55 μs
6.71 μs
20261122T002521Z-565231f-registered-repeat-1
Off
157 ns · 1980 calls
388 ns · 1184 calls
5.15 μs
5.16 μs
20261122T002521Z-565231f
On · no reduction
157 ns · 2564 calls
401 ns · 1072 calls
3.55 μs
6.71 μs
20261122T002521Z-565231f
Off
157 ns · 1980 calls
388 ns · 1184 calls
5.15 μs
5.16 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
150 ns · 2652 calls
394 ns · 636 calls
3.71 μs
6.69 μs
20261122T000034Z-565231f-registered-repeat-1
Off
152 ns · 2404 calls
407 ns · 1004 calls
3.69 μs
6.83 μs
20261122T000034Z-565231f
On · no reduction
150 ns · 2652 calls
394 ns · 636 calls
3.71 μs
6.69 μs
20261122T000034Z-565231f
Off
152 ns · 2404 calls
407 ns · 1004 calls
3.69 μs
6.83 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
403 ns · 408 calls
3.61 μs
5.05 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
492 ns · 61 calls
3.5 μs
4.98 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
403 ns · 408 calls
3.61 μs
5.05 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
492 ns · 61 calls
3.5 μs
4.98 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density mismatch · value and gradient mismatch
PosteriorDB model soil_incubation · dataset soil_carbon · SHA-256 4e5506af4aaeaf3ae44b163d6ea3dfbe9954e844d9cd4aeaca8fced27e1d1c2e
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
423 ns
2.11 μs
FlatPPL · normal optimizations
3.55 μs · 8.39× Wren
6.71 μs · 3.18× Wren
FlatPPL · equal work
5.15 μs · 12.2× Wren
5.16 μs · 2.45× Wren
Wren definition in this run
@wren function soil_incubation(ts, observed, total, t0)
k1 ~ WD.HalfNormal(0.0, 1.0)
k2 ~ WD.HalfNormal(0.0, 1.0)
alpha21 ~ WD.HalfNormal(0.0, 1.0)
alpha12 ~ WD.HalfNormal(0.0, 1.0)
gamma ~ WD.Beta(10.0, 1.0)
sigma ~ WD.HalfCauchy(0.0, 1.0)
mu = Vector{typeof(k1 + k2 + alpha21 + alpha12 + gamma + sigma)}(
undef, length(ts))
for i in eachindex(ts)
mu[i] = evolved_carbon(ts[i] - t0, total, gamma, k1, k2,
alpha21, alpha12)
end
@batch for i in eachindex(ts)
@observe observed[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
447 ns
2.1 μs
FlatPPL · normal optimizations
3.71 μs · 8.31× Wren
6.69 μs · 3.19× Wren
FlatPPL · equal work
3.69 μs · 8.26× Wren
6.83 μs · 3.26× Wren
Wren definition in this run
@wren function soil_incubation(ts, observed, total, t0)
k1 ~ WD.HalfNormal(0.0, 1.0)
k2 ~ WD.HalfNormal(0.0, 1.0)
alpha21 ~ WD.HalfNormal(0.0, 1.0)
alpha12 ~ WD.HalfNormal(0.0, 1.0)
gamma ~ WD.Beta(10.0, 1.0)
sigma ~ WD.HalfCauchy(0.0, 1.0)
mu = Vector{typeof(k1 + k2 + alpha21 + alpha12 + gamma + sigma)}(
undef, length(ts))
for i in eachindex(ts)
mu[i] = evolved_carbon(ts[i] - t0, total, gamma, k1, k2,
alpha21, alpha12)
end
@batch for i in eachindex(ts)
@observe observed[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
445 ns
2.13 μs
FlatPPL · normal optimizations
3.61 μs · 8.11× Wren
5.05 μs · 2.37× Wren
FlatPPL · equal work
3.5 μs · 7.87× Wren
4.98 μs · 2.33× Wren
Wren definition in this run
@wren function soil_incubation(ts, observed, total, t0)
k1 ~ WD.HalfNormal(0.0, 1.0)
k2 ~ WD.HalfNormal(0.0, 1.0)
alpha21 ~ WD.HalfNormal(0.0, 1.0)
alpha12 ~ WD.HalfNormal(0.0, 1.0)
gamma ~ WD.Beta(10.0, 1.0)
sigma ~ WD.HalfCauchy(0.0, 1.0)
mu = Vector{typeof(k1 + k2 + alpha21 + alpha12 + gamma + sigma)}(
undef, length(ts))
for i in eachindex(ts)
mu[i] = evolved_carbon(ts[i] - t0, total, gamma, k1, k2,
alpha21, alpha12)
end
@batch for i in eachindex(ts)
@observe observed[i] ~ WD.Normal(mu[i], sigma)
end
return nothing
end
function gp_exp_quad_cov(x, sigma, length_scale)
return [sigma^2 * exp(-0.5 * ((a - b) / length_scale)^2) for a in x, b in x]
end
@model function pdb_hierarchical_gp(
N,
N_states,
N_regions,
N_years_obs,
N_years,
state_region_ind,
state_ind,
region_ind,
year_ind,
y,
)
# Keep homogeneous transforms structured, then materialize only at BLAS.
GP_region_std ~ product_distribution(Fill(Normal(0, 1), N_years * N_regions))
GP_state_std ~ product_distribution(Fill(Normal(0, 1), N_years * N_states))
year_std ~ product_distribution(Fill(Normal(0, 1), N_years_obs))
state_std ~ product_distribution(Fill(Normal(0, 1), N_states))
region_std ~ product_distribution(Fill(Normal(0, 1), N_regions))
tot_var ~ Gamma(3, inv(3))
prop_var ~ Dirichlet(fill(2, 17))
mu ~ Normal(0.5, 0.5)
length_GP_region_long ~ Weibull(30, 8)
length_GP_state_long ~ Weibull(30, 8)
length_GP_region_short ~ Weibull(30, 3)
length_GP_state_short ~ Weibull(30, 3)
years = 1:N_years
vars = 17 * prop_var * tot_var
sigma_year = sqrt(vars[1])
sigma_region = sqrt(vars[2])
sigma_state = sqrt.(vars[3:end])
sigma_GP_region_long = sqrt(vars[13])
sigma_GP_state_long = sqrt(vars[14])
sigma_GP_region_short = sqrt(vars[15])
sigma_GP_state_short = sqrt(vars[16])
sigma_error_state_2 = sqrt(vars[17])
region_re = sigma_region * region_std
year_re = sigma_year * year_std
state_re = sigma_state[state_region_ind] .* state_std
cov_region =
gp_exp_quad_cov(years, sigma_GP_region_long, length_GP_region_long) +
gp_exp_quad_cov(years, sigma_GP_region_short, length_GP_region_short)
cov_state =
gp_exp_quad_cov(years, sigma_GP_state_long, length_GP_state_long) +
gp_exp_quad_cov(years, sigma_GP_state_short, length_GP_state_short)
for year in 1:N_years
cov_region[year, year] = cov_region[year, year] + 1.0e-6
cov_state[year, year] = cov_state[year, year] + 1.0e-6
end
L_cov_region = cholesky(Symmetric(cov_region)).L
L_cov_state = cholesky(Symmetric(cov_state)).L
GP_region_matrix = Matrix(reshape(GP_region_std, N_years, N_regions))
GP_state_matrix = Matrix(reshape(GP_state_std, N_years, N_states))
GP_region = L_cov_region * GP_region_matrix
GP_state = L_cov_state * GP_state_matrix
obs_mu = zeros(typeof(mu + sigma_error_state_2), N)
for n in 1:N
obs_mu[n] =
mu +
year_re[year_ind[n]] +
state_re[state_ind[n]] +
region_re[region_ind[n]] +
GP_region[year_ind[n], region_ind[n]] +
GP_state[year_ind[n], state_ind[n]]
end
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma_error_state_2), N)), y .- obs_mu
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
37 μs · 4 calls
75.5 μs · 4 calls
38.4 μs
93.8 μs
20261122T002521Z-565231f-registered-repeat-1
Off
32.5 μs · 16 calls
90.5 μs · 4 calls
39 μs
98.3 μs
20261122T002521Z-565231f
On · no reduction
37 μs · 4 calls
75.5 μs · 4 calls
38.4 μs
93.8 μs
20261122T002521Z-565231f
Off
32.5 μs · 16 calls
90.5 μs · 4 calls
39 μs
98.3 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
32 μs · 12 calls
74.8 μs · 12 calls
49.6 μs
121 μs
20261122T000034Z-565231f-registered-repeat-1
Off
43.1 μs · 4 calls
74.2 μs · 4 calls
38.2 μs
92.1 μs
20261122T000034Z-565231f
On · no reduction
32 μs · 12 calls
74.8 μs · 12 calls
49.6 μs
121 μs
20261122T000034Z-565231f
Off
43.1 μs · 4 calls
74.2 μs · 4 calls
38.2 μs
92.1 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
78.9 μs · 9 calls
42.2 μs
91.8 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
76 μs · 4 calls
39.9 μs
96.2 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
78.9 μs · 9 calls
42.2 μs
91.8 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
76 μs · 4 calls
39.9 μs
96.2 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 37.1 μs · value and gradient 107 μs
PosteriorDB model hierarchical_gp · dataset state_wide_presidential_votes · SHA-256 95f6ba56a4269ceb8b58789a7c600b203e5ebe423dc4043a326e69cc343c100b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@wren function surgical_model(r, n)
mu ~ WD.Normal(0.0, 1000.0)
sigmasq ~ WD.InverseGamma(0.001, 0.001)
sigma = sqrt(sigmasq)
@iid b ~ WD.Normal(mu, sigma) size=length(r)
@batch for i in eachindex(r)
@observe r[i] ~ WD.BinomialLogit(n[i], b[i])
end
return nothing
end
@model function surgical(r, n)
mu ~ Normal(0, 1000)
precision ~ Gamma(0.001, 1000)
sigma = inv(sqrt(precision))
b ~ MvNormal(fill(mu, length(r)), sigma^2 * I)
r .~ BinomialLogit.(n, b)
end
%%%
# Surgical mortality
PosteriorDB's `surgical_data-surgical_model`. Deaths in twelve hospitals are
binomial with logit rates b. The rates are Normal around mu with an inverse-
gamma variance.
%%%
flatppl_compat = "0.1"
N = 12
data = load_data("data.json", cartprod(
n = cartpow(nonnegintegers, N), r = cartpow(nonnegintegers, N)))
mu ~ Normal(0, 1000)
sigmasq ~ InverseGamma(0.001, 0.001)
b ~ iid(Normal(mu, sqrt(sigmasq)), N)
r ~ Binomial.(data.n, invlogit.(b))
Pi_prior = lawof(record(mu = mu, sigmasq = sigmasq, b = b))
K_model = kernelof(record(r = r), mu = mu, sigmasq = sigmasq, b = b)
L = likelihoodof(K_model, record(r = data.r))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(mu = reals, sigmasq = posreals, b = cartpow(reals, 12))
Pi_post_input = record(mu = -2.47, sigmasq = 0.161, b = fill(-2.44, 12))
@model function pdb_surgical_model(N, r, n)
mu ~ Normal(0.0, 1000.0)
sigmasq ~ InverseGamma(0.001, 0.001)
b ~ product_distribution(Fill(Flat(), N))
sigma = sqrt(sigmasq)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(mu, sigma), size(b))), b
)
DynamicPPL.@addlogprob! logpdf(product_distribution(map(BinomialLogit, n, b)), r)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
348 ns · 1128 calls
297 ns · 1752 calls
3.99 μs
5.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
333 ns · 1480 calls
318 ns · 1592 calls
4.14 μs
5.29 μs
20261122T002521Z-565231f
On · no reduction
348 ns · 1128 calls
297 ns · 1752 calls
3.99 μs
5.6 μs
20261122T002521Z-565231f
Off
333 ns · 1480 calls
318 ns · 1592 calls
4.14 μs
5.29 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
325 ns · 1600 calls
284 ns · 1664 calls
3.94 μs
5.55 μs
20261122T000034Z-565231f-registered-repeat-1
Off
327 ns · 1740 calls
291 ns · 1520 calls
4 μs
5.34 μs
20261122T000034Z-565231f
On · no reduction
325 ns · 1600 calls
284 ns · 1664 calls
3.94 μs
5.55 μs
20261122T000034Z-565231f
Off
327 ns · 1740 calls
291 ns · 1520 calls
4 μs
5.34 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
356 ns · 429 calls
3.92 μs
5.48 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
340 ns · 472 calls
3.85 μs
5.3 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
356 ns · 429 calls
3.92 μs
5.48 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
340 ns · 472 calls
3.85 μs
5.3 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 4.13 μs · value and gradient 5.45 μs
PosteriorDB model surgical_model · dataset surgical_data · SHA-256 1cb463b630377b30ab27ec89a49269f58f5a0c1841fcb9a5ebe7cc638f9d422a
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
384 ns
1.12 μs
FlatPPL · normal optimizations
3.99 μs · 10.4× Wren
5.6 μs · 5.0× Wren
FlatPPL · equal work
4.14 μs · 10.8× Wren
5.29 μs · 4.72× Wren
Wren definition in this run
@wren function surgical_model(r, n)
mu ~ WD.Normal(0.0, 1000.0)
sigmasq ~ WD.InverseGamma(0.001, 0.001)
sigma = sqrt(sigmasq)
@iid b ~ WD.Normal(mu, sigma) size=length(r)
@batch for i in eachindex(r)
@observe r[i] ~ WD.BinomialLogit(n[i], b[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
399 ns
1.14 μs
FlatPPL · normal optimizations
3.94 μs · 9.87× Wren
5.55 μs · 4.86× Wren
FlatPPL · equal work
4 μs · 10.0× Wren
5.34 μs · 4.67× Wren
Wren definition in this run
@wren function surgical_model(r, n)
mu ~ WD.Normal(0.0, 1000.0)
sigmasq ~ WD.InverseGamma(0.001, 0.001)
sigma = sqrt(sigmasq)
@iid b ~ WD.Normal(mu, sigma) size=length(r)
@batch for i in eachindex(r)
@observe r[i] ~ WD.BinomialLogit(n[i], b[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
378 ns
1.11 μs
FlatPPL · normal optimizations
3.92 μs · 10.4× Wren
5.48 μs · 4.92× Wren
FlatPPL · equal work
3.85 μs · 10.2× Wren
5.3 μs · 4.76× Wren
Wren definition in this run
@wren function surgical_model(r, n)
mu ~ WD.Normal(0.0, 1000.0)
sigmasq ~ WD.InverseGamma(0.001, 0.001)
sigma = sqrt(sigmasq)
@iid b ~ WD.Normal(mu, sigma) size=length(r)
@batch for i in eachindex(r)
@observe r[i] ~ WD.BinomialLogit(n[i], b[i])
end
return nothing
end
@model function survey(k, nmax)
theta ~ Uniform(0, 1)
@addlogprob! logsumexp([log(1 / nmax) + sum(logpdf.(Binomial.(n, theta), k)) for n in 1:nmax])
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
17.4 μs · 4 calls
19.4 μs · 4 calls
21.9 μs
34 μs
20261122T002521Z-565231f-registered-repeat-1
Off
23.9 μs · 32 calls
19.2 μs · 8 calls
22.8 μs
25.4 μs
20261122T002521Z-565231f
On · no reduction
17.4 μs · 4 calls
19.4 μs · 4 calls
21.9 μs
34 μs
20261122T002521Z-565231f
Off
23.9 μs · 32 calls
19.2 μs · 8 calls
22.8 μs
25.4 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
15.3 μs · 36 calls
17.7 μs · 36 calls
20.9 μs
24.6 μs
20261122T000034Z-565231f-registered-repeat-1
Off
15.5 μs · 36 calls
17.8 μs · 36 calls
20.9 μs
24.4 μs
20261122T000034Z-565231f
On · no reduction
15.3 μs · 36 calls
17.7 μs · 36 calls
20.9 μs
24.6 μs
20261122T000034Z-565231f
Off
15.5 μs · 36 calls
17.8 μs · 36 calls
20.9 μs
24.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
17.4 μs · 27 calls
20.9 μs
26.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
17.1 μs · 36 calls
21.7 μs
33.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
17.4 μs · 27 calls
20.9 μs
26.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
17.1 μs · 36 calls
21.7 μs
33.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 20.1 μs · value and gradient 24.8 μs
PosteriorDB model Survey_model · dataset Survey_data · SHA-256 8e2c1f37de9116c12a3a5efab9002ad73dda1a27ad7d7480751f966c3f482afb
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
78.4 μs
184 μs
FlatPPL · normal optimizations
21.9 μs · 0.28× Wren
34 μs · 0.185× Wren
FlatPPL · equal work
22.8 μs · 0.291× Wren
25.4 μs · 0.138× Wren
Wren definition in this run
@wren function survey_model(k, nmax)
theta ~ WD.Uniform(0.0, 1.0)
@addloglikelihood survey_mixture_logp(theta, k, nmax)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
76.9 μs
189 μs
FlatPPL · normal optimizations
20.9 μs · 0.271× Wren
24.6 μs · 0.131× Wren
FlatPPL · equal work
20.9 μs · 0.271× Wren
24.4 μs · 0.13× Wren
Wren definition in this run
@wren function survey_model(k, nmax)
theta ~ WD.Uniform(0.0, 1.0)
@addloglikelihood survey_mixture_logp(theta, k, nmax)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
73.7 μs
172 μs
FlatPPL · normal optimizations
20.9 μs · 0.283× Wren
26.3 μs · 0.153× Wren
FlatPPL · equal work
21.7 μs · 0.295× Wren
33.5 μs · 0.195× Wren
Wren definition in this run
@wren function survey_model(k, nmax)
theta ~ WD.Uniform(0.0, 1.0)
@addloglikelihood survey_mixture_logp(theta, k, nmax)
return nothing
end
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
const LDA_DOCUMENT_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for m in eachindex(words)
words[m] .~ Categorical(phi * theta[:, m])
end
end
const LDA_WORD_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for i in eachindex(w)
w[i] ~ Categorical(phi * theta[:, doc[i]])
end
end
%%%
# Latent Dirichlet allocation with two topics
PosteriorDB's `three_docs1200-ldaK2`. Three documents of 400 words use a
vocabulary of three words. Each document mixes two topics with weights
theta, and each topic draws words with probabilities phi. Summing over the
topic of each word gives the word probabilities theta * phi. All simplex
priors are uniform.
%%%
flatppl_compat = "0.1"
V = 3
M = 3
N = 1200
K = 2
data = load_data("data.json", cartprod(
w = cartpow(posintegers, N), doc = cartpow(posintegers, N)))
theta ~ iid(Dirichlet(ones(K)), M)
phi ~ iid(Dirichlet(ones(V)), K)
word_probs = rowstack(theta) * rowstack(phi)
document_words = [word_probs[1, :], word_probs[2, :], word_probs[3, :]]
w ~ Categorical.(document_words[data.doc])
Pi_prior = lawof(record(theta = theta, phi = phi))
K_model = kernelof(record(w = w), theta = theta, phi = phi)
L = likelihoodof(K_model, record(w = data.w))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta = cartpow(stdsimplex(K), M), phi = cartpow(stdsimplex(V), K))
Pi_post_input = record(theta = fill(fill(1 / K, K), M), phi = fill(fill(1 / V, V), K))
@model function pdb_ldaK2(V, M, N, w, doc)
K = 2
theta ~ product_distribution(Fill(Dirichlet(ones(K)), M))
phi ~ product_distribution(Fill(Dirichlet(ones(V)), K))
logits = permutedims(log.(view(theta, :, doc))) .+ log.(view(phi, w, :))
DynamicPPL.@addlogprob! sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
8.81 μs · 32 calls
10.5 μs · 20 calls
16.4 μs
20.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
13.4 μs · 4 calls
10.6 μs · 20 calls
22 μs
20.8 μs
20261122T002521Z-565231f
On · no reduction
8.81 μs · 32 calls
10.5 μs · 20 calls
16.4 μs
20.7 μs
20261122T002521Z-565231f
Off
13.4 μs · 4 calls
10.6 μs · 20 calls
22 μs
20.8 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
7.46 μs · 84 calls
9.88 μs · 76 calls
18.2 μs
21.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
7.72 μs · 76 calls
10.5 μs · 20 calls
16.5 μs
19.9 μs
20261122T000034Z-565231f
On · no reduction
7.46 μs · 84 calls
9.88 μs · 76 calls
18.2 μs
21.4 μs
20261122T000034Z-565231f
Off
7.72 μs · 76 calls
10.5 μs · 20 calls
16.5 μs
19.9 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 17.8 μs · value and gradient 21 μs
PosteriorDB model ldaK2 · dataset three_docs1200 · SHA-256 fb52039f21de5fd0937f5da83924be69d2132adff6dca1f0f1a51eb95b658736
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
44 μs
87.2 μs
FlatPPL · normal optimizations
16.4 μs · 0.372× Wren
20.7 μs · 0.237× Wren
FlatPPL · equal work
22 μs · 0.5× Wren
20.8 μs · 0.238× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
44 μs
89.8 μs
FlatPPL · normal optimizations
18.2 μs · 0.415× Wren
21.4 μs · 0.238× Wren
FlatPPL · equal work
16.5 μs · 0.376× Wren
19.9 μs · 0.222× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
44.9 μs
85.6 μs
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
const LDA_DOCUMENT_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for m in eachindex(words)
words[m] .~ Categorical(phi * theta[:, m])
end
end
const LDA_WORD_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for i in eachindex(w)
w[i] ~ Categorical(phi * theta[:, doc[i]])
end
end
%%%
# Latent Dirichlet allocation with two topics, three_men1
PosteriorDB's `three_men1-ldaK2`. 6 documents with 4999 words in all use a
vocabulary of 249 words. Each document mixes two topics with weights theta,
and each topic draws words with probabilities phi. Summing over the topic of
each word gives the word probabilities theta * phi. All simplex priors are
uniform.
%%%
flatppl_compat = "0.1"
V = 249
M = 6
N = 4999
K = 2
data = load_data("data.json", cartprod(
w = cartpow(posintegers, N), doc = cartpow(posintegers, N)))
theta ~ iid(Dirichlet(ones(K)), M)
phi ~ iid(Dirichlet(ones(V)), K)
word_probs = rowstack(theta) * rowstack(phi)
document_words = [word_probs[1, :], word_probs[2, :], word_probs[3, :], word_probs[4, :], word_probs[5, :], word_probs[6, :]]
w ~ Categorical.(document_words[data.doc])
Pi_prior = lawof(record(theta = theta, phi = phi))
K_model = kernelof(record(w = w), theta = theta, phi = phi)
L = likelihoodof(K_model, record(w = data.w))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta = cartpow(stdsimplex(2), 6), phi = cartpow(stdsimplex(249), 2))
Pi_post_input = record(theta = fill(fill(1 / K, K), M), phi = fill(fill(1 / V, V), K))
@model function pdb_ldaK2(V, M, N, w, doc)
K = 2
theta ~ product_distribution(Fill(Dirichlet(ones(K)), M))
phi ~ product_distribution(Fill(Dirichlet(ones(V)), K))
logits = permutedims(log.(view(theta, :, doc))) .+ log.(view(phi, w, :))
DynamicPPL.@addlogprob! sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
135 μs · 4 calls
117 μs · 4 calls
131 μs
107 μs
20261122T002521Z-565231f-registered-repeat-1
Off
125 μs · 4 calls
94 μs · 4 calls
128 μs
142 μs
20261122T002521Z-565231f
On · no reduction
135 μs · 4 calls
117 μs · 4 calls
131 μs
107 μs
20261122T002521Z-565231f
Off
125 μs · 4 calls
94 μs · 4 calls
128 μs
142 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
121 μs · 4 calls
115 μs · 8 calls
128 μs
110 μs
20261122T000034Z-565231f-registered-repeat-1
Off
117 μs · 4 calls
96.2 μs · 8 calls
130 μs
103 μs
20261122T000034Z-565231f
On · no reduction
121 μs · 4 calls
115 μs · 8 calls
128 μs
110 μs
20261122T000034Z-565231f
Off
117 μs · 4 calls
96.2 μs · 8 calls
130 μs
103 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 122 μs · value and gradient 127 μs
PosteriorDB model ldaK2 · dataset three_men1 · SHA-256 75fce59287b405c757dba659d687108b1431598aa0386e7582009cbc2d4f0c9b
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
189 μs
359 μs
FlatPPL · normal optimizations
131 μs · 0.697× Wren
107 μs · 0.299× Wren
FlatPPL · equal work
128 μs · 0.68× Wren
142 μs · 0.396× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
192 μs
347 μs
FlatPPL · normal optimizations
128 μs · 0.666× Wren
110 μs · 0.318× Wren
FlatPPL · equal work
130 μs · 0.675× Wren
103 μs · 0.298× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
195 μs
353 μs
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
const LDA_DOCUMENT_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for m in eachindex(words)
words[m] .~ Categorical(phi * theta[:, m])
end
end
const LDA_WORD_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for i in eachindex(w)
w[i] ~ Categorical(phi * theta[:, doc[i]])
end
end
@model function pdb_ldaK2(V, M, N, w, doc)
K = 2
theta ~ product_distribution(Fill(Dirichlet(ones(K)), M))
phi ~ product_distribution(Fill(Dirichlet(ones(V)), K))
logits = permutedims(log.(view(theta, :, doc))) .+ log.(view(phi, w, :))
DynamicPPL.@addlogprob! sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
128 μs · 4 calls
105 μs · 4 calls
132 μs
117 μs
20261122T002521Z-565231f-registered-repeat-1
Off
134 μs · 4 calls
101 μs · 4 calls
130 μs
142 μs
20261122T002521Z-565231f
On · no reduction
128 μs · 4 calls
105 μs · 4 calls
132 μs
117 μs
20261122T002521Z-565231f
Off
134 μs · 4 calls
101 μs · 4 calls
130 μs
142 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
118 μs · 4 calls
95.3 μs · 4 calls
131 μs
108 μs
20261122T000034Z-565231f-registered-repeat-1
Off
118 μs · 8 calls
95.6 μs · 8 calls
129 μs
112 μs
20261122T000034Z-565231f
On · no reduction
118 μs · 4 calls
95.3 μs · 4 calls
131 μs
108 μs
20261122T000034Z-565231f
Off
118 μs · 8 calls
95.6 μs · 8 calls
129 μs
112 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 122 μs · value and gradient 139 μs
PosteriorDB model ldaK2 · dataset three_men2 · SHA-256 3c50b699473613e47c7abcdae27b70b1bed5756f5c3fdfddb5bc87fd1997218c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
209 μs
369 μs
FlatPPL · normal optimizations
132 μs · 0.632× Wren
117 μs · 0.316× Wren
FlatPPL · equal work
130 μs · 0.623× Wren
142 μs · 0.384× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
209 μs
375 μs
FlatPPL · normal optimizations
131 μs · 0.628× Wren
108 μs · 0.288× Wren
FlatPPL · equal work
129 μs · 0.617× Wren
112 μs · 0.298× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
209 μs
394 μs
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
const LDA_DOCUMENT_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for m in eachindex(words)
words[m] .~ Categorical(phi * theta[:, m])
end
end
const LDA_WORD_CATEGORICAL = @rkppl begin
eachcol(theta[1:2, 1:M]) .~ Dirichlet(ones(2))
eachcol(phi[1:V, 1:2]) .~ Dirichlet(ones(V))
@plate for i in eachindex(w)
w[i] ~ Categorical(phi * theta[:, doc[i]])
end
end
%%%
# Latent Dirichlet allocation with two topics, three_men3
PosteriorDB's `three_men3-ldaK2`. 9 documents with 4999 words in all use a
vocabulary of 249 words. Each document mixes two topics with weights theta,
and each topic draws words with probabilities phi. Summing over the topic of
each word gives the word probabilities theta * phi. All simplex priors are
uniform.
%%%
flatppl_compat = "0.1"
V = 249
M = 9
N = 4999
K = 2
data = load_data("data.json", cartprod(
w = cartpow(posintegers, N), doc = cartpow(posintegers, N)))
theta ~ iid(Dirichlet(ones(K)), M)
phi ~ iid(Dirichlet(ones(V)), K)
word_probs = rowstack(theta) * rowstack(phi)
document_words = [word_probs[1, :], word_probs[2, :], word_probs[3, :], word_probs[4, :], word_probs[5, :], word_probs[6, :], word_probs[7, :], word_probs[8, :], word_probs[9, :]]
w ~ Categorical.(document_words[data.doc])
Pi_prior = lawof(record(theta = theta, phi = phi))
K_model = kernelof(record(w = w), theta = theta, phi = phi)
L = likelihoodof(K_model, record(w = data.w))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(theta = cartpow(stdsimplex(2), 9), phi = cartpow(stdsimplex(249), 2))
Pi_post_input = record(theta = fill(fill(1 / K, K), M), phi = fill(fill(1 / V, V), K))
@model function pdb_ldaK2(V, M, N, w, doc)
K = 2
theta ~ product_distribution(Fill(Dirichlet(ones(K)), M))
phi ~ product_distribution(Fill(Dirichlet(ones(V)), K))
logits = permutedims(log.(view(theta, :, doc))) .+ log.(view(phi, w, :))
DynamicPPL.@addlogprob! sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
142 μs · 4 calls
99.6 μs · 4 calls
133 μs
143 μs
20261122T002521Z-565231f-registered-repeat-1
Off
124 μs · 4 calls
103 μs · 4 calls
146 μs
115 μs
20261122T002521Z-565231f
On · no reduction
142 μs · 4 calls
99.6 μs · 4 calls
133 μs
143 μs
20261122T002521Z-565231f
Off
124 μs · 4 calls
103 μs · 4 calls
146 μs
115 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
123 μs · 4 calls
101 μs · 4 calls
131 μs
116 μs
20261122T000034Z-565231f-registered-repeat-1
Off
117 μs · 4 calls
98 μs · 4 calls
126 μs
120 μs
20261122T000034Z-565231f
On · no reduction
123 μs · 4 calls
101 μs · 4 calls
131 μs
116 μs
20261122T000034Z-565231f
Off
117 μs · 4 calls
98 μs · 4 calls
126 μs
120 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 128 μs · value and gradient 112 μs
PosteriorDB model ldaK2 · dataset three_men3 · SHA-256 ff43018e8b71772d7e0ca2bb8d59dccf2f879a38f79925f3f0356d63efcce8ec
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
292 μs
457 μs
FlatPPL · normal optimizations
133 μs · 0.456× Wren
143 μs · 0.312× Wren
FlatPPL · equal work
146 μs · 0.501× Wren
115 μs · 0.252× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
201 μs
360 μs
FlatPPL · normal optimizations
131 μs · 0.654× Wren
116 μs · 0.321× Wren
FlatPPL · equal work
126 μs · 0.626× Wren
120 μs · 0.332× Wren
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
199 μs
369 μs
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function lda_k2(w, doc, V, M)
theta = zeros(2, M)
for m in 1:M
theta[:, m] ~ WD.Dirichlet(ones(2))
end
phi = zeros(V, 2)
for k in 1:2
phi[:, k] ~ WD.Dirichlet(ones(V))
end
@addloglikelihood lda_logdensity(w, doc, theta, phi)
return nothing
end
%%%
# Generalized partial credit model with latent regression
PosteriorDB's `timssAusTwn_irt-gpcm_latent_reg_irt`. 500 students answer 11
items scored 0 to m[i], where m[i] is the largest observed score on item i,
as Stan's transformed data computes. Items with m[i] = 1 have one step and
items with m[i] = 2 have two. With t = alpha[i] * theta[j], the score is
Categorical with probabilities softmax(cumsum([0, t - b_1, ..., t - b_m]))
over the item's own steps, so a two-step item adds the logit 2t - b_1 - b_2.
The step parameters of all items form one vector beta whose last entry is
minus the sum of the others. Stan adds normal_lpdf(beta | 0, 3) over the
full vector, a log weight on Lebesgue measure for beta_free. Abilities are
Normal around a regression on five covariates. Stan's test for binary
columns never succeeds because of operator precedence, so columns 2 to 5 are
centered by their mean and scaled by twice their standard deviation, and
column 1 is kept as is.
%%%
flatppl_compat = "0.1"
I = 11
J = 500
N = 5500
K = 5
data = load_data("data.json", cartprod(
ii = cartpow(posintegers, N), jj = cartpow(posintegers, N), y = cartpow(nonnegintegers, N),
W = cartpow(reals, [J, K])))
% The first and second step of each item in beta, and whether the item has a second step.
first_step = [1, 2, 3, 5, 7, 8, 9, 11, 13, 14, 15]
second_step = [1, 2, 4, 6, 7, 8, 10, 12, 13, 14, 15]
two_steps = [false, false, true, true, false, false, true, true, false, false, false]
column_mean = aggregate(mean, [.k], data.W[.j, .k])
column_std = aggregate(std, [.k], data.W[.j, .k])
shift = cat([0.0], column_mean[[2, 3, 4, 5]])
scale = cat([1.0], 2 .* column_std[[2, 3, 4, 5]])
W_adj = aggregate(sum, [.j, .k], (data.W[.j, .k] - shift[.k]) / scale[.k])
alpha ~ iid(LogNormal(1, 1), I)
lambda_adj ~ iid(StudentT(3), K)
theta ~ Normal.(W_adj * lambda_adj, 1)
beta_free = elementof(cartpow(reals, 14))
beta = cat(beta_free, [-sum(beta_free)])
pcm_probs(t, b1, b2, two) = softmax([0.0, t - b1, ifelse(two, 2 * t - b1 - b2, -inf)])
y ~ Categorical.(pcm_probs.(alpha[data.ii] .* theta[data.jj], beta[first_step[data.ii]],
beta[second_step[data.ii]], two_steps[data.ii]))
step_weight(p) = sum(logdensityof.(Normal(0, 3), cat(p.beta_free, [-sum(p.beta_free)])))
Pi_steps = logweighted(step_weight, Lebesgue(cartprod(beta_free = cartpow(reals, 14))))
Pi_prior = joint(lawof(record(alpha = alpha, theta = theta, lambda_adj = lambda_adj)), Pi_steps)
K_model = kernelof(record(y = y), alpha = alpha, theta = theta, lambda_adj = lambda_adj, beta_free = beta_free)
L = likelihoodof(K_model, record(y = data.y .+ 1))
Pi_post = bayesupdate(L, Pi_prior)
Pi_post_domain = cartprod(alpha = cartpow(posreals, 11), theta = cartpow(reals, 500), lambda_adj = cartpow(reals, 5), beta_free = cartpow(reals, 14))
Pi_post_input = record(alpha = fill(1.59, 11), theta = fill(0.0, 500), lambda_adj = [0.0662, 1.37, 0.0649, -0.119, 0.159], beta_free = fill(0.0745, 14))
@model function pdb_gpcm_latent_reg_irt(
I, J, N, ii, jj, response, m, W_adj, levels, valid, response_indices, step_design
)
K = size(W_adj, 2)
alpha ~ product_distribution(Fill(LogNormal(1, 1), I))
beta_free ~ product_distribution(Fill(Flat(), sum(m) - 1))
lambda_adj ~ product_distribution(Fill(LocationScale(0, 1, TDist(3)), K))
theta ~ MvNormal(W_adj * lambda_adj, 1.0)
beta = vcat(beta_free, -(sum(beta_free)))
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, 3), size(beta))), beta
)
ability = alpha[ii] .* theta[jj]
cumulative_difficulty = reshape(step_design * beta, I, size(levels, 2))
logits = reshape(ability, N, 1) .* levels .- cumulative_difficulty[ii, :]
logits = ifelse.(valid, logits, -Inf)
DynamicPPL.@addlogprob! sum(logits[response_indices]) - sum(logsumexp(logits; dims=2))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
87.2 μs · 4 calls
473 μs · 4 calls
91.9 μs
169 μs
20261122T002521Z-565231f-registered-repeat-1
Off
103 μs · 8 calls
241 μs · 4 calls
126 μs
188 μs
20261122T002521Z-565231f
On · no reduction
87.2 μs · 4 calls
473 μs · 4 calls
91.9 μs
169 μs
20261122T002521Z-565231f
Off
103 μs · 8 calls
241 μs · 4 calls
126 μs
188 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
83.9 μs · 8 calls
168 μs · 4 calls
83.8 μs
157 μs
20261122T000034Z-565231f-registered-repeat-1
Off
76 μs · 8 calls
225 μs · 4 calls
87.1 μs
145 μs
20261122T000034Z-565231f
On · no reduction
83.9 μs · 8 calls
168 μs · 4 calls
83.8 μs
157 μs
20261122T000034Z-565231f
Off
76 μs · 8 calls
225 μs · 4 calls
87.1 μs
145 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
163 μs · 5 calls
73 μs
141 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
131 μs · 7 calls
74.8 μs
144 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
163 μs · 5 calls
73 μs
141 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
131 μs · 7 calls
74.8 μs
144 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 82.4 μs · value and gradient 206 μs
PosteriorDB model gpcm_latent_reg_irt · dataset timssAusTwn_irt · SHA-256 588b3aad2093813ddff8dbb7d0e04cee9fbce93cf87092b26941924bd02f0ee3
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
102 μs
1.19 ms
FlatPPL · normal optimizations
91.9 μs · 0.905× Wren
169 μs · 0.142× Wren
FlatPPL · equal work
126 μs · 1.24× Wren
188 μs · 0.158× Wren
Wren definition in this run
@wren function latent_reg_gpcm(y, ii, jj, W_adj, m, pos, I, J, K, nsteps)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(nsteps - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood timss_logdensity(y, ii, jj, W_adj, m, pos,
alpha, beta_free, theta, lambda_adj)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
103 μs
1 ms
FlatPPL · normal optimizations
83.8 μs · 0.817× Wren
157 μs · 0.157× Wren
FlatPPL · equal work
87.1 μs · 0.85× Wren
145 μs · 0.145× Wren
Wren definition in this run
@wren function latent_reg_gpcm(y, ii, jj, W_adj, m, pos, I, J, K, nsteps)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(nsteps - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood timss_logdensity(y, ii, jj, W_adj, m, pos,
alpha, beta_free, theta, lambda_adj)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
104 μs
1.29 ms
FlatPPL · normal optimizations
73 μs · 0.705× Wren
141 μs · 0.109× Wren
FlatPPL · equal work
74.8 μs · 0.722× Wren
144 μs · 0.112× Wren
Wren definition in this run
@wren function latent_reg_gpcm(y, ii, jj, W_adj, m, pos, I, J, K, nsteps)
@iid alpha ~ WD.LogNormal(1.0, 1.0) size=I
@iid beta_free ~ WD.Flat() size=(nsteps - 1)
@iid theta ~ WD.Flat() size=J
@iid lambda_adj ~ WD.TDist(3.0, 0.0, 1.0) size=K
@addloglikelihood timss_logdensity(y, ii, jj, W_adj, m, pos,
alpha, beta_free, theta, lambda_adj)
return nothing
end
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
48.9 μs · 20 calls
43.1 μs · 20 calls
37.6 μs
48.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
33.5 μs · 12 calls
36.1 μs · 4 calls
44.7 μs
46 μs
20261122T002521Z-565231f
On · no reduction
48.9 μs · 20 calls
43.1 μs · 20 calls
37.6 μs
48.2 μs
20261122T002521Z-565231f
Off
33.5 μs · 12 calls
36.1 μs · 4 calls
44.7 μs
46 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
37 μs · 4 calls
36.7 μs · 4 calls
36.8 μs
45.8 μs
20261122T000034Z-565231f-registered-repeat-1
Off
35.4 μs · 16 calls
33 μs · 28 calls
35.5 μs
44.3 μs
20261122T000034Z-565231f
On · no reduction
37 μs · 4 calls
36.7 μs · 4 calls
36.8 μs
45.8 μs
20261122T000034Z-565231f
Off
35.4 μs · 16 calls
33 μs · 28 calls
35.5 μs
44.3 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
32 μs · 23 calls
31.8 μs
39.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
32.8 μs · 17 calls
34.5 μs
40.2 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
32 μs · 23 calls
31.8 μs
39.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
32.8 μs · 17 calls
34.5 μs
40.2 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 34.1 μs · value and gradient 43.4 μs
PosteriorDB model bym2_offset_only · dataset traffic_accident_nyc · SHA-256 c7bae55788db89a30a809a38cea46ad725b0dcd218b10e398abfd67a03dd20c4
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
@model function pdb_state_space_stochastic_level_stochastic_seasonal(
n, y, x, w, seasonal_design, mu_lower, mu_upper
)
mu ~ product_distribution(Fill(Uniform(mu_lower, mu_upper), n))
seasonal ~ product_distribution(Fill(Flat(), n))
beta ~ Flat()
lambda ~ Flat()
sigma ~ ordered(product_distribution(Fill(FlatPos(0.0), 3)))
seasonal_location = seasonal_design * seasonal
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma[1]), n - 11)),
seasonal[12:n] .- seasonal_location,
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma[2]), n - 1)), mu[2:n] .- mu[1:(n - 1)]
)
prediction = mu .+ beta .* x .+ lambda .* w .+ seasonal
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(Normal(0, sigma[3]), n)), y .- prediction
)
DynamicPPL.@addlogprob! logpdf(
product_distribution(Fill(LocationScale(0, 1, TDist(4)), size(sigma))), sigma
)
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
2.32 μs · 92 calls
6.38 μs · 176 calls
9.08 μs
24.3 μs
20261122T002521Z-565231f-registered-repeat-1
Off
2.46 μs · 104 calls
5.14 μs · 148 calls
9.75 μs
25.5 μs
20261122T002521Z-565231f
On · no reduction
2.32 μs · 92 calls
6.38 μs · 176 calls
9.08 μs
24.3 μs
20261122T002521Z-565231f
Off
2.46 μs · 104 calls
5.14 μs · 148 calls
9.75 μs
25.5 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
2.45 μs · 356 calls
5.48 μs · 124 calls
9.66 μs
22.3 μs
20261122T000034Z-565231f-registered-repeat-1
Off
2.05 μs · 312 calls
5.42 μs · 132 calls
9.56 μs
19 μs
20261122T000034Z-565231f
On · no reduction
2.45 μs · 356 calls
5.48 μs · 124 calls
9.66 μs
22.3 μs
20261122T000034Z-565231f
Off
2.05 μs · 312 calls
5.42 μs · 132 calls
9.56 μs
19 μs
20261121T195722Z-565231f-registered-repeat-1
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 10.1 μs · value and gradient 20.2 μs
PosteriorDB model state_space_stochastic_level_stochastic_seasonal · dataset uk_drivers · SHA-256 c48362b036a8bcff8d5be24e20cb7ffc026d243736d7b04d5b89376bf01e02dd
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.87 μs
10.7 μs
FlatPPL · normal optimizations
9.08 μs · 1.55× Wren
24.3 μs · 2.28× Wren
FlatPPL · equal work
9.75 μs · 1.66× Wren
25.5 μs · 2.39× Wren
Wren definition in this run
@wren function uk_drivers(y, x, w, lower, width)
@iid mu ~ WD.Uniform(lower, lower + width) size=length(y)
@iid seasonal ~ WD.Flat() size=length(y)
beta ~ WD.Flat()
lambda ~ WD.Flat()
raw_sigma1 ~ WD.Flat()
raw_sigma_gap2 ~ WD.Flat()
raw_sigma_gap3 ~ WD.Flat()
sigma1 = exp(raw_sigma1)
sigma2 = sigma1 + exp(raw_sigma_gap2)
sigma3 = sigma2 + exp(raw_sigma_gap3)
# Stan's positive_ordered[3] transform and the three untruncated
# Student-t prior factors on its positive components.
# Native positive-ordered prior support is tracked in #207.
@addloglikelihood raw_sigma1 + raw_sigma_gap2 + raw_sigma_gap3 +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma1) +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma2) +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma3)
@addloglikelihood state_space_loglikelihood(y, x, w, mu, seasonal,
beta, lambda, sigma1, sigma2, sigma3)
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.83 μs
9.79 μs
FlatPPL · normal optimizations
9.66 μs · 1.66× Wren
22.3 μs · 2.28× Wren
FlatPPL · equal work
9.56 μs · 1.64× Wren
19 μs · 1.94× Wren
Wren definition in this run
@wren function uk_drivers(y, x, w, lower, width)
@iid mu ~ WD.Uniform(lower, lower + width) size=length(y)
@iid seasonal ~ WD.Flat() size=length(y)
beta ~ WD.Flat()
lambda ~ WD.Flat()
raw_sigma1 ~ WD.Flat()
raw_sigma_gap2 ~ WD.Flat()
raw_sigma_gap3 ~ WD.Flat()
sigma1 = exp(raw_sigma1)
sigma2 = sigma1 + exp(raw_sigma_gap2)
sigma3 = sigma2 + exp(raw_sigma_gap3)
# Stan's positive_ordered[3] transform and the three untruncated
# Student-t prior factors on its positive components.
# Native positive-ordered prior support is tracked in #207.
@addloglikelihood raw_sigma1 + raw_sigma_gap2 + raw_sigma_gap3 +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma1) +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma2) +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma3)
@addloglikelihood state_space_loglikelihood(y, x, w, mu, seasonal,
beta, lambda, sigma1, sigma2, sigma3)
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
5.87 μs
10.9 μs
FlatPPL · normal optimizations
build failed
build failed
FlatPPL · equal work
build failed
build failed
Wren definition in this run
@wren function uk_drivers(y, x, w, lower, width)
@iid mu ~ WD.Uniform(lower, lower + width) size=length(y)
@iid seasonal ~ WD.Flat() size=length(y)
beta ~ WD.Flat()
lambda ~ WD.Flat()
raw_sigma1 ~ WD.Flat()
raw_sigma_gap2 ~ WD.Flat()
raw_sigma_gap3 ~ WD.Flat()
sigma1 = exp(raw_sigma1)
sigma2 = sigma1 + exp(raw_sigma_gap2)
sigma3 = sigma2 + exp(raw_sigma_gap3)
# Stan's positive_ordered[3] transform and the three untruncated
# Student-t prior factors on its positive components.
# Native positive-ordered prior support is tracked in #207.
@addloglikelihood raw_sigma1 + raw_sigma_gap2 + raw_sigma_gap3 +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma1) +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma2) +
logdensityof(WD.TDist(4.0, 0.0, 1.0), sigma3)
@addloglikelihood state_space_loglikelihood(y, x, w, mu, seasonal,
beta, lambda, sigma1, sigma2, sigma3)
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_daae_c_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 5))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
25.9 μs · 28 calls
15.6 μs · 44 calls
27.2 μs
22.2 μs
20261122T002521Z-565231f-registered-repeat-1
Off
29.4 μs · 28 calls
16.2 μs · 20 calls
26 μs
28.8 μs
20261122T002521Z-565231f
On · no reduction
25.9 μs · 28 calls
15.6 μs · 44 calls
27.2 μs
22.2 μs
20261122T002521Z-565231f
Off
29.4 μs · 28 calls
16.2 μs · 20 calls
26 μs
28.8 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
26.4 μs · 4 calls
15.1 μs · 44 calls
28.6 μs
20.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
24.3 μs · 36 calls
16 μs · 24 calls
23.9 μs
19 μs
20261122T000034Z-565231f
On · no reduction
26.4 μs · 4 calls
15.1 μs · 44 calls
28.6 μs
20.9 μs
20261122T000034Z-565231f
Off
24.3 μs · 36 calls
16 μs · 24 calls
23.9 μs
19 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
14 μs · 48 calls
26.2 μs
18.6 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
13.6 μs · 50 calls
27.6 μs
19.3 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
14 μs · 48 calls
26.2 μs
18.6 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
13.6 μs · 50 calls
27.6 μs
19.3 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 24.7 μs · value and gradient 21.5 μs
PosteriorDB model wells_daae_c_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
26.2 μs
53.5 μs
FlatPPL · normal optimizations
27.2 μs · 1.04× Wren
22.2 μs · 0.416× Wren
FlatPPL · equal work
26 μs · 0.996× Wren
28.8 μs · 0.538× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
27.3 μs
53.2 μs
FlatPPL · normal optimizations
28.6 μs · 1.05× Wren
20.9 μs · 0.393× Wren
FlatPPL · equal work
23.9 μs · 0.875× Wren
19 μs · 0.356× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
27.1 μs
56.8 μs
FlatPPL · normal optimizations
26.2 μs · 0.967× Wren
18.6 μs · 0.327× Wren
FlatPPL · equal work
27.6 μs · 1.02× Wren
19.3 μs · 0.339× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_dae_c_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 4))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
26.7 μs · 12 calls
22.7 μs · 8 calls
25.2 μs
21.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
24.5 μs · 32 calls
15.8 μs · 44 calls
25.1 μs
26.6 μs
20261122T002521Z-565231f
On · no reduction
26.7 μs · 12 calls
22.7 μs · 8 calls
25.2 μs
21.7 μs
20261122T002521Z-565231f
Off
24.5 μs · 32 calls
15.8 μs · 44 calls
25.1 μs
26.6 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
25.8 μs · 20 calls
15.6 μs · 40 calls
25.2 μs
21 μs
20261122T000034Z-565231f-registered-repeat-1
Off
26.7 μs · 32 calls
16.2 μs · 52 calls
24.8 μs
21 μs
20261122T000034Z-565231f
On · no reduction
25.8 μs · 20 calls
15.6 μs · 40 calls
25.2 μs
21 μs
20261122T000034Z-565231f
Off
26.7 μs · 32 calls
16.2 μs · 52 calls
24.8 μs
21 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
13.6 μs · 48 calls
24.5 μs
18.6 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
13.9 μs · 46 calls
25.6 μs
19.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
13.6 μs · 48 calls
24.5 μs
18.6 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
13.9 μs · 46 calls
25.6 μs
19.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 23.9 μs · value and gradient 20.5 μs
PosteriorDB model wells_dae_c_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
38.4 μs
56.2 μs
FlatPPL · normal optimizations
25.2 μs · 0.656× Wren
21.7 μs · 0.386× Wren
FlatPPL · equal work
25.1 μs · 0.652× Wren
26.6 μs · 0.472× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
35.8 μs
52.9 μs
FlatPPL · normal optimizations
25.2 μs · 0.705× Wren
21 μs · 0.398× Wren
FlatPPL · equal work
24.8 μs · 0.693× Wren
21 μs · 0.397× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
38.1 μs
60.3 μs
FlatPPL · normal optimizations
24.5 μs · 0.643× Wren
18.6 μs · 0.308× Wren
FlatPPL · equal work
25.6 μs · 0.673× Wren
19.5 μs · 0.324× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_dae_inter_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 6))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
28.5 μs · 28 calls
18.1 μs · 40 calls
26.5 μs
26.4 μs
20261122T002521Z-565231f-registered-repeat-1
Off
27.4 μs · 24 calls
19.4 μs · 40 calls
26.6 μs
22.2 μs
20261122T002521Z-565231f
On · no reduction
28.5 μs · 28 calls
18.1 μs · 40 calls
26.5 μs
26.4 μs
20261122T002521Z-565231f
Off
27.4 μs · 24 calls
19.4 μs · 40 calls
26.6 μs
22.2 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
26.4 μs · 4 calls
15.7 μs · 36 calls
25.1 μs
21 μs
20261122T000034Z-565231f-registered-repeat-1
Off
25.8 μs · 28 calls
18.2 μs · 40 calls
24.3 μs
19.6 μs
20261122T000034Z-565231f
On · no reduction
26.4 μs · 4 calls
15.7 μs · 36 calls
25.1 μs
21 μs
20261122T000034Z-565231f
Off
25.8 μs · 28 calls
18.2 μs · 40 calls
24.3 μs
19.6 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
14.8 μs · 48 calls
25.9 μs
19.3 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
14.2 μs · 44 calls
26.9 μs
19.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
14.8 μs · 48 calls
25.9 μs
19.3 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
14.2 μs · 44 calls
26.9 μs
19.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 24.8 μs · value and gradient 21.8 μs
PosteriorDB model wells_dae_inter_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
27.3 μs
52 μs
FlatPPL · normal optimizations
26.5 μs · 0.969× Wren
26.4 μs · 0.508× Wren
FlatPPL · equal work
26.6 μs · 0.975× Wren
22.2 μs · 0.426× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
27.6 μs
49.8 μs
FlatPPL · normal optimizations
25.1 μs · 0.911× Wren
21 μs · 0.421× Wren
FlatPPL · equal work
24.3 μs · 0.881× Wren
19.6 μs · 0.394× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
37.2 μs
51.7 μs
FlatPPL · normal optimizations
25.9 μs · 0.697× Wren
19.3 μs · 0.374× Wren
FlatPPL · equal work
26.9 μs · 0.723× Wren
19.5 μs · 0.377× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_dae_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 3))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
27.3 μs · 28 calls
18.6 μs · 16 calls
34 μs
22.6 μs
20261122T002521Z-565231f-registered-repeat-1
Off
25.4 μs · 28 calls
16.3 μs · 8 calls
34.8 μs
21.7 μs
20261122T002521Z-565231f
On · no reduction
27.3 μs · 28 calls
18.6 μs · 16 calls
34 μs
22.6 μs
20261122T002521Z-565231f
Off
25.4 μs · 28 calls
16.3 μs · 8 calls
34.8 μs
21.7 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
25.2 μs · 32 calls
15.4 μs · 32 calls
27.1 μs
28.9 μs
20261122T000034Z-565231f-registered-repeat-1
Off
24 μs · 32 calls
15.6 μs · 44 calls
27.7 μs
21.9 μs
20261122T000034Z-565231f
On · no reduction
25.2 μs · 32 calls
15.4 μs · 32 calls
27.1 μs
28.9 μs
20261122T000034Z-565231f
Off
24 μs · 32 calls
15.6 μs · 44 calls
27.7 μs
21.9 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
15.5 μs · 48 calls
26.7 μs
20.1 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
15.7 μs · 4 calls
25.8 μs
20.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
15.5 μs · 48 calls
26.7 μs
20.1 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
15.7 μs · 4 calls
25.8 μs
20.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 26.1 μs · value and gradient 21.1 μs
PosteriorDB model wells_dae_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
33.6 μs
54.4 μs
FlatPPL · normal optimizations
34 μs · 1.01× Wren
22.6 μs · 0.415× Wren
FlatPPL · equal work
34.8 μs · 1.04× Wren
21.7 μs · 0.399× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
33.7 μs
50.5 μs
FlatPPL · normal optimizations
27.1 μs · 0.805× Wren
28.9 μs · 0.573× Wren
FlatPPL · equal work
27.7 μs · 0.823× Wren
21.9 μs · 0.434× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
34.6 μs
54.2 μs
FlatPPL · normal optimizations
26.7 μs · 0.773× Wren
20.1 μs · 0.371× Wren
FlatPPL · equal work
25.8 μs · 0.746× Wren
20.5 μs · 0.377× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_dist_model(switched, X)
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function wells_dist(X, switched)
beta ~ filldist(Flat(), size(X, 2))
switched ~ product_distribution(BernoulliLogit.(X * beta))
end
@model function wells_dist_loop(X, switched)
beta ~ filldist(Flat(), size(X, 2))
logit_p = X * beta
for i in eachindex(switched)
switched[i] ~ BernoulliLogit(logit_p[i])
end
end
@model function pdb_wells_dist(signs, X)
X = X.value
beta ~ product_distribution(Fill(Flat(), 2))
logits = beta[1] .+ X * view(beta, 2:2)
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
20.7 μs · 44 calls
17.6 μs · 40 calls
18.6 μs
18.5 μs
20261122T002521Z-565231f-registered-repeat-1
Off
19.1 μs · 16 calls
16.5 μs · 4 calls
21.9 μs
18.9 μs
20261122T002521Z-565231f
On · no reduction
20.7 μs · 44 calls
17.6 μs · 40 calls
18.6 μs
18.5 μs
20261122T002521Z-565231f
Off
19.1 μs · 16 calls
16.5 μs · 4 calls
21.9 μs
18.9 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
17.9 μs · 48 calls
13.5 μs · 64 calls
17.8 μs
18 μs
20261122T000034Z-565231f-registered-repeat-1
Off
17.2 μs · 44 calls
13.6 μs · 52 calls
18.4 μs
17.7 μs
20261122T000034Z-565231f
On · no reduction
17.9 μs · 48 calls
13.5 μs · 64 calls
17.8 μs
18 μs
20261122T000034Z-565231f
Off
17.2 μs · 44 calls
13.6 μs · 52 calls
18.4 μs
17.7 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261114T233319Z-f022c87
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261114T233319Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261114T225256Z-f022c87
On · no reduction
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
20261114T225256Z-f022c87
Off
JIT-loop timing not recorded
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 23.7 μs · value and gradient 19.9 μs
PosteriorDB model wells_dist · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.17 μs
24 μs
FlatPPL · normal optimizations
18.6 μs · 2.03× Wren
18.5 μs · 0.771× Wren
FlatPPL · equal work
21.9 μs · 2.39× Wren
18.9 μs · 0.787× Wren
Wren definition in this run
@wren function wells_dist_model(switched, X)
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.32 μs
24.7 μs
FlatPPL · normal optimizations
17.8 μs · 1.91× Wren
18 μs · 0.729× Wren
FlatPPL · equal work
18.4 μs · 1.98× Wren
17.7 μs · 0.718× Wren
Wren definition in this run
@wren function wells_dist_model(switched, X)
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
9.62 μs
25.7 μs
FlatPPL · normal optimizations
evaluation failed
evaluation failed
FlatPPL · equal work
evaluation failed
evaluation failed
Wren definition in this run
@wren function wells_dist_model(switched, X)
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_dist100_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 1))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
25.4 μs · 28 calls
23 μs · 40 calls
27.3 μs
23.4 μs
20261122T002521Z-565231f-registered-repeat-1
Off
26.6 μs · 32 calls
18.4 μs · 8 calls
27.7 μs
32 μs
20261122T002521Z-565231f
On · no reduction
25.4 μs · 28 calls
23 μs · 40 calls
27.3 μs
23.4 μs
20261122T002521Z-565231f
Off
26.6 μs · 32 calls
18.4 μs · 8 calls
27.7 μs
32 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
25 μs · 32 calls
16.4 μs · 40 calls
27.4 μs
22 μs
20261122T000034Z-565231f-registered-repeat-1
Off
25.2 μs · 40 calls
17.6 μs · 36 calls
26.7 μs
22.5 μs
20261122T000034Z-565231f
On · no reduction
25 μs · 32 calls
16.4 μs · 40 calls
27.4 μs
22 μs
20261122T000034Z-565231f
Off
25.2 μs · 40 calls
17.6 μs · 36 calls
26.7 μs
22.5 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
17.6 μs · 15 calls
28.1 μs
21.9 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
17 μs · 36 calls
29 μs
24.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
17.6 μs · 15 calls
28.1 μs
21.9 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
17 μs · 36 calls
29 μs
24.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 25.5 μs · value and gradient 21.4 μs
PosteriorDB model wells_dist100_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
28 μs
50.2 μs
FlatPPL · normal optimizations
27.3 μs · 0.977× Wren
23.4 μs · 0.466× Wren
FlatPPL · equal work
27.7 μs · 0.992× Wren
32 μs · 0.637× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
28 μs
53.1 μs
FlatPPL · normal optimizations
27.4 μs · 0.979× Wren
22 μs · 0.415× Wren
FlatPPL · equal work
26.7 μs · 0.954× Wren
22.5 μs · 0.423× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
27.7 μs
54.7 μs
FlatPPL · normal optimizations
28.1 μs · 1.01× Wren
21.9 μs · 0.401× Wren
FlatPPL · equal work
29 μs · 1.05× Wren
24.5 μs · 0.448× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_dist100ars_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 2))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
28.8 μs · 8 calls
15.7 μs · 12 calls
26 μs
21.1 μs
20261122T002521Z-565231f-registered-repeat-1
Off
25.2 μs · 32 calls
17.8 μs · 44 calls
27.6 μs
28.8 μs
20261122T002521Z-565231f
On · no reduction
28.8 μs · 8 calls
15.7 μs · 12 calls
26 μs
21.1 μs
20261122T002521Z-565231f
Off
25.2 μs · 32 calls
17.8 μs · 44 calls
27.6 μs
28.8 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
25 μs · 28 calls
16.6 μs · 40 calls
26.3 μs
20.5 μs
20261122T000034Z-565231f-registered-repeat-1
Off
23.3 μs · 32 calls
14.8 μs · 56 calls
25 μs
19.4 μs
20261122T000034Z-565231f
On · no reduction
25 μs · 28 calls
16.6 μs · 40 calls
26.3 μs
20.5 μs
20261122T000034Z-565231f
Off
23.3 μs · 32 calls
14.8 μs · 56 calls
25 μs
19.4 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
17.9 μs · 6 calls
25.6 μs
19.1 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
16.1 μs · 51 calls
29.7 μs
20.5 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
17.9 μs · 6 calls
25.6 μs
19.1 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
16.1 μs · 51 calls
29.7 μs
20.5 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 24.3 μs · value and gradient 20 μs
PosteriorDB model wells_dist100ars_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
28.2 μs
50.9 μs
FlatPPL · normal optimizations
26 μs · 0.92× Wren
21.1 μs · 0.415× Wren
FlatPPL · equal work
27.6 μs · 0.978× Wren
28.8 μs · 0.566× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
28.6 μs
57.9 μs
FlatPPL · normal optimizations
26.3 μs · 0.917× Wren
20.5 μs · 0.354× Wren
FlatPPL · equal work
25 μs · 0.871× Wren
19.4 μs · 0.335× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
30 μs
56.5 μs
FlatPPL · normal optimizations
25.6 μs · 0.856× Wren
19.1 μs · 0.339× Wren
FlatPPL · equal work
29.7 μs · 0.993× Wren
20.5 μs · 0.363× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_interaction_c_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 3))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
32.7 μs · 20 calls
19.2 μs · 36 calls
28.7 μs
23.9 μs
20261122T002521Z-565231f-registered-repeat-1
Off
29.3 μs · 4 calls
19.2 μs · 8 calls
30.8 μs
23.3 μs
20261122T002521Z-565231f
On · no reduction
32.7 μs · 20 calls
19.2 μs · 36 calls
28.7 μs
23.9 μs
20261122T002521Z-565231f
Off
29.3 μs · 4 calls
19.2 μs · 8 calls
30.8 μs
23.3 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
26.6 μs · 28 calls
18.1 μs · 40 calls
27.5 μs
21.4 μs
20261122T000034Z-565231f-registered-repeat-1
Off
30.6 μs · 4 calls
17.7 μs · 60 calls
27.9 μs
22 μs
20261122T000034Z-565231f
On · no reduction
26.6 μs · 28 calls
18.1 μs · 40 calls
27.5 μs
21.4 μs
20261122T000034Z-565231f
Off
30.6 μs · 4 calls
17.7 μs · 60 calls
27.9 μs
22 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
JIT-loop timing not recorded
20.6 μs · 36 calls
30.2 μs
23 μs
20261121T195722Z-565231f-registered-repeat-1
Off
JIT-loop timing not recorded
17.5 μs · 25 calls
28.4 μs
21.9 μs
20261121T195722Z-565231f
On · no reduction
JIT-loop timing not recorded
20.6 μs · 36 calls
30.2 μs
23 μs
20261121T195722Z-565231f
Off
JIT-loop timing not recorded
17.5 μs · 25 calls
28.4 μs
21.9 μs
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 27.3 μs · value and gradient 21.4 μs
PosteriorDB model wells_interaction_c_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
33.6 μs
53.4 μs
FlatPPL · normal optimizations
28.7 μs · 0.854× Wren
23.9 μs · 0.448× Wren
FlatPPL · equal work
30.8 μs · 0.917× Wren
23.3 μs · 0.435× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
33.5 μs
81.5 μs
FlatPPL · normal optimizations
27.5 μs · 0.82× Wren
21.4 μs · 0.263× Wren
FlatPPL · equal work
27.9 μs · 0.833× Wren
22 μs · 0.27× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
34 μs
51.8 μs
FlatPPL · normal optimizations
30.2 μs · 0.891× Wren
23 μs · 0.444× Wren
FlatPPL · equal work
28.4 μs · 0.837× Wren
21.9 μs · 0.423× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
@model function pdb_wells_interaction_model(signs, X)
X = X.value
alpha ~ Flat()
beta ~ product_distribution(Fill(Flat(), 3))
logits = alpha .+ X * beta
DynamicPPL.@addlogprob! -sum(log1pexp.(signs .* logits))
end
FlatPPL JIT-loop and single-call timings
A single call includes Python dispatch and synchronizes at the first checked point. A JIT batch cycles through the checked points and synchronizes once. Each iteration adds the log density to a running sum. For value and gradient it also adds the sum of the gradient components. The table reports batch time per inner call.
Run
Sufficient statistics
JIT log density per call
JIT value and gradient per call
Single log density
Single value and gradient
20261122T002521Z-565231f-registered-repeat-1
On · no reduction
31.4 μs · 32 calls
16 μs · 40 calls
27.2 μs
21.7 μs
20261122T002521Z-565231f-registered-repeat-1
Off
27.4 μs · 8 calls
18.2 μs · 40 calls
27.4 μs
28 μs
20261122T002521Z-565231f
On · no reduction
31.4 μs · 32 calls
16 μs · 40 calls
27.2 μs
21.7 μs
20261122T002521Z-565231f
Off
27.4 μs · 8 calls
18.2 μs · 40 calls
27.4 μs
28 μs
20261122T000034Z-565231f-registered-repeat-1
On · no reduction
26.2 μs · 32 calls
15.1 μs · 44 calls
25.9 μs
27.3 μs
20261122T000034Z-565231f-registered-repeat-1
Off
24.1 μs · 28 calls
15.2 μs · 56 calls
26.5 μs
27.7 μs
20261122T000034Z-565231f
On · no reduction
26.2 μs · 32 calls
15.1 μs · 44 calls
25.9 μs
27.3 μs
20261122T000034Z-565231f
Off
24.1 μs · 28 calls
15.2 μs · 56 calls
26.5 μs
27.7 μs
20261121T195722Z-565231f-registered-repeat-1
On · no reduction
FlatPPL density disagrees with the reference
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f-registered-repeat-1
Off
FlatPPL density disagrees with the reference
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
On · no reduction
FlatPPL density disagrees with the reference
JIT-loop timing not recorded
Not measured
Not measured
20261121T195722Z-565231f
Off
FlatPPL density disagrees with the reference
JIT-loop timing not recorded
Not measured
Not measured
Timings, reference checks and dataset
Standalone FlatPPL single call · sufficient statistics on · log density 25.1 μs · value and gradient 20.2 μs
PosteriorDB model wells_interaction_model · dataset wells_data · SHA-256 dfa61ec04d9785a0b811553d1366221fd75f509b0c308275cd314df2cc2b879c
Paired Wren run · 20261122T002521Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
36.6 μs
51.1 μs
FlatPPL · normal optimizations
27.2 μs · 0.743× Wren
21.7 μs · 0.425× Wren
FlatPPL · equal work
27.4 μs · 0.749× Wren
28 μs · 0.549× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261122T000034Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
45.2 μs
51.3 μs
FlatPPL · normal optimizations
25.9 μs · 0.573× Wren
27.3 μs · 0.532× Wren
FlatPPL · equal work
26.5 μs · 0.586× Wren
27.7 μs · 0.539× Wren
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Paired Wren run · 20261121T195722Z-565231f-registered-repeat-1
Warm single calls
Log density
Value and gradient
Wren
45.3 μs
52.3 μs
FlatPPL · normal optimizations
FlatPPL density disagrees with the reference
disagrees
FlatPPL · equal work
FlatPPL density disagrees with the reference
disagrees
Wren definition in this run
@wren function wells_glm_model(switched, X)
alpha ~ WD.Flat()
@iid beta ~ WD.Flat() size=size(X, 2)
logit_p = alpha .+ X * beta
@batch for i in eachindex(switched)
@observe switched[i] ~ WD.BernoulliLogit(logit_p[i])
end
return nothing
end
Ratios divide times for the same posterior, operation and timing regime in one run. Each cell counts models that passed its checks. Direct RKPPL and FlatPPL comparisons use registered workers with verified shared inputs and matching sufficient-statistic settings. The FlatPPL timing selector controls both numerator and denominator. JIT-loop mode uses time per inner call against the other engine’s recorded call.
Wren and RKPPL · chapter and paragraph LDA · registered and development Enzyme · sufficient statistics on · 2 models · 20261122T031115Z-565231f · 2026-11-22T03:21:52.899Z Julia 1.13.1 · AMD Ryzen 9 9950X 16-Core Processor · registry Enzyme 0.13.221 · development 37b2a484727a28a78679d28a24e7071d916ca437 · Wren 565231f650353fc32886f922d310f7ae395a2294 · benchmark and port sources 62e6bf3397bf61e8321de4f6835f95a6497a4529 · receipt SHA-256 118d3c9fca274bd73a470f7f9db3ab346f00d04b6997d04bd0a14ce7d07d998f
Frozen references use provenance.stan_log_density. Legacy generated BridgeStan references use the score from log_density_gradient. The three dual-call ODE references preserve log_density and the value from log_density_gradient separately.
Source and coverage audit
Catalogue source and dataset audit SHA-256 21049e09a12b84580e24d2f5496b1ef2ba4b02b3dd25ddca95098a710acbb016