The paper fits its basic laws in the form , where is the model size or the dataset size , is the exponent and a scale. It fits on the non-embedding parameter count and leaves 1-layer models out. Write the fit, then use it on a set of runs.
Implement two functions.
fit_power_law(xs, losses): least-squares straight line of against (ordinary least squares, slope and intercept). Since , the exponent is minus the slope and . Return the tuple (alpha, x_c) with alpha rounded to 4 decimals and x_c a float rounded to 4 significant figures (float(f"{x:.4g}")). Raise ValueError if fewer than two distinct values are given.
fit_l_of_n(runs, count="non_embedding", min_layers=2): each run is a dict with keys n_layer, d_model, n_vocab, n_ctx, loss (standard shape). Its size is when count == "non_embedding", and when count == "total". Use only runs with n_layer >= min_layers, fit with fit_power_law, and return a dict:
"alpha", "N_c": as returned by the fit;"used": the number of runs used;"rms": the root-mean-square residual of the fit in (computed from the unrounded fit), rounded to 4 decimals.