aai-institute / nnbench

A small framework for benchmarking machine learning models.
https://aai-institute.github.io/nnbench/
Apache License 2.0
10 stars 3 forks source link

Parameter representations instead of parameters in benchmark records #122

Closed nicholasjng closed 6 months ago

nicholasjng commented 6 months ago

TL,DR: Retaining references to parameters in benchmark records prevents garbage collection and wastes memory - how can we do better?

103 introduced saving the parameters to the records. This is fine for standard Python types, but wasteful for models and datasets which have a large memory footprint. In the worst (and unfortunately common) case, garbage collection is inhibited since the reference counts of models and data that are not needed anymore never drop to zero.

There are a few ideas here:

  1. Rolling without the parameters. This was the case until #103, but means that we have no straightforward way to find out what parameters were used in a run.
  2. Saving a unique representation of the parameters instead of the parameters. This can a no-op for standard types, and turn large models and data into a small struct (e.g. by saving file path(s), hash(es)). This requires knowing how to translate custom types into representations, and probably filtering out parameters that are too large / not trivially representable. This could also take a parameter schema.
  3. Saving some kind of stamp that uniquely represents the parameters (potentially not even bidirectional, e.g. a hash function).

I'm leaning towards 2), but if the serialization is too difficult, I prefer dropping the parameters again.

nicholasjng commented 6 months ago

Let's discuss object lifetimes here without parameters in the record, assuming no unknown outside references.

So it seems either way that the best way to get rid of parameters is to supply models by hand, and if you want to parametrize, doing it with memoization.

nicholasjng commented 6 months ago

124 contains a built-in transform for dealing with compressed parameter representations. For the current memoization approach, this is good enough, since params are still freed, and memos do not themselves hold references to their values.

Once the global cache + eviction API is in, we'll run a memory profiler on a multi-model benchmark and see what happens if we evict by hand after the completion of a model benchmark family.

TL,DR: Blocked by #125, revisit afterwards.

Maciej818 commented 6 months ago

Addressed by #124 and #120 . We close the ticket.