Power law
Power-law prediction: log-log linear fits in the compute, one per predicted quantity.
LOSS: the loss on the (flops, loss) Pareto front, see arxiv.org/abs/2001.08361, above a fitted irreducible loss E:log10(loss - E) = slope * log10(flops) + intercept.
The LOSS and FULL fits skip the low-compute plateau of the front, if any, see
scaling_regime_start.
* COARSE: the model size on the learning-curve envelope (Chinchilla approach 1),
with n_data = flops / (6 * n_params).
* FULL: every searchable hyperparameter on the (flops, loss) Pareto front.
PowerLawCoarseInfo
dataclass
#
The model size power law fit behind a coarse prediction.
PowerLawFullFit
dataclass
#
PowerLawFullFit(
hp_fits: dict[str, LogLogPowerLawFit],
pareto_ids: list[int],
pareto_configs: list[dict[str, Any]],
pareto_flops: list[float],
pareto_losses: list[float],
fit_start: int = 0,
)
One power law per searchable HP, plus the Pareto front it was fitted on.
The HPs are fitted on the front from fit_start on, past its low-compute plateau.
PowerLawLossInfo
dataclass
#
PowerLawLossInfo(
slope: float,
intercept: float,
r_squared: float,
slope_std_err: float,
num_pareto_points: int,
predicted_loss: float,
predicted_loss_upper: float,
predicted_loss_lower: float,
irreducible_loss: float = 0.0,
)
The loss power law fit and its prediction at one compute budget.
compute_full_pareto
#
compute_full_pareto(
*,
configs: list[dict[str, Any]],
losses: list[float],
flops: list[float]
) -> tuple[
list[int],
list[dict[str, Any]],
list[float],
list[float],
]
(ids, configs, flops, losses) of the (flops, loss) Pareto front.
Source code in scalefm/prediction/power_law.py
fit_coarse
#
Fit log10(n_params) against log10(flops) on the compute optimal rows.
Source code in scalefm/prediction/power_law.py
fit_from_row
#
fit_from_row(row: ndarray) -> LogLogPowerLawFit | None
Deserialize a fit row, None for a failed fit.
Only a NaN slope/intercept means the fit failed: linregress legitimately returns
NaN r_squared/stderr (division by zero) when the fitted quantity is constant across
the Pareto front, even though slope/intercept are perfectly valid.
Source code in scalefm/prediction/power_law.py
fit_full
#
fit_full(
*,
space: SearchSpace,
configs: list[dict[str, Any]],
losses: list[float],
flops: list[float]
) -> PowerLawFullFit
Fit one power law per searchable HP on the Pareto front of the configs, past
its low-compute plateau, see scaling_regime_start.
Source code in scalefm/prediction/power_law.py
fit_hp_power_laws
#
fit_hp_power_laws(
*,
space: SearchSpace,
pareto_configs: list[dict[str, Any]],
pareto_flops: list[float]
) -> dict[str, LogLogPowerLawFit]
Fit one power law per searchable HP, independent of any target_flops.
Source code in scalefm/prediction/power_law.py
fit_loss
#
fit_loss(rows: list[Row]) -> LogLogPowerLawFit
Fit log10(loss - E) = slope * log10(flops) + intercept on the (flops, loss)
Pareto front, with the irreducible loss E (the offset of the fit) in
[0, min(loss)), see fit_power_law_with_offset.
Only the front past its low-compute plateau is fit, see scaling_regime_start.
Source code in scalefm/prediction/power_law.py
fit_to_row
#
fit_to_row(fit: LogLogPowerLawFit | None) -> list[float]
Serialize a fit to a fixed-width row; a failed fit becomes an all-NaN row.
Source code in scalefm/prediction/power_law.py
predict_coarse
#
predict_coarse(
fit: LogLogPowerLawFit, target_flop: float
) -> tuple[tuple[float, float], PowerLawCoarseInfo]
The compute optimal (n_params, n_data) the power law predicts at a budget.
Source code in scalefm/prediction/power_law.py
predict_full
#
predict_full(
fit: PowerLawFullFit,
space: SearchSpace,
target_flops: float,
) -> dict[str, Any]
The config whose HPs the per-HP power laws extrapolate to target_flops, and
in fitted_config the values of the power laws in the bounds of the space, before
they are rounded to it.
Source code in scalefm/prediction/power_law.py
predict_loss
#
predict_loss(
fit: LogLogPowerLawFit, target_flop: float
) -> tuple[float, PowerLawLossInfo]
The loss the power law predicts at target_flop.
Source code in scalefm/prediction/power_law.py
prepare_rows_for_coarse_prediction
#
prepare_rows_for_coarse_prediction(
rows: list[Row] | list[list[Row]],
) -> tuple[list[Row], list[Row]]
Rows to fit the model size on, and all rows.
Plain rows keep the lowest loss per flops value; grouped learning-curve rows become their loss envelope.
Source code in scalefm/prediction/power_law.py
smoothed_learning_curves
#
Every learning curve as _learning_curve_envelope sees it.
Returns one (n_params, flops, loss) per usable curve, interpolated on the shared log-flops grid and Gaussian smoothed, or None if the curves span no flops range. Curves with fewer than two usable points are left out.