Make a run faster¶
A run’s time is the time of its replicates, each a number of kernel applications, plus that of the tuning pilot and the meeting-time pilot before them. Each section below is one lever, with its effect and the page that holds its facts; Measured times times the first three on one target.
Where the time goes¶
A replicate applies the kernel to its first chain alone for the first \(L\) steps, to both chains until they meet, and to the met chain until \(m\) (Theory):
The kernel applications of one pair run by telescopic, with random-walk Metropolis on a
standard normal target, as cells along time: \(X\) steps alone for the first \(L\) steps,
the lag; both chains step until the meeting time \(\tau\), each step counting as two
applications; and the met chain steps alone from \(\tau\) to \(m\). The sum is the
replicate’s entry of result.costs.¶
How many evaluations of the log-density and its gradient an application costs depends on
the kernel, and the pilots add their own
(A slow log-density). A result records the
evaluations and the seconds of its replicates, result.n_log_prob, result.n_grad and
result.wall_time, without those of the pilots
(What a result holds).
Vectorize the log-density¶
With vectorize=True, one call of the log-density evaluates a batch of chains instead of
one point, which saves the time of the calls
(The log-density); its effect on reproducibility is in
Reproducibility.
Run on a pool¶
pool runs the replicates on worker processes, which pays off for runs longer than the
start of the workers (Pools,
Chunks and workers).
Skip the pilots¶
A kernel whose parameters are all given skips tuning, and a given k skips the
meeting-time pilot (A slow log-density), so several
jobs on one target can tune once (Tuning).
Choose the kernel by its inefficiency¶
Kernels differ in how fast their pairs meet and in what an application costs. The inefficiency, the cost of a replicate times the variance of its estimate, is the figure to minimize at equal work, counted in evaluations or seconds when kernels differ in the cost of an application (Cost). Choosing a kernel says when each kernel suits, and Gradients compares the random walk, MALA and HMC on one target.
Store less¶
thin and keep save memory, not time
(Memory and thinning,
Keeping a subset).
Measured times¶
benchmarks/run_faster.py
times telescopic.sample() on telescopic.examples.gaussian() in 10 dimensions,
with a random walk whose covariance is the target’s and a fixed k, so that no pilot
runs: with the log-density evaluated point by point and vectorized, in this process and
on pools of worker processes that each call starts. It then times the automatic
pipeline at the default settings against the same run with the kernel and k given. The
table and its setup are read from the script’s output:
Seconds; telescopic.sample on examples.gaussian(10), R = 1024, rng=1; RandomWalk(cov) with the target's cov and k = 200 unless automatic.
point by point vectorized
in this process 10.59 3.00
2 workers 8.28 3.04
4 workers 4.85 2.43
Automatic pipeline: 3.34 s, of which the replicates 2.97 s (k = 222); kernel and k given: 3.11 s.
Setup: telescopic at commit db025af, Python 3.13.18, NumPy 2.5.3 and SciPy 1.18.1, openblas 0.3.31.dev, openblas 0.3.34.106.0 on one thread, on Intel(R) Xeon(R) Processor @ 2.10GHz, 4 CPUs, Linux 6.18.44-fc-v470, with 4 CPUs available.