Tensor Size Calculator
Calculate the memory footprint of a tensor from its shape (dimensions) and data type.
Inputs
e.g. "32, 512, 4096" for a (batch, sequence, hidden) tensor.
Tensor Size (MB)
128.000MB
Tensor Size (GB)
0.125000GB
Total Elements
67,108,864
Step by step
Total elements: product of all dimensions
∏ [32 × 512 × 4096]
= 67,108,864
Size in bytes: elements × bytes per element
67,108,864 × 2
= 134,217,728 bytes
Size in MB / GB
134,217,728 ÷ 1024² / 1024³
= 128.000 MB / 0.125000 GB
How it works
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)
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.