Prophet: R crashes when fitting in a loop

Created on 28 Jun 2018  Β·  32Comments  Β·  Source: facebook/prophet

Hi

When I run a loop of prophet models I get an "R session terminated" in Rstudio. The intervals are random. Either the first or the nth model crash. I read a whole number of posts for the same issue but I found no solution. I tried the:
devtools::install_github('facebookincubator/prophet', subdir='R', ref='loop_debug')
devtools::install_github('facebookincubator/prophet', subdir='R')
loading rstan and rcpp before prophet, although I could make prophet work without these besides the crash. Another thing is that the same code used to run in my stolen work laptop(i5/8G/128SSD) while my brand new work pc (i7/16G/256SSD) suffers from the crashes.
Any ideas?
Thanks
George

bug ready

Most helpful comment

Interesting, It definitely doesn't sound like RAM then. I haven't tried it in Windows or RStudio, I'll try it in Windows later today. I'm a bit surprised to see differences across platform in R, we haven't really had any windows vs. unix issues in the R version before (unlike Py). I'm pretty unsure of what is happening here but let me repro in Windows and then hopefully we can figure out how to debug further.

All 32 comments

Maybe it's related to this https://github.com/facebook/prophet/issues/285 ?

@IronistM I don't believe I have the same "symptoms". Rstudio crashes completely and restarts.

In that case, can you provide a reproducible example, so others could take a look (https://github.com/tidyverse/reprex).

@IronistM Is there any time series dataset you suggest I use? I cannot use mine because it is sensitive sales data

Probably anything from this list will suffice, built-in data. There are sales data as well.

@IronistM Many thanks!

same problem with my model
I want to forecast for 1220 iterations but prophet crashes rstudio after some iterations so now it took a day for forecasting for the whole bunch.
my next step is to forecast for 1220*180 iteration so according to this it would take 180 days to forecast the same please somebody help me out

Hi again! With this code:

library(prophet)
df=data.frame(ds=seq.Date(from=as.Date('1900-01-01'),to=as.Date('2017-12-1'),by=1),
              y=runif(as.Date('2017-12-1')-as.Date('1900-01-01')+1,1,1000))
for (i in 1:1000) {
  print(i)
  m <- prophet(df[1:(nrow(df)-1000),])
  future <- make_future_dataframe(m, periods = 30)
  forecast=predict(m,future)
}

Or with this code:

library(prophet)
df=data.frame(y=as.vector(BJsales),ds=seq.Date(from = as.Date('2017-01-01'), to=as.Date('2017-01-01')+NROW(BJsales)-1,by=1))
for (i in 1:30) {
  m <- prophet(df[1:(nrow(df)-30),])
  future <- make_future_dataframe(m, periods = 30)
  forecast=predict(m,future)
}

I do NOT have any problem.
But with the code in the R file attached I do. RStudio crashes
prophet-grid-cv.txt
@IronistM any ideas?

With this code Rstudio crashed randomly

for(j in 1:length(unique_code_train))
{
train1<- filter(train, CODE==unique_code_train[j])
train1<-arrange(train1, BILLDATE)
train1<-data.table(train1)
names(train1)<-c("ds","y") # billdate= ds , sum(saleamt)= y
m<-prophet(train1 ,changepoint.range = 1.0, seasonality.mode =
'multiplicative', holidays = holidays)
future <- make_future_dataframe(m, periods = 26)
forecast <- predict(m, future)
forecast$yhat<-as.integer(forecast$yhat)
}

prophet-grid-cv.txt crashes for me as well although this could just be because of the actual setup of the machine (propably RAM)

> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.3.3 (2017-03-06)
 os       Debian GNU/Linux 9 (stretch)
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       Europe/Athens               
 date     2018-07-09                  

─ Packages ───────────────────────────────────────────────────────────────────
 package             * version    date      
 assertthat            0.2.0      2017-04-11
 backports             1.1.2      2017-12-13
 clisymbols            1.2.0      2017-05-21
 commonmark            1.4        2017-09-01
 curl                  3.2        2018-03-28
 devtools            * 1.13.5     2018-02-18
 digest                0.6.15     2018-01-28
 evaluate              0.10.1     2017-06-24
 googleAuthR           0.6.2.9000 2018-01-23
 googleCloudStorageR   0.4.0      2017-11-17
 htmltools             0.3.6      2017-04-28
 httr                  1.3.1      2017-08-20
 jsonlite              1.5        2017-06-01
 knitr               * 1.20       2018-02-20
 magrittr              1.5        2014-11-22
 memoise               1.1.0      2017-04-21
 openssl               0.9.9      2017-11-10
 R6                    2.2.2      2017-06-17
 Rcpp                  0.12.16    2018-03-13
 rlang                 0.1.6      2017-12-21
 rmarkdown           * 1.8        2017-11-17
 roxygen2            * 6.0.1      2017-02-06
 rprojroot             1.3-2      2018-01-03
 sessioninfo           1.0.0      2017-06-21
 stringi               1.1.7      2018-03-12
 stringr               1.3.0      2018-02-19
 testthat            * 2.0.0      2017-12-13
 withr                 2.1.2      2018-03-15
 xml2                  1.1.1      2017-01-24
 yaml                  2.1.18     2018-03-08
 zip                   1.0.0      2017-04-25

and this is the machine setup (in google Cloud)

```shell
~$ cat /proc/meminfo
MemTotal: 7663652 kB
MemFree: 6721036 kB
MemAvailable: 6663024 kB
Buffers: 16992 kB
Cached: 207600 kB
SwapCached: 0 kB
Active: 725016 kB
Inactive: 144488 kB
Active(anon): 645176 kB
Inactive(anon): 83708 kB
Active(file): 79840 kB
Inactive(file): 60780 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 40 kB
Writeback: 0 kB
AnonPages: 644932 kB
Mapped: 56144 kB
Shmem: 83952 kB
Slab: 28416 kB
SReclaimable: 13364 kB
SUnreclaim: 15052 kB
KernelStack: 1760 kB
PageTables: 6876 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 3831824 kB
Committed_AS: 860652 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 325620 kB
DirectMap2M: 7538688 kB
DirectMap1G: 0 kB
~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU @ 2.50GHz
stepping : 4
microcode : 0x1
cpu MHz : 2499.998
cache size : 30720 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes xsave avx f16c rdrand hypervisor lahf_lm fsgsbase tsc_adjust smep erms xsaveopt
bugs :
bogomips : 4999.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU @ 2.50GHz
stepping : 4
microcode : 0x1
cpu MHz : 2499.998
cache size : 30720 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes xsave avx f16c rdrand hypervisor lahf_lm fsgsbase tsc_adjust smep erms xsaveopt
bugs :
bogomips : 4999.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:```

I wrote the exact equivalent in python and works just fine! Are you sure there is nothing wrong with the priority of packages or some other conflict? Have you seen #128 ?

@gkourogiorgas I believe that I'm having the exact same problem. Random crashes, but always within predict.

Here is in the system that I'm working on. I have the latest version of prophet and Rcpp. I have Rtools installed properly and can use Rcpp from the console. I'm using Rstudio 1.1.447. This also happens in Rgui and R command line.

    > sessionInfo()
    R version 3.5.0 (2018-04-23)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows Server >= 2012 x64 (build 9200)

    Matrix products: default

    locale:
    [1] C

    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     

    other attached packages:
     [1] healthcareai_2.0.0 bindrcpp_0.2.2     odbc_1.1.6         reshape2_1.4.3     rmarkdown_1.10     prophet_0.3.0.1    Rcpp_0.12.17       lubridate_1.7.4   
     [9] dbplyr_1.2.1       forcats_0.3.0      stringr_1.3.1      dplyr_0.7.5        purrr_0.2.5        readr_1.1.1        tidyr_0.8.1        tibble_1.4.2      
    [17] ggplot2_2.2.1      tidyverse_1.2.1    DBI_1.0.0         

    loaded via a namespace (and not attached):
     [1] nlme_3.1-137       bit64_0.9-7        dimRed_0.1.0       httr_1.3.1         rprojroot_1.3-2    rstan_2.17.3       tools_3.5.0        backports_1.1.2   
     [9] utf8_1.1.4         R6_2.2.2           rpart_4.1-13       lazyeval_0.2.1     colorspace_1.3-2   nnet_7.3-12        withr_2.1.2        tidyselect_0.2.4  
    [17] gridExtra_2.3      mnormt_1.5-5       bit_1.1-12         compiler_3.5.0     glmnet_2.0-16      cli_1.0.0          rvest_0.3.2        xml2_1.2.0        
    [25] scales_0.5.0       sfsmisc_1.1-2      DEoptimR_1.0-8     psych_1.8.4        robustbase_0.93-1  digest_0.6.15      StanHeaders_2.17.2 foreign_0.8-70    
    [33] pkgconfig_2.0.1    htmltools_0.3.6    rlang_0.2.1        readxl_1.1.0       ddalpha_1.3.4      MLmetrics_1.1.1    rstudioapi_0.7     bindr_0.1.1       
    [41] jsonlite_1.5       ModelMetrics_1.1.0 inline_0.3.15      magrittr_1.5       Matrix_1.2-14      munsell_0.5.0      abind_1.4-5        stringi_1.1.7     
    [49] yaml_2.1.19        MASS_7.3-49        plyr_1.8.4         recipes_0.1.3      grid_3.5.0         blob_1.1.1         pls_2.6-0          parallel_3.5.0    
    [57] crayon_1.3.4       lattice_0.20-35    cowplot_0.9.2      haven_1.1.1        splines_3.5.0      hms_0.4.2          knitr_1.20         pillar_1.2.3      
    [65] ranger_0.10.1      igraph_1.2.1       codetools_0.2-15   stats4_3.5.0       CVST_0.2-2         magic_1.5-8        glue_1.2.0         evaluate_0.10.1   
    [73] data.table_1.11.4  modelr_0.1.2       foreach_1.4.4      cellranger_1.1.0   gtable_0.2.0       kernlab_0.9-26     assertthat_0.2.0   DRR_0.0.3         
    [81] gower_0.1.2        prodlim_2018.04.18 broom_0.4.4        e1071_1.6-8        class_7.3-14       survival_2.41-3    geometry_0.3-6     timeDate_3043.102 
    [89] RcppRoll_0.3.0     kknn_1.3.1         iterators_1.0.9    lava_1.6.1         caret_6.0-80       ipred_0.9-6  

Here is the code that I'm running. It sometimes (1/5 times?) crashes Rstudio with a "session terminated" error.

    for (i in 1:length(f_names)) {
      d <- data_list[[i]]

      m <- prophet(df = d, 
                   holidays = h_daily,
                   n.changepoints = 100,
                   changepoint.prior.scale = 100)

      future <- make_future_dataframe(m, periods = 14, freq = "day")

      f <- predict(m, future)
      forecast_list[[i]] <- f
    }

Removing the loop still crashes. In each case, I get an Optimization terminated normally: Maximum number of iterations hit, may not be an optima. Then, prophet.predict will crash.

This data seems to crash predict when n.changepoints = 100 but not when it is left at the default of 25. The following code crashes on my system about 1 out of 5 times in Rstudio, more often from command line and Rgui. Holiday file.

m <- prophet(df = d, 
               holidays = h_daily,
               n.changepoints = 100,
               changepoint.prior.scale = 100)
f <- predict(m, future)

It might also help to see the fitted model params (with n.changepoints = 100)

m$params
$`k`
[1] -1.138085

$m
[1] 0.8222738

$delta
         [,1]     [,2]      [,3]      [,4]      [,5]      [,6]    [,7]     [,8]     [,9]    [,10]    [,11]     [,12]     [,13]       [,14]      [,15]     [,16]     [,17]       [,18]
[1,] 2.334568 3.494886 -1.773157 -2.081523 0.9612112 -4.969669 -3.7573 3.707501 4.571612 2.119058 1.417295 -2.978753 -2.798355 -0.05299566 -0.6926565 0.1065993 0.6083212 -0.02864444
        [,19]     [,20]     [,21]     [,22]    [,23]    [,24]  [,25]      [,26]      [,27]      [,28]     [,29]     [,30]    [,31]     [,32]      [,33]     [,34]     [,35]    [,36]
[1,] 2.009173 0.5180497 -4.176661 -2.735215 3.956182 1.037668 3.5147 -0.4260985 -0.3432206 -0.2975715 -2.718574 0.6600023 1.401722 -1.901232 -0.8088495 -2.902458 -1.248606 4.034081
        [,37]    [,38]     [,39]     [,40]    [,41]      [,42]      [,43]     [,44]    [,45]    [,46]     [,47]     [,48]    [,49]      [,50]     [,51]     [,52]     [,53]    [,54]
[1,] 4.511242 2.352525 -1.622641 -3.066312 -2.08716 -0.6718364 -0.8937765 -1.784267 3.434544 3.738103 -1.367384 -1.499655 2.421935 0.06482566 -1.218594 -5.065767 -2.515074 2.396449
        [,55]    [,56]     [,57]    [,58]    [,59]     [,60]     [,61]     [,62]     [,63]     [,64]   [,65]       [,66]      [,67]     [,68]    [,69]      [,70]      [,71]    [,72]
[1,] 6.189719 3.969027 -1.593742 -2.98556 1.189839 -2.659704 -2.484149 -0.233014 -1.194009 0.7820382 5.99631 -0.06176763 -0.4490243 -3.070607 1.717133 0.09027586 -0.2350436 2.234323
         [,73]     [,74]     [,75]    [,76]   [,77]     [,78]      [,79]    [,80]    [,81]     [,82]     [,83]     [,84]    [,85]   [,86]     [,87]     [,88]   [,89]     [,90]
[1,] -2.726454 -3.506865 -0.350494 4.243313 1.36145 -3.697612 -0.9251407 2.652391 3.567603 0.6855114 -5.030902 -1.593756 3.552675 2.82495 -2.846224 -4.221557 0.13765 0.1150848
          [,91]    [,92]    [,93]    [,94]     [,95]    [,96]     [,97]      [,98]    [,99]    [,100]
[1,] -0.7162126 1.516346 2.510509 1.045162 0.3875017 1.414051 -1.473202 0.09487695 1.828219 -3.881565

$sigma_obs
[1] 0.02355829

$beta
             [,1]        [,2]        [,3]       [,4]        [,5]      [,6]        [,7]        [,8]         [,9]         [,10]     [,11]        [,12]       [,13]         [,14]
[1,] -0.005857085 0.005101511 -0.02736722 0.00160508 0.005797819 0.0111764 0.005712171 -0.01175952 -0.005242927 -6.362081e-05 0.0043023 -0.001049901 0.001981849 -0.0006774321
            [,15]        [,16]       [,17]        [,18]       [,19]        [,20]       [,21]        [,22]       [,23]       [,24]        [,25]       [,26]        [,27]       [,28]
[1,] 0.0004352273 -0.008409914 0.001323272 -0.009778935 0.004225623 -0.007217392 -0.02352385 -0.001453518 0.001449412 0.007514585 -0.001293534 0.002865492 -0.002882684 0.001749184
           [,29]       [,30]        [,31]        [,32]       [,33]       [,34]     [,35]      [,36]       [,37]       [,38]      [,39]       [,40]       [,41]      [,42]       [,43]
[1,] 0.008481155 0.008986393 0.0007563347 -0.001433893 -0.02318635 -0.02175433 0.0161223 0.01890834 -0.04615702 -0.03494507 -0.1055527 -0.04615702 0.009048852 0.01421348 0.003094254
            [,44]      [,45]      [,46]       [,47]       [,48]       [,49]       [,50]        [,51]       [,52]     [,53]       [,54]        [,55]        [,56]       [,57]        [,58]
[1,] -0.005511655 0.01484215 0.01588147 0.001889546 0.001962408 -0.03494507 -0.03651648 -0.007343539 -0.01549923 0.0110743 0.000481688 -0.004575238 -0.004480398 -0.02614122 -0.004575238
          [,59]      [,60]      [,61]      [,62]       [,63]       [,64]      [,65]       [,66]       [,67]      [,68]       [,69]       [,70]       [,71]       [,72]       [,73]
[1,] 0.02454516 0.02269369 0.02267436 0.02816206 -0.02727419 -0.01926511 0.02110072 0.008791502 0.003763352 0.01038361 -0.03049107 -0.02066269 -0.03228359 0.003988819 -0.02809614
            [,74]      [,75]      [,76]        [,77]        [,78]       [,79]        [,80]       [,81]       [,82]       [,83]       [,84]       [,85]      [,86]       [,87]       [,88]
[1,] -0.003268488 0.01322264 0.02062054 -0.009450988 -0.009840397 -0.02565352 -0.006246221 -0.01135525 0.001896198 0.001779884 -0.01130572 0.005048998 0.01911699 -0.01489073 -0.01616953
           [,89]       [,90]        [,91]       [,92]        [,93]      [,94]       [,95]        [,96]      [,97]      [,98]      [,99]     [,100]      [,101]      [,102]      [,103]
[1,] -0.04539614 -0.01489073 -0.005734777 -0.00130059 0.0005494399 0.01679042 -0.01343054 -0.006422309 0.01548469 0.01382339 0.01166993 0.01548469 -0.02106295 0.002638766 0.004892348
          [,104]       [,105]      [,106]      [,107]      [,108]      [,109]      [,110]      [,111]     [,112]      [,113]      [,114]       [,115]      [,116]      [,117]     [,118]
[1,] 0.001562777 -0.003231096 0.003094254 -0.03076939 -0.01135525 0.008951222 0.006802886 0.002921609 0.01067793 -0.08847039 -0.02318635 -0.007915796 0.000435316 0.005393198 0.01163514
           [,119]      [,120]
[1,] -0.009789128 0.009285019

There was an bug with a memory leak that caused a crash in a loop (#73, #93) but this was fixed a while ago. Please do check with sessionInfo() that you are on the latest version of Prophet (0.3.0.1).

I do not get a crash with this loop, using the data from @mmastand:

library(prophet)

d = read.delim('data.tsv')
h_daily = read.delim('holidays_df.tsv')

d$ds = as.Date(d$ds, '%m/%d/%Y')
h_daily$ds = as.Date(h_daily$ds, '%m/%d/%Y')


for (i in 1:50) {
  print(i)

  m <- prophet(df = d, 
               holidays = h_daily,
               n.changepoints = 100,
               changepoint.prior.scale = 100)
  future <- make_future_dataframe(m, periods = 14, freq = "day")
  f <- predict(m, future)
}

If someone is able to post a reproducable example along with the data to run it that'd be really useful.

One possibility would be running out of RAM, especially if the crashes are happening during predict which is the most RAM intensive operation. Also, the output dataframe from predict can be quite large if there are a large number of dates in future, so storing all of those across a big loop could start to use a lot of RAM. If you have this issue, could you check what your RAM usage looks like?

Also, try reducing the number of samples for estimating uncertainty with prophet(df, uncertainty.samples = 10) . This significantly reduces the amount of RAM used by predict. Does it help with the crashes?

@bletham Thanks for the reply. The code from @mmastand crashes in my machine. As for the RAM thing, the same code I run in my new machine and crashes did not crash in my old machine that had lower specs. Anyway, here is my session info:

> sessioninfo::session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 os       Windows >= 8 x64            
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United Kingdom.1252 
 tz       Europe/London               
 date     2018-07-10                  

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date       source                           
 assertthat    0.2.0   2017-04-11 CRAN (R 3.4.4)                   
 bindr         0.1.1   2018-03-13 CRAN (R 3.4.4)                   
 bindrcpp      0.2.2   2018-03-29 CRAN (R 3.4.4)                   
 clisymbols    1.2.0   2017-05-21 CRAN (R 3.4.4)                   
 codetools     0.2-15  2016-10-05 CRAN (R 3.4.4)                   
 colorspace    1.3-2   2016-12-14 CRAN (R 3.4.4)                   
 dplyr         0.7.5   2018-05-19 CRAN (R 3.4.4)                   
 ggplot2       2.2.1   2016-12-30 CRAN (R 3.4.4)                   
 glue          1.2.0   2017-10-29 CRAN (R 3.4.4)                   
 gridExtra     2.3     2017-09-09 CRAN (R 3.4.4)                   
 gtable        0.2.0   2016-02-26 CRAN (R 3.4.4)                   
 inline        0.3.15  2018-05-18 CRAN (R 3.4.4)                   
 lazyeval      0.2.1   2017-10-29 CRAN (R 3.4.4)                   
 magrittr      1.5     2014-11-22 CRAN (R 3.4.4)                   
 munsell       0.5.0   2018-06-12 CRAN (R 3.4.4)                   
 pillar        1.2.3   2018-05-25 CRAN (R 3.4.4)                   
 pkgconfig     2.0.1   2017-03-21 CRAN (R 3.4.4)                   
 plyr          1.8.4   2016-06-08 CRAN (R 3.4.4)                   
 prophet     * 0.3.0.1 2018-06-28 Github (facebook/prophet@8d804fc)
 purrr         0.2.5   2018-05-29 CRAN (R 3.4.4)                   
 R6            2.2.2   2017-06-17 CRAN (R 3.4.4)                   
 Rcpp        * 0.12.17 2018-05-18 CRAN (R 3.4.4)                   
 rlang         0.2.1   2018-05-30 CRAN (R 3.4.4)                   
 rstan         2.17.3  2018-01-20 CRAN (R 3.4.4)                   
 scales        0.5.0   2017-08-24 CRAN (R 3.4.4)                   
 sessioninfo   1.0.0   2017-06-21 CRAN (R 3.4.4)                   
 StanHeaders   2.17.2  2018-01-20 CRAN (R 3.4.4)                   
 tibble        1.4.2   2018-01-22 CRAN (R 3.4.4)                   
 tidyselect    0.2.4   2018-02-26 CRAN (R 3.4.4)                   
 withr         2.1.2   2018-03-15 CRAN (R 3.4.4)                   
 yaml          2.1.19  2018-05-01 CRAN (R 3.4.4)  

I also used uncertainty.samples=10 but it still crashed

George

@bletham just to make sure, you are running on Windows? I haven't been able to reproduce on Unix-based machines. I tried with uncertainty.samples = 10 and got the same errors. It doesn't look like an available memory issue as I have 16gb and am only using 80mb. I've also notice that the failure rate is much higher when running through powershell > Rscript myTestFile.R

library(prophet)
library(tidyverse)
library(pryr)

d = read_csv('reprex_data.csv')
h_daily = read_csv('reprex_holidays.csv')

d$ds = as.Date(d$ds, '%m/%d/%Y')
h_daily$ds = as.Date(h_daily$ds, '%m/%d/%Y')

print(paste("before loop:", mem_used()/1e6))
for (i in 1:50) {
  print(paste("iteration:", i))

  m <- prophet(df = d, 
               holidays = h_daily,
               n.changepoints = 100,
               changepoint.prior.scale = 100,
               uncertainty.samples = 10)
  future <- make_future_dataframe(m, periods = 14, freq = "day")

  print(paste("after fitting:", mem_used()/1e6))
  f <- predict(m, future)

  print(paste("after predict:", mem_used()/1e6))
}

image

Interesting, It definitely doesn't sound like RAM then. I haven't tried it in Windows or RStudio, I'll try it in Windows later today. I'm a bit surprised to see differences across platform in R, we haven't really had any windows vs. unix issues in the R version before (unlike Py). I'm pretty unsure of what is happening here but let me repro in Windows and then hopefully we can figure out how to debug further.

Just to add that I am seeing the same issue: Windows 10 (16 GB RAM) , R 3.5.1, RStudio 1.1.453, prophet 0.3.0.1. I'm using purrr to map the prophet model, future df and predict df into list columns and RStudio terminates about 10 rows into a dataset of around 2000 rows. Termination occurs when the prophet() function is run.

I'm not able to replicate this in Windows, but using vanilla R and not RStudio. (R i386 3.4.1, prophet 0.3.0.1). That is, the loop above of 50 model fits finishes without error.
Since I don't have RStudio set up, if there is someone that has run into this could you try it in just vanilla R and maybe see if the issue is limited to RStudio?

I had reproduced the error from command line using Rscript as well as in Rgui.

I see you were on R 3.5.0 and @neilfws is on 3.5.1, let me upgrade and see what happens.

The cause seems to be in the latest version of rlang 0.2.1.
I have installed an old version 0.2.0 and solved it.

install.packages("https://cran.r-project.org/src/contrib/Archive/rlang/rlang_0.2.0.tar.gz", repos = NULL, type = "source")

@hoxo-m Wow, that's great, I've been trying to get to the bottom of this for the last few hours and wasn't able to identify the actual package.

I was able to reproduce the issue in R3.5.1 x64.

In R3.4.1, I initially had rlang 0.1.2 and it worked (no error). I then upgraded rlang to 0.2.1 and it crashes, so that does seem to be the root cause. Downgrading to 0.2.0 as you recommended seems to fix it again.

FYI you can install a specific version of a package with devtools:

devtools::install_version("rlang", version="0.2.0")

I did check if maybe there was just something bad with the pre-compiled package, by doing

install.packages("rlang", type="source")

but it still crashes with 0.2.1.

The root cause here is definitely beyond my knowledge of R, but I would assume must be impacting rstan also. Perhaps best is to make a repro example that just uses rstan and then raise the issue upstream.

I still don't get this issue in Linux with rlang=0.2.1 (albeit R 3.3.3), so unless @hoxo-m you are not on Windows, I think we can assume the problem is windows specific.

Hi,

devtools::install_version("rlang", version="0.2.0") fixed the issue on my Centos 7.

>sessionInfo() R version 3.5.0 (2018-04-23) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: CentOS Linux 7 (Core)

Matrix products: default BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] bindrcpp_0.2.2 foreach_1.4.4 prophet_0.3.0.1 Rcpp_0.12.18 dplyr_0.7.6 RRZ_2018.8.01.1004 [7] data.table_1.11.4

loaded via a namespace (and not attached): [1] plyr_1.8.4 pillar_1.2.3 compiler_3.5.0 bindr_0.1.1 iterators_1.0.9 tools_3.5.0 [7] digest_0.6.15 lubridate_1.7.4 memoise_1.1.0 tibble_1.4.2 gtable_0.2.0 doSNOW_1.0.16 [13] pkgconfig_2.0.1 rlang_0.2.0 parallel_3.5.0 curl_3.2 gridExtra_2.3 extraDistr_1.8.9 [19] withr_2.1.2 httr_1.3.1 stringr_1.3.1 devtools_1.13.6 stats4_3.5.0 grid_3.5.0 [25] tidyselect_0.2.4 glue_1.2.0 inline_0.3.15 R6_2.2.2 snow_0.4-2 rstan_2.17.3 [31] tidyr_0.8.1 purrr_0.2.5 ggplot2_3.0.0 magrittr_1.5 scales_0.5.0 codetools_0.2-15 [37] StanHeaders_2.17.2 assertthat_0.2.0 colorspace_1.3-2 stringi_1.2.3 lazyeval_0.2.1 munsell_0.5.0

rlang 0.2.2 (published 2018-08-16) might have fixed this issue for me (using R 3.5.1 on Ubuntu 16.04.5). The corresponding NEWS indicate

This is a maintenance release that fixes several garbage collection protection issues.

I didn't run excessive tests though.

devtools::install_version("rlang", version="0.2.0") fixed the issues on windows for me. Thanks for the work!

rlang 0.2.0 solved this issue for me as well

The latest version (rlang 0.3.0.1) seems to be working. I'm going to fix this by setting an rlang>=0.3.0.1 requirement here: https://github.com/facebook/prophet/commit/fe677f290b3cabf9090a182b28bffecbcd4f3390

The issue still came up for me in 0.3.0.1.

@jpastore001 hm, thanks for the feeback. For my test problem, I was able to get it to crash with 0.2.1 an then updated to 0.3.0.1 and it worked.
Maybe there is one of the other tidyverse packages involved also? what is your sessionInfo() when you get the crash?

The current version of dplyr requires rlang >= 0.3, so I don't pinning at 0.2.1 will be an option unfortunately.

This is fixed for me with the latest version, so I'm going to close it but please re-open if you are on v0.4 with rlang 0.3.0.1 and still have it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Earththing picture Earththing  Β·  3Comments

andrew-pollock picture andrew-pollock  Β·  3Comments

datafool picture datafool  Β·  3Comments

annabednarska picture annabednarska  Β·  3Comments

ahash52 picture ahash52  Β·  3Comments