categorical(softmax) has a memory leak

180 views
Skip to first unread message

WallSt

unread,
Dec 29, 2013, 12:50:08 PM12/29/13
to stan-...@googlegroups.com
I saw an earlier thread which suggested this is a known issue but was being corrected in Version 2.0.  However, the error still appears to be there.  When you run a model, memory usage increases until the computer runs out of memory.  I am running Windows with Stan 2.1.

I tried using categorical_logit and this clears the problem but I would like to use softmax in other settings as well.

Thanks,




Bob Carpenter

unread,
Dec 29, 2013, 2:21:40 PM12/29/13
to stan-...@googlegroups.com
Thanks for reporting. It indeed looks like there's a problem,
which is identified in the issue I just opened:

https://github.com/stan-dev/stan/issues/472

This will let me exercise my new understanding of hotfixes
in GitFlow :-)

May I thank you for reporting in the manual, and if so, what
name should I use?

- Bob

WallSt

unread,
Dec 29, 2013, 2:58:28 PM12/29/13
to stan-...@googlegroups.com
Thanks Bob,
Howard

Guido Biele

unread,
May 28, 2014, 8:29:38 AM5/28/14
to stan-...@googlegroups.com
Hello,

should the softmax memory leak be fixed in rstan 2.2.0 (on windows)?
I stell seem to have a memory leak, for softmax (as Howard already found out not for categorical_logit)

Guido

Bob Carpenter

unread,
May 28, 2014, 8:47:50 AM5/28/14
to stan-...@googlegroups.com
It should be fixed cross platform. If not, I can try to fix
again for 2.3.0 if I can reproduce the leak.

Could you send us the R model, data, and calling code that
reproduce the leaky behavior? If so, I can try to get a fix
in for 2.3.0, which should be out very soon.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Herra Huu

unread,
Jun 10, 2014, 7:43:24 AM6/10/14
to
Has this problem been fixed in version 2.3.0? If not, here is a simple example of the model with memory leak (R code including the data generation + Stan model).

Edit: fixed small typo in data generation, should not effect the results though
leaky_model_v2.R

Bob Carpenter

unread,
Jun 10, 2014, 12:13:45 PM6/10/14
to stan-...@googlegroups.com
On Jun 10, 2014, at 1:43 PM, Herra Huu <heikki.uu...@gmail.com> wrote:

> Has this problem been fixed in version 2.3.0? If not, here is a simple example of the model with memory leak (R code including the data generation + Stan model).

Thanks for the example.

I just verified that Herra Huu's model

* leaks in RStan 2.2.0 (over 4GB at 2K iterations), but

* is fine on the develop branch for CmdStan (under 5MB
at 2K iterations!).

We should make sure the RStan 2.3.0 release candidate doesn't
leak. It shouldn't --- if there was a function leak, that'd be
in the Stan C++ code that is called by both CmdStan and RStan.

- Bob

P.S. As an aside, for a real model, you almost certainly
don't want to do this:

data {
int<lower=1,upper=K> y[N_obs];
...

model {
for (n in 1:N_obs)
y ~ categorical_logit(beta);
...

which uses each of the N_obs data items N_obs times due to vectorization.
I would've expected this:

for (n in 1:N_obs)
y[n] ~ categorical_logit(beta);

Bob Carpenter

unread,
Jun 10, 2014, 12:19:31 PM6/10/14
to stan-...@googlegroups.com
Thanks. I'll look into it. I had thought it
was fixed and I don't see anything in the leak,
but maybe there's something about our operator new
override that I'm missing.

- Bob


On Jun 10, 2014, at 1:43 PM, Herra Huu <heikki.uu...@gmail.com> wrote:

> Has this problem been fixed in version 2.3.0? If not, here is a simple example of the model with memory leak (R code including the data generation + Stan model).
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <leaky_model.R>

Herra Huu

unread,
Jun 10, 2014, 12:31:33 PM6/10/14
to stan-...@googlegroups.com
Oh yes, I guess there was two typos in the model after all. I was kinda wondering why the model was so slow, but this explains it.

Btw, whats up with the multiple responses? Almost seems like there are two Bob Carpenters :) If I edit my post through Google group page, will it be send twice to your email or something like that?

Bob Carpenter

unread,
Jun 11, 2014, 6:01:32 AM6/11/14
to stan-...@googlegroups.com

On Jun 10, 2014, at 5:31 PM, Herra Huu <heikki.uu...@gmail.com> wrote:

> Oh yes, I guess there was two typos in the model after all. I was kinda wondering why the model was so slow, but this explains it.
>
> Btw, whats up with the multiple responses? Almost seems like there are two Bob Carpenters :)

Are all of my mails getting duplicated? I thought it
was just when I messed up in Apple Mail's broken "Drafts"
feature, which leaves drafts around even after you've sent
them. Sometimes I don't realize I've sent them and send them
off a second time.

> If I edit my post through Google group page, will it be send twice to your email or something like that?

No idea. The Google groups interface seems as broken as every
other interface Google's ever designed (not counting their first
minimal textbox), so I never use it directly. Don't get me started
on the Google hangouts interface --- great service, terrible interface.

- Bob

Herra Huu

unread,
Jun 11, 2014, 8:00:25 AM6/11/14
to stan-...@googlegroups.com
Your mails are not exactly duplicated, but more like two different answers to the same email/post. For example in this case, in the first email you wrote:
"I just verified that Herra Huu's model * leaks in RStan 2.2.0 (over 4GB at 2K iterations)..."

then 5 min later in the second email (replying to the same email as in the first one):
"Thanks.  I'll look into it.  I had thought it was fixed and I don't see anything in the leak, ...."

Something like that has happened before as well I think. I did edit my post once, which might have something to do with that. I guess second possibility is that you actually send the 2nd email first and so on.




keskiviikko, 11. kesäkuuta 2014 13.01.32 UTC+3 Bob Carpenter kirjoitti:

On Jun 10, 2014, at 5:31 PM, Herra Huu <heikki.uu...@gmail.com> wrote:

> Oh yes, I guess there was two typos in the model after all. I was kinda wondering why the model was so slow, but this explains it.
>
> Btw, whats up with the multiple responses? Almost seems like there are two Bob Carpenters :)

Are all of my mails getting duplicated?  I thought it
was just when I messed up in Apple Mail's broken "Drafts"
feature, which leaves drafts around even after you've sent
them.  Sometimes I don't realize I've sent them and send them
off a second time.

- Bob

Bob Carpenter

unread,
Jun 11, 2014, 11:06:34 AM6/11/14
to stan-...@googlegroups.com
That's just me being sloppy and forgetful about what I've
responded to. The usual problem is that I start responding,
then realize I have to run something, and then start a new
response and then send both of them out (the latter step being
the mistake on my part).

Anyway, there's only one of me, so I hope my responses are at
least consistent!

- Bob
Reply all
Reply to author
Forward
0 new messages