Lesson 1 · Unit 02
Precision
Bits per weight, and what each format can represent
What you practise
- 32-bit and 16-bit floats and 8-bit and 4-bit integers, bytes per parameter, range and rounding error shown on real values
Try a question from this lesson
Pick one
A 16-bit float cannot hold 0.1 exactly. It stores the nearest value it can. What does this print?
import numpy as np
x = np.float16(0.1)
print(float(x))Correct answer
0.0999755859375
Why
The nearest 16-bit float to 0.1 is 0.0999755859375, off by about 0.00002: three good digits. For a weight that was only ever an approximation found by training, an error that small is usually harmless.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Four ways to store a weight
Models are trained with 32-bit floats. For running them, fewer bits often do.
Floats keep roughly a fixed number of significant digits. Integers are a fixed set of evenly spaced levels, and need a rule to map them onto real weights.
float32 4 bytes ~7 digits
float16 2 bytes ~3 digits
int8 1 byte 256 levels
4-bit half byte 16 levelsConcept
Where the levels sit
A float spends its bits on significant digits, so its levels crowd together near zero and spread out for large values.
An integer format has evenly spaced levels and no idea what they mean. To store a weight like 0.37 in one, you must choose a step size. That choice is quantisation.
10 more exercises in the app
- 4× type the answer
- 2× true or false
- 1× fill the blanks
- 1× multiple choice
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.