Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator bug - matrix indexing after refactor is inefficient #2748

Closed
mitzimorris opened this issue Apr 10, 2019 · 2 comments
Closed

generator bug - matrix indexing after refactor is inefficient #2748

mitzimorris opened this issue Apr 10, 2019 · 2 comments
Assignees
Milestone

Comments

@mitzimorris
Copy link
Member

Summary:

models compiled with Stan 2.19.0 which do a lot of matrix element access are running 10x slower than same model compiled with Stan 2.18.1

see: https://discourse.mc-stan.org/t/cmdstan-slower-than-pystan/8332/11

Description:

The parser/generator code refactor went in with the 2.19 release, which is what introduced this bug. The culprit is in file src/stan/lang/generator/generate_indexed_expr.hpp.

Reproducible Steps:

See model and file referenced in discourse post.
Running compiled model with supplied data from command line using unix time command
under cmdstan 2.18.1 and cmdstan 2.19.0 shows consistent difference in time.
On a MacBook Pro w/ 2 cores, for 2.18.1 1 chain with all defaults runs in 24s, 2.19.0 takes just under 4 minutes - 240 seconds.

Current Output:

Running compiled model with supplied data from command line using unix time command
under cmdstan 2.18.1 and cmdstan 2.19.0 shows consistent difference in time.
On a MacBook Pro w/ 2 cores, for 2.18.1 1 chain with all defaults runs in 24s, 2.19.0 takes just under 4 minutes - 240 seconds.

Expected Output:

2.19.0 should run as fast or faster.

Additional Information:

Current Version:

v2.19.0

@mitzimorris
Copy link
Member Author

multiple indexing semantics described here:
https://mc-stan.org/docs/2_19/reference-manual/language-multi-indexing-section.html

further examples in test model:
https://github.com/stan-dev/stan/blob/develop/src/test/test-models/good/assignments.stan

in particular, note semantics for indexing on arrays of matrices:

matrix[5,6] m2[2,3];
matrix[5,6] m3[2,3,4];
row_vector[6] tz;
tz <- m2[1,1,1];
tz <- m3[1,1,1,1];

@mitzimorris mitzimorris self-assigned this Apr 10, 2019
@mitzimorris mitzimorris added this to the 2.19.0++ milestone Apr 10, 2019
@seantalts
Copy link
Member

I think I added the model to example-models to a new "regressions" directory and updated the performance-cmdstan-tests to make sure we run it. That job will run here: http://d1m1s1b1.stat.columbia.edu:8080/job/CmdStan%20Performance%20Tests/job/master/590/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants