Neural network parameter and memory reference

LayerCal is a free, browser-based calculator for deep learning models. Drag layers onto a canvas to get parameter counts, forward-pass FLOPs and memory estimates, then export the model as runnable PyTorch, TensorFlow or JAX code. Nothing is uploaded and no account is needed. The formulas it uses are below.

Parameter count by layer type

Layer Parameters Notes
Embedding V × EVocabulary size by embedding dimension
Linear I × O + OBias term adds one per output unit
Conv2D Cin × Cout × K² + CoutIndependent of input resolution
LSTM 4(IH + H² + 2H) × L × dirFour gates, two bias vectors per gate
GRU 3(IH + H² + 2H) × L × dirThree gates, so 75 percent of an LSTM
Transformer block 12d² + 13dWhen dff equals 4d
Self-attention 4(d² + d)Query, key, value and output projections
BatchNorm, LayerNorm 2FOne scale and one shift per feature
ReLU, Softmax, Dropout, Pooling 0No learnable parameters

Memory per parameter

Mode Bytes per parameter Breakdown
Inference FP32 4Weights only
Inference FP16 or BF16 2Weights only
Inference INT8 1Quantised weights
Training with Adam 16Weights, gradients and two moment buffers, at any precision

Activation memory is excluded because it depends on batch size and input shape.

Frequently asked questions

How do you calculate the number of parameters in a neural network layer?
Each layer type has its own formula. A Linear layer has input_dim × output_dim weights plus one bias per output unit. A Conv2D layer has in_channels × out_channels × kernel_size² weights plus one bias per output channel. An Embedding layer has vocab_size × embedding_dim weights. LSTM and GRU repeat their gate formula once per layer and once per direction. Activation, dropout and pooling layers have no learnable parameters at all.
How much GPU memory does training a model need?
With the Adam optimiser, budget roughly 16 bytes per parameter. Pure FP32 training holds 4 bytes of weights, 4 of gradients and 8 across the two moment buffers. Activation memory sits on top of that and scales with batch size and input shape.
Does FP16 or BF16 halve training memory?
No, and this is the most common estimation mistake. Mixed precision halves the weights and gradients, but the optimiser still keeps an FP32 master copy of the weights next to its two moment buffers, which cancels the saving out. Adam training costs about 16 bytes per parameter whatever the weight dtype. Inference is the opposite case: there, FP16 and BF16 really do halve memory against FP32, and INT8 quarters it.
How many parameters does a transformer block have?
A standard encoder block needs 4(d² + d) for the four attention projections, 2 × d × d_ff + d_ff + d for the feed-forward network, and 4d for the two layer norms. With d_ff = 4d that collapses to 12d² + 13d, so a block with d_model 512 and d_ff 2048 has 3,152,384 parameters.
How do you count FLOPs for a forward pass?
Count each multiply-accumulate as two floating point operations. A Linear layer costs 2 × I × O, and a Conv2D layer costs 2 × Cin × Cout × K² × Hout × Wout. Attention adds a quadratic term in sequence length. Because every figure depends on input shape, LayerCal shows the shapes it assumed directly under the FLOPs number.
Is LayerCal free, and does it send my data anywhere?
It is free and open source under the MIT licence. Calculations and code generation run entirely in your browser, with no account and no backend. The AI Architecture Advisor is bring-your-own-key: the key stays in your browser and is sent only to the provider you pick, which is Google, OpenAI or Anthropic. You can switch key storage off completely under advanced settings.

Source on GitHub · MIT licence