-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Returning matrices from generated quantities is slow #519
Comments
For one additional piece of context, we are trying to move all of the prediction for |
Thanks for exploring further and moving. We want to make this fast because we're about to roll out some standalone generated quantities evaluation so that you can posterior draws and rerun with new generated quantities blocks. |
That functionality would be extremely useful, really excited to hear about it! |
At least a couple of copying is done in this case (see here https://github.com/stan-dev/rstan/blob/develop/rstan/rstan/inst/include/rstan/stan_fit.hpp#L535). However, this might not be the main reason it takes an unexpected time. For now, it takes quite some time to generate the names for the parameters. For example,
|
seq_array_ind loops over all the indexes (at a glance I think it does) so that would be slow. That could easily use R's 'gl' function. |
Hey @bob-carpenter and @bgoodri, do you think you could estimate how long this will take to fix? Two weeks vs two months vs. 6 months would make a big difference for us. We'd like to plan the next Prophet release and this is a big decision point for us (whether to push our prediction into generated quantities or keep it in Python/R). |
I'll work on it, but I don't know what the ultimate fix is. I suspect we
need to move to storing things in a matrix rather than a std::vector for
each margin, but that would entail a lot of change to very old code.
…On Apr 30, 2018 2:07 PM, "Sean J. Taylor" ***@***.***> wrote:
Hey @bob-carpenter <https://github.com/bob-carpenter> and @bgoodri
<https://github.com/bgoodri>, do you think you could estimate how long
this will take to fix? Two weeks vs two months vs. 6 months would make a
big difference for us. We'd like to plan the next Prophet release and this
is a big decision point for us (whether to push our prediction into
generated quantities or keep it in Python/R).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#519 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqnc3GTrUo9dhpKondcQ6_fgdN0uIks5tt1LigaJpZM4TiL9t>
.
|
That conversion shouldn't be expensive if we do it on the C++ side. Given that the CmdStan version isn't slow, the bottleneck isn't just in traversing the existing data structures.
|
For me, the bottleneck is the stack overflow.
…On Mon, Apr 30, 2018 at 8:23 PM, Bob Carpenter ***@***.***> wrote:
That conversion shouldn't be expensive if we do it on the C++ side. Given
that the CmdStan version isn't slow, the bottleneck isn't just in
traversing the existing data structures.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#519 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqtc8QAYIhUftIzUc2BqMVHLl0DpCks5tt6rtgaJpZM4TiL9t>
.
|
I will see if using the names returned from c++ code is faster. |
this helps a lot. 73f4ba7 but in the above case, it still needs 2 or 3 seconds. |
Summary:
Returning medium-sized matrices from generated quantities is extremely slow.
Description:
I originally raised this in stan-dev/stan#2516. I'm doing some computation in generated quantities in which I produce a bunch of samples from already-fitted model parameters. To do this with a point estimate, I am running
rstan::optimizing
initialized at the point estimate, and withiter=0
. This does the computation I expect, but is extremely slow if the thing being generated in generated quantities is a medium-sized matrix.The optimization finishes immediately with "Optimization terminated normally: Maximum number of iterations hit", but then there is a long delay before the command actually finishes: With a 3000x100 matrix it is a 5s delay, with a 3000x200 matrix a 10s delay, etc.
Optimizing the model below runs instantly in cmdstan, suggesting that it is an issue at the interface. It also returns very quickly in pystan.
This may be related to #464. Is there a workaround here? 3000x200 didn't seem to me like that large of a matrix to be causing 10s of I/O, especially relative to the amount of data produced by MCMC.
Reproducible Steps:
RStan Version:
2.17.3
R Version:
3.3.3
Operating System:
Debian
The text was updated successfully, but these errors were encountered: