853. Kaplan scaling law L(N, D)
Why it matters Scaling laws decide how big a model to train for a budget. Interviewers ask you to plug numbers in and to explain why Chinchilla later changed the answer.
Paper: "Scaling Laws for Neural Language Models", Kaplan et al., 2020, arXiv 2001.08361.
The paper fits test loss as a function of non-embedding parameters N and training tokens D:
L(N, D) = ((N_c / N) ** (alpha_N / alpha_D) + D_c / D) ** alpha_D
with the paper's fitted constants alpha_N = 0.076, alpha_D = 0.095, N_c = 8.8e13 and D_c = 5.4e13.
Write kaplan_loss(N, D). N and D are positive ints or floats, or lists of equal length. For scalars return a float; for lists return a list of floats, one per pair. Round every value to 4 decimals with round(x, 4).
def kaplan_loss(N, D)Example 1
Input: kaplan_loss(1e9, 2e10)
Output: 2.4354
Example 2
Input: N = 1e8, D = 1e12
Output: 2.8302
Example 3
Input: N = [1e7, 1e10], D = [1e9, 1e11]
Output: [3.4163, 2.0559]
Constraints
- Python 3 standard library. Code runs in your browser.
- Your code must pass all 4 tests to be accepted.
Hint 1
Write the constants once at the top.
Hint 2
The exponent on N_c / N is alpha_N / alpha_D, then the sum is raised to alpha_D.
Hint 3
Round with round(x, 4) at the end, per value.
Common mistakes
- Raising N_c / N to alpha_N directly.
- Adding the terms after raising each to alpha_D.
- Rounding before the final power.
Understand the idea
Loss falls as a power law in both N and D, and the formula adds the two bottlenecks so the worse one dominates. For N = 1e9 and D = 2e10 the parameter term (N_c / N) ** (alpha_N / alpha_D) is about 9028 and the data term D_c / D is 2700, so at that point a bigger model lowers the loss more than more data does.
Shapes and data flow
Scalars or equal-length lists.