The scaling-laws paper measures model size as , the number of non-embedding parameters of a decoder-only Transformer, and training compute as floating-point operations. Compute both from a model's shape and its training run.
Implement kaplan_counts(n_layer, d_model, d_ff=None, d_attn=None, n_ctx=1024, n_vocab=50257, batch_tokens=524288, steps=250000):
d_ff defaults to and d_attn to (the standard shape).steps updates of batch_tokens tokens each: FLOPs, and the same in PF-days, where one PF-day is FLOPs.Return a dict:
"N", "embedding", "total" (their sum), "forward_flops_per_token", "train_flops_per_token", "C_flops": ints;"context_share": the context term's share of the forward FLOPs, rounded to 4 decimals;"context_small": True when (the paper's condition for ignoring the context term);"C_pf_days": in PF-days as a float rounded to 4 significant figures (float(f"{x:.4g}")).