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

Add global memo cache and eviction API #126

Closed
nicholasjng opened this issue Mar 21, 2024 · 0 comments · Fixed by #130
Closed

Add global memo cache and eviction API #126

nicholasjng opened this issue Mar 21, 2024 · 0 comments · Fixed by #130
Assignees
Labels
enhancement New feature or request

Comments

@nicholasjng
Copy link
Collaborator

nicholasjng commented Mar 21, 2024

As per this TODO:

class Memo(Generic[T]):
@functools.cache
# TODO: Swap this out for a local type-wide memo cache.
# Could also be a decorator, should look a bit like this:
# global memo_cache, memo_cache_lock
# _tid = id(self)
# val: T
# with memocache_lock:
# if _tid in memo_cache:
# val = memo_cache[_tid]
# return val
# val = self.compute()
# memo_cache[_tid] = val
# return val
def __call__(self) -> T:
raise NotImplementedError

Steps are

1 - bring back the global cache + lock,
2 - insert values based on the id of the inserting memo,
3 - add a clear_memo_cache API, maybe factoring out everything related into a nnbench.types.memo submodule.
4 - (optional) - check if evicting the memoized value in Memo.del() does anything (debug logs!)
5 - drop functools.cache decorators everywhere (examples!)

NB: Check that the Memo.__call__() type annotation is not affected by the solution, since that breaks typechecking in benchmarks. (With a decorator, this should not be a problem.)

What would be super nice: Showcase a parametrized benchmark with a collection of large numpy array memos, checking if evicting an array after the last run of the family and triggering GC (gc.collect()) does anything. memray is (hopefully) your friend: https://bloomberg.github.io/memray/index.html
-> This needs #125.

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 a pull request may close this issue.

2 participants