brmp icon indicating copy to clipboard operation
brmp copied to clipboard

Avoid recompiling NumPyro models where possible

Open null-a opened this issue 5 years ago • 2 comments

If we do something like:

model = define_model(...)
fit1 = model.run_algo('nuts', ...)
fit2 = model.run_algo('nuts', ...)

... then each call to run_algo will invoke NumPyro's model compilation. It ought to be possible to avoid this (in cases where the data shape doesn't change between calls) by caching the MCMC instance and reusing it on subsequent calls.

null-a avatar Dec 03 '19 09:12 null-a

(in cases where the data shape doesn't change between calls)

Even if the data shape changes, but we can commit to a certain max size, it might be possible to use a masked distribution to enable this. We haven't needed a masked distribution in numpyro yet, but this may be a good use case. cc. @fehiepsi

neerajprad avatar Dec 03 '19 22:12 neerajprad

The feature is available in NumPyro >=0.2.2.

null-a avatar Dec 06 '19 08:12 null-a