Spooky Sale: 10% off Premium yearly · $118.80 for the first year · until Nov 6Get it

Deep-ML
Learn
Problems1,200+ hands-on ML problemsLearning PathA guided route through the fundamentalsLabsInteractive labs on real techniquesProjectsBuild a GPT, an RL agent, CUDA kernelsCollectionsCurated problem sets and videosMathPen-and-paper math for MLIntuitionInvent the idea behind the formula yourselfPlaylistsYour own problem lists, shareableStudy AssistantAn AI teacher that knows your progress
Interview Prep
Compete
ContestsFresh problem sets, ranked liveLeaderboardWhere you stand, globallyBuddiesSolve with a friend: streaks, a weekly board, chat
Discuss
Deep-Path
Premium
      Intuition
      101 of 102

      One outlier ruins it

      To fit a big model on a small chip, each weight is stored as one byte: a whole number from −127 to 127, times a scale shared by a group of group_size neighbouring weights. A weight is stored as round(weight / scale) and comes back as stored × scale. Write quantize(weights, group_size): the weights as they come back out of storage.

      Each weight is stored as a whole number from −127 to 127 times one step shared by its group, so the group’s ruler is marked every step and every weight snaps to the nearest mark. Fine, until one huge weight sets the step and the small ones snap to 0.

      A group of weights to squeeze into one byte each.four ordinary weights · step ?−0.77100.771a mark every step · 127 each side of 00.314−0.7710.120.586quantize(weights, group_size) → each weight as it comes back?
      Your functionquantize(weights, group_size)
      weightsthe numbers to storee.g. [0.314, −0.771, 0.12, 0.586, 1.904, −0.442…
      group_sizehow many neighbouring weights share one scale a weight is stored as round(weight / scale), a whole number from -127 to 127e.g. 4
      returnsthe weights rebuilt from storage (stored number * scale)
      solution.pyLoading Python
      Sign in for an AI hint
      ← Is it the math or the memory?Don’t redo the work →