Lesson 2 · Unit 02
Quantising by hand
Scale, zero point, rounding and the error that comes back
What you practise
- Scale and zero point, round to the grid, map back, measure the error
- One scale per tensor against one per channel
- Quantising after training against training with it, in outline
Try a question from this lesson
Pick one
You may store each weight only as a whole number from -127 to 127. The weights lie between -1.0 and 1.0. What is a sensible way to store 0.5?
Correct answer
Multiply by 127 and round, giving 64
Why
Stretch the range so that 1.0 lands on 127, then round: 0.5 × 127 = 63.5, stored as 64. To read it back, divide by 127: 0.504. Rounding 0.5 directly would leave only -1, 0 and 1 for every weight.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The scale
The scale is the real-number distance between two neighbouring integers.
To quantise, divide by the scale and round. To get the weight back, multiply by the scale. What comes back is the nearest point on the grid, never more than half a step away.
scale = 0.01
q = round(0.117 / scale) # 12
back = q * scale # 0.12Concept
Zero point and clipping
Values that are not centred on zero (say, all between 0 and 6) waste half of a symmetric grid. An offset fixes that: the zero point is the integer that stands for real 0.
Anything outside the grid is clipped to the nearest end. A clipped value loses far more than rounding error.
q = round(x / scale) + zero_point
back = (q - zero_point) * scale10 more exercises in the app
- 2× type the answer
- 2× fill the blanks
- 4× multiple choice
- 1× true or false
- 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.