Skip to content

[WIP] Add numpyro.ops.gaussian and GaussianHMM with parallel Kalman marginalization - #2273

Draft
juanitorduz wants to merge 26 commits into
pyro-ppl:masterfrom
juanitorduz:feat/gaussian-hmm-ops
Draft

juanitorduz wants to merge 26 commits into
pyro-ppl:masterfrom
juanitorduz:feat/gaussian-hmm-ops

Conversation

@juanitorduz

Copy link
Copy Markdown
Collaborator

Ports Pyro's information-form Gaussian factor algebra (numpyro.ops.gaussian) and adds GaussianHMM / IndependentHMM with O(log T) parallel marginalization, filter, sample, sample_posterior, conjugate_update, prefix_condition, reshape_batch.
Left-acting matrices as in GaussianStateSpace; shapes are leaf-derived and rank-aligned (compatible with #2271).
Verified against dense joint oracles, Pyro's factor identities, sampler moments, GaussianStateSpace moment identities, and a NUTS local-level smoke test; float32 by default with an x64 CI case.
Stacked: a follow-up PR adds GammaGaussianHMM, LinearHMM, GaussianMRF, StudentTReparam and LinearHMMReparam.

@github-actions github-actions Bot added the awaiting review Awaiting review from maintainers label Sep 17, 2026
@juanitorduz juanitorduz changed the title Add numpyro.ops.gaussian and GaussianHMM with parallel Kalman marginalization [WIP] Add numpyro.ops.gaussian and GaussianHMM with parallel Kalman marginalization Sep 17, 2026
@juanitorduz juanitorduz added WIP Work In Progress and removed awaiting review Awaiting review from maintainers labels Sep 17, 2026
@juanitorduz juanitorduz self-assigned this Sep 17, 2026
@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

Benchmark report

this PR feat/gaussian-hmm-ops at 439de1d0 vs baseline master at 07501df3

+ run time:     2 faster
  compile time: unchanged across 32 benchmarks

Significant changes (2)

                                  ─────── run time ───────     ───── compile time ─────
  benchmark                       baseline  this PR      Δ     baseline  this PR      Δ
───────────────────────────────────────────────────────────────────────────────────────
+ gamma_log_prob                    1.4 ms   1.3 ms  -5.2%       1.99 s   1.93 s  -3.3%
+ initialize_model_hierarchical    31.4 ms  29.6 ms  -5.6%       3.23 s   3.17 s  -2.0%

Red is slower, green is faster; a row is coloured by the worse of its two columns. A delta in parentheses cleared the threshold on a measurement below the resolution floor, so it is shown without being called a change. † marks a benchmark that could not be compared — see below.

Full results

distributions

                                 ─────── run time ───────     ────── compile time ─────
  benchmark                      baseline  this PR      Δ     baseline   this PR      Δ
───────────────────────────────────────────────────────────────────────────────────────
  biject_to_constraints            3.1 ms   2.9 ms  -4.6%     190.7 ms  200.7 ms  +5.3%
  categorical_log_prob             1.2 ms   1.2 ms  -0.6%      54.9 ms   49.9 ms  -9.0%
  dirichlet_log_prob               410 µs   392 µs  -4.4%     348.1 ms  334.6 ms  -3.9%
  dirichlet_sample                42.4 ms  42.7 ms  +0.7%     592.7 ms  569.4 ms  -3.9%
+ gamma_log_prob                   1.4 ms   1.3 ms  -5.2%       1.99 s    1.93 s  -3.3%
  gamma_sample                    19.6 ms  19.6 ms  +0.2%     543.7 ms  528.2 ms  -2.9%
  lkj_cholesky_sample              4.3 ms   4.3 ms  -0.8%     827.4 ms  820.0 ms  -0.9%
  mixture_same_family_log_prob     574 µs   568 µs  -1.1%      61.7 ms   61.8 ms  +0.1%
  multivariate_normal_log_prob     407 µs   403 µs  -0.9%     466.3 ms  455.3 ms  -2.4%
  normal_log_prob                  439 µs   436 µs  -0.7%      50.0 ms   47.7 ms  -4.6%
  normal_sample                   19.1 ms  19.3 ms  +0.7%     151.9 ms  157.7 ms  +3.8%
  stick_breaking_transform         4.5 ms   4.6 ms  +2.2%     162.9 ms  160.6 ms  -1.4%
  student_t_log_prob               2.5 ms   2.5 ms  +1.4%      71.1 ms   68.4 ms  -3.9%
  truncated_normal_log_prob        483 µs   477 µs  -1.2%      44.7 ms   42.4 ms  -5.1%

handlers

                                  ──────── run time ───────     ────── compile time ──────
  benchmark                       baseline   this PR      Δ     baseline   this PR       Δ
──────────────────────────────────────────────────────────────────────────────────────────
+ initialize_model_hierarchical    31.4 ms   29.6 ms  -5.6%       3.23 s    3.17 s   -2.0%
  log_density_hierarchical          2.4 ms    2.3 ms  -2.4%       1.09 s    1.13 s   +3.2%
  nested_handler_stack              978 µs    945 µs  -3.4%       653 µs    654 µs   +0.2%
  potential_energy_and_grad          19 µs     19 µs  +1.4%      79.1 ms   78.2 ms   -1.2%
  predictive_forward_sampling     523.0 ms  513.9 ms  -1.8%     143.2 ms  124.8 ms  -12.8%
  trace_seeded_model                528 µs    521 µs  -1.3%     444.8 ms  416.5 ms   -6.4%

mcmc

                             ──────── run time ───────     ───── compile time ─────
  benchmark                  baseline   this PR      Δ     baseline  this PR      Δ
───────────────────────────────────────────────────────────────────────────────────
  hmc_logistic_regression    572.3 ms  561.6 ms  -1.9%       2.65 s   2.45 s  -7.4%
  nuts_dense_mass_funnel     878.7 ms  882.3 ms  +0.4%       2.16 s   1.97 s  -8.7%
  nuts_eight_schools         894.0 ms  876.9 ms  -1.9%       2.11 s   1.92 s  -9.1%
  nuts_hierarchical_glm        3.18 s    3.19 s  +0.2%       3.77 s   3.59 s  -4.8%
  nuts_logistic_regression   839.8 ms  828.2 ms  -1.4%       2.64 s   2.47 s  -6.6%
  nuts_vectorized_chains       1.91 s    1.87 s  -2.1%       2.19 s   2.13 s  -2.7%

svi

                                             ──────── run time ───────     ────── compile time ─────
  benchmark                                  baseline   this PR      Δ     baseline  this PR       Δ
────────────────────────────────────────────────────────────────────────────────────────────────────
  svi_autodelta_map_logistic                 238.9 ms  236.3 ms  -1.1%       2.56 s   2.47 s   -3.5%
  svi_autodiagonalnormal_hierarchical        801.1 ms  800.4 ms  -0.1%       4.07 s   4.06 s   -0.2%
  svi_automultivariatenormal_eight_schools   579.3 ms  579.7 ms  +0.1%       3.65 s   3.55 s   -2.9%
  svi_autonormal_logistic                    578.0 ms  585.4 ms  +1.3%       2.86 s   2.94 s   +3.1%
  svi_multi_particle_elbo                      1.10 s    1.11 s  +1.0%       2.97 s   2.80 s   -5.7%
  svi_trace_mean_field_elbo                  961.7 ms  945.0 ms  -1.7%       4.57 s   4.02 s  -12.1%
Methodology and environment

Each benchmark is set up untimed, then called once with the JAX caches cleared and several more times warm. Run is the fastest warm call; compile is the first call minus that, i.e. the tracing, lowering and XLA compilation the warm calls did not have to pay for.

Both refs were measured on the same runner over 2 interleaved round(s), taking the best observation per benchmark. A result is called neutral when it moves less than ±5% (run) or ±25% (compile), or when the measurement itself is under 1 ms (run) / 50 ms (compile) — a shared CI runner cannot resolve changes below that. Compile time gets the looser band because it is measured once per round rather than best-of-N, and swings by roughly 20% even between two runs of identical code. A delta shown in parentheses did clear its threshold, but on a measurement below the resolution floor, so it is reported without being called a change.

baseline this PR
ref master feat/gaussian-hmm-ops
commit 07501df3 439de1d0
numpyro 0.21.0 0.21.0
jax 0.11.1 0.11.1
backend cpu cpu
python 3.14.7 3.14.7

Runner: Linux-6.17.0-1022-azure-x86_64-with-glibc2.39, 4 CPUs.

Produced by this benchmark run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP Work In Progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant