TuringLang / papers

A Bayesian zoo
15 stars 10 forks source link

Stan hmm_semisup model is broken #29

Closed mohamed82008 closed 4 years ago

mohamed82008 commented 4 years ago

I am running the benchmarks again locally and ran into the following error with the hmm_semisup benchmark.

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_41e51c1fbfa42cb7296f09ba07955a71 NOW.

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0xf3c581 -- unknown function (ip: 0000000000F3C581)
in expression starting at C:\Users\user\.julia\dev\TuringExamples\benchmarks\infer_stan.jl:42
unknown function (ip: 0000000000F3C581)
unknown function (ip: 0000000000EC1875)
unknown function (ip: 0000000000F875AB)
unknown function (ip: 0000000000EF136F)
unknown function (ip: 0000000000EFA585)
unknown function (ip: 0000000000F530FE)
unknown function (ip: 0000000000F5689A)
unknown function (ip: 0000000000E9D9AE)
unknown function (ip: 0000000000EA9F60)
PySlice_New at C:\Users\user\miniconda3\python37.dll (unknown line)
unknown function (ip: 0000000000E63143)
unknown function (ip: 0000000000E6BDE7)
PyMethodDef_RawFastCallDict at C:\Users\user\miniconda3\python37.dll (unknown line)
PyObject_FastCallDict at C:\Users\user\miniconda3\python37.dll (unknown line)
PyUnicode_RichCompare at C:\Users\user\miniconda3\python37.dll (unknown line)
PyList_Extend at C:\Users\user\miniconda3\python37.dll (unknown line)
PyBuiltin_Init at C:\Users\user\miniconda3\python37.dll (unknown line)
PyBuiltin_Init at C:\Users\user\miniconda3\python37.dll (unknown line)
PyObject_FastCallKeywords at C:\Users\user\miniconda3\python37.dll (unknown line)
PyObject_FastCallKeywords at C:\Users\user\miniconda3\python37.dll (unknown line)
PyMethodDef_RawFastCallKeywords at C:\Users\user\miniconda3\python37.dll (unknown line)
PyEval_EvalFrameDefault at C:\Users\user\miniconda3\python37.dll (unknown line)
PyMethodDef_RawFastCallKeywords at C:\Users\user\miniconda3\python37.dll (unknown line)
PyEval_EvalFrameDefault at C:\Users\user\miniconda3\python37.dll (unknown line)
PyEval_EvalCodeWithName at C:\Users\user\miniconda3\python37.dll (unknown line)
PyFunction_FastCallDict at C:\Users\user\miniconda3\python37.dll (unknown line)
PyMethodDef_RawFastCallDict at C:\Users\user\miniconda3\python37.dll (unknown line)
PyObject_Call at C:\Users\user\miniconda3\python37.dll (unknown line)
macro expansion at C:\Users\user\.julia\packages\PyCall\zqDXB\src\exception.jl:93 [inlined]
#110 at C:\Users\user\.julia\packages\PyCall\zqDXB\src\pyfncall.jl:43 [inlined]
disable_sigint at .\c.jl:446 [inlined]
__pycall! at C:\Users\user\.julia\packages\PyCall\zqDXB\src\pyfncall.jl:42 [inlined]
_pycall! at C:\Users\user\.julia\packages\PyCall\zqDXB\src\pyfncall.jl:29
_pycall! at C:\Users\user\.julia\packages\PyCall\zqDXB\src\pyfncall.jl:11
#_#117 at C:\Users\user\.julia\packages\PyCall\zqDXB\src\pyfncall.jl:86 [inlined]
Any##kw at C:\Users\user\.julia\packages\PyCall\zqDXB\src\pyfncall.jl:86
fit_stan at C:\Users\user\.julia\dev\TuringExamples\benchmarks\infer_stan.jl:31
unknown function (ip: 0000000017172259)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1692 [inlined]
do_call at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:369
eval_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:458
eval_stmt_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:409 [inlined]
eval_body at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:799
jl_interpret_toplevel_thunk at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:911
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:814
jl_parse_eval_all at /cygdrive/d/buildbot/worker/package_win64/build/src\ast.c:872
jl_load at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:872 [inlined]
jl_load_ at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:879
include at .\client.jl:439
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1692 [inlined]
do_call at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:369
eval_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:458
eval_stmt_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:409 [inlined]
eval_body at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:799
jl_interpret_toplevel_thunk at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:911
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:814
jl_parse_eval_all at /cygdrive/d/buildbot/worker/package_win64/build/src\ast.c:872
jl_load at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:872 [inlined]
jl_load_ at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:879
include at .\Base.jl:377
exec_options at .\client.jl:288
_start at .\client.jl:484
jfptr__start_2088 at C:\Users\user\AppData\Local\Programs\Julia\Julia-1.4.0\lib\julia\sys.dll (unknown line)
unknown function (ip: 00000000004017E1)
unknown function (ip: 0000000000401BD6)
unknown function (ip: 00000000004013DE)
unknown function (ip: 000000000040151A)
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 12754566 (Pool: 12752545; Big: 2021); GC: 12
ERROR: LoadError: failed process: Process(`julia 'C:\Users\user\.julia\dev\TuringExamples\benchmarks\hmm_semisup\stan.jl' --benchmark`, ProcessExited(1)) [1]

Any idea why this is happening @SteveBronder?

SteveBronder commented 4 years ago

I'm not sure, when I tried running this in julia I'm getting

julia benchmark.jl --hmm_semisup-only --stan-only
 Activating environment at `~/open_source/open_projects/misc/TuringExamples/Project.toml`
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_41e51c1fbfa42cb7296f09ba07955a71 NOW.
ERROR: LoadError: LoadError: PyError ($(Expr(:escape, :(ccall(#= /home/steve/.julia/packages/PyCall/zqDXB/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'ImportError'>
ImportError("/home/steve/packages/julias/julia-1.4-latest/bin/../lib/julia/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /tmp/tmpey1s8fp0/stanfit4anon_model_41e51c1fbfa42cb7296f09ba07955a71_6353149747872547922.cpython-37m-x86_64-linux-gnu.so)")
  File "/home/steve/.julia/conda/3/lib/python3.7/site-packages/pystan/model.py", line 355, in __init__
    self.module = load_module(self.module_name, lib_dir)
  File "/home/steve/.julia/conda/3/lib/python3.7/site-packages/pystan/model.py", line 50, in load_module
    return __import__(module_name)

But when I run this directly in python it's fine

import pystan
model_str = """
 data {
   int<lower=1> K;  // num categories
   int<lower=1> V;  // num words
   int<lower=0> T;  // num supervised items
   int<lower=1> T_unsup;  // num unsupervised items
   int<lower=1,upper=V> w[T]; // words
   int<lower=1,upper=K> z[T]; // categories
   int<lower=1,upper=V> u[T_unsup]; // unsup words
   vector<lower=0>[K] alpha;  // transit prior
   vector<lower=0>[V] beta;   // emit prior
 }
 parameters {
   simplex[K] theta[K];  // transit probs
   simplex[V] phi[K];    // emit probs
 }
 model {
   for (k in 1:K)
     theta[k] ~ dirichlet(alpha);
   for (k in 1:K)
     phi[k] ~ dirichlet(beta);
   for (t in 1:T)
     w[t] ~ categorical(phi[z[t]]);
   for (t in 2:T)
     z[t] ~ categorical(theta[z[t-1]]);

   {
     // forward algorithm computes log p(u|)
     vector[K] acc;
     real gamma[T_unsup,K];
     gamma[1,] = log(phi[,u[1]]);
     for (t in 2:T_unsup) {
       for (k in 1:K) {
         for (j in 1:K) {
           acc[j] = gamma[t-1,j] + log(theta[j,k]) + log(phi[k,u[t]]);
         }
         gamma[t,k] = log_sum_exp(acc);
       }
     }
     target += log_sum_exp(gamma[T_unsup]);
   }
 }
 """
 sm = pystan.StanModel(model_code=model_str, 
   extra_compile_args = ["-ftemplate-depth-256", "-O3",
   "-mtune=native", "-march=native", "-pipe"])

Does it work for you if you revert my PR?

mohamed82008 commented 4 years ago

Yes it works fine without the new changes from the PR.

mohamed82008 commented 4 years ago

I pushed a change back.