Parameter
Parameter
The weights and biases a model learns. GPT-4 has trillions of parameters.
Parameter
The weights and biases a model learns. GPT-4 has trillions of parameters.
A parameter is the set of weight and bias values that a machine learning model learns from data during training. The model's predictive ability is determined by these parameter values, and training is the process of finding the optimal parameter values.
With the advancement of deep learning, the number of parameters in models has increased dramatically. AlexNet in 2012 had 60 million parameters, BERT in 2018 had 340 million, GPT-3 in 2020 had 175 billion, and GPT-4 in 2023 has an estimated 1.8 trillion.
Parameters are determined by the model architecture. In a Transformer-based LLM, the number of parameters is determined mainly by the embedding dimension (d_model), the number of layers (n_layers), the number of heads (n_heads), and the vocabulary size (vocab_size). It has roughly 12 * n_layers * d_model^2 parameters.
In practice, the number of parameters is a key indicator that determines a model's capacity, training time, inference cost, and required GPU memory. In general, more parameters mean better performance, but they also require more data and computing resources.
# λͺ¨λΈ νλΌλ―Έν° νμΈ λ° λΆμ
import torch
import torch.nn as nn
from transformers import AutoModel
# 1. κ°λ¨ν μ κ²½λ§ νλΌλ―Έν° μμ
class SimpleNN(nn.Module):
def __init__(self, input_dim=784, hidden_dim=256, output_dim=10):
super().__init__()
self.fc1 = nn.Linear(input_dim, hidden_dim) # κ°μ€μΉ + νΈν₯
self.fc2 = nn.Linear(hidden_dim, output_dim)
def forward(self, x):
return self.fc2(torch.relu(self.fc1(x)))
model = SimpleNN()
# νλΌλ―Έν° μ κ³μ°
def count_parameters(model):
total = sum(p.numel() for p in model.parameters())
trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)
return total, trainable
total, trainable = count_parameters(model)
print(f"Total: {total:,}, Trainable: {trainable:,}")
# μΆλ ₯: Total: 203,530, Trainable: 203,530
# fc1: 784*256 + 256 = 200,960
# fc2: 256*10 + 10 = 2,570
# 2. LLM νλΌλ―Έν° νμΈ
llm = AutoModel.from_pretrained("bert-base-uncased")
total_llm, _ = count_parameters(llm)
print(f"BERT-base parameters: {total_llm / 1e6:.1f}M")
# μΆλ ₯: BERT-base parameters: 109.5M
# 3. λ μ΄μ΄λ³ νλΌλ―Έν° λΆν¬
print("\nλ μ΄μ΄λ³ νλΌλ―Έν°:")
for name, param in model.named_parameters():
print(f" {name}: {param.shape} = {param.numel():,}")
# 4. νμ΅ κ°λ₯ μ¬λΆ μ μ΄ (νμΈνλ μ)
for param in llm.encoder.layer[:10].parameters():
param.requires_grad = False # νμ 10κ° λ μ΄μ΄ λκ²°
_, trainable_after = count_parameters(llm)
print(f"λκ²° ν νμ΅ κ°λ₯: {trainable_after/1e6:.1f}M")
As of January 2025, the number of parameters in major AI models
| Model | Parameter | Notes |
|---|---|---|
| GPT-2 | 1.5B | 2019, open source |
| BERT-large | 340M | Encoder model |
| GPT-3 | 175B | 2020, API only |
| Llama 2 | 7B / 13B / 70B | 2023, open source |
| Llama 3.1 | 8B / 70B / 405B | 2024, open source |
| GPT-4 | ~1.8T (estimated) | MoE architecture |
| Claude 3 Opus | Undisclosed | Anthropic |
| Phi-3-mini | 3.8B | Microsoft SLM |
"A 7B model needs about 2 bytes per parameter (FP16), so it requires at least 14GB of VRAM. With 4-bit quantization, it can be reduced to 3.5GB."
"A parameter is a value learned from training data, while a hyperparameter is a value set by a person before training. Learning rate and batch size are hyperparameters."
"According to the Scaling Law, the number of parameters, the amount of training data, and the compute budget determine model performance. Simply increasing the parameters alone can lead to overfitting due to insufficient data."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
A parameter is a weight determined through training, while a hyperparameter (such as the learning rate) is a value set by a person. It is a concept frequently asked about in interviews.
Phi-3 (3.8B) outperforms Llama 2 (7B) on some benchmarks. Data quality and training techniques also matter.
Choose a model size suited to the task. Fine-tuning a small model is often more efficient than prompting a large model.