CmdStanR models crash instantly on Windows (serial or parallel)

Hello,

I have a persistent issue where any model run via the cmdstanr backend fails instantly. The model compiles successfully, but when sampling starts, the chains finish unexpectedly with no log output files created.

Crucially, this problem is NOT related to parallelism. The crash occurs:

  • With OpenCL (opencl = c(0, 0)).

  • With CPU threading (threads = threading(...)).

  • Even in the simplest serial mode (cores = 1, chains = 1).

However, if I comment out backend = "cmdstanr" and let brms use the default rstan backend, the model runs perfectly with parallel chains (cores > 1).

This proves the issue is specific to the executables generated and/or run by the cmdstanr backend on my system.

Here is the complete output from the diagnostic guide suggested on another thread:

--- Checking Versions ---
[1] "2.37.0"

--- Checking the Toolchain ---
The C++ toolchain required for CmdStan is setup properly!

--- Checking the PATH variable ---
[1] "C:\\RBuildTools\\4.4\\x86_64-w64-mingw32.static.posix\\bin;C:\\RBuildTools\\4.4\\usr\\bin;C:\\Program Files\\R\\R-4.4.2\\bin\\x64;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.0\\bin\\x64;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files\\NVIDIA Corporation\\Nsight Compute 2025.3.1;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Users\\Usuario\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\Usuario\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64;C:\\Users\\Usuario\\AppData\\Roaming\\TinyTeX\\bin\\win32;C:\\Program Files\\RStudio\\resources\\app\\bin\\quarto\\bin;C:\\Program Files\\RStudio\\resources\\app\\bin\\postback"

--- Testing the execution of the Bernoulli model ---
Model executable is up to date!
Running MCMC with 1 chain...
Chain 1 finished unexpectedly!
Error : Fitting failed. Unable to print.

--- END OF DIAGNOSTIC GUIDE ---

And here is my system information:

  • Operating System: Windows 11

  • CmdStan Version: 2.37.0

  • CmdStanR Version: 0.9.0.9000

  • Compiler/Toolkit: Rtools44

  • GPU Model: NVIDIA GeForce GTX 1050 Ti

  • NVIDIA Driver Version: NVIDIA Studio v 581.57

I have already tried a full clean install of the NVIDIA Studio Driver and completely disabling all antivirus/firewall software, but the problem persists.

Thank you for any help you can provide.

Does cmdstanr work for any models (e.g., ones without opencl)?

Can you share the output of the commands from Guide: Diagnosing a complete lack of output on Windows

1 Like

Thank you for the guidance! I have now edited my original post above with the answers to your questions and the full output from the diagnostic guide.

The key new finding is that cmdstanr fails even in serial mode, while the rstan backend works perfectly. This points to a cmdstanr-specific execution issue on my system.

TBB could still be to blame, as it is linked even when the serial execution is requested. Can you run where.exe tbb.dll in a command prompt?

Thank you so much for the excellent suggestion!

I ran where.exe tbb.dll in the command prompt as you requested, and the result was that the file was not found:

INFO: Could not find files for the given pattern(s).

This suggested that the TBB library was not on my system PATH. Following this lead, I will now manually add the CmdStan TBB path to my system PATH variable and reboot the computer. The path I will add is: C:\Users\User\.cmdstan\cmdstan-2.37.0\stan\lib\stan_math\lib\tbb

Did adding tbb to the path make a difference?