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

Investigate binding params to benchmarks with weakrefs #138

Open
nicholasjng opened this issue Mar 28, 2024 · 0 comments
Open

Investigate binding params to benchmarks with weakrefs #138

nicholasjng opened this issue Mar 28, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@nicholasjng
Copy link
Collaborator

Experimentation only (for the time being).

What happens when we bind parameters to benchmarks via weakrefs' WeakValueDicts?

Since we keep benchmarks registered in the runner class, we are potentially keeping around references to parameter structs indefinitely. This means the same memory pressure that we just solved for the parametrization case via memos.

In the end, large in-memory values should be released once a particular benchmark set is unloaded from the runner. Consider this parametrization with a large array:

@nnbench.parametrize({"a": np.zeros((1000000,))})
def mmul(a, b):
    return a @ b

If I load four of these parametrized benchmarks, I will potentially run into memory troubles.

So in the end, there are some things to investigate:

  1. Check how memory behaves when unloading a benchmark set from the runner, by calling runner.clear() at the end of a run in a loop.
  2. If the memory usage does not go down, see if it's fixed by evicting the source module from sys.modules.
  3. Check if weakrefs for the benchmark parameters (in all core decorators) help with automatic garbage collection, but also whether they introduce bugs / regressions in our current behavior (e.g. by running a current example with weakrefs).
@nicholasjng nicholasjng added the enhancement New feature or request label Mar 28, 2024
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

No branches or pull requests

2 participants