Windows RStudio crashing with RStan model loaded


#1

Hey,

I’m in a course with @betanalpha right now and I think every Windows user is seeing RStudio crash sort of randomly at some point after loading RStan. There are 4 people that I know of with the same issue and at least some of them are on RStan 2.18 (maybe all of them). @bgoodri have you seen anything like this? Are there easy instructions somewhere for trying RStan 2.17.x for these folks? I pointed them to the cloud but the wifi is not working.

@jonah Any progress on RCmdStan? 😂


#2

Are they using threading?


#3

To install a specific version of RStan, this worked for me:

  1. remove.packages("rstan"); if (file.exists(".RData")) file.remove(".RData")
  2. install.packages("devtools")
  3. Create decent Makevars if we don’t have it:
dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars.win")
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native",
    "CXX14 = g++ -m$(WIN) -std=c++1y",
    "CXX11FLAGS=-O3 -march=native",
    file = M, sep = "\n", append = TRUE)
  1. Restart R[Studio]
  2. library(devtools); install_version("rstan", version="2.17.4")

#4

Nope, at least not on purpose. From some light experimentation, it seems like it might only happen when using the algebraic solver (possibly only in 2.18).


#5

We had a divided-by-zero problem on windows with mingw that crashed the whole session.


#6

What’s RCmdStan?


#7

Do you have an example of algebraic_solver() that crashes things?


#8
functions {
  vector tail_delta(vector y, vector theta, real[] x_r, int[] x_i) {
    vector[1] deltas;
    deltas[1] = 2 * (normal_cdf(theta[1], 0, exp(y[1])) - 0.5) - 0.99;
    return deltas;
} }
transformed data {
  vector[1] y_guess = [log(5)]';
  vector[1] theta = [15]';
  vector[1] y;
  real x_r[0];
  int x_i[0];
  y = algebra_solver(tail_delta, y_guess, theta, x_r, x_i);
  print("Standard deviation = ", exp(y[1]));
}
generated quantities {
  real sigma = exp(y[1]);
}

#9

I have not been able to replicate this on the Windows computer in my office. If there is anyone who had this problem that wants to stay around at the end of the workshop to recreate it, I could use some more information, such as what was the error message / stack trace and whether they were tuning the compiler to the processor.


#10

Talked with one of the people with the issue and he says the RStudio crash happens about half the time. Got him to run the model without either march=native or mtune=native and with -O2 instead of -O3 and it still crashed RStudio on the 2nd stan call.


#11

OK. I can trigger it if I call it enough times. The backtrace does not help that much though. It looks like something may be getting left on the heap that was supposed to be cleaned up.

SAMPLING FOR MODEL 'crash' NOW (CHAIN 1).
Chain 1: Iteration: 1 / 1 [100%]  (Sampling)
Chain 1:
Chain 1:  Elapsed Time: 0 seconds (Warm-up)
Chain 1:                0.003 seconds (Sampling)
Chain 1:                0.003 seconds (Total)
Chain 1:
warning: HEAP[Rterm.exe]:
warning: Heap block at 0000000017A8FCB0 modified at 0000000017A8FCC8 past reques
ted size of 8


Program received signal SIGTRAP, Trace/breakpoint trap.
0x0000000077a69372 in ntdll!EtwEventProviderEnabled ()
   from C:\windows\SYSTEM32\ntdll.dll
(gdb) bt
#0  0x0000000077a69372 in ntdll!EtwEventProviderEnabled ()
   from C:\windows\SYSTEM32\ntdll.dll
#1  0x0000000077a795f1 in ntdll!RtlFindClearBits ()
   from C:\windows\SYSTEM32\ntdll.dll
#2  0x0000000077a40290 in ntdll!longjmp () from C:\windows\SYSTEM32\ntdll.dll
#3  0x0000000077a84869 in ntdll!RtlLogStackBackTrace ()
   from C:\windows\SYSTEM32\ntdll.dll
#4  0x0000000077a45972 in ntdll!longjmp () from C:\windows\SYSTEM32\ntdll.dll
#5  0x000007fefe0010c8 in msvcrt!free () from C:\windows\system32\msvcrt.dll
#6  0x000000006ae46c40 in rstan!effective_sample_size ()
   from C:\Users\Stan\Documents\R\win-library\3.5\rstan\libs\x64\rstan.dll
#7  0x000000006c7f3ef9 in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#8  0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#9  0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#10 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#11 0x000000006c7f531a in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#12 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#13 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#14 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#15 0x000000006c807e89 in R_forceAndCall ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#16 0x000000006c8eab2a in rwarn_ () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#17 0x000000006c836b77 in do_Rprofmem ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#18 0x000000006c7ed988 in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#19 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#20 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#21 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#22 0x000000006c7f531a in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#23 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#24 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#25 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#26 0x000000006c7f531a in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#27 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#28 0x000000006c8003dc in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#29 0x000000006c7fdf2c in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#30 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#31 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#32 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#33 0x000000006c7f531a in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#34 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#35 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#36 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#37 0x000000006c7ffd02 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#38 0x000000006c8003dc in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#39 0x000000006c7fdf2c in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#40 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#41 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#42 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#43 0x000000006c7ffd02 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#44 0x000000006c7fff06 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#45 0x000000006c802e76 in R_execMethod ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#46 0x000000006c7fff06 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#47 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
---Type <return> to continue, or q <return> to quit---
#48 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#49 0x000000006c7f531a in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#50 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#51 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#52 0x000000006c80265e in R_execMethod ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#53 0x0000000064a42cf2 in methods!R_dispatchGeneric ()
   from C:\Program Files\R\R-3.5.1\library\methods\libs\x64\methods.dll
#54 0x000000006c83b972 in R_set_standardGeneric_ptr ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#55 0x000000006c800062 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#56 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#57 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#58 0x000000006c7f531a in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#59 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#60 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#61 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#62 0x000000006c7f531a in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#63 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#64 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#65 0x000000006c80265e in R_execMethod ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#66 0x0000000064a42cf2 in methods!R_dispatchGeneric ()
   from C:\Program Files\R\R-3.5.1\library\methods\libs\x64\methods.dll
#67 0x000000006c83b972 in R_set_standardGeneric_ptr ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#68 0x000000006c7f7b5d in R_initAssignSymbols ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#69 0x000000006c7ffd41 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#70 0x000000006c801354 in R_cmpfun1 ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#71 0x000000006c8023e2 in Rf_applyClosure ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#72 0x000000006c7ffd02 in Rf_eval () from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#73 0x000000006c861026 in Rf_PrintDefaults ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#74 0x000000006c826337 in Rf_ReplIteration ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#75 0x000000006c826581 in Rf_ReplIteration ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#76 0x000000006c826612 in run_Rmainloop ()
   from C:\PROGRA~1\R\R-35~1.1\bin\x64\R.dll
#77 0x000000000040171c in ?? ()
#78 0x000000000040155a in ?? ()
#79 0x00000000004013e8 in ?? ()
#80 0x000000000040151b in ?? ()
#81 0x00000000777b59cd in KERNEL32!BaseThreadInitThunk ()
   from C:\windows\system32\kernel32.dll
#82 0x0000000077a1385d in ntdll!RtlUserThreadStart ()
   from C:\windows\SYSTEM32\ntdll.dll
#83 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

#12

Nice, at least it’s replicating. Maybe time to break out Clang’s address sanitizer or something?


#13

See the overall roadmap. We’re going to build a lightweight wrapper along the same lines as the existing PyCmdStan (which we did not build, but which we will build out), which calls CmdStan out of process. This avoids all the C++ entanglements with R and CRAN. One nice side effect is that it won’t crash sessions. On reason we want to do this that we have install problems all the time when teaching.