Estimate Parameters and Memory for a 32-Layer Transformer
Last updated: November 29, 2026
Quick Overview
For a decoder-only transformer with hidden size 4096, 32 layers, a 4x MLP and a 50,000 token vocabulary, estimate the parameter count, the memory to serve it in 16-bit, and the memory to train it with Adam in mixed precision.
Cerebras
November 29, 20260
0
0 solved
For a decoder-only transformer with hidden size 4096, 32 layers, a 4x MLP and a 50,000 token vocabulary, estimate the parameter count, the memory to serve it in 16-bit, and the memory to train it with Adam in mixed precision.
Whether a model's weights fit in on-chip memory, or must be streamed or spread across systems, decides how it is compiled and served. This warm-up checks that you can size a model from its shape and know what training state costs beyond the weights.
What the Interviewer Expects
- Uses 4d^2 for attention projections and 8d^2 for a 4x MLP, so 12d^2 per layer
- Adds embeddings and notes tied versus untied output head
- Converts to bytes for 16-bit inference
- Uses about 16 bytes per parameter for mixed-precision Adam training
- Mentions activations and KV cache as extra memory not counted in the weights
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- How does a SwiGLU MLP with hidden size 8/3 d change the count?
- How big is the KV cache per token for this model, and with grouped-query attention?
- How much does 8-bit weight quantization save, and what does it cost?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Decoder-only, d = 4096, L = 32, MLP hidden 4d with two matrices, vocab V = 50,000, tied input and output embeddings, ignore biases and layer norm parameters (they are tiny)....
Approach
Count per-layer weights from matrix shapes, multiply by L, add embeddings, then convert to bytes for each use case....