"How big is this model?" is the very first question anyone asks about a network before they even train it — does it fit in memory, is it comparable to a known baseline, how much would fine-tuning it cost. The answer is a single number: the total count of individual learnable scalar values across every weight and bias tensor.
Implement count_parameters(params), the total element count across a list of parameter arrays, and count_trainable_parameters(params, requires_grad), the same count restricted to parameters that are actually trainable (not frozen).
params: a list of NumPy arrays of any shapes.count_parameters returns the sum of every array's total element count.requires_grad: a list of booleans, one per entry in params.count_trainable_parameters returns the sum of element counts only where the matching requires_grad entry is True.params list returns 0.Open one at a time. Each gives away a little more than the last.
A NumPy array's .size attribute is exactly its total element count, regardless of how many dimensions it has.
count_trainable_parameters is count_parameters's same sum, but only over the (param, trainable) pairs where trainable is True — zip(params, requires_grad) pairs them up.
No results yet
Run your code to check it against the examples, or submit to run every test.