nutpie icon indicating copy to clipboard operation
nutpie copied to clipboard

Slow initialization running PyMC model

Open ghost opened this issue 1 year ago • 4 comments

I am trying to run a PyMC model with the nutpie sampler, but initialization seems to be very slow and sampling does not start with these Warning statements:

C:\Users\TsubasaTakaya\miniconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:379: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
  warnings.warn(
C:\Users\TsubasaTakaya\miniconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:379: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
  warnings.warn(
C:\Users\TsubasaTakaya\miniconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py:416: NumbaWarning: Cannot cache compiled function "numba_funcified_fgraph" as it uses dynamic globals (such as ctypes pointers and large global arrays)
  return inner(x)
C:\Users\TsubasaTakaya\miniconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py:416: NumbaWarning: Cannot cache compiled function "numba_funcified_fgraph" as it uses dynamic globals (such as ctypes pointers and large global arrays)
  return inner(x)

How can I fix this issue? I am using nutpie==0.10.0, numba==0.59.1, pymc==5.13.0.

ghost avatar May 26 '24 12:05 ghost

Yeah if it's using objmode it'll be very slow. Here seems to be the relevant issue: https://github.com/pymc-devs/pytensor/issues/772 Pull requests are welcome, we're happy to help :).

twiecki avatar May 26 '24 15:05 twiecki

Just to understand the problem, is nopython mode for Numba not used for some operations (e.g. AdvancedSetSubtensor) of PyMC?

ghost avatar May 26 '24 19:05 ghost

Yes.

twiecki avatar May 27 '24 02:05 twiecki

The slow starting is probably just known compilation times in Numba. Should get better with https://github.com/pymc-devs/pytensor/pull/765 which is part of PyTensor 2.21.0. The next PyMC release should be compatible with it

ricardoV94 avatar May 27 '24 10:05 ricardoV94

Since I don't think we can do much about the numba compilation times in nutpie, I'll close this here.

aseyboldt avatar Jan 22 '25 18:01 aseyboldt