COE 592Lecture 5.1المحاضرة 5.1Part 08الجزء 08
What K-means saves at runtime, and the road to linear quantizationماذا يوفر K-means وقت التشغيل، والطريق إلى التكميم الخطي
At inference the indexes are decoded through the codebook back to float weights, so K-means quantization saves only storage; computation and memory access stay floating point. Linear quantization stores integers and computes in integers, which is the next lecture.عند الاستدلال تُفك الفهارس عبر دفتر الترميز إلى أوزان عائمة، لذا يوفر تكميم K-means التخزين فقط؛ أما الحساب والوصول إلى الذاكرة فيبقيان بالفاصلة العائمة. التكميم الخطي يخزّن أعدادًا صحيحة ويحسب بأعداد صحيحة، وهو موضوع المحاضرة التالية.
- Conceptsالمفاهيم
- 3
- Slidesالشرائح
- 42-45
- Readingمدة القراءة
- 18 min18 دقيقة
Why this part mattersلماذا يهمّ هذا الجزء
Parts 05 to 07 made a K-means quantized model small: 2-bit indexes, a tiny codebook, Huffman coding on top, and SqueezeNet squeezed to under half a megabyte. This part asks what happens when that model actually runs. The answer is the single most examinable fact in the lecture: the model is small on disk and cheap to fetch, but every multiplication is still a full floating-point one.
That limitation is exactly what the second approach, linear quantization, fixes. Slide 43 previews it by finishing the storage and computation table from part 04, and the preview reuses the same 4 x 4 matrix, so you can compare the two methods number by number. Expect a short-answer question of the form "does K-means quantization speed up inference?" on the COE 592 midterm on Wed 28 Oct 2026, and expect the distinction between saving bytes and saving arithmetic to come back in every embedded deployment you design.
الأجزاء من 05 إلى 07 جعلت نموذج K-means المكمَّم صغيرًا: فهارس بحجم 2-bit، و codebook صغير جدًا، وترميز Huffman فوق ذلك، و SqueezeNet مضغوطًا إلى أقل من نصف ميغابايت. هذا الجزء يسأل: ماذا يحدث عندما يعمل هذا النموذج فعلًا؟ الجواب هو أكثر حقيقة قابلة للسؤال في الامتحان في هذه المحاضرة: النموذج صغير على القرص ورخيص في الجلب، لكن كل عملية ضرب ما زالت عملية فاصلة عائمة كاملة.
هذا القيد بالضبط هو ما يصلحه النهج الثاني، التكميم الخطي. تقدّم الشريحة 43 لمحة عنه بإكمال جدول التخزين والحساب من الجزء 04، وتعيد اللمحة استخدام المصفوفة نفسها 4 x 4، فتستطيع مقارنة الطريقتين رقمًا برقم. توقّع سؤالًا قصير الإجابة من نوع "هل يسرّع تكميم K-means الاستدلال؟" في اختبار منتصف الفصل لمقرر COE 592 يوم Wed 28 Oct 2026، وتوقّع أن يعود التمييز بين توفير البايتات وتوفير العمليات الحسابية في كل نظام مدمج تصممه.
By the end you canفي نهاية هذا الجزء ستستطيع
- Trace the K-means inference dataflow on slide 42 and label every edge with its data type: uint into decode, float everywhere after.تتبّع مسار البيانات أثناء الاستدلال في K-means على الشريحة 42، وسمِّ نوع البيانات على كل حافة: uint داخلًا إلى decode، و float في كل مكان بعده.
- Answer the exam question precisely: K-means quantization shrinks the model and its off-chip weight traffic, but every multiply-accumulate stays floating point.تجيب عن سؤال الامتحان بدقة: تكميم K-means يصغّر النموذج ويقلّل نقل الأوزان من الذاكرة خارج الشريحة، لكن كل عملية multiply-accumulate تبقى بالفاصلة العائمة.
- Fill in the full storage and computation table of slide 43 for floating point, K-means and linear quantization.تملأ جدول التخزين والحساب الكامل في الشريحة 43 لكل من الفاصلة العائمة و K-means والتكميم الخطي.
- Reconstruct any weight of the linear example with r = S(q - Z), S = 1.07, Z = -1, and compare its error with the K-means codebook.تعيد بناء أي وزن في المثال الخطي باستخدام r = S(q - Z) حيث S = 1.07 و Z = -1، وتقارن خطأه بخطأ الـ codebook في K-means.
- Name the real sources behind this lecture's numbers, since the slide 44 reference list belongs to the pruning lectures.تسمّي المصادر الحقيقية وراء أرقام هذه المحاضرة، لأن قائمة المراجع في الشريحة 44 تخص محاضرات التقليم (pruning).
Follow one weight of the running example through inference. The top-left weight was 2.09. In storage it is now the 2-bit index 3. When the convolution needs it, the hardware reads 3, looks up entry 3 of the Codebook, gets the FP32 value 2.00, and hands 2.00 to an ordinary floating-point multiplier, which multiplies it by an FP32 input activation. The 2-bit form existed only between the disk and the lookup.
تابع وزنًا واحدًا من المثال الجاري عبر الاستدلال. الوزن في أعلى اليسار كان 2.09. في التخزين أصبح الآن الفهرس ذا 2-bit وقيمته 3. عندما يحتاجه الالتفاف (convolution)، يقرأ العتاد 3، ويبحث عن المدخل 3 في codebook، فيحصل على القيمة 2.00 بصيغة FP32، ويسلّم 2.00 إلى ضارب عادي بالفاصلة العائمة، فيضربه في تفعيل دخل (input activation) بصيغة FP32. صيغة 2-bit لم توجد إلا بين القرص وعملية البحث.
Slide 42 draws this as a small dataflow graph. At the bottom sit the quantized weights and the float codebook. They enter a decode block on an edge labelled uint. Every edge after decode is labelled float: decoded weights and float inputs enter Conv, a float bias is added, ReLU runs, and float outputs leave. The two bullets under the figure state the consequence plainly: the weights are decompressed using a lookup table during runtime inference, and K-means-based weight quantization only saves the storage cost of the model, because all the computation and memory access are still floating point.
ترسم الشريحة 42 هذا كمخطط صغير لتدفق البيانات (dataflow). في الأسفل تجلس الأوزان المكمَّمة و الـ codebook العائم. يدخلان كتلة decode عبر حافة مكتوب عليها uint. كل حافة بعد decode مكتوب عليها float: الأوزان المفكوكة والمدخلات العائمة تدخل Conv، ثم يُضاف bias عائم، ثم يعمل ReLU، وتخرج مخرجات عائمة. النقطتان تحت الشكل تصرّحان بالنتيجة بوضوح: الأوزان يُفك ضغطها باستخدام جدول بحث (lookup table) أثناء الاستدلال وقت التشغيل، وتكميم الأوزان المبني على K-means يوفّر كلفة تخزين النموذج فقط، لأن كل الحسابات والوصول إلى الذاكرة ما زالت بالفاصلة العائمة.
Every edge of the slide 42 dataflow and its data typeكل حافة في مخطط تدفق البيانات في الشريحة 42 ونوع بياناتها
- quantized weights to decodeالأوزان المكمَّمة إلى decode
- uint: the 2-bit cluster indexes, read from storageuint: فهارس المجموعات ذات 2-bit، تُقرأ من التخزين
- codebook to decodeالـ codebook إلى decode
- float: four 32-bit centroids, read once and kept on chipfloat: أربعة مراكز بحجم 32-bit، تُقرأ مرة واحدة وتبقى على الشريحة
- decode to Conv (weights)من decode إلى Conv (الأوزان)
- float: every index is replaced by its centroid, so the Conv sees ordinary FP32 weightsfloat: كل فهرس يُستبدل بمركزه، فيرى Conv أوزانًا عادية بصيغة FP32
- inputs to Convالمدخلات إلى Conv
- float: activations are never quantized by this methodfloat: التفعيلات لا تُكمَّم أبدًا بهذه الطريقة
- Conv to +, bias to +من Conv إلى +، ومن bias إلى +
- float: the partial sums and the bias stay FP32float: المجاميع الجزئية والـ bias تبقى بصيغة FP32
- + to ReLU, ReLU to outputsمن + إلى ReLU، ومن ReLU إلى المخرجات
- float: the next layer receives FP32 activationsfloat: الطبقة التالية تستقبل تفعيلات بصيغة FP32
So what does it save? Bytes moved, not operationsإذن ماذا يوفّر؟ البايتات المنقولة، لا العمليات
"Only storage" sounds like a small win until you remember where the energy goes. EIE's Table I (Han et al., ISCA 2016, 45 nm) puts a 32-bit DRAM read at 640 pJ and an FP32 multiply at 3.7 pJ. A model whose weights live off chip spends far more energy fetching them than multiplying them. If the stored form is what crosses the DRAM bus, and the lookup happens on chip, then the indexes are what get fetched and the saving in traffic equals the saving in storage.
"التخزين فقط" تبدو مكسبًا صغيرًا حتى تتذكر أين تذهب الطاقة. الجدول I في ورقة EIE (Han et al., ISCA 2016، بتقنية 45 nm) يضع قراءة 32-bit من DRAM عند 640 pJ وعملية ضرب FP32 عند 3.7 pJ. النموذج الذي تعيش أوزانه خارج الشريحة يصرف طاقة في جلبها أكثر بكثير مما يصرفه في ضربها. فإذا كانت الصيغة المخزّنة هي ما يعبر ناقل DRAM، وكان البحث في الجدول يحدث على الشريحة، فالفهارس هي ما يُجلب، ويكون التوفير في النقل مساويًا للتوفير في التخزين.
Worked exampleمثال محلول
Energy for the 16-weight example, weights fetched from DRAM onceالطاقة في مثال الأوزان الستة عشر، مع جلب الأوزان من DRAM مرة واحدة
Dense FP32 baselineخط الأساس الكثيف بـ FP32
16 weights of 32 bit are 16 DRAM words, so 16 x 640 pJ = 10,240 pJ of fetch energy.16 وزنًا كل منها 32 bit تساوي 16 كلمة من DRAM، أي 16 x 640 pJ = 10,240 pJ من طاقة الجلب.K-means, 2-bit indexes plus codebookK-means: فهارس 2-bit مع codebook
The indexes are 16 x 2 bit = 32 bit, one word. The codebook is 4 x 32 bit, four words. That is 5 x 640 pJ = 3,200 pJ, the same 3.2x as the 64 B to 20 B storage ratio of slide 27.الفهارس 16 x 2 bit = 32 bit، أي كلمة واحدة. الـ codebook حجمه 4 x 32 bit، أي أربع كلمات. المجموع 5 x 640 pJ = 3,200 pJ، وهو نفس النسبة 3.2x في التخزين من 64 B إلى 20 B في الشريحة 27.The arithmeticالعمليات الحسابية
Both versions perform 16 FP32 multiplies and 16 FP32 adds: 16 x 3.7 + 16 x 0.9 = 73.6 pJ, unchanged. K-means also adds 16 table lookups.كلا الإصدارين ينفّذ 16 عملية ضرب FP32 و 16 عملية جمع FP32: 16 x 3.7 + 16 x 0.9 = 73.6 pJ، دون تغيير. ويضيف K-means كذلك 16 عملية بحث في الجدول.Resultالنتيجة
Fetch energy drops 3.2x here and approaches 32/N = 16x for a large layer where the codebook is negligible. MAC energy does not drop at all, and decode adds a little.تنخفض طاقة الجلب هنا بمقدار 3.2x، وتقترب من 32/N = 16x في طبقة كبيرة يصبح فيها الـ codebook مهملًا. طاقة MAC لا تنخفض إطلاقًا، ويضيف الـ decode قليلًا.
| Costالكلفة | FP32 weightsأوزان FP32 | K-means, 2-bitK-means بـ 2-bit |
|---|---|---|
| Weight words read from DRAMكلمات الأوزان المقروءة من DRAM | 16 x 32 bit = 16 words16 x 32 bit = 16 words | 1 word of indexes + 4 words of codebook = 5 wordsكلمة فهارس واحدة + 4 كلمات codebook = 5 كلمات |
| DRAM energy at 640 pJ per 32-bit readطاقة DRAM عند 640 pJ لكل قراءة 32-bit | 16 x 640 = 10,240 pJ16 x 640 = 10,240 pJ | 5 x 640 = 3,200 pJ (3.2x less)5 x 640 = 3,200 pJ (أقل بمقدار 3.2x) |
| FP32 multiplies at 3.7 pJعمليات ضرب FP32 عند 3.7 pJ | 16 x 3.7 = 59.2 pJ16 x 3.7 = 59.2 pJ | 16 x 3.7 = 59.2 pJ (unchanged)16 x 3.7 = 59.2 pJ (دون تغيير) |
| FP32 adds at 0.9 pJعمليات جمع FP32 عند 0.9 pJ | 16 x 0.9 = 14.4 pJ16 x 0.9 = 14.4 pJ | 16 x 0.9 = 14.4 pJ (unchanged)16 x 0.9 = 14.4 pJ (دون تغيير) |
| Codebook lookupsعمليات البحث في الـ codebook | noneلا شيء | 16 extra small on-chip reads16 قراءة صغيرة إضافية على الشريحة |
Read the slide's phrase "memory access is still floating point" with this in mind. The off-chip weight traffic does shrink, because indexes are fetched and decoded on chip. What stays floating point is everything the datapath touches after decode: the decoded weights fed to the multipliers, the input and output activations (which K-means never quantizes), the partial sums and the bias. Deep Compression itself notes that the forward pass has "one level of indirection" through the weight table, and that standard sparse libraries such as cuSPARSEand MKL did not support this indirect lookup, so speedups needed custom kernels or custom hardware. EIE is that hardware: it stores 4-bit indexes and expands each one through a table lookup before its arithmetic unit uses it.
اقرأ عبارة الشريحة "الوصول إلى الذاكرة ما زال بالفاصلة العائمة" وهذا في ذهنك. نقل الأوزان من خارج الشريحة يتقلّص فعلًا، لأن الفهارس هي ما يُجلب ثم تُفك على الشريحة. ما يبقى بالفاصلة العائمة هو كل ما يلمسه مسار البيانات (datapath) بعد decode: الأوزان المفكوكة التي تُغذّى إلى الضوارب، وتفعيلات الدخل والخرج (التي لا يكمّمها K-means أبدًا)، والمجاميع الجزئية، والـ bias. ورقة Deep Compression نفسها تذكر أن التمرير الأمامي فيه "مستوى واحد من الإحالة غير المباشرة" (one level of indirection) عبر جدول الأوزان، وأن مكتبات المصفوفات المتناثرة القياسية مثل cuSPARSE و MKL لم تكن تدعم هذا البحث غير المباشر، فكانت التسريعات تحتاج إلى نوى (kernels) مخصّصة أو عتاد مخصّص. و EIE هو ذلك العتاد: يخزّن فهارس 4-bit ويوسّع كل واحد منها عبر بحث في جدول قبل أن تستخدمه وحدته الحسابية.
Recall
List the data type on each edge of the slide 42 dataflow, from storage to output.اذكر نوع البيانات على كل حافة في مخطط تدفق البيانات في الشريحة 42، من التخزين حتى الخرج.
Recall
Why can't the hardware multiply directly with the 2-bit K-means indexes?لماذا لا يستطيع العتاد الضرب مباشرة بفهارس K-means ذات 2-bit؟
Quick checkاختبار سريع
A 2-bit K-means quantized convolution runs on a phone CPU. Which cost does the quantization actually reduce?التفاف مكمَّم بـ K-means بحجم 2-bit يعمل على معالج هاتف. أي كلفة يقلّلها التكميم فعلًا؟
Take the stored integer 1 from the top-left of slide 43's third matrix. Subtract -1, giving 2. Multiply by 1.07, giving 2.14. The original weight was 2.09. Now take the integer -2 just to its right: -2 - (-1) = -1, times 1.07 is -1.07, against an original -0.98. No table was consulted. The value came out of one subtraction and one multiplication, the same rule for every weight.
خذ العدد الصحيح المخزَّن 1 من أعلى يسار المصفوفة الثالثة في الشريحة 43. اطرح منه -1 فتحصل على 2. اضرب في 1.07 فتحصل على 2.14. الوزن الأصلي كان 2.09. الآن خذ العدد الصحيح -2 الذي على يمينه مباشرة: -2 - (-1) = -1، مضروبًا في 1.07 يساوي -1.07، مقابل قيمة أصلية -0.98. لم نستشر أي جدول. القيمة خرجت من عملية طرح واحدة وعملية ضرب واحدة، بالقاعدة نفسها لكل وزن.
That rule is Linear quantization, the second column of approaches from part 04. It is an affine map from integers to reals with two parameters, a scale S and a zero point Z:
تلك القاعدة هي linear quantization (التكميم الخطي)، العمود الثاني من النُّهج في الجزء 04. إنها تحويل تآلفي (affine) من الأعداد الصحيحة إلى الأعداد الحقيقية بمعاملين: مقياس (scale) S ونقطة صفر (zero point) Z:
With 2-bit signed integers (Two's complement, range -2 to 1) the four possible values are evenly spaced, one scale step apart. Here is the whole decode table for the example.
مع أعداد صحيحة بإشارة بحجم 2-bit (two's complement، المدى من -2 إلى 1) تكون القيم الأربع الممكنة متساوية التباعد، تفصل بين كل اثنتين خطوة مقياس واحدة. هذا جدول الفك الكامل للمثال.
| Stored qq المخزَّنة | q - Zq - Z | r = 1.07 (q - Z)r = 1.07 (q - Z) | Original weights mapped hereالأوزان الأصلية التي تُربط هنا |
|---|---|---|---|
| -2-2 | -2 - (-1) = -1-2 - (-1) = -1 | -1 x 1.07 = -1.07-1 x 1.07 = -1.07 | -0.98, -1.08, -0.91, -1.03-0.98, -1.08, -0.91, -1.03 |
| -1-1 | -1 - (-1) = 0-1 - (-1) = 0 | 0 x 1.07 = 00 x 1.07 = 0 | 0.09, 0.05, -0.14, 0, 00.09, 0.05, -0.14, 0, 0 |
| 00 | 0 - (-1) = 10 - (-1) = 1 | 1 x 1.07 = 1.071 x 1.07 = 1.07 | 1.48, 1.53, 1.491.48, 1.53, 1.49 |
| 11 | 1 - (-1) = 21 - (-1) = 2 | 2 x 1.07 = 2.142 x 1.07 = 2.14 | 2.09, 2.12, 1.92, 1.872.09, 2.12, 1.92, 1.87 |
Notice the colours on slide 43: the integer matrix uses the same four colour groups as the K-means clustering, and the integers are simply the K-means indexes shifted down by two (index 3 becomes 1, index 0 becomes -2). The grouping is the same; what changed is the meaning of the integer. In K-means it pointed into a table; here it is a number on a scaled number line. This is the Fixed-point number idea from part 01 generalised: a fixed-point value is an integer times a power-of-two scale, and a linearly quantized value is an offset integer times an arbitrary real scale.
لاحظ الألوان في الشريحة 43: مصفوفة الأعداد الصحيحة تستخدم مجموعات الألوان الأربع نفسها التي في تجميع K-means، والأعداد الصحيحة هي ببساطة فهارس K-means مُزاحة للأسفل بمقدار اثنين (الفهرس 3 يصبح 1، والفهرس 0 يصبح -2). التجميع هو نفسه؛ ما تغيّر هو معنى العدد الصحيح. في K-means كان يشير إلى مدخل في جدول؛ هنا هو عدد على خط أعداد مُقاس. هذه فكرة fixed point (الفاصلة الثابتة) من الجزء 01 بصورة معمّمة: القيمة ذات الفاصلة الثابتة هي عدد صحيح مضروب في مقياس من قوى العدد اثنين، والقيمة المكمَّمة خطيًا هي عدد صحيح مُزاح مضروب في مقياس حقيقي اعتباطي.
Why that buys integer arithmeticلماذا يمنحنا ذلك حسابًا بالأعداد الصحيحة
Because the map is affine, a dot product of quantized weights and quantized activations factors cleanly. Every term inside the sum is a product of small integers, so the multiply-accumulate loop runs entirely on integer hardware, and the real-valued scales are applied once per output, not once per weight. This is the scheme Jacob et al. built for integer-arithmetic-only inference on mobile CPUs, and lecture 05-2 derives it in full, including where S and Z come from.
لأن التحويل تآلفي، فإن الضرب النقطي (dot product) بين الأوزان المكمَّمة والتفعيلات المكمَّمة يتحلّل بشكل نظيف. كل حد داخل المجموع هو حاصل ضرب أعداد صحيحة صغيرة، فتعمل حلقة multiply-accumulate بالكامل على عتاد الأعداد الصحيحة، وتُطبَّق المقاييس الحقيقية مرة واحدة لكل خرج، وليس مرة لكل وزن. هذا هو المخطط الذي بناه Jacob et al. للاستدلال بالأعداد الصحيحة فقط على معالجات الهواتف، والمحاضرة 05-2 تشتقّه بالكامل، بما في ذلك من أين تأتي S و Z.
What it costs: a uniform grid fits this matrix worseما كلفته: الشبكة المنتظمة تلائم هذه المصفوفة بشكل أسوأ
K-means places its four values where the weights cluster: -1.00, 0.00, 1.50, 2.00. The linear grid must be evenly spaced: -1.07, 0, 1.07, 2.14. The cluster around 1.5 falls in the gap between 1.07 and 2.14 and rounds down, so 1.53 is stored as 1.07, a Quantization error of 0.46 where K-means made only 0.03.
يضع K-means قيمه الأربع حيث تتجمّع الأوزان: -1.00, 0.00, 1.50, 2.00. أما الشبكة الخطية فيجب أن تكون متساوية التباعد: -1.07, 0, 1.07, 2.14. المجموعة حول 1.5 تقع في الفجوة بين 1.07 و 2.14 وتُقرَّب للأسفل، فتُخزَّن 1.53 على أنها 1.07، أي quantization error (خطأ تكميم) قدره 0.46 حيث لم يتجاوز خطأ K-means القيمة 0.03.
| Originalالأصلي | K-means centroidمركز K-means | Linear S(q - Z)الخطي S(q - Z) |
|---|---|---|
| 2.092.09 | 2.00 (error 0.09)2.00 (الخطأ 0.09) | 2.14 (error -0.05)2.14 (الخطأ -0.05) |
| 1.871.87 | 2.00 (error -0.13)2.00 (الخطأ -0.13) | 2.14 (error -0.27)2.14 (الخطأ -0.27) |
| 1.481.48 | 1.50 (error -0.02)1.50 (الخطأ -0.02) | 1.07 (error 0.41)1.07 (الخطأ 0.41) |
| 1.531.53 | 1.50 (error 0.03)1.50 (الخطأ 0.03) | 1.07 (error 0.46)1.07 (الخطأ 0.46) |
| -0.91-0.91 | -1.00 (error 0.09)-1.00 (الخطأ 0.09) | -1.07 (error 0.16)-1.07 (الخطأ 0.16) |
| All 16 weights, mean squared errorمتوسط مربع الخطأ لكل الأوزان الستة عشر | about 0.006نحو 0.006 | about 0.047نحو 0.047 |
This is the trade the whole quantization field lives on. Learned, non-uniform levels fit the weights better, but they cannot be computed with directly; the Gholami et al. survey notes that non-uniform schemes are typically hard to deploy efficiently on general hardware, which is why uniform quantization is the de facto choice. Uniform levels waste some precision, but in exchange both storage and arithmetic become integer. In practice 8-bit linear quantization has so many levels that the grid is fine enough for most layers; the 2-bit example here exaggerates the error to make the shape of the grid visible.
هذه هي المقايضة التي يقوم عليها مجال التكميم كله. المستويات المتعلَّمة غير المنتظمة تلائم الأوزان أفضل، لكن لا يمكن الحساب بها مباشرة؛ ويذكر مسح Gholami et al. أن المخططات غير المنتظمة يصعب عادةً نشرها بكفاءة على العتاد العام، ولهذا يكون التكميم المنتظم هو الخيار الفعلي السائد. المستويات المنتظمة تهدر بعض الدقة، لكن في المقابل يصبح التخزين والحساب كلاهما بالأعداد الصحيحة. عمليًا، التكميم الخطي بـ 8-bit فيه مستويات كثيرة بما يكفي لتكون الشبكة دقيقة بما يكفي لمعظم الطبقات؛ ومثال 2-bit هنا يضخّم الخطأ ليجعل شكل الشبكة مرئيًا.
| Floating pointالفاصلة العائمة | K-means-basedمبني على K-means | Linearخطي | |
|---|---|---|---|
| Storageالتخزين | Floating-point weightsأوزان بالفاصلة العائمة | Integer weights; floating-point codebookأوزان صحيحة؛ codebook بالفاصلة العائمة | Integer weightsأوزان صحيحة |
| Computationالحساب | Floating-point arithmeticحساب بالفاصلة العائمة | Floating-point arithmeticحساب بالفاصلة العائمة | Integer arithmeticحساب بالأعداد الصحيحة |
| Running example sizeحجم المثال الجاري | 64 B64 B | 4 B + 16 B = 20 B4 B + 16 B = 20 B | 4 B of 2-bit integers + one scale S + one zero point Z4 B من أعداد صحيحة بحجم 2-bit + مقياس واحد S + نقطة صفر واحدة Z |
| Values a weight can takeالقيم التي يمكن أن يأخذها الوزن | any FP32 valueأي قيمة FP32 | four learned centroids -1.00, 0.00, 1.50, 2.00أربعة مراكز متعلَّمة -1.00, 0.00, 1.50, 2.00 | four evenly spaced levels -1.07, 0, 1.07, 2.14أربعة مستويات متساوية التباعد -1.07, 0, 1.07, 2.14 |
The fourth column, Binary and ternary quantization, stays greyed out on the slide. It pushes the integer idea to one bit or three levels and is a later lecture.
العمود الرابع، binary/ternary quantization (التكميم الثنائي والثلاثي)، يبقى رماديًا على الشريحة. إنه يدفع فكرة الأعداد الصحيحة إلى بت واحد أو ثلاثة مستويات، وموضوعه محاضرة لاحقة.
Recall
Decode q = 0 and q = -1 from the slide 43 example, and say which original weights land on each.فك القيمتين q = 0 و q = -1 من مثال الشريحة 43، وقل أي الأوزان الأصلية تقع على كل منهما.
Quick checkاختبار سريع
In the slide 43 linear example, which original weight is reconstructed with the largest error?في المثال الخطي في الشريحة 43، أي وزن أصلي يُعاد بناؤه بأكبر خطأ؟
Quick checkاختبار سريع
A linearly quantized weight is stored as q = 0 with S = 1.07 and Z = -1. Which value does inference use?وزن مكمَّم خطيًا مخزَّن على أنه q = 0 مع S = 1.07 و Z = -1. ما القيمة التي يستخدمها الاستدلال؟
If you went to slide 44 to find the paper behind the 3.2x codebook example or the 35x AlexNet result, you would not find it. The list there starts with a compression survey and Horowitz's energy paper, then runs through Optimal Brain Damage, AMC, network slimming, ThiNet, SparseGPT and other pruning work. Only two entries reach the quantization material, and only indirectly: Song Han's Stanford thesis (entry 5, which contains Deep Compression) and Prof. Han's TinyML course (entry 19, the origin of the slide figures). Slide 45 is a blank closing slide.
لو ذهبت إلى الشريحة 44 لتجد الورقة وراء مثال الـ codebook بنسبة 3.2x أو نتيجة 35x على AlexNet، فلن تجدها. القائمة هناك تبدأ بمسح عن الضغط وورقة Horowitz عن الطاقة، ثم تمر على Optimal Brain Damage و AMC و network slimming و ThiNet و SparseGPT وأعمال تقليم أخرى. مدخلان فقط يصلان إلى مادة التكميم، وبشكل غير مباشر: أطروحة Song Han في Stanford (المدخل 5، الذي يحتوي Deep Compression) ومقرر TinyML للبروفيسور Han (المدخل 19، مصدر أشكال الشرائح). الشريحة 45 شريحة ختامية فارغة.
For revision and for any citation in your own work, use the sources the lecture actually draws on. They are listed below and in the Sources section of this part.
للمراجعة، ولأي استشهاد في عملك الخاص، استخدم المصادر التي تعتمد عليها المحاضرة فعلًا. هي مدرجة أدناه وفي قسم المصادر (Sources) في هذا الجزء.
Which source backs which slides of lecture 05-1أي مصدر يدعم أي شرائح في المحاضرة 05-1
- Slides 22 to 29 and 42 to 43الشرائح من 22 إلى 29 ومن 42 إلى 43
- The running 4 x 4 example, the codebook, centroid fine-tuning and the dataflow figure come from Han's MIT efficient ML course and the Deep Compression paper (Han, Mao and Dally, ICLR 2016).المثال الجاري 4 x 4، والـ codebook، والضبط الدقيق للمراكز، وشكل تدفق البيانات، كلها مأخوذة من مقرر Han في MIT عن تعلم الآلة الكفء وورقة Deep Compression (Han, Mao and Dally, ICLR 2016).
- Slides 37 to 39الشرائح من 37 إلى 39
- Huffman coding and the prune, quantize, encode pipeline: Deep Compression, ICLR 2016.ترميز Huffman وخط المعالجة تقليم ثم تكميم ثم ترميز: Deep Compression, ICLR 2016.
- Slides 40 and 41الشريحتان 40 و 41
- SqueezeNet (Iandola et al., 2016): AlexNet-level accuracy with 50x fewer parameters, 0.47 MB after compression.SqueezeNet (Iandola et al., 2016): دقة بمستوى AlexNet بمعاملات أقل بمقدار 50x، و 0.47 MB بعد الضغط.
- Slide 3الشريحة 3
- Energy per operation: Horowitz, ISSCC 2014, which slide 44 does list.الطاقة لكل عملية: Horowitz, ISSCC 2014، وهذه تذكرها الشريحة 44 فعلًا.
- Slide 43 linear exampleالمثال الخطي في الشريحة 43
- The affine scheme r = S(q - Z): Jacob et al., integer-arithmetic-only inference (CVPR 2018), the basis of lecture 05-2.المخطط التآلفي r = S(q - Z): Jacob et al.، الاستدلال بالأعداد الصحيحة فقط (CVPR 2018)، وهو أساس المحاضرة 05-2.
Recall
Which two papers should slide 44 have listed for this lecture, and what result from each should you remember?ما الورقتان اللتان كان يجب أن تذكرهما الشريحة 44 لهذه المحاضرة، وما النتيجة التي يجب أن تتذكرها من كل منهما؟
- Deep Compression is the source for weight sharing, the codebook, centroid fine-tuning and Huffman coding.Deep Compression هي مصدر مشاركة الأوزان (weight sharing)، والـ codebook، والضبط الدقيق للمراكز (centroid fine-tuning)، وترميز Huffman.
- SqueezeNet shows that compression stacks with a small architecture.SqueezeNet تُظهر أن الضغط يتراكم مع معمارية صغيرة.
- Jacob et al. is the source for the linear scheme previewed on slide 43 and developed in lecture 05-2.Jacob et al. هي مصدر المخطط الخطي الذي تقدّم الشريحة 43 لمحة عنه، والذي تطوّره المحاضرة 05-2.
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- At runtime the 2-bit indexes go through a codebook lookup (decode) and become FP32 weights; the convolution, bias add and ReLU all run in float.أثناء التشغيل تمر الفهارس ذات 2-bit عبر بحث في الـ codebook (decode) فتصبح أوزانًا من نوع FP32، ثم يجري الالتفاف (convolution) وإضافة الـ bias و ReLU كلها بالفاصلة العائمة.
- K-means weight quantization only saves storage: the model file, the flash footprint and the off-chip bytes fetched per weight. It does not make a single MAC cheaper, and the lookup adds work.تكميم الأوزان بـ K-means يوفّر التخزين فقط: حجم ملف النموذج، والمساحة في الـ flash، والبايتات المجلوبة من خارج الشريحة لكل وزن. لا يجعل أي عملية MAC واحدة أرخص، والبحث في الجدول يضيف عملًا.
- In the 16-weight example, DRAM traffic drops from 16 words to 5 (4 B of indexes plus a 16 B codebook), the same 3.2x as the storage ratio; the 16 FP32 multiply-adds are unchanged.في مثال الأوزان الستة عشر ينخفض النقل من DRAM من 16 كلمة إلى 5 كلمات (4 B من الفهارس مع codebook حجمه 16 B)، أي نفس نسبة 3.2x في التخزين، بينما تبقى عمليات الضرب والجمع الست عشرة بـ FP32 كما هي.
- Slide 43's completed table: floating point stores and computes in float; K-means stores integer indexes plus a float codebook but computes in float; linear quantization stores integers and computes with integer arithmetic.جدول الشريحة 43 بعد اكتماله: الفاصلة العائمة تخزّن وتحسب بالفاصلة العائمة؛ K-means تخزّن فهارس صحيحة مع codebook عائم لكنها تحسب بالفاصلة العائمة؛ التكميم الخطي يخزّن أعدادًا صحيحة ويحسب بحساب الأعداد الصحيحة.
- Linear quantization uses an evenly spaced grid r = S(q - Z). With S = 1.07 and Z = -1, q in {-2, -1, 0, 1} decodes to {-1.07, 0, 1.07, 2.14}.التكميم الخطي يستخدم شبكة قيم متساوية التباعد r = S(q - Z). مع S = 1.07 و Z = -1 تُفك القيم q في {-2, -1, 0, 1} إلى {-1.07, 0, 1.07, 2.14}.
- The uniform grid fits this matrix worse than K-means (1.53 lands on 1.07, error 0.46; mean squared error about 0.047 versus 0.006), and that accuracy cost buys integer-only arithmetic. Full treatment is lecture 05-2.الشبكة المنتظمة تلائم هذه المصفوفة أسوأ من K-means (القيمة 1.53 تقع على 1.07 بخطأ 0.46؛ ومتوسط مربع الخطأ نحو 0.047 مقابل 0.006)، وهذه الكلفة في الدقة هي ثمن الحساب بالأعداد الصحيحة فقط. الشرح الكامل في المحاضرة 05-2.
- Slide 42 swaps the codebook colours of 1.50 and 0.00 (cosmetic), slide 44 lists pruning references instead of Deep Compression and SqueezeNet, and slide 45 is blank.الشريحة 42 تبادل لوني القيمتين 1.50 و 0.00 في الـ codebook (خطأ شكلي)، والشريحة 44 تسرد مراجع التقليم بدلًا من Deep Compression و SqueezeNet، والشريحة 45 فارغة.
Sourcesالمصادر
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman CodingPaperHan, Mao and Dally, ICLR 2016Weight sharing with an index into a shared-weight table, one level of indirection in the forward pass, 35x to 49x storage reduction.مشاركة الأوزان عبر فهرس إلى جدول أوزان مشتركة، ومستوى واحد من الإحالة غير المباشرة في التمرير الأمامي، وتقليل التخزين من 35x إلى 49x.(opens in a new tab)(يفتح في تبويب جديد)
- EIE: Efficient Inference Engine on Compressed Deep Neural NetworkPaperHan et al., ISCA 2016Table I energy per operation (DRAM read 640 pJ, FP32 multiply 3.7 pJ) and 4-bit indexes expanded through a table lookup before arithmetic.الجدول I للطاقة لكل عملية (قراءة DRAM عند 640 pJ، وضرب FP32 عند 3.7 pJ)، وفهارس 4-bit تُوسَّع عبر بحث في جدول قبل الحساب.(opens in a new tab)(يفتح في تبويب جديد)
- SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model sizePaperIandola et al., 2016The architecture of slides 40 and 41, 510x smaller than AlexNet after compression.معمارية الشريحتين 40 و 41، أصغر من AlexNet بمقدار 510x بعد الضغط.(opens in a new tab)(يفتح في تبويب جديد)
- Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only InferencePaperJacob et al., CVPR 2018The affine scheme r = S(q - Z) that allows inference with integer-only arithmetic.المخطط التآلفي r = S(q - Z) الذي يتيح الاستدلال بحساب الأعداد الصحيحة فقط.(opens in a new tab)(يفتح في تبويب جديد)
- A Survey of Quantization Methods for Efficient Neural Network InferencePaperGholami et al., 2021Uniform quantization Q(r) = Int(r/S) - Z, and why non-uniform schemes are hard to deploy on general hardware.التكميم المنتظم Q(r) = Int(r/S) - Z، ولماذا يصعب نشر المخططات غير المنتظمة على العتاد العام.(opens in a new tab)(يفتح في تبويب جديد)