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 integrate with the setUp and teardown injection #130

Merged
merged 5 commits into from
Mar 26, 2024

Conversation

maxmynter
Copy link
Collaborator

@maxmynter maxmynter commented Mar 25, 2024

Closes #126
Needs #127

  • Integrate Cache into setup and teardown based on state (This is to be done by the user in the setUp and tearDown hooks).

with the help of two classes. The MemoCache is not intended to be
instantiated but holds a global cache. One can interact with this
cache via classmethods.

The `Memo` class is to be used as a decorator on whatever one wants
to cache. It computes a value lazily and caches it within
`MemoCache`.

You can delete the class to empty the cache.
@nicholasjng
Copy link
Collaborator

nicholasjng commented Mar 26, 2024

Before you continue: Let's try with a bare dict with lock in nnbench.types.memo as a cache first, since all methods you implemented are class-scoped.

Likewise, getting a memo from cache should prompt a key lookup first:

# this in a decorator applied to Memo.__call__():
_sid = id(self)
if _sid in _memo_cache:
    return _memo_cache[_sid]
return self.__call__()

Also some very rough memo cache manip APIs.

This means all required parts are in place for user memory management
with memos.
@maxmynter maxmynter marked this pull request as ready for review March 26, 2024 16:17
@maxmynter maxmynter merged commit 636d18b into main Mar 26, 2024
5 checks passed
@maxmynter maxmynter deleted the memo branch March 26, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add global memo cache and eviction API
2 participants