ALBERT › Memory and Speed Trade-offs

Michael BrenndoerferUpdated July 19, 20253 min read
Language AI HandbookAll chapters
Part 24 of 67BERT and Variants
Chapter 174ALBERT › Memory and Speed Trade-offs
Reading section 12 of 18 · Memory and Speed Trade-offs · 3 minSection 12 of 18 · 3 min

Book contents

Section 12 of 18 · 3 min read

ALBERT › Memory and Speed Trade-offsOne section · Sections in this chapter12 / 18 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Parameter sharing reduces memory for storing weights but doesn't reduce computation. ALBERT still performs the same number of matrix multiplications as BERT. The savings come from:

  • Model storage: The saved model is smaller.
  • Gradient memory: Only one set of layer gradients needed.
  • Optimizer states: Adam's momentum and variance buffers are smaller.

However, inference speed remains similar because the same operations execute.

In[41]:
Code
def compare_memory_requirements(bert_params, albert_params):
    """Compare memory requirements for training."""

    # Assumptions: FP32 (4 bytes), Adam optimizer (2x model for momentum/variance)
    bytes_per_param = 4

    bert_model_memory = bert_params * bytes_per_param / 1e9  # GB
    albert_model_memory = albert_params * bytes_per_param / 1e9

    # Adam optimizer states
    bert_optimizer_memory = 2 * bert_model_memory
    albert_optimizer_memory = 2 * albert_model_memory

    # Gradients (same as model)
    bert_gradient_memory = bert_model_memory
    albert_gradient_memory = albert_model_memory

    return {
        "bert": {
            "model": bert_model_memory,
            "optimizer": bert_optimizer_memory,
            "gradients": bert_gradient_memory,
            "total": bert_model_memory
            + bert_optimizer_memory
            + bert_gradient_memory,
        },
        "albert": {
            "model": albert_model_memory,
            "optimizer": albert_optimizer_memory,
            "gradients": albert_gradient_memory,
            "total": albert_model_memory
            + albert_optimizer_memory
            + albert_gradient_memory,
        },
    }
Out[42]:
Console
Training Memory Requirements (FP32, Adam optimizer):
--------------------------------------------------
Component               BERT-Base  ALBERT-Base
--------------------------------------------------
Model weights              0.44 GB       0.05 GB
Optimizer states           0.88 GB       0.10 GB
Gradients                  0.44 GB       0.05 GB
--------------------------------------------------
Total (weights only)       1.76 GB       0.19 GB

Note: Activation memory (batch, sequence length) is the same for both.
Out[43]:
Visualization
Stacked bar chart comparing memory requirements for BERT and ALBERT training components.
Training memory breakdown for BERT vs ALBERT. Parameter-related memory (weights, optimizer states, gradients) scales with model size. ALBERT's smaller parameter count dramatically reduces these components, though activation memory remains unchanged.