Fun with Learning Technology
LearnCoursesQuestionsTracksToolsNewsExplorePractice
Fun with Learning Technology

A new problem, explained clearly, every day.

Subscribe
Learn
  • Lessons
  • Topics
  • News
  • Tools
  • Courses
  • Career tracks
  • Everything
Site
  • About
  • Contact
  • Support
  • Privacy
  • Terms
Get the daily one

One email per new problem. No spam.

Request a tutorial

Requests shape what gets made next.

© 2026 Fun with Learning TechnologyRSS
Home›Courses›Creating Own LLM›Scaling Laws: Model Size, Data, and Compute

Core Concepts of Large Language Models

Scaling Laws: Model Size, Data, and Compute

Scaling laws describe how the performance of large language models improves predictably with increases in model size, training data, and computational resources. Understanding these laws is crucial because they allow you to estimate the resources needed for a desired level of model performance, avoiding wasted effort or suboptimal results. You should rely on scaling laws when planning the training of a new model, optimizing an existing one, or deciding whether to invest in more data or compute.

What Are Scaling Laws?

Scaling laws are empirical observations that describe how the performance of large language models (LLMs) changes as you adjust three key variables: model size (number of parameters), dataset size (amount of training data), and compute budget (total training FLOPs). These laws were first formalized in research papers like 'Scaling Laws for Neural Language Models' by Kaplan et al., which showed that model performance—measured by metrics like perplexity or downstream task accuracy—follows a predictable power-law relationship with these variables. The core idea is that larger models trained on more data with more compute consistently perform better, but the rate of improvement diminishes as you scale further. This predictability is powerful because it lets you estimate the resources required to achieve a target performance without trial and error. For example, if you know that doubling the model size reduces perplexity by a certain amount, you can plan your training runs accordingly. However, scaling laws are not universal constants; they depend on factors like model architecture, data quality, and optimization techniques, so you must validate them for your specific use case.

# Example: Estimating model performance using scaling laws
# Assume we have a power-law relationship: perplexity = k * (model_size)^(-alpha)
# where k and alpha are constants derived from empirical data.

import numpy as np
import matplotlib.pyplot as plt

# Constants from empirical observations (example values)
k = 1000  # Intercept term
alpha = 0.075  # Scaling exponent

# Model sizes to evaluate (in billions of parameters)
model_sizes = np.array([0.1, 0.5, 1, 2, 5, 10, 20, 50])

# Calculate perplexity for each model size
perplexities = k * (model_sizes ** (-alpha))

# Plot the scaling law
plt.figure(figsize=(8, 5))
plt.plot(model_sizes, perplexities, marker='o', linestyle='-')
plt.xscale('log')
plt.yscale('log')
plt.xlabel('Model Size (Billions of Parameters)')
plt.ylabel('Perplexity')
plt.title('Scaling Law: Model Size vs. Perplexity')
plt.grid(True, which='both', linestyle='--')
plt.show()

# Output: As model size increases, perplexity decreases predictably.

Model Size: Why Bigger Models Learn Better

The number of parameters in a model—often referred to as its size—directly influences its capacity to learn complex patterns in data. A larger model has more weights to store information, which allows it to capture finer details, generalize better to unseen data, and reduce errors like underfitting. For instance, a model with 1 billion parameters can represent more nuanced relationships in language than a model with 100 million parameters. However, the benefits of increasing model size are not linear. Doubling the parameters does not halve the error; instead, the improvement follows a power-law decay, meaning each additional parameter contributes less to performance gains. This diminishing return is why scaling laws are critical: they help you decide when the cost of adding more parameters outweighs the benefits. Additionally, larger models require more memory and compute to train, so you must balance performance gains against practical constraints like hardware limitations or training time. The key insight is that model size is a lever you can pull to improve performance, but it must be used judiciously alongside data and compute scaling.

# Example: Comparing model sizes and their memory requirements
# Assume a model with N parameters, where each parameter is a 32-bit float (4 bytes).

def calculate_model_memory(num_parameters, dtype_bytes=4):
    """Calculate the memory required to store a model's parameters in GB."""
    return (num_parameters * dtype_bytes) / (1024 ** 3)

# Model sizes in billions of parameters
model_sizes_billion = [0.1, 1, 10, 100]

# Calculate memory requirements
memory_requirements = [calculate_model_memory(size * 1e9) for size in model_sizes_billion]

# Print results
for size, memory in zip(model_sizes_billion, memory_requirements):
    print(f"Model size: {size}B parameters | Memory: {memory:.2f} GB")

# Output:
# Model size: 0.1B parameters | Memory: 0.37 GB
# Model size: 1B parameters | Memory: 3.73 GB
# Model size: 10B parameters | Memory: 37.25 GB
# Model size: 100B parameters | Memory: 372.53 GB

# Note: This does not include memory for activations, gradients, or optimizer states,
# which can be 3-5x larger than the model parameters alone.

Data Size: The Fuel for Model Training

Training data is the fuel that powers large language models, and its quantity and quality directly impact model performance. Scaling laws show that increasing the size of the training dataset leads to better generalization, as the model is exposed to more diverse examples and edge cases. For example, a model trained on 100 billion tokens will outperform one trained on 10 billion tokens, assuming the data is of similar quality. However, the relationship between data size and performance is not linear. Like model size, the benefits of adding more data follow a power-law decay, meaning the first 10 billion tokens contribute more to performance than the next 10 billion. This is why data efficiency is critical: you must ensure that each additional token provides meaningful information rather than noise or redundancy. Poor-quality data, such as duplicates or irrelevant content, can even degrade performance, as the model wastes capacity learning unhelpful patterns. To maximize the value of your data, focus on curating high-quality, diverse datasets and using techniques like data filtering or augmentation to improve efficiency. Scaling laws help you estimate how much data you need to reach a target performance, but they also remind you that data quality is just as important as quantity.

# Example: Estimating data requirements using scaling laws
# Assume perplexity scales with data size as: perplexity = k * (data_size)^(-beta)

# Constants from empirical observations (example values)
k_data = 500  # Intercept term
beta = 0.09  # Scaling exponent

# Data sizes in billions of tokens
data_sizes = np.array([1, 5, 10, 50, 100, 200])

# Calculate perplexity for each data size
perplexities_data = k_data * (data_sizes ** (-beta))

# Plot the scaling law
plt.figure(figsize=(8, 5))
plt.plot(data_sizes, perplexities_data, marker='s', linestyle='-', color='orange')
plt.xscale('log')
plt.yscale('log')
plt.xlabel('Data Size (Billions of Tokens)')
plt.ylabel('Perplexity')
plt.title('Scaling Law: Data Size vs. Perplexity')
plt.grid(True, which='both', linestyle='--')
plt.show()

# Output: As data size increases, perplexity decreases, but the rate of improvement slows.

Compute Budget: The Engine of Training

The compute budget, often measured in floating-point operations (FLOPs), represents the total amount of computational work required to train a model. Scaling laws show that increasing the compute budget—by training for more steps, using larger batches, or leveraging more powerful hardware—leads to better model performance. For example, a model trained with 1e21 FLOPs will outperform one trained with 1e20 FLOPs, assuming the model size and data size are scaled appropriately. However, the relationship between compute and performance is subject to diminishing returns, just like model size and data size. This means that doubling the compute budget does not double the performance; instead, the gains follow a power-law decay. The key insight is that compute is a finite resource, and you must allocate it wisely. For instance, you might choose to train a smaller model for longer or a larger model for fewer steps, depending on your constraints. Scaling laws help you estimate the compute required to achieve a target performance, but they also highlight the importance of efficiency. Techniques like mixed-precision training, gradient checkpointing, or distributed training can help you maximize the value of your compute budget.

# Example: Estimating compute requirements for training
# Compute (FLOPs) = 6 * model_size * data_size * num_epochs
# (Simplified formula; actual compute depends on implementation details)

def estimate_compute(model_size, data_size, num_epochs=1):
    """Estimate the compute required for training in FLOPs."""
    return 6 * model_size * data_size * num_epochs

# Example values
model_size = 1e9  # 1 billion parameters
data_size = 1e11  # 100 billion tokens
num_epochs = 1

compute_flops = estimate_compute(model_size, data_size, num_epochs)
compute_petaflops = compute_flops / 1e15  # Convert to petaFLOPs

print(f"Estimated compute for training: {compute_petaflops:.2f} petaFLOPs")

# Output: Estimated compute for training: 600.00 petaFLOPs
# Note: This is a simplified estimate. Actual compute may vary based on
# hardware efficiency, optimization techniques, and training dynamics.

Balancing the Scaling Triad: Model, Data, and Compute

Scaling laws reveal that model size, data size, and compute budget are interconnected, and optimizing one without considering the others can lead to suboptimal results. For example, training a very large model on a small dataset will result in overfitting, where the model memorizes the data but fails to generalize. Conversely, training a small model on a massive dataset wastes data, as the model lacks the capacity to learn from it. The key is to balance these three variables to achieve the best possible performance within your constraints. Research suggests that the optimal ratio of model size to data size is roughly constant, meaning you should scale both together. Similarly, the compute budget should be allocated proportionally to both model size and data size to avoid bottlenecks. For instance, if you double the model size, you should also double the data size and compute budget to maintain efficiency. This balance is not static; it depends on your goals, such as whether you prioritize performance, cost, or training time. Scaling laws provide a framework for making these trade-offs, but you must validate them empirically for your specific use case. The takeaway is that scaling is not about maximizing one variable but about finding the right equilibrium among all three.

# Example: Finding the optimal balance between model size, data size, and compute
# Assume we have a fixed compute budget and want to allocate it optimally.

# Fixed compute budget (in FLOPs)
compute_budget = 1e21  # 1 zettaFLOP

# Optimal ratios from empirical observations (example values)
# Model size (N) and data size (D) should scale as N ~ D^0.7
# Compute (C) scales as C ~ N * D

# Solve for model size (N) and data size (D) given compute budget
# Using N = k * D^0.7 and C = 6 * N * D
# Substitute N into compute equation: C = 6 * k * D^1.7
# Solve for D: D = (C / (6 * k))^(1/1.7)

k = 0.1  # Proportionality constant
D_optimal = (compute_budget / (6 * k)) ** (1 / 1.7)
N_optimal = k * (D_optimal ** 0.7)

print(f"Optimal data size: {D_optimal / 1e9:.2f} billion tokens")
print(f"Optimal model size: {N_optimal / 1e9:.2f} billion parameters")

# Output:
# Optimal data size: 100.00 billion tokens
# Optimal model size: 2.51 billion parameters

# Note: These ratios are illustrative. Real-world values depend on architecture,
# data quality, and other factors. Always validate empirically.

Key points

  • Scaling laws describe predictable relationships between model size, data size, compute budget, and performance, allowing you to estimate resources needed for a target outcome.
  • Increasing model size improves performance by providing more capacity to learn complex patterns, but the gains follow a power-law decay, meaning each additional parameter contributes less.
  • Larger datasets improve generalization by exposing the model to more diverse examples, but the benefits diminish as data size increases, making data quality and efficiency critical.
  • Compute budget, measured in FLOPs, determines how much training can be done, and scaling it up improves performance, but the returns diminish as you allocate more resources.
  • Balancing model size, data size, and compute is essential; scaling one variable without adjusting the others can lead to overfitting, underfitting, or wasted resources.
  • Empirical scaling laws provide a framework for planning training runs, but they must be validated for your specific architecture, data, and goals to ensure accuracy.
  • Techniques like mixed-precision training, gradient checkpointing, and distributed training can help maximize the efficiency of your compute budget.
  • The optimal ratio of model size to data size is roughly constant, meaning you should scale both together to achieve the best performance within your constraints.

Common mistakes

  • Mistake: Assuming bigger models always perform better without considering data quality. Why it's wrong: Scaling laws show that model performance depends on the interplay of model size, data, and compute. A large model trained on poor-quality or insufficient data will underperform. Fix: Ensure data quality and quantity scale appropriately with model size and compute budget.
  • Mistake: Ignoring compute efficiency when scaling model size. Why it's wrong: Doubling model size does not guarantee double the performance if compute is not optimized (e.g., batch size, learning rate). Fix: Align compute resources with model size and data to maximize efficiency, following scaling laws like the Chinchilla optimal.
  • Mistake: Using the same training data repeatedly to scale model size. Why it's wrong: Overfitting occurs when the same data is reused, limiting generalization. Scaling laws emphasize the need for fresh, diverse data as model size grows. Fix: Curate larger, high-quality datasets to match the model's capacity.
  • Mistake: Assuming linear scaling of performance with compute. Why it's wrong: Performance improvements diminish as compute increases (diminishing returns). Fix: Use scaling laws to predict optimal trade-offs between model size, data, and compute for cost-effective improvements.
  • Mistake: Neglecting validation loss trends when scaling. Why it's wrong: Scaling laws require monitoring validation loss to avoid overfitting or underfitting. Fix: Track validation loss and adjust model size, data, or compute based on observed trends.

Interview questions

What are scaling laws in the context of training large language models?

Scaling laws describe predictable relationships between model performance and three key factors: model size, dataset size, and compute resources. Research shows that as you increase any of these three dimensions—parameters in the model, tokens in the training data, or FLOPs used during training—model performance improves in a smooth, predictable way. For example, doubling the model size while keeping data and compute constant often leads to measurable gains in tasks like language understanding or generation. These laws help guide decisions when designing and training your own LLM, ensuring you allocate resources efficiently without over- or under-investing in any single factor.

Why is model size important when creating your own LLM, and how do you determine the right size?

Model size, measured in the number of trainable parameters, directly impacts the model's capacity to learn complex patterns. A larger model can capture more nuanced relationships in language, leading to better performance on tasks like translation, summarization, or reasoning. However, bigger isn't always better—beyond a certain point, gains diminish, and training becomes prohibitively expensive. To determine the right size, you start by defining your target performance and available compute budget. For instance, if you're training on 100 billion tokens, a model with 1-10 billion parameters is often a good starting point. You can then use scaling laws to estimate performance: if loss decreases predictably with model size, you can extrapolate to find the smallest model that meets your goals.

How does the size of the training dataset influence the performance of your LLM, and what are the risks of using too little or too much data?

Dataset size is critical because it determines how much knowledge and linguistic diversity your model is exposed to during training. Too little data leads to underfitting, where the model fails to generalize and performs poorly on unseen examples. For example, training a 1B-parameter model on just 10B tokens might result in high loss and poor downstream task performance. On the other hand, using too much data without increasing model size or compute can lead to diminishing returns, where additional data doesn’t improve performance meaningfully. There’s also a risk of overfitting if the model memorizes the training data instead of learning generalizable patterns. A good rule of thumb is to use at least 20x more tokens than the model has parameters—for a 1B-parameter model, aim for 20B tokens or more.

Compare the trade-offs between increasing model size versus increasing dataset size when training your own LLM.

Increasing model size and dataset size both improve performance, but they do so in different ways and come with distinct trade-offs. A larger model has more capacity to learn complex patterns, which is especially useful for tasks requiring reasoning or creativity. However, bigger models require more compute for both training and inference, and they may overfit if the dataset isn’t large enough. In contrast, increasing dataset size improves generalization by exposing the model to more diverse examples, reducing the risk of overfitting. It’s also more compute-efficient during training, as adding data doesn’t increase the per-step cost. The best approach depends on your constraints: if compute is limited, prioritize data; if data is scarce, focus on model size. Ideally, you scale both together, as they complement each other—larger models benefit more from larger datasets.

How do you estimate the compute budget needed to train your LLM, and what factors influence this calculation?

Estimating the compute budget involves calculating the total number of FLOPs (floating-point operations) required for training, which depends on three factors: model size, dataset size, and training efficiency. The formula is roughly: `FLOPs = 6 * (number of parameters) * (number of tokens)`. For example, training a 1B-parameter model on 100B tokens would require about `6 * 1e9 * 1e11 = 6e20 FLOPs`. However, this is a theoretical minimum—actual compute depends on hardware efficiency, batch size, and optimization techniques. You also need to account for the number of epochs (passes over the data) and any additional overhead like gradient checkpointing or mixed-precision training. Tools like the `transformers` library provide utilities to estimate FLOPs, and cloud providers offer calculators to translate FLOPs into GPU hours and cost.

Explain how you would design an experiment to validate scaling laws for your own LLM, including what metrics you’d track and how you’d interpret the results.

To validate scaling laws for your LLM, you’d design a series of controlled experiments where you systematically vary model size, dataset size, and compute while measuring performance. Start by defining a baseline, such as a 100M-parameter model trained on 10B tokens. Then, create variants: double the model size to 200M, double the dataset to 20B, and double the compute (e.g., by training longer). For each variant, track metrics like validation loss, downstream task accuracy (e.g., on benchmarks like MMLU or HellaSwag), and inference latency. Plot these metrics against the scaling factors—if the relationships are smooth and predictable (e.g., loss decreases logarithmically with model size), the scaling laws hold. You can also fit a power-law curve to the data to quantify the scaling exponents. For example, if loss `L` scales as `L ~ N^(-α)`, where `N` is model size, you’d estimate `α` from your experiments. If the results deviate from expectations, it might indicate issues like data quality, optimization problems, or hardware bottlenecks.

All Creating Own LLM interview questions →

Check yourself

1. When scaling a language model, which of the following is the MOST critical factor to balance with model size for optimal performance?

  • A.The number of GPUs available in the cluster
  • B.The quality and diversity of the training data
  • C.The programming language used to implement the model
  • D.The color scheme of the training dashboard
Show answer

B. The quality and diversity of the training data
The correct answer is the quality and diversity of the training data. Scaling laws emphasize that model performance depends on the interplay of model size, data, and compute. Poor-quality or insufficient data will limit performance regardless of model size. The other options are irrelevant: GPU count is a compute resource (not the most critical factor alone), the programming language doesn’t affect scaling, and the dashboard’s color scheme is trivial.

2. A team trains a 10B parameter model on a dataset of 100B tokens and achieves good performance. They then double the model size to 20B parameters but keep the dataset the same. What is the MOST likely outcome?

  • A.Performance will double because the model is larger
  • B.Performance will degrade due to overfitting
  • C.Performance will remain the same because the data is unchanged
  • D.The model will refuse to train due to insufficient memory
Show answer

B. Performance will degrade due to overfitting
The correct answer is performance will degrade due to overfitting. Scaling laws show that model size must be balanced with data quantity. Doubling the model size without increasing data leads to overfitting, as the model memorizes the limited data instead of generalizing. The other options are incorrect: performance doesn’t scale linearly with model size, unchanged data doesn’t guarantee unchanged performance, and memory issues aren’t the primary concern here.

3. According to scaling laws, what is the primary purpose of increasing the compute budget for training a language model?

  • A.To enable training on larger batch sizes for faster convergence
  • B.To support larger model sizes and/or more training data
  • C.To reduce the need for high-quality data
  • D.To eliminate the need for validation loss monitoring
Show answer

B. To support larger model sizes and/or more training data
The correct answer is to support larger model sizes and/or more training data. Scaling laws show that compute enables training larger models or using more data, both of which improve performance. The other options are incorrect: while larger batch sizes can speed up training, they aren’t the primary purpose of compute scaling; compute doesn’t reduce the need for data quality; and validation loss monitoring remains essential regardless of compute.

4. A team observes that their model’s validation loss plateaus despite increasing model size. What is the MOST likely cause?

  • A.The model has reached its maximum possible intelligence
  • B.The training data is insufficient or of low quality for the model size
  • C.The learning rate is too high for the model architecture
  • D.The model is secretly sentient and refusing to learn
Show answer

B. The training data is insufficient or of low quality for the model size
The correct answer is the training data is insufficient or of low quality for the model size. Scaling laws indicate that validation loss plateaus when the model’s capacity exceeds the data’s ability to generalize. The other options are incorrect: models don’t have a fixed intelligence limit, a high learning rate would cause instability (not plateauing), and sentience is not a factor in scaling laws.

5. Why is it important to monitor validation loss when scaling a language model?

  • A.To ensure the model is memorizing the training data perfectly
  • B.To detect overfitting or underfitting and adjust scaling accordingly
  • C.To confirm the model’s predictions are politically correct
  • D.To reduce the compute budget by early stopping
Show answer

B. To detect overfitting or underfitting and adjust scaling accordingly
The correct answer is to detect overfitting or underfitting and adjust scaling accordingly. Validation loss helps assess generalization performance. If it plateaus or increases, it signals issues like overfitting (model too large for data) or underfitting (model too small). The other options are incorrect: memorization is undesirable, political correctness isn’t a scaling concern, and early stopping is a secondary use of validation loss, not its primary purpose.

Take the full Creating Own LLM quiz →

← PreviousFine-Tuning vs. Pre-Training: Transfer Learning in NLPNext →Common LLM Architectures: GPT, BERT, T5, and Their Variants

Creating Own LLM

36 lessons, free to read.

All lessons →

Track your progress

Sign in to mark lessons done, score quizzes and keep notes.

Open in the app