Replies: 1 comment 6 replies
|
I think a similar idea has benn implemented already. Here's a post on this: https://modelx.io/blog/2022/03/26/running-model-while-saving-memory/ |
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
From question #157
While using a complex vectorized model, memory usage was so large that I could only use a small number of model points, which caused significant slowdowns in model runs. The advantage of vectorization is performing large-scale operations at once, but I wasn't able to take full advantage of it. According to our tests, we need to handle about 2,000 model points at a time to be competitive compared to compiled languages.
Upon investigating the cause of the high memory usage, I realized that NumPy consumes a significant amount of memory compared to the size of the cached variables. (For example, 75% of the memory is used by NumPy and 25% by cached in exported model).
Modelx's export function explicitly uses caching. Therefore, I thought that if there were a way to use gc.collect for everything except the rest of the cached information in exported, it could solve the memory issue.
Here are the ideas I propose:
When there is a very large computation like BEL, split the calculation into intermediate steps. For example, BEL_sub1.
After calculating BEL_sub1, keep the cached function in exported, and use gc.collect to free up memory for the remainings.
(Currently, it seems impossible because gc.collect can be used in export, the entire class is removed).
Perform subsequent calculations for BEL using the cached information.
If there's any way to do this currently, it would be great to know.
Even if it becomes possible later, I believe this approach could dramatically reduce memory issues.
Thanks.
All reactions