Bitpath

Lesson 2 · Unit 02

Quantising by hand

Scale, zero point, rounding and the error that comes back

13 exercisesabout 3 min

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?

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.

Python
scale = 0.01
q = round(0.117 / scale)   # 12
back = q * scale           # 0.12

Concept

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) * scale

10 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.

One email when Bitpath is ready to try. Nothing else. Privacy