-
Notifications
You must be signed in to change notification settings - Fork 86
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
Adding Supply Explodes Memory Usage #36
Comments
So the most demanding part of supply-side estimation is computing the gradient. Doing so requires lots of tensor products. When markets are large, this can use a lot of memory, especially if you're using a numerical integration routine with lots of nodes. Two things I'd try out:
And thanks for your interest in the project! Let me know what you find. Maybe there's something here that I can do to reduce memory usage. |
If you look on Appendix p.2 in Conlon and Gortmaker -- you can see the problem: I bet the problematic step is the d \Delta / d \xi (where Delta is the dQ/dP matrix) calculation which is a tensor Jacobian of a (J x J) matrix with respect to a (J x J) vector. The resulting tensor has J^3 elements and 9000^3 is like 729 billion. Since it gets accumulated into a J x 1 vector at the end of the day it might be better to avoid storing the J^3 tensor and just unroll the loop. This looks like a discrete project that would benefit from some low-level optimization in case anyone is interested. |
Otherwise that tensor needs about 6TB of memory. |
Yeah, that sounds right. I think the loop (over delta/xi) would probably start with the first 3D array and end by filling the last subsequent 2D array that depends on 3D ones. Micro moments' contribution to the gradient probably suffers from the same problem, so it unfortunately might be necessarily to unroll that as well. |
Update: setting Do you guys want me to close this issue? Thanks for quick response! |
Great, thanks for confirming! If you don't mind, I'm going to keep this issue open as a reminder to work on this at some point. |
As a follow-up to this, 95404c7 re-structures how we do supply-side gradients so that we no longer need to compute a J^3 tensor. This is in the dev version of the code for now, but I'll include it in the next stable release. |
I'm facing an issue that looks similar to what's described here. I have a problem with the dimensions below and see memory usage peak at around 400GB, which happens only if I do
Thanks for your help and for your work in maintaining the package. Best, |
You have a large problem, but I'm not sure it's 400GB large. A few questions to help pinpoint the issue:
|
|
Thanks, I think the issue is with how I was adjusting Jacobians after the linear IV regression. This is only needed with covariance moments, so it makes sense that disabling those would reduce memory usage. Specifically, my approach created a I just pushed a commit that should do the calculation without ever creating a large matrix (just re-ordering matrix operations). Can you (1) Hopefully that fixes the issue. And thanks for the report! This is definitely a useful improvement for anyone doing covariance moments with a nontrivial number of observations. |
That fixed it! Thanks so much! |
I am running a fairly big problem with about 9000 product firms, absorbing a single fixed effect (with ~250 levels), with five random coefficients (price being endogenous). I can give more details in needed. Using only the demand side, I can estimate the model in Matlab and via pyBLP and get the same results (though your pyBLP is much faster). There is no memory strain on my 16gb RAM laptop. In fact I can run three or four notebooks with no problem.
Issue: I wanted to try out pyBLP's Supply Side which I have not coded in Matlab. When I did this, the memory usage exploded and the kernel died. Do you know why this could be the case? Is there anything that could be done given the problem size?
Note: I chose the log option, used the cost bounds from the BLP example, and absorbed the FEs as in the X1 matrix for demand.
Aside: thank you for all your work in developing pyBLP; I've implemented some items into my Matlab code and am looking forward to using you package in other projects going forward
Best,
Luke
The text was updated successfully, but these errors were encountered: