question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FR Streaming MCMC interface for big models

See original GitHub issue

This issue proposes a streaming architecture for MCMC on models with large memory footprint.

The problem this addresses is that, in models with high-dimensional latents (say >1M latent variables), it becomes difficult to save a list of samples, especially on GPUs with limited memory. The proposed solution is to eagerly compute statistics on those samples, and discard them during inference.

@fehiepsi suggested creating a new MCMC class (say StreamingMCMC) with similar interface to MCMC and still independent of kernel (using either HMC or NUTS) but that follows an internal streaming architecture. Since large models like these usually run on GPU or are otherwise memory constrained, it is reasonable to avoid multiprocessing support in StreamingMCMC.

Along with the new StreamingMCMC class I think there should be a set of helpers to streamingly compute statistics from sample streams, e.g. mean, variance, covariance, r_hat statistics.

Tasks (to be split into multiple PRs)

@mtsokol

  • #2857 Create a StreamingMCMC class with interface identical to MCMC (except disallowing parallel chains).
  • #2857 Generalize unit tests of MCMC to parametrize over both MCMC and StreamingMCMC
  • Add some tests ensuring StreamingMCMC and MCMC perform identical computations, up to numerical precision
  • Create a tutorial using StreamingMCMC on a big model

@fritzo

  • #2856 Create streaming helpers for mean, variance, etc.
  • Add r_hat to pyro.ops.streaming
  • Add n_eff = ess to pyro.ops.streaming

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
fritzocommented, Jun 2, 2021

@mtsokol answering your latest questions:

  1. tl;dr keep it simple. I do not foresee a performance hit here: it is cheap to create dicts, and StreamingMCMC will typically be used with large memory-bound models with huge tensors, where the python overhead is negligible. For this same reason I think we should avoid batching since that increases memory overhead. (In fact I suspect the bottleneck will be in pyro.ops.streaming where we may need to refactor to perform tensor operations in-place).
  2. Yes, I believe we will want to compute both per-chain and total-aggregated statistics. I have added a .merge() operation in #2856 to make this easy for you. The main motivation is to compute cross-chain statistics like r_hat.
  3. It looks like the cloning is explained earlier in the file. I would recommend keeping that logic.

https://github.com/pyro-ppl/pyro/blob/4a61ef2f9050ef81d1b0aa148d14ecc876f24a51/pyro/infer/mcmc/api.py#L389-L392

1reaction
mtsokolcommented, Jun 2, 2021

@fritzo thanks for guidance! Right now I’m looking at the current implementation and starting working on this. This abstraction with StreamingStatistic is sound to me. StreamingMCMC will only iterate and call method on passed objects implementing that interface.

Sure! I can start working on StreamingMCMC and already follow StreamingStatistic notion. When your RP is ready I will adjust my implementation.

Should I introduce some AbstractMCMC interface that existing MCMC and StreamingMCMC will implement?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interface Guide - Turing.jl
Turing implements a sampling interface (hosted at AbstractMCMC) that is intended to provide a common framework for Markov chain Monte Carlo samplers.
Read more >
Particle Markov chain Monte Carlo methods - statistics
Our novel approach exploits differing strengths of. MCMC and SMC algorithms, which allow us to design efficient and flexible MCMC algorithms for important ......
Read more >
R News 6 (1) - The R Project for Statistical Computing
In the remainder of this article, we illustrate the user interface and functionality of MCMCpack with three examples. User interface. The model fitting ......
Read more >
The MCMC Procedure - SAS Support
PROC MCMC Compared with Other SAS Procedures . ... the random stream. ... especially in random-effects models that have a large number of...
Read more >
(PDF) Parallelizing MCMC for Bayesian spatiotemporal ...
PDF | Abstract When MCMC methods for Bayesian spatiotemporal modeling are applied to large geostatistical problems, challenges arise as a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found