fp32, bf16, int8\text{fp32},\ \text{bf16},\ \text{int8}

Data type — how each number is stored

The format each number in a tensor is stored in, which sets its size in bytes and its precision. fp32 uses 4 bytes, bf16 and fp16 use 2, int8 uses 1.

A computer cannot store an arbitrary real number, so each entry is rounded to a fixed format. Floating-point formats keep a sign, an exponent (the range) and a mantissa (the precision): fp32 is standard, while bf16 and fp16 halve the memory. Integer formats such as int8 store whole numbers plus a shared scale, the subject of section 24.2.

The memory of a tensor is its number of entries times the bytes per entry. That is why the same model can need 4, 2 or 1 byte per weight depending on its data type.

Example

50,257×768=38,597,376 numbers×4 bytes≈154 MB50{,}257 \times 768 = 38{,}597{,}376 \text{ numbers} \times 4 \text{ bytes} \approx 154 \text{ MB}

GPT-2's token embedding matrix in fp32. In bf16 it is about 77 MB.

Where the course uses it

Related terms