Numpyro: Avoid compiling 2 times in HMC

Created on 7 Apr 2019  路  7Comments  路  Source: pyro-ppl/numpyro

Currently, we do compiling 2 times: 1 at init, 1 at sample, so it would be better if we only compile 1 time.

One way is to modify tscan with additional parameters: skip to skip first warmup_steps; put warmup_state to a lax.cond to decide if it will be updated or not (depending on we are in warmup phase or sampling phase).

discussion enhancement

All 7 comments

1 at init, 1 at sample, so it would be better if we only compile 1 time.

I think the compiled function is cached, so we shouldn't have to pay the cost the second time around, but lets verify this.

@fehiepsi - I think we can update this issue now to reflect the next steps on this task?

It seems that we don't need to revise the api. It is likely an unexpected behaviour of lax.while_loop. More context about it can be found in https://github.com/google/jax/issues/587.

That's great! Should we close this issue then, or are there any things to follow up on?

I think that it is better to let this open. In case it is not an issue of while_loop, I would prefer to add a small utility to do scan including warmup phase and avoid this issue.

@neerajprad After working with the benchmark on covtype dataset, I think that we don't need to work around these issues of prims if we use nonprim version of lax.scan. Here are some benefits:

  • Allows us force fast-compiling by feeding a test_state which makes hmc_next/nuts_next run fast
  • Allows us separate compiling time and sampling time
  • Allows us print/tqdm the sampling the progress

Here is a trade-off:

  • We lost the benefit of using lax.scan/lax.fori_loop for the outer loop. But I expect that this is small.

Because we don't want the above trade-off create regressions on small model, let's address this issue again when more examples/benchmarks are added.

@fehiepsi - can we close this issue now?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neerajprad picture neerajprad  路  5Comments

peterroelants picture peterroelants  路  5Comments

fehiepsi picture fehiepsi  路  6Comments

lumip picture lumip  路  3Comments

jeremiecoullon picture jeremiecoullon  路  4Comments