Slow sampling speed with newer versions of PyMC

I am experiencing a really weird issue where newer versions of PyMC are significantly slower than an older version of PyMC. Here is a reproducible example:

  • There is a environment.yml (statistical-rethinking-2023.yml) file on this repo https://github.com/dustinstansbury/statistical-rethinking-2023 That will setup a conda environment with PyMC version 5.8.0

  • In the same repo there is a “Lecture 18 - Missing Data.ipynb” notebook where code block number 25 samples in 1 minute for me on a MacOS 14.4.1 using the conda environment that is set up with the environment.yml file from above

  • Now if I run conda update --all this will install PyMC version 5.15.0. Trying to run code block number 25 from the aforementioned notebook samples extremely slowly with an ETA of 15 hours until completion. I have let this sample for 10 minutes to make sure it is not just an issue with the ETA

I am wondering if this is just an issue on MacOS? Can someone else reproduce this?

Installing old versions of PyMC and then trying to update them is not recommended as it can lead to version conflicts and other issues with your python environment.

The official installation instructions are here. In this case, you may need other packages in order to run the Rethinking notebooks. You can try and figure out what those packages are and install them into the environment you have freshly created and installed PyMC into. Alternatively, you can ask the person responsible for those notebooks for a more up-to-date environment specification.

Hey @cluhmann thank you for your response. I have already tried installing a PyMC using the linked instructions into a new conda environment. I just tried again using a fresh install following the instructions in the link you provided me. I am still experiencing slow sampling. There aren’t any external samplers being used in this example either. Are you unable to reproduce the issue that I am experiencing?

A couple of questions. First, when you import pymc in a fresh python session, are there any warnings or errors? If so, hwat are they? Second, what is the output when you run conda list in the relevant environment?

@cluhmann Thank you for helping me with this. I get no warning messages when importing pymc. Here is the output from conda list:

# packages in environment at /opt/miniconda3/envs/pymc_env:
#
# Name                    Version                   Build  Channel
accelerate                0.30.1             pyhd8ed1ab_0    conda-forge
appnope                   0.1.4              pyhd8ed1ab_0    conda-forge
arviz                     0.18.0             pyhd8ed1ab_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
atk-1.0                   2.38.0               hd03087b_2    conda-forge
blas                      2.122                  openblas    conda-forge
blas-devel                3.9.0           22_osxarm64_openblas    conda-forge
brotli                    1.1.0                hb547adb_1    conda-forge
brotli-bin                1.1.0                hb547adb_1    conda-forge
brotli-python             1.1.0           py312h9f69965_1    conda-forge
bzip2                     1.0.8                h93a5062_5    conda-forge
c-ares                    1.28.1               h93a5062_0    conda-forge
ca-certificates           2024.2.2             hf0a4a13_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cachetools                5.3.3              pyhd8ed1ab_0    conda-forge
cairo                     1.18.0               hd1e100b_0    conda-forge
cctools_osx-arm64         986                  h62378fb_0    conda-forge
certifi                   2024.2.2           pyhd8ed1ab_0    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
clang                     16.0.6               h30cc82d_6    conda-forge
clang-16                  16.0.6          default_he012953_6    conda-forge
clang_impl_osx-arm64      16.0.6              hc421ffc_14    conda-forge
clang_osx-arm64           16.0.6              h54d7cd3_14    conda-forge
clangxx                   16.0.6          default_h4cf2255_6    conda-forge
clangxx_impl_osx-arm64    16.0.6              hcd7bac0_14    conda-forge
clangxx_osx-arm64         16.0.6              h54d7cd3_14    conda-forge
cloudpickle               3.0.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
comm                      0.2.2              pyhd8ed1ab_0    conda-forge
compiler-rt               16.0.6               h3808999_2    conda-forge
compiler-rt_osx-arm64     16.0.6               h3808999_2    conda-forge
cons                      0.4.6              pyhd8ed1ab_0    conda-forge
contourpy                 1.2.1           py312h0fef576_0    conda-forge
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
debugpy                   1.8.1           py312h20a0b95_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
dm-tree                   0.1.8           py312h1a610f3_4    conda-forge
etuples                   0.3.9              pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
expat                     2.6.2                hebf3989_0    conda-forge
filelock                  3.14.0             pyhd8ed1ab_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 h77eed37_2    conda-forge
fontconfig                2.14.2               h82840c6_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.51.0          py312he37b823_0    conda-forge
freetype                  2.12.1               hadb7bae_2    conda-forge
fribidi                   1.0.10               h27ca646_0    conda-forge
fsspec                    2024.3.1           pyhca7485f_0    conda-forge
gdk-pixbuf                2.42.11              h13c029f_0    conda-forge
gettext                   0.22.5               h8fbad5d_2    conda-forge
gettext-tools             0.22.5               h8fbad5d_2    conda-forge
giflib                    5.2.2                h93a5062_0    conda-forge
gmp                       6.3.0                hebf3989_1    conda-forge
gmpy2                     2.1.5           py312hfa9fade_1    conda-forge
graphite2                 1.3.13            hebf3989_1003    conda-forge
graphviz                  9.0.0                h3face73_1    conda-forge
gtk2                      2.24.33              h7895bb2_4    conda-forge
gts                       0.7.6                he42f4ea_4    conda-forge
h5netcdf                  1.3.0              pyhd8ed1ab_0    conda-forge
h5py                      3.11.0          nompi_py312hac0f6fd_100    conda-forge
harfbuzz                  8.4.0                hbe0f7c0_0    conda-forge
hdf5                      1.14.3          nompi_h751145d_101    conda-forge
huggingface_hub           0.23.0             pyhd8ed1ab_0    conda-forge
icu                       73.2                 hc8870d7_0    conda-forge
idna                      3.7                pyhd8ed1ab_0    conda-forge
importlib-metadata        7.1.0              pyha770c72_0    conda-forge
importlib_metadata        7.1.0                hd8ed1ab_0    conda-forge
ipykernel                 6.29.3             pyh3cd1d5f_0    conda-forge
ipython                   8.24.0             pyh707e725_0    conda-forge
ipywidgets                8.1.2              pyhd8ed1ab_1    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.4              pyhd8ed1ab_0    conda-forge
jupyter_client            8.6.1              pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.2           py312h81bd7bf_0    conda-forge
jupyterlab_widgets        3.0.10             pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.5           py312h389731b_1    conda-forge
krb5                      1.21.2               h92f50d5_0    conda-forge
lcms2                     2.16                 ha0e7c42_0    conda-forge
ld64_osx-arm64            711                  ha4bd21c_0    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libabseil                 20240116.2      cxx17_hebf3989_0    conda-forge
libaec                    1.1.3                hebf3989_0    conda-forge
libasprintf               0.22.5               h8fbad5d_2    conda-forge
libasprintf-devel         0.22.5               h8fbad5d_2    conda-forge
libblas                   3.9.0           22_osxarm64_openblas    conda-forge
libbrotlicommon           1.1.0                hb547adb_1    conda-forge
libbrotlidec              1.1.0                hb547adb_1    conda-forge
libbrotlienc              1.1.0                hb547adb_1    conda-forge
libcblas                  3.9.0           22_osxarm64_openblas    conda-forge
libclang-cpp16            16.0.6          default_he012953_6    conda-forge
libcurl                   8.7.1                h2d989ff_0    conda-forge
libcxx                    17.0.6               h5f092b4_0    conda-forge
libdeflate                1.20                 h93a5062_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h93a5062_2    conda-forge
libexpat                  2.6.2                hebf3989_0    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgd                     2.3.3                hfdf3952_9    conda-forge
libgettextpo              0.22.5               h8fbad5d_2    conda-forge
libgettextpo-devel        0.22.5               h8fbad5d_2    conda-forge
libgfortran               5.0.0           13_2_0_hd922786_3    conda-forge
libgfortran5              13.2.0               hf226fd6_3    conda-forge
libglib                   2.80.2               h535f939_0    conda-forge
libiconv                  1.17                 h0d3ecfb_2    conda-forge
libintl                   0.22.5               h8fbad5d_2    conda-forge
libintl-devel             0.22.5               h8fbad5d_2    conda-forge
libjpeg-turbo             3.0.0                hb547adb_1    conda-forge
liblapack                 3.9.0           22_osxarm64_openblas    conda-forge
liblapacke                3.9.0           22_osxarm64_openblas    conda-forge
libllvm16                 16.0.6               haab561b_3    conda-forge
libnghttp2                1.58.0               ha4dd798_1    conda-forge
libopenblas               0.3.27          openmp_h6c19121_0    conda-forge
libpng                    1.6.43               h091b4b1_0    conda-forge
libprotobuf               4.25.3               hbfab5d5_0    conda-forge
librsvg                   2.58.0               hb3d354b_1    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libsqlite                 3.45.3               h091b4b1_0    conda-forge
libssh2                   1.11.0               h7a5bd25_0    conda-forge
libtiff                   4.6.0                h07db509_3    conda-forge
libtorch                  2.3.0           cpu_generic_hed86ac2_0    conda-forge
libuv                     1.48.0               h93a5062_0    conda-forge
libwebp                   1.4.0                h54798ee_0    conda-forge
libwebp-base              1.4.0                h93a5062_0    conda-forge
libxcb                    1.15                 hf346824_0    conda-forge
libxml2                   2.12.7               ha661575_0    conda-forge
libzlib                   1.2.13               h53f4e23_5    conda-forge
llvm-openmp               18.1.5               hde57baf_0    conda-forge
llvm-tools                16.0.6               haab561b_3    conda-forge
logical-unification       0.4.6              pyhd8ed1ab_0    conda-forge
markdown-it-py            3.0.0              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.5           py312he37b823_0    conda-forge
matplotlib-base           3.8.4           py312ha6faf65_0    conda-forge
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
mdurl                     0.1.2              pyhd8ed1ab_0    conda-forge
minikanren                1.0.3              pyhd8ed1ab_0    conda-forge
mpc                       1.3.1                h91ba8db_0    conda-forge
mpfr                      4.2.1                h41d338b_1    conda-forge
mpmath                    1.3.0              pyhd8ed1ab_0    conda-forge
multipledispatch          0.6.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
ncurses                   6.5                  hb89a1cb_0    conda-forge
nest-asyncio              1.6.0              pyhd8ed1ab_0    conda-forge
networkx                  3.3                pyhd8ed1ab_1    conda-forge
nomkl                     1.0                  h5ca1d4c_0    conda-forge
numpy                     1.26.4          py312h8442bc7_0    conda-forge
openblas                  0.3.27          openmp_h55c453e_0    conda-forge
openjpeg                  2.5.2                h9f1df11_0    conda-forge
openssl                   3.3.0                h0d3ecfb_0    conda-forge
packaging                 24.0               pyhd8ed1ab_0    conda-forge
pandas                    2.2.2           py312h88edd18_0    conda-forge
pango                     1.52.2               hb067d4f_0    conda-forge
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
patsy                     0.5.6              pyhd8ed1ab_0    conda-forge
pcre2                     10.43                h26f9a81_0    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.3.0          py312h8a801b1_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pixman                    0.43.4               hebf3989_0    conda-forge
platformdirs              4.2.1              pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.42             pyha770c72_0    conda-forge
psutil                    5.9.8           py312he37b823_0    conda-forge
pthread-stubs             0.4               h27ca646_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pymc                      5.15.0               hd8ed1ab_0    conda-forge
pymc-base                 5.15.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
pytensor                  2.20.0          py312hfc7750a_1    conda-forge
pytensor-base             2.20.0          py312h88edd18_1    conda-forge
python                    3.12.3          h4a7b5fc_0_cpython    conda-forge
python-dateutil           2.9.0              pyhd8ed1ab_0    conda-forge
python-graphviz           0.20.3             pyh717bed2_0    conda-forge
python-tzdata             2024.1             pyhd8ed1ab_0    conda-forge
python_abi                3.12                    4_cp312    conda-forge
pytorch                   2.3.0           cpu_generic_py312h16b77fb_0    conda-forge
pytz                      2024.1             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.1           py312h02f2b3b_1    conda-forge
pyzmq                     26.0.3          py312hfa13136_0    conda-forge
readline                  8.2                  h92ec313_1    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
rich                      13.7.1             pyhd8ed1ab_0    conda-forge
safetensors               0.4.3           py312h5280bc4_0    conda-forge
scipy                     1.13.0          py312h14ffa8f_1    conda-forge
setuptools                69.5.1             pyhd8ed1ab_0    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sleef                     3.5.1                h156473d_2    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
statsmodels               0.14.1          py312hf635c46_0    conda-forge
sympy                     1.12            pypyh9d50eac_103    conda-forge
tapi                      1100.0.11            he4954df_0    conda-forge
tk                        8.6.13               h5083fa2_1    conda-forge
toolz                     0.12.1             pyhd8ed1ab_0    conda-forge
tornado                   6.4             py312he37b823_0    conda-forge
tqdm                      4.66.4             pyhd8ed1ab_0    conda-forge
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
typing-extensions         4.11.0               hd8ed1ab_0    conda-forge
typing_extensions         4.11.0             pyha770c72_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
urllib3                   2.2.1              pyhd8ed1ab_0    conda-forge
watermark                 2.4.3              pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
widgetsnbextension        4.0.10             pyhd8ed1ab_0    conda-forge
xarray                    2024.5.0           pyhd8ed1ab_0    conda-forge
xarray-einstats           0.7.0              pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hb547adb_0    conda-forge
xorg-libxdmcp             1.1.3                h27ca646_0    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
zeromq                    4.3.5                hcc0f68c_4    conda-forge
zipp                      3.17.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h53f4e23_5    conda-forge
zstd                      1.5.6                hb46c0d2_0    conda-forge

Ok, that doesn’t look terrible with my quick glance. And do you have an example of a model that is sampling slowly? Something smaller would be easier to work with.

Yeah, there is a model already set up in this notebook on code block 25 https://github.com/dustinstansbury/statistical-rethinking-2023/blob/main/Lecture%2018%20-%20Missing%20Data.ipynb . Everything is already set up all you have to do is execute the code blocks. When I install PyMC using the official instructions sampling is extremely slow. However, when I use the environment.yml file that install version 5.8.0 sampling finishes in 1 minute.

I can also pull out the relevant code and paste them here if you prefer?

I’m a bit suspicious of generic openblas being installed along side the (correct) arm64 libblas. I’d run the test_blas script with:

python `python -c "import os, pytensor; print(os.path.dirname(pytensor.__file__))"`/misc/check_blas.py

And make sure the right version is getting picked (check blas__ldflags in the output)

Thank you @jessegrabowski for your suggestion. I ran the command you suggested and got:

print(os.path.dirname(pytensor.__file__))"`/misc/check_blas.py

        Some results that you can compare against. They were 10 executions
        of gemm in float64 with matrices of shape 2000x2000 (M=N=K=2000).
        All memory layout was in C order.

        CPU tested: Xeon E5345(2.33Ghz, 8M L2 cache, 1333Mhz FSB),
                    Xeon E5430(2.66Ghz, 12M L2 cache, 1333Mhz FSB),
                    Xeon E5450(3Ghz, 12M L2 cache, 1333Mhz FSB),
                    Xeon X5560(2.8Ghz, 12M L2 cache, hyper-threads?)
                    Core 2 E8500, Core i7 930(2.8Ghz, hyper-threads enabled),
                    Core i7 950(3.07GHz, hyper-threads enabled)
                    Xeon X5550(2.67GHz, 8M l2 cache?, hyper-threads enabled)


        Libraries tested:
            * numpy with ATLAS from distribution (FC9) package (1 thread)
            * manually compiled numpy and ATLAS with 2 threads
            * goto 1.26 with 1, 2, 4 and 8 threads
            * goto2 1.13 compiled with multiple threads enabled

                          Xeon   Xeon   Xeon  Core2 i7    i7     Xeon   Xeon
        lib/nb threads    E5345  E5430  E5450 E8500 930   950    X5560  X5550

        numpy 1.3.0 blas                                                775.92s
        numpy_FC9_atlas/1 39.2s  35.0s  30.7s 29.6s 21.5s 19.60s
        goto/1            18.7s  16.1s  14.2s 13.7s 16.1s 14.67s
        numpy_MAN_atlas/2 12.0s  11.6s  10.2s  9.2s  9.0s
        goto/2             9.5s   8.1s   7.1s  7.3s  8.1s  7.4s
        goto/4             4.9s   4.4s   3.7s  -     4.1s  3.8s
        goto/8             2.7s   2.4s   2.0s  -     4.1s  3.8s
        openblas/1                                        14.04s
        openblas/2                                         7.16s
        openblas/4                                         3.71s
        openblas/8                                         3.70s
        mkl 11.0.083/1            7.97s
        mkl 10.2.2.025/1                                         13.7s
        mkl 10.2.2.025/2                                          7.6s
        mkl 10.2.2.025/4                                          4.0s
        mkl 10.2.2.025/8                                          2.0s
        goto2 1.13/1                                                     14.37s
        goto2 1.13/2                                                      7.26s
        goto2 1.13/4                                                      3.70s
        goto2 1.13/8                                                      1.94s
        goto2 1.13/16                                                     3.16s

        Test time in float32. There were 10 executions of gemm in
        float32 with matrices of shape 5000x5000 (M=N=K=5000)
        All memory layout was in C order.


        cuda version      8.0    7.5    7.0
        gpu
        M40               0.45s  0.47s
        k80               0.92s  0.96s
        K6000/NOECC       0.71s         0.69s
        P6000/NOECC       0.25s

        Titan X (Pascal)  0.28s
        GTX Titan X       0.45s  0.45s  0.47s
        GTX Titan Black   0.66s  0.64s  0.64s
        GTX 1080          0.35s
        GTX 980 Ti               0.41s
        GTX 970                  0.66s
        GTX 680                         1.57s
        GTX 750 Ti               2.01s  2.01s
        GTX 750                  2.46s  2.37s
        GTX 660                  2.32s  2.32s
        GTX 580                  2.42s
        GTX 480                  2.87s
        TX1                             7.6s (float32 storage and computation)
        GT 610                          33.5s
        
Some PyTensor flags:
    blas__ldflags= -L/opt/miniconda3/envs/pymc_env/lib -llapack -lblas -lcblas -lm -Wl,-rpath,/opt/miniconda3/envs/pymc_env/lib
    compiledir= /Users/dekermanjian/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64
    floatX= float64
    device= cpu
Some OS information:
    sys.platform= darwin
    sys.version= 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:35:20) [Clang 16.0.6 ]
    sys.prefix= /opt/miniconda3/envs/pymc_env
Some environment variables:
    MKL_NUM_THREADS= None
    OMP_NUM_THREADS= None
    GOTO_NUM_THREADS= None

Numpy config: (used when the PyTensor flag "blas__ldflags" is empty)
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: /opt/miniconda3/envs/pymc_env/include
    lib directory: /opt/miniconda3/envs/pymc_env/lib
    name: blas
    openblas configuration: unknown
    pc file directory: /opt/miniconda3/envs/pymc_env/lib/pkgconfig
    version: 3.9.0
  lapack:
    detection method: internal
    found: true
    include directory: unknown
    lib directory: unknown
    name: dep4569863840
    openblas configuration: unknown
    pc file directory: unknown
    version: 1.26.4
Compilers:
  c:
    args: -ftree-vectorize, -fPIC, -fstack-protector-strong, -O2, -pipe, -isystem,
      /opt/miniconda3/envs/pymc_env/include, -fdebug-prefix-map=/Users/runner/miniforge3/conda-bld/numpy_1707225421156/work=/usr/local/src/conda/numpy-1.26.4,
      -fdebug-prefix-map=/opt/miniconda3/envs/pymc_env=/usr/local/src/conda-prefix,
      -D_FORTIFY_SOURCE=2, -isystem, /opt/miniconda3/envs/pymc_env/include, -mmacosx-version-min=11.0
    commands: arm64-apple-darwin20.0.0-clang
    linker: ld64
    linker args: -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs, -Wl,-rpath,/opt/miniconda3/envs/pymc_env/lib,
      -L/opt/miniconda3/envs/pymc_env/lib, -ftree-vectorize, -fPIC, -fstack-protector-strong,
      -O2, -pipe, -isystem, /opt/miniconda3/envs/pymc_env/include, -fdebug-prefix-map=/Users/runner/miniforge3/conda-bld/numpy_1707225421156/work=/usr/local/src/conda/numpy-1.26.4,
      -fdebug-prefix-map=/opt/miniconda3/envs/pymc_env=/usr/local/src/conda-prefix,
      -D_FORTIFY_SOURCE=2, -isystem, /opt/miniconda3/envs/pymc_env/include, -mmacosx-version-min=11.0
    name: clang
    version: 16.0.6
  c++:
    args: -ftree-vectorize, -fPIC, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++,
      -fvisibility-inlines-hidden, -fmessage-length=0, -isystem, /opt/miniconda3/envs/pymc_env/include,
      -fdebug-prefix-map=/Users/runner/miniforge3/conda-bld/numpy_1707225421156/work=/usr/local/src/conda/numpy-1.26.4,
      -fdebug-prefix-map=/opt/miniconda3/envs/pymc_env=/usr/local/src/conda-prefix,
      -D_FORTIFY_SOURCE=2, -isystem, /opt/miniconda3/envs/pymc_env/include, -mmacosx-version-min=11.0
    commands: arm64-apple-darwin20.0.0-clang++
    linker: ld64
    linker args: -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs, -Wl,-rpath,/opt/miniconda3/envs/pymc_env/lib,
      -L/opt/miniconda3/envs/pymc_env/lib, -ftree-vectorize, -fPIC, -fstack-protector-strong,
      -O2, -pipe, -stdlib=libc++, -fvisibility-inlines-hidden, -fmessage-length=0,
      -isystem, /opt/miniconda3/envs/pymc_env/include, -fdebug-prefix-map=/Users/runner/miniforge3/conda-bld/numpy_1707225421156/work=/usr/local/src/conda/numpy-1.26.4,
      -fdebug-prefix-map=/opt/miniconda3/envs/pymc_env=/usr/local/src/conda-prefix,
      -D_FORTIFY_SOURCE=2, -isystem, /opt/miniconda3/envs/pymc_env/include, -mmacosx-version-min=11.0
    name: clang
    version: 16.0.6
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 3.0.8
Machine Information:
  build:
    cpu: aarch64
    endian: little
    family: aarch64
    system: darwin
  cross-compiled: true
  host:
    cpu: arm64
    endian: little
    family: aarch64
    system: darwin
Python Information:
  path: /opt/miniconda3/envs/pymc_env/bin/python
  version: '3.12'
SIMD Extensions:
  baseline:
  - NEON
  - NEON_FP16
  - NEON_VFPV4
  - ASIMD
  found:
  - ASIMDHP
  not found:
  - ASIMDFHM

Numpy dot module: numpy
Numpy location: /opt/miniconda3/envs/pymc_env/lib/python3.12/site-packages/numpy/__init__.py
Numpy version: 1.26.4

We executed 10 calls to gemm with a and b matrices of shapes (5000, 5000) and (5000, 5000).

Total execution time: 7.34s on CPU (with direct PyTensor binding to blas).

Try to run this script a few times. Experience shows that the first time is not as fast as following calls. The difference is not big, but consistent.

There are two areas that mention the blas__ldflags one points to some path and the other says it is used when it is empty. I am not sure how to interpret that.

All of this is correct (or at least it matches what I get on my macbook). I’ll run the notebook you’re talking about a bit later and see if I get the same slow sampling.

In the meantime, can you try sampling the model with an alternative backend (either jax or numba) and let me know if that’s also slow?

Thank you @jessegrabowski. I tried using numpyro and nutpie. Numpyro samples in around 6 minutes, however, there is a model on code block 36 that it complains about some “Not Implemented” function. Nutpie samples the model but is extremely slow. These models get sampled in a around 2 - 3 minutes using the native pymc sampler when I setup the environment using the environment.yml file that is included in the repo.

Well I can report slow sampling on my end. If there really is a performance regression, it’d be good to know exactly which PR caused it? You said it runs fast on 5.8, I looked through the changelogs and 5.9.1 has a PR that directly touched MvN. Otherwise I don’t see any obvious candidates – though that doesn’t mean it wasn’t something else. If you’re willing to keep testing, I’d ask you to try 5.9 and 5.9.1. If those are both good, see if you can find the newest version that samples quickly for you?

Try it just with conda create env -n pymc_env "pymc==5.9.0" (rather than updating the environment yaml from that rethinking repo), because the environment in that repo has a ton of other packages I’d rather not interfere with the speed tests.

Thank you @jessegrabowski. Yes, I am willing to do that testing today and will report back here.

1 Like

Okay, @jessegrabowski it might not be the PyMC version that is the culprit. I installed a fresh environment using conda create env -n pymc_env "pymc==5.8.0" This matches the PyMC version that samples quickly when installed from the env.yml file on the repo. The sampling on this fresh environment is still very slow. Here is the output from conda list for the fresh env:

# packages in environment at /opt/miniconda3/envs/pymc_env:
#
# Name                    Version                   Build  Channel
appnope                   0.1.4              pyhd8ed1ab_0    conda-forge
arviz                     0.18.0             pyhd8ed1ab_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
blas                      2.122                  openblas    conda-forge
blas-devel                3.9.0           22_osxarm64_openblas    conda-forge
brotli                    1.1.0                hb547adb_1    conda-forge
brotli-bin                1.1.0                hb547adb_1    conda-forge
bzip2                     1.0.8                h93a5062_5    conda-forge
c-ares                    1.28.1               h93a5062_0    conda-forge
ca-certificates           2024.2.2             hf0a4a13_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cachetools                5.3.3              pyhd8ed1ab_0    conda-forge
cctools_osx-arm64         973.0.1             h2a25c60_15    conda-forge
certifi                   2024.2.2           pyhd8ed1ab_0    conda-forge
clang                     15.0.7               h30cc82d_5    conda-forge
clang-15                  15.0.7          default_he012953_5    conda-forge
clang_impl_osx-arm64      15.0.7               h77e971b_8    conda-forge
clang_osx-arm64           15.0.7               h54d7cd3_8    conda-forge
clangxx                   15.0.7          default_h4cf2255_5    conda-forge
clangxx_impl_osx-arm64    15.0.7               h768a7fd_8    conda-forge
clangxx_osx-arm64         15.0.7               h54d7cd3_8    conda-forge
cloudpickle               3.0.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6                    pypi_0    pypi
comm                      0.2.2              pyhd8ed1ab_0    conda-forge
compiler-rt               15.0.7               h3808999_2    conda-forge
compiler-rt_osx-arm64     15.0.7               h3808999_2    conda-forge
cons                      0.4.6              pyhd8ed1ab_0    conda-forge
contourpy                 1.2.1           py311hcc98501_0    conda-forge
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
debugpy                   1.8.1           py311h92babd0_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
dm-tree                   0.1.8           py311hea19e3d_4    conda-forge
etuples                   0.3.9              pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
fastprogress              1.0.3              pyhd8ed1ab_0    conda-forge
filelock                  3.14.0             pyhd8ed1ab_0    conda-forge
fonttools                 4.51.0          py311h05b510d_0    conda-forge
freetype                  2.12.1               hadb7bae_2    conda-forge
h5netcdf                  1.3.0              pyhd8ed1ab_0    conda-forge
h5py                      3.11.0          nompi_py311hd00467f_100    conda-forge
hdf5                      1.14.3          nompi_h751145d_101    conda-forge
icu                       73.2                 hc8870d7_0    conda-forge
importlib-metadata        7.1.0              pyha770c72_0    conda-forge
importlib_metadata        7.1.0                hd8ed1ab_0    conda-forge
ipykernel                 6.29.3             pyh3cd1d5f_0    conda-forge
ipython                   8.24.0             pyh707e725_0    conda-forge
ipywidgets                8.1.2              pyhd8ed1ab_1    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jupyter_client            8.6.1              pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.2           py311h267d04e_0    conda-forge
jupyterlab_widgets        3.0.10             pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.5           py311he4fd1f5_1    conda-forge
krb5                      1.21.2               h92f50d5_0    conda-forge
lcms2                     2.16                 ha0e7c42_0    conda-forge
ld64_osx-arm64            609                 hc4dc95b_15    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libabseil                 20240116.2      cxx17_hebf3989_0    conda-forge
libaec                    1.1.3                hebf3989_0    conda-forge
libblas                   3.9.0           22_osxarm64_openblas    conda-forge
libbrotlicommon           1.1.0                hb547adb_1    conda-forge
libbrotlidec              1.1.0                hb547adb_1    conda-forge
libbrotlienc              1.1.0                hb547adb_1    conda-forge
libcblas                  3.9.0           22_osxarm64_openblas    conda-forge
libclang-cpp15            15.0.7          default_he012953_5    conda-forge
libcurl                   8.7.1                h2d989ff_0    conda-forge
libcxx                    17.0.6               h5f092b4_0    conda-forge
libdeflate                1.20                 h93a5062_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h93a5062_2    conda-forge
libexpat                  2.6.2                hebf3989_0    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgfortran               5.0.0           13_2_0_hd922786_3    conda-forge
libgfortran5              13.2.0               hf226fd6_3    conda-forge
libiconv                  1.17                 h0d3ecfb_2    conda-forge
libjpeg-turbo             3.0.0                hb547adb_1    conda-forge
liblapack                 3.9.0           22_osxarm64_openblas    conda-forge
liblapacke                3.9.0           22_osxarm64_openblas    conda-forge
libllvm15                 15.0.7               h2621b3d_4    conda-forge
libnghttp2                1.58.0               ha4dd798_1    conda-forge
libopenblas               0.3.27          openmp_h6c19121_0    conda-forge
libpng                    1.6.43               h091b4b1_0    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libsqlite                 3.45.3               h091b4b1_0    conda-forge
libssh2                   1.11.0               h7a5bd25_0    conda-forge
libtiff                   4.6.0                h07db509_3    conda-forge
libwebp-base              1.4.0                h93a5062_0    conda-forge
libxcb                    1.15                 hf346824_0    conda-forge
libxml2                   2.12.7               ha661575_0    conda-forge
libzlib                   1.2.13               h53f4e23_5    conda-forge
llvm-openmp               18.1.5               hde57baf_0    conda-forge
llvm-tools                15.0.7               h2621b3d_4    conda-forge
logical-unification       0.4.6              pyhd8ed1ab_0    conda-forge
matplotlib-base           3.8.4           py311hb58f1d1_0    conda-forge
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
minikanren                1.0.3              pyhd8ed1ab_0    conda-forge
multipledispatch          0.6.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
ncurses                   6.5                  hb89a1cb_0    conda-forge
nest-asyncio              1.6.0              pyhd8ed1ab_0    conda-forge
networkx                  3.3                      pypi_0    pypi
numpy                     1.25.2          py311hb8f3215_0    conda-forge
openblas                  0.3.27          openmp_h55c453e_0    conda-forge
openjpeg                  2.5.2                h9f1df11_0    conda-forge
openssl                   3.3.0                h0d3ecfb_0    conda-forge
packaging                 24.0               pyhd8ed1ab_0    conda-forge
pandas                    2.2.2           py311hfbe21a1_0    conda-forge
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
patsy                     0.5.6              pyhd8ed1ab_0    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.3.0          py311h0b5d0a1_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
platformdirs              4.2.1              pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.42             pyha770c72_0    conda-forge
psutil                    5.9.8           py311h05b510d_0    conda-forge
pthread-stubs             0.4               h27ca646_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pymc                      5.8.0                hd8ed1ab_0    conda-forge
pymc-base                 5.8.0              pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
pytensor                  2.15.0          py311hbee6d41_0    conda-forge
pytensor-base             2.15.0          py311h9e438b8_0    conda-forge
python                    3.11.9          h932a869_0_cpython    conda-forge
python-dateutil           2.9.0              pyhd8ed1ab_0    conda-forge
python-graphviz           0.20.3                   pypi_0    pypi
python-tzdata             2024.1             pyhd8ed1ab_0    conda-forge
python_abi                3.11                    4_cp311    conda-forge
pytz                      2024.1             pyhd8ed1ab_0    conda-forge
pyzmq                     26.0.3          py311h9bed540_0    conda-forge
readline                  8.2                  h92ec313_1    conda-forge
scipy                     1.13.0          py311hceeca8c_1    conda-forge
setuptools                69.5.1             pyhd8ed1ab_0    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
statsmodels               0.14.1          py311h9ea6feb_0    conda-forge
tapi                      1100.0.11            he4954df_0    conda-forge
tk                        8.6.13               h5083fa2_1    conda-forge
toolz                     0.12.1             pyhd8ed1ab_0    conda-forge
tornado                   6.4             py311h05b510d_0    conda-forge
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
typing-extensions         4.11.0               hd8ed1ab_0    conda-forge
typing_extensions         4.11.0             pyha770c72_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
watermark                 2.4.3              pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
widgetsnbextension        4.0.10             pyhd8ed1ab_0    conda-forge
xarray                    2024.5.0           pyhd8ed1ab_0    conda-forge
xarray-einstats           0.7.0              pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hb547adb_0    conda-forge
xorg-libxdmcp             1.1.3                h27ca646_0    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
zeromq                    4.3.5                hcc0f68c_4    conda-forge
zipp                      3.17.0             pyhd8ed1ab_0    conda-forge
zstd                      1.5.6                hb46c0d2_0    conda-forge

Here is the output from conda list from the environment that samples quickly:

# packages in environment at /opt/miniconda3/envs/statistical-rethinking-2023:
#
# Name                    Version                   Build  Channel
anyio                     4.0.0              pyhd8ed1ab_0    conda-forge
appnope                   0.1.3              pyhd8ed1ab_0    conda-forge
argon2-cffi               23.1.0             pyhd8ed1ab_0    conda-forge
argon2-cffi-bindings      21.2.0          py310h8e9501a_3    conda-forge
arrow                     1.2.3              pyhd8ed1ab_0    conda-forge
arviz                     0.16.1             pyhd8ed1ab_0    conda-forge
asttokens                 2.4.0              pyhd8ed1ab_0    conda-forge
async-lru                 2.0.4              pyhd8ed1ab_0    conda-forge
atk-1.0                   2.38.0               hcb7b3dd_1    conda-forge
attrs                     23.1.0             pyh71513ae_1    conda-forge
babel                     2.12.1             pyhd8ed1ab_1    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.5              pyhd8ed1ab_0    conda-forge
beautifulsoup4            4.12.2             pyha770c72_0    conda-forge
blas                      2.117                accelerate    conda-forge
blas-devel                3.9.0           17_osxarm64_accelerate    conda-forge
bleach                    6.0.0              pyhd8ed1ab_0    conda-forge
brotli                    1.1.0                hb547adb_0    conda-forge
brotli-bin                1.1.0                hb547adb_0    conda-forge
brotli-python             1.1.0           py310h1253130_0    conda-forge
bzip2                     1.0.8                h3422bc3_4    conda-forge
c-ares                    1.19.1               hb547adb_0    conda-forge
ca-certificates           2023.7.22            hf0a4a13_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cachetools                5.3.1              pyhd8ed1ab_0    conda-forge
cairo                     1.16.0            hc5b65c1_1017    conda-forge
cctools_osx-arm64         973.0.1             h2a25c60_14    conda-forge
certifi                   2023.7.22          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py310h2399d43_3    conda-forge
charset-normalizer        3.2.0              pyhd8ed1ab_0    conda-forge
clang                     15.0.7               hce30654_3    conda-forge
clang-15                  15.0.7          default_h5dc8d65_3    conda-forge
clang_osx-arm64           15.0.7               h77e971b_3    conda-forge
clangxx                   15.0.7          default_h610c423_3    conda-forge
clangxx_osx-arm64         15.0.7               h768a7fd_3    conda-forge
cloudpickle               2.2.1              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
comm                      0.1.4              pyhd8ed1ab_0    conda-forge
compiler-rt               15.0.7               hf8d1dfb_1    conda-forge
compiler-rt_osx-arm64     15.0.7               hf8d1dfb_1    conda-forge
cons                      0.4.6              pyhd8ed1ab_0    conda-forge
contourpy                 1.1.0           py310h38f39d4_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
debugpy                   1.7.0           py310h1253130_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
etuples                   0.3.9              pyhd8ed1ab_0    conda-forge
exceptiongroup            1.1.3              pyhd8ed1ab_0    conda-forge
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
expat                     2.5.0                hb7217d7_1    conda-forge
fastprogress              1.0.3              pyhd8ed1ab_0    conda-forge
filelock                  3.12.3             pyhd8ed1ab_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.2               h82840c6_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.42.1          py310h2aa6e3c_0    conda-forge
fqdn                      1.5.1              pyhd8ed1ab_0    conda-forge
freetype                  2.12.1               hd633e50_1    conda-forge
fribidi                   1.0.10               h27ca646_0    conda-forge
gdk-pixbuf                2.42.10              h1ac0d0d_2    conda-forge
gettext                   0.21.1               h0186832_0    conda-forge
giflib                    5.2.1                h1a8c8d9_3    conda-forge
graphite2                 1.3.13            h9f76cd9_1001    conda-forge
graphviz                  8.1.0                h10878c0_0    conda-forge
gtk2                      2.24.33              h57013de_2    conda-forge
gts                       0.7.6                he42f4ea_4    conda-forge
h5netcdf                  1.2.0              pyhd8ed1ab_0    conda-forge
h5py                      3.9.0           nompi_py310hba14233_102    conda-forge
harfbuzz                  8.2.0                hf1a6348_0    conda-forge
hdf5                      1.14.2          nompi_h3aba7b3_100    conda-forge
icu                       73.2                 hc8870d7_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
importlib-metadata        6.8.0              pyha770c72_0    conda-forge
importlib_metadata        6.8.0                hd8ed1ab_0    conda-forge
importlib_resources       6.0.1              pyhd8ed1ab_0    conda-forge
ipykernel                 6.25.2             pyh1050b4e_0    conda-forge
ipython                   8.15.0             pyh31c8845_0    conda-forge
isoduration               20.11.0            pyhd8ed1ab_0    conda-forge
jax                       0.4.14             pyhd8ed1ab_1    conda-forge
jaxlib                    0.4.14          cpu_py310hec32d7d_1    conda-forge
jedi                      0.19.0             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
json5                     0.9.14             pyhd8ed1ab_0    conda-forge
jsonpointer               2.0                        py_0    conda-forge
jsonschema                4.19.0             pyhd8ed1ab_1    conda-forge
jsonschema-specifications 2023.7.1           pyhd8ed1ab_0    conda-forge
jsonschema-with-format-nongpl 4.19.0             pyhd8ed1ab_1    conda-forge
jupyter-lsp               2.2.0              pyhd8ed1ab_0    conda-forge
jupyter_client            8.3.1              pyhd8ed1ab_0    conda-forge
jupyter_core              5.3.1           py310hbe9552e_0    conda-forge
jupyter_events            0.7.0              pyhd8ed1ab_2    conda-forge
jupyter_server            2.7.3              pyhd8ed1ab_0    conda-forge
jupyter_server_terminals  0.4.4              pyhd8ed1ab_1    conda-forge
jupyterlab                4.0.5              pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
jupyterlab_server         2.24.0             pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.5           py310h38f39d4_0    conda-forge
krb5                      1.21.2               h92f50d5_0    conda-forge
lcms2                     2.15                 hd835a16_1    conda-forge
ld64_osx-arm64            609                 hc4dc95b_14    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libabseil                 20230125.3      cxx17_h13dd4ca_0    conda-forge
libaec                    1.0.6                hb7217d7_1    conda-forge
libblas                   3.9.0           17_osxarm64_accelerate    conda-forge
libbrotlicommon           1.1.0                hb547adb_0    conda-forge
libbrotlidec              1.1.0                hb547adb_0    conda-forge
libbrotlienc              1.1.0                hb547adb_0    conda-forge
libcblas                  3.9.0           17_osxarm64_accelerate    conda-forge
libclang-cpp15            15.0.7          default_h5dc8d65_3    conda-forge
libcurl                   8.2.1                hc52a3a8_0    conda-forge
libcxx                    16.0.6               h4653b0c_0    conda-forge
libdeflate                1.18                 h1a8c8d9_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h642e427_1    conda-forge
libexpat                  2.5.0                hb7217d7_1    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgd                     2.3.3                h32cdd76_7    conda-forge
libgfortran               5.0.0           13_2_0_hd922786_1    conda-forge
libgfortran5              13.2.0               hf226fd6_1    conda-forge
libglib                   2.78.0               h24e9cb9_0    conda-forge
libgrpc                   1.56.2               h9075ed4_1    conda-forge
libiconv                  1.17                 he4db4b2_0    conda-forge
libjpeg-turbo             2.1.5.1              h1a8c8d9_0    conda-forge
liblapack                 3.9.0           17_osxarm64_accelerate    conda-forge
liblapacke                3.9.0           17_osxarm64_accelerate    conda-forge
libllvm15                 15.0.7               h504e6bf_3    conda-forge
libnghttp2                1.52.0               hae82a92_0    conda-forge
libopenblas               0.3.24          openmp_hd76b1f2_0    conda-forge
libpng                    1.6.39               h76d750c_0    conda-forge
libprotobuf               4.23.3               hf32f9b9_1    conda-forge
librsvg                   2.56.3               h0db3404_0    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libsqlite                 3.43.0               hb31c410_0    conda-forge
libssh2                   1.11.0               h7a5bd25_0    conda-forge
libtiff                   4.5.1                h23a1a89_1    conda-forge
libtool                   2.4.7                hb7217d7_0    conda-forge
libwebp                   1.3.1                h3dd3bb6_0    conda-forge
libwebp-base              1.3.1                hb547adb_0    conda-forge
libxcb                    1.15                 hf346824_0    conda-forge
libxml2                   2.11.5               h25269f3_1    conda-forge
libzlib                   1.2.13               h53f4e23_5    conda-forge
llvm-openmp               16.0.6               h1c12783_0    conda-forge
llvm-tools                15.0.7               h504e6bf_3    conda-forge
logical-unification       0.4.6              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.3           py310h2aa6e3c_0    conda-forge
matplotlib-base           3.7.2           py310h49faba3_0    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
minikanren                1.0.3              pyhd8ed1ab_0    conda-forge
mistune                   3.0.1              pyhd8ed1ab_0    conda-forge
ml_dtypes                 0.2.0           py310h1cdf563_1    conda-forge
multipledispatch          0.6.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
nbclient                  0.8.0              pyhd8ed1ab_0    conda-forge
nbconvert-core            7.8.0              pyhd8ed1ab_0    conda-forge
nbformat                  5.9.2              pyhd8ed1ab_0    conda-forge
ncurses                   6.4                  h7ea286d_0    conda-forge
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
networkx                  3.1                pyhd8ed1ab_0    conda-forge
notebook-shim             0.2.3              pyhd8ed1ab_0    conda-forge
numpy                     1.25.2          py310haa1e00c_0    conda-forge
numpyro                   0.13.0             pyhd8ed1ab_0    conda-forge
openblas                  0.3.24          openmp_hce3e5ba_0    conda-forge
openjpeg                  2.5.0                hbc2ba62_2    conda-forge
openssl                   3.1.2                h53f4e23_0    conda-forge
opt_einsum                3.3.0              pyhd8ed1ab_1    conda-forge
overrides                 7.4.0              pyhd8ed1ab_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pandas                    2.1.0           py310h5924a0a_0    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
pango                     1.50.14              hcf40dda_2    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
patsy                     0.5.3              pyhd8ed1ab_0    conda-forge
pcre2                     10.40                hb34f9b4_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.0.0          py310h60ecbdf_0    conda-forge
pip                       23.2.1             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               h27ca646_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_0    conda-forge
platformdirs              3.10.0             pyhd8ed1ab_0    conda-forge
pooch                     1.7.0              pyha770c72_3    conda-forge
prometheus_client         0.17.1             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.39             pyha770c72_0    conda-forge
prompt_toolkit            3.0.39               hd8ed1ab_0    conda-forge
psutil                    5.9.5           py310h8e9501a_0    conda-forge
pthread-stubs             0.4               h27ca646_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pygments                  2.16.1             pyhd8ed1ab_0    conda-forge
pymc                      5.8.0                hd8ed1ab_0    conda-forge
pymc-base                 5.8.0              pyhd8ed1ab_0    conda-forge
pyobjc-core               9.2             py310hd07e440_0    conda-forge
pyobjc-framework-cocoa    9.2             py310hd07e440_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
pytensor                  2.15.0          py310h5993952_0    conda-forge
pytensor-base             2.15.0          py310h5924a0a_0    conda-forge
python                    3.10.12         h01493a6_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.18.0             pyhd8ed1ab_0    conda-forge
python-graphviz           0.20.1             pyh22cad53_0    conda-forge
python-json-logger        2.0.7              pyhd8ed1ab_0    conda-forge
python-tzdata             2023.3             pyhd8ed1ab_0    conda-forge
python_abi                3.10                    3_cp310    conda-forge
pytz                      2023.3.post1       pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.1           py310h2aa6e3c_0    conda-forge
pyzmq                     25.1.1          py310h30b7201_0    conda-forge
re2                       2023.03.02           hc5e2d97_0    conda-forge
readline                  8.2                  h92ec313_1    conda-forge
referencing               0.30.2             pyhd8ed1ab_0    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
rfc3339-validator         0.1.4              pyhd8ed1ab_0    conda-forge
rfc3986-validator         0.1.1              pyh9f0ad1d_0    conda-forge
rpds-py                   0.10.2          py310had9acf8_0    conda-forge
scipy                     1.11.2          py310h0975f3d_0    conda-forge
seaborn                   0.12.2               hd8ed1ab_0    conda-forge
seaborn-base              0.12.2             pyhd8ed1ab_0    conda-forge
send2trash                1.8.2              pyhd1c38e8_0    conda-forge
setuptools                68.1.2             pyhd8ed1ab_0    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sniffio                   1.3.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.5                pyhd8ed1ab_1    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
statsmodels               0.14.0          py310ha11ecec_1    conda-forge
tapi                      1100.0.11            he4954df_0    conda-forge
terminado                 0.17.1             pyhd1c38e8_0    conda-forge
tinycss2                  1.2.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               he1e0b03_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tornado                   6.3.3           py310h2aa6e3c_0    conda-forge
tqdm                      4.66.1             pyhd8ed1ab_0    conda-forge
traitlets                 5.9.0              pyhd8ed1ab_0    conda-forge
typing-extensions         4.7.1                hd8ed1ab_0    conda-forge
typing_extensions         4.7.1              pyha770c72_0    conda-forge
typing_utils              0.1.0              pyhd8ed1ab_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
unicodedata2              15.0.0          py310h8e9501a_0    conda-forge
uri-template              1.3.0              pyhd8ed1ab_0    conda-forge
urllib3                   2.0.4              pyhd8ed1ab_0    conda-forge
watermark                 2.4.3              pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.6              pyhd8ed1ab_0    conda-forge
webcolors                 1.13               pyhd8ed1ab_0    conda-forge
webencodings              0.5.1                      py_1    conda-forge
websocket-client          1.6.3              pyhd8ed1ab_0    conda-forge
wheel                     0.41.2             pyhd8ed1ab_0    conda-forge
xarray                    2023.8.0           pyhd8ed1ab_0    conda-forge
xarray-einstats           0.6.0              pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hb547adb_0    conda-forge
xorg-libxdmcp             1.1.3                h27ca646_0    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
zeromq                    4.3.4                hbdafb3b_1    conda-forge
zipp                      3.16.2             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h53f4e23_5    conda-forge
zstd                      1.5.5                h4f39d0f_0    conda-forge

I have tried downgrading the following packages from the fresh env to match the fast sampling env but none of them made the sampling fast:

blas
xarray
xarray-einstats
scipy
patsy
statsmodels

I am not sure what other packages are relevant here?

The relevant packages should only be pymc, pymc-base, pytensor, pytensor-base, and the blas library.

What if you try the apple accelerate blas? conda install libblas=*=*accelerate*

I just tried the accelerate blas by installing it in the fresh environment but sampling is still slow. Would there be any packages that are used specifically for MvN in PyMC?

@ricardoV94 @aseyboldt

For ease of reference, here is a copy+pastable snippet we’re trying to figure out:

import pymc as pm
import pytensor.tensor as pt
import pandas as pd
import numpy as np

df = pd.read_csv('https://raw.githubusercontent.com/dustinstansbury/statistical-rethinking-2023/main/data/Primates301.csv', delimiter=';')
distance_matrix = pd.read_csv('https://raw.githubusercontent.com/dustinstansbury/statistical-rethinking-2023/main/data/Primates301_distance_matrix.csv', delimiter=';')
distance_matrix.columns = distance_matrix.columns.map(int)

df.dropna(subset='brain', inplace=True)
distance_matrix = distance_matrix.loc[df.index, :].loc[:, df.index].copy()

D_mat = (distance_matrix / distance_matrix.max())

def log_standardize(x):
    x = np.log(x)
    return (x - x.mean()) / x.std()

coords = {'primate': df['name'].values}
with pm.Model(coords=coords) as naive_imputation_model:    
    G_obs = log_standardize(df.group_size.values)
    M_obs = log_standardize(df.body.values)
    B_obs = log_standardize(df.brain.values)
    
    # Priors
    alpha = pm.Normal("alpha", 0, 1)
    beta_G = pm.Normal("beta_G", 0, 0.5)
    beta_M = pm.Normal("beta_M", 0, 0.5)

    # Phylogenetic distance covariance prior, L1-kernel function
    eta_squared = pm.TruncatedNormal("eta_squared", 1, .25, lower=.001)
    rho = pm.TruncatedNormal("rho", 3, .25, lower=.001)
    K = pm.Deterministic('K', eta_squared * pt.exp(-rho * D_mat))

    # Naive imputation for G, M
    G = pm.Normal("G", 0, 1, observed=G_obs, dims='primate')
    M = pm.Normal("M", 0, 1, observed=M_obs, dims='primate')

    # Likelihood for B
    mu = alpha + beta_G * G + beta_M * M
    pm.MvNormal("B", mu=mu, cov=K, observed=B_obs)

    naive_imputation_inference = pm.sample()

Thank you for all of your help @jessegrabowski. I really appreciate it.

Hey @jessegrabowski, I think I figured out the problem. Would you mind trying this on your end to confirm it works?

1). conda create -n pymc_env "pymc==5.8.0"
2). Sample the model confirm it is slow then interrupt the kernel
3). conda install libopenblas=0.3.24 libsqlite=3.43.0 (you may need to restart Jupyter/vs code)
4). Sample the model and confirm it is fast

I can also confirm that this works for me with the latest version of PyMC