Tensor Bit Width Memory Calculator – Free

Enter the number of elements and the bits per element, and this tensor memory calculator returns the packed size in bytes and MiB for any width from 1-bit masks to 64-bit floats.

How to use the Tensor memory Calculator tool

  1. Multiply the dimensions of the tensor to get its element count and type it in the Number of values field.
  2. Enter the storage width of one element, from 1 to 64, in the Bits per value field.
  3. Select Calculate. Select Example to run 1048576 values at 4 bits.
  4. Read the size in bytes on the first line and in MiB on the second, followed by the Payload, Padding and Efficiency lines.
  5. Select Copy to copy all five lines.

How tensor memory is calculated from bit width

The size of a dense tensor depends on two numbers only: how many elements it has and how many bits each one occupies. The tool multiplies them to get the payload in bits, divides by 8 and rounds up to a whole byte. It then expresses the byte count in MiB, where 1 MiB is 1,048,576 bytes.

The element count is the product of the shape. A 3 x 224 x 224 image tensor has 150,528 elements, and a batch of 32 of them has 4,816,896. The byte count is computed with exact integers, so counts of up to 24 digits do not lose precision.

Worked example: one image tensor at two precisions

Stored as float32, the 150,528 values of a 3 x 224 x 224 input take 602,112 bytes. Converted to 8-bit integers, the same tensor takes a quarter of that. Both sizes are whole bytes, so the padding is zero.

Number of values: 150528, Bits per value: 32
602,112 bytes
0.574219 MiB
Payload: 4816896 bits
Padding: 0 bits
Efficiency: 100.00%

Number of values: 150528, Bits per value: 8
150,528 bytes
0.143555 MiB
Payload: 1204224 bits
Padding: 0 bits
Efficiency: 100.00%

Bit widths of common tensor types

Use the width of the data type that the tensor is stored in. The usual values are in the list below.

One caveat: frameworks usually store a boolean tensor with one byte per element. Enter 8, not 1, unless your code packs the bits.

  • 64 bits: float64 and int64, for example index tensors in some frameworks.
  • 32 bits: float32, the default for training, and int32.
  • 16 bits: float16 and bfloat16, common for inference on GPUs.
  • 8 bits: int8 and uint8, used for quantized weights and raw image pixels.
  • 2 to 6 bits: low-bit quantized weights, which exist only in packed form.
  • 1 bit: binary masks or binarized weights when bit-packed.

What the estimate leaves out

The result is the size of the raw element data, tightly packed. It does not include the header of the tensor object, alignment padding added by an allocator, or the metadata of a file format. For widths of 8, 16, 32 and 64 bits it matches the size of the underlying array. For other widths it tells you the smallest buffer that can hold the values, which a real format may round up.

During training, memory use is several times the weight size, because gradients, optimizer state and saved activations are tensors too. Calculate each one separately and add them. The calculation itself runs locally in your browser.

Frequently asked questions

How do I calculate the memory of a tensor?

Multiply the dimensions to get the number of elements, multiply by the bits per element and divide by 8 for bytes. A 1024 x 1024 float32 matrix is 1,048,576 x 32 / 8 = 4,194,304 bytes, exactly 4 MiB.

What is the difference between MiB and MB?

A mebibyte is 1,048,576 bytes and a megabyte is 1,000,000 bytes. This tool reports MiB, with up to six decimal places. To convert to megabytes, divide the byte count on the first line by 1,000,000.

Can I enter the shape directly, like 3x224x224?

No. The Number of values field accepts a single positive whole number made of digits only. Multiply the dimensions first. Commas, spaces inside the number, decimals and scientific notation such as 1e6 are rejected.

What does the Padding line mean?

It is the number of unused bits in the final byte. Whenever the element count times the bit width is not a multiple of 8, the buffer is rounded up to a whole byte. Padding is always between 0 and 7 bits.

What is the largest bit width I can enter?

Sixty-four. Bits per value must be a whole number from 1 to 64, which covers every standard numeric type. For complex128 or other wider elements, count each element as two 64-bit values.

Related tools