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

Implement caching for Estimators and Transformers #845

Merged
merged 13 commits into from
Dec 13, 2023

Conversation

JulioAPeraza
Copy link
Collaborator

Closes #844.

Changes proposed in this pull request:

We are implementing caching at three levels of a meta-analysis:

  • High-level (or estimator-level): caches _fit()
  • Mid-level (or transformer-level): caches _transform()
  • Low-level (or modeled activation (ma)-level): caches _get_ma_map()

The most typical use case will be at lower levels, given that it is very common to recompute the same MA maps when working with the same database (e.g., Neurosynth).

Transformer, at the mid-level, will benefit as well from caching.

At the estimator level, caching was implemented just for the sake of completeness. We currently recommend saving the MetaResult object to a pickle file and loading it again if will be reused. This reduces the large overhead that comes from hashing a whole NiMARE database object.

@JulioAPeraza JulioAPeraza added the enhancement New feature or request label Nov 7, 2023
Copy link

codecov bot commented Nov 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (720c5c6) 89.12% compared to head (391f52e) 89.13%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #845   +/-   ##
=======================================
  Coverage   89.12%   89.13%           
=======================================
  Files          49       49           
  Lines        6142     6155   +13     
=======================================
+ Hits         5474     5486   +12     
- Misses        668      669    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JulioAPeraza
Copy link
Collaborator Author

This shows the performance at memory level 1 (caching only _fit()). With memory level 2 (caching _fit() and _transform()) the performance was the same. However, at memory level 3 (caching _fit(), _transform(), and _get_ma_map()) I saw a minimal decrease in the performance but still better than no caching.

output

@JulioAPeraza
Copy link
Collaborator Author

I tested the hierarchy inverted:

Memory level 1: caching _get_ma_map().
Memory level 2: caching _get_ma_map(), _transform().
Memory level 3: caching _get_ma_map(), _transform(), and _fit().

However, the performance at level 1 with caching was worse than no caching, probably because the computation in _get_ma_map() is not that expensive.

@JulioAPeraza JulioAPeraza marked this pull request as ready for review November 28, 2023 18:58
@JulioAPeraza JulioAPeraza requested a review from jdkent November 28, 2023 18:59
Copy link
Member

@jdkent jdkent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jdkent jdkent merged commit a1c0414 into neurostuff:main Dec 13, 2023
19 checks passed
@JulioAPeraza JulioAPeraza deleted the caching-ma-maps branch December 13, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add caching for nimare.meta algorithms
2 participants