numpyro/NUTS fit_map path is significantly slower than emcee
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- python
- Domain
- machine-learning, performance
Research direction
Start with the numpyro path and profile the 9-parameter fit described in docs/tutorials/tutorial_6_numpyro.ipynb, comparing it with the emcee path. Read REFACTORING_PLAN.md §5.1b and inspect _make_model, the JIT cache, and NUTS settings. Done means identifying and validating a concrete speed improvement while preserving the reported posterior behavior.
Written by the indexing model from the issue text.
Description
Summary
After the fit_map emcee speedups (f23cf29, 867bc38, 215a45e, cumulatively ~16×), the mcmc='numpyro' path is now wall-clock-slower than mcmc='emcee' on typical fits, even though it is dramatically more sample-efficient (256× fewer samples to reach the same posterior resolution on the validation fit in REFACTORING_PLAN.md §5.1b).
The two emcee speedups (JIT closure + vmap'd batch ln-prob) compile the per-step log-probability into a single XLA dispatch that vmaps across walkers. numpyro can't share that optimisation: NUTS extends its trajectory until a U-turn, which is a per-chain condition, so vmap'ing across chains doesn't help.
Profile of a current fit
9-parameter HD163296 3D fit (docs/tutorials/tutorial_6_numpyro.ipynb), 500 warmup + 500 samples, single chain:
- Mean leapfrog steps per NUTS iteration: 127
- Median: 95
- ~39 % of iterations hit the
max_tree_depth=8cap (256 leapfrog steps) - Each gradient evaluation costs ~2× a likelihood evaluation
So one numpyro sample does the gradient work of ~250 emcee evaluations.
Micro-benchmark (50 warmup + 50 sample, post-JIT-warm)
| config | wall |
|---|---|
1 chain, max_tree_depth=8 (previous tutorial default) |
40.1 s |
1 chain, max_tree_depth=6 (new tutorial default) |
23.1 s |
4 chains, chain_method='sequential' |
197.3 s |
4 chains, chain_method='vectorized' |
194.3 s |
Findings
- Capping
max_tree_depthat 6 gives a ~42 % wall-time speedup with minimal posterior loss — tutorial 6 now recommends 6. chain_method='vectorized'does not help. NUTS' adaptive tree length is per-chain; vmap'd chains must all run to the longest tree on each iteration, cancelling the vmap win. (vectorizedis only a win for HMC with fixed L.)
Untried directions
target_accept_prob< 0.8 default — accept noisier steps, smaller trajectories. Trade-off: more divergences.dense_mass=True— adapt a full covariance preconditioner. Could help the strongly-correlatedz0/psi/r_taper/q_taperblock, but the warmup adaptation is slower.- More aggressive image downsampling —
_make_modelcost scales with pixel count; high-SNR pixels dominate the posterior. - Audit the numpyro JIT cache: confirm the model is compiled exactly once per fit and not invalidated between iterations.
- See whether a bounded-horizon scan over leapfrog steps is feasible (probably blocked by the U-turn termination condition, but worth checking).
Workaround
Stay on mcmc='emcee' (the default) for routine fits. Use mcmc='numpyro' when sample efficiency is the actual bottleneck (very expensive single likelihood, very long autocorrelation under emcee, or GPU-available).
- Dominant language
- Python
- Stars
- 23
- Forks
- 10
- Avg merge
- 28m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PlanetFormationLab/eddy
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
PlanetFormationLab/eddy#36 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
PlanetFormationLab/eddy#39 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
PlanetFormationLab/eddy#35 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
PlanetFormationLab/eddy#33 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
PlanetFormationLab/eddy#32 ·
All issues in PlanetFormationLab/eddy
Similar issues
-
tool-calling
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vllm-project/vllm#59838 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
raullenchai/Rapid-MLX#4042 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 92/100
transitmatters/mbta-slow-zone-bot#70 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
litestar-org/advanced-alchemy#811 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day