Neural Network Parameter Counter

Add layers, configure their dimensions, and see the total parameter count and memory footprint update live.

πŸ”’100% Client-Side.Β Everything runs in your browser β€” no data is sent to any server.

LOAD EXAMPLE ARCHITECTURE

Layers
1
Layer type
num_emb
emb_dim
23,440,896
params
Embedding(30522, 768)
2
Layer type
embed_dim
num_heads
2,362,368
params
MultiheadAttention(embed_dim=768, num_heads=12)
3
Layer type
norm_shape
1,536
params
LayerNorm(768)
4
Layer type
in_features
out_features
bias
2,362,368
params
Linear(768, 3072, bias=True)
5
Layer type
in_features
out_features
bias
2,360,064
params
Linear(3072, 768, bias=True)
Summary
Total Parameters
30,527,232
30.5M params
Memory β€” float32
122.11 MB
4 bytes / param
Memory β€” float16 / bf16
61.05 MB
2 bytes / param
Memory β€” int8
30.53 MB
1 byte / param

Size comparison (log scale)

ResNet-50
25.6M
BERT-Base
110.0M
GPT-2 Small
117.0M
Your model
30.5M
GPT-4 (est.)
1.8T
Per-layer breakdown
#LayerParameters% of total
1Embedding(30522, 768)23,440,89676.8%
2MultiheadAttention(embed_dim=768, num_heads=12)2,362,3687.7%
3LayerNorm(768)1,5360.0%
4Linear(768, 3072, bias=True)2,362,3687.7%
5Linear(3072, 768, bias=True)2,360,0647.7%
Total30,527,232100%

How to count parameters in PyTorch

The canonical one-liner counts all learnable parameters across every layer:

import torch import torch.nn as nn model = ... # your model # Total trainable parameters total = sum(p.numel() for p in model.parameters()) print(f"Total parameters: {total:,}") # Trainable vs frozen (useful after freezing layers for fine-tuning) trainable = sum(p.numel() for p in model.parameters() if p.requires_grad) frozen = sum(p.numel() for p in model.parameters() if not p.requires_grad) print(f"Trainable: {trainable:,}") print(f"Frozen: {frozen:,}")

You can also use torchinfo for a Keras-style summary with input/output shapes per layer:

# pip install torchinfo from torchinfo import summary summary(model, input_size=(1, 3, 224, 224)) # Output: # ================================================================== # Layer (type) Output Shape Param # # ================================================================== # Conv2d-1 [1, 64, 112, 112] 9,408 # BatchNorm2d-2 [1, 64, 112, 112] 128 # ... # Total params: 25,557,032 # Trainable params: 25,557,032

Trainable vs frozen parameters

When fine-tuning a pre-trained model you often freeze the backbone and only train the head. Frozen parameters are still stored in VRAM (they are needed for the forward pass and gradients through them), but their gradient buffers are not allocated, saving roughly 8 bytes Γ— frozen_params in mixed-precision training (2 bytes weights + 2 bytes gradients + 4 bytes optimizer state).

# Freeze all parameters (e.g., backbone) for param in model.backbone.parameters(): param.requires_grad = False # Only the head is updated for param in model.head.parameters(): param.requires_grad = True

Memory formula: from parameters to GPU VRAM

Storing weights alone is just the start. During training you also need:
  • Weights: P Γ— dtype_bytes (e.g. 4 for float32, 2 for float16)
  • Gradients: same size as weights β‰ˆ P Γ— dtype_bytes
  • Optimizer state (Adam): 2 Γ— P Γ— 4 bytes (first and second moment, stored in float32)
  • Activations: depends on batch size and sequence length β€” often 2–5Γ— the weight memory
# Rule of thumb for training with Adam in float32: # VRAM β‰ˆ P Γ— 4 (weights) # + P Γ— 4 (gradients) # + P Γ— 8 (Adam m1 + m2) # = P Γ— 16 bytes β€” ignoring activations # Mixed-precision (AMP) training β€” weights in fp16, optimizer in fp32: # VRAM β‰ˆ P Γ— 2 (fp16 weights) # + P Γ— 2 (fp16 gradients) # + P Γ— 4 (fp32 master weights) # + P Γ— 8 (fp32 Adam state) # = P Γ— 16 bytes β€” same total, but faster compute # BERT-Base (110M params) in float32: params = 110_000_000 training_vram_gb = params * 16 / 1e9 print(f"~{training_vram_gb:.1f} GB for weights + optimizer β€” plus activations")

Rule of thumb: model size vs GPU VRAM

ModelParamsInference (fp16)Training (fp32 Adam)
ResNet-5025.6M~50 MB~410 MB
BERT-Base110M~220 MB~1.8 GB
GPT-2 Small117M~234 MB~1.9 GB
LLaMA-7B7B~14 GB~112 GB
LLaMA-70B70B~140 GB~1.1 TB
Training estimates include weights + gradients + Adam optimizer state. Activations depend on batch size and are not included.