Tensor Size Calculator
Calculate the memory footprint of a tensor from its shape and data type.
About Tensor Size Calculator
A tensor's memory footprint is the product of all its dimensions (total element count) multiplied by the number of bytes each element occupies for the chosen data type: size_bytes = ∏(dimensions) × bytes_per_element. A (32, 512, 4096) FP16 activation tensor, for example, holds 32×512×4096 ≈ 67M elements at 2 bytes each, for roughly 134 MB. This calculation is the foundation for estimating activation memory, KV cache size, and intermediate buffer requirements when planning batch sizes and model architectures that must fit within a GPU's VRAM budget.
Formula
size_bytes = product(dimensions) × bytes_per_element
- dimensions
- Shape of the tensor (e.g. batch × seq_len × hidden)
- bytes_per_element
- Bytes per element for the data type (e.g. 2 for FP16)
Worked example
With the default values below, Tensor Size Calculator returns Tensor Size (MB) of 128.000. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Dimensions (comma-separated)
- 32, 512, 4096
- Data Typeone of FP64 (8 bytes), FP32 (4 bytes), FP16 / BF16 (2 bytes), INT8 (1 byte), INT4 (0.5 bytes)
- FP16 / BF16 (2 bytes)
Results
- Tensor Size (MB)
- 128.000 MB
- Tensor Size (GB)
- 0.125000 GB
- Total Elements
- 67,108,864
Step by step
- 1Total elements: product of all dimensions= 67,108,864
- 2Size in bytes: elements × bytes per element= 134,217,728 bytes
- 3Size in MB / GB= 128.000 MB / 0.125000 GB
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 6 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
How do I find the dimensions of a PyTorch/TensorFlow tensor?
In PyTorch, call tensor.shape or tensor.size(); in TensorFlow, call tensor.shape — either gives you the dimension list to enter here (e.g. a shape of torch.Size([32, 512, 4096]) becomes "32, 512, 4096").
Why does data type matter so much for tensor size?
Size scales linearly with bytes per element, so simply switching a tensor from FP32 (4 bytes) to FP16 (2 bytes) halves its memory footprint with no change to its shape — this is a major reason mixed-precision and quantized inference reduce memory usage.
How is this used to estimate total activation memory in a model?
Sum the tensor size across every intermediate activation tensor retained for the backward pass (or for a KV cache during inference) — this per-tensor calculation is the building block for larger memory-budgeting calculators like the VRAM Usage Calculator.
