COE 592/Lecture 5.1المحاضرة 5.1/Full guideالشرح الكامل
Quantization (I)التكميم (Quantization) الجزء الأول
The whole lecture on one page, taught concept by concept. Work through the parts in order, mark each concept once you understand it, and open the slide chips when you want the original slides.المحاضرة كاملة في صفحة واحدة، مشروحة مفهومًا مفهومًا. امشِ على الأجزاء بالترتيب، وعلّم كل مفهوم بعد أن تفهمه، وافتح أزرار الشرائح عندما تريد الرجوع إلى الشرائح الأصلية.
Partsالأجزاء
8
Conceptsالمفاهيم
29
Slidesالشرائح
45
Readingمدة القراءة
174 min174 دقيقة
Understoodما فهمته
0/29 conceptsمفاهيم
01
Part 01: Why fewer bits, integers and fixed pointلماذا بتات أقل، والأعداد الصحيحة والفاصلة الثابتة
Lower bit-width means cheaper arithmetic and memory traffic. Covers unsigned, sign-magnitude and two's complement integers, then fixed-point numbers as an integer times a power-of-two scale.عرض بت أقل يعني حسابًا وحركة ذاكرة أرخص. يغطي الأعداد الصحيحة بلا إشارة، وبالإشارة والمقدار (sign-magnitude)، والمتمم الثنائي (two's complement)، ثم أعداد الفاصلة الثابتة بوصفها عددًا صحيحًا مضروبًا في مقياس هو قوة للعدد 2.
3 concepts3 مفاهيم, ، slides 1-6الشرائح 1-6
Why this part mattersلماذا يهمّ هذا الجزء
Lecture 05-1 opens with a plan in three steps. First, review how computers store numbers: integers, fixed point and floating point (FP32, FP16, INT4 and friends). Second, learn what neural network Quantization is. Third, meet the common ways to do it: K-means-based, linear, and binary or ternary quantization. The outline slide makes the point with a picture: a smooth sine wave sampled at points that snap to a few dashed levels. Snapping to a small set of levels is the whole subject.
This part covers the first step and the reason behind it. We start with the energy bill, because it explains why anyone would give up precision on purpose. Then we ask the slide's simple question, how is numeric data represented, and answer it for integers. Finally, we read fixed point as an integer with a hidden scale. That reading is the bridge to linear quantization, r=S(q−Z), in lecture 05-2. For the midterm, expect range formulas for n bits, hand encodings such as -49, a fixed-point decode, and ratios read off the energy table.
تبدأ المحاضرة 05-1 بخطة من ثلاث خطوات. أولاً، مراجعة طريقة تخزين الحاسوب للأعداد: الأعداد الصحيحة (integers) والـ fixed point والـ floating point (FP32 وFP16 وINT4 وأخواتها). ثانياً، فهم ما هو quantization في الشبكات العصبية. ثالثاً، التعرف على الطرق الشائعة لتنفيذه: الطريقة القائمة على K-means، والطريقة الخطية (linear)، والـ quantization الثنائي أو الثلاثي (binary أو ternary). شريحة المخطط العام توضح الفكرة بصورة: موجة جيبية ناعمة نأخذ منها عينات عند نقاط تُجبر على الالتصاق بعدد قليل من المستويات المتقطعة. هذا الالتصاق بمجموعة صغيرة من المستويات هو الموضوع كله.
يغطي هذا الجزء الخطوة الأولى والسبب وراءها. نبدأ بفاتورة الطاقة، لأنها تشرح لماذا قد يتنازل أحد عن الدقة عن قصد. ثم نطرح سؤال الشريحة البسيط: كيف تُمثَّل البيانات العددية؟ ونجيب عنه للأعداد الصحيحة. وأخيراً نقرأ الـ fixed point على أنه عدد صحيح بمقياس (scale) مخفي. هذه القراءة هي الجسر إلى الـ linear quantization، أي r=S(q−Z)، في المحاضرة 05-2. في الاختبار النصفي توقع صيغ النطاق لعدد n من البتات، وترميزات يدوية مثل -49، وفك ترميز عدد fixed-point، ونسباً تُقرأ من جدول الطاقة.
By the end you canفي نهاية هذا الجزء ستستطيع
01Quote the 45 nm energy table and compute the 30x add ratio and the roughly 16x multiply ratio between 32-bit and 8-bit operations.تستشهد بجدول الطاقة لتقنية 45 nm وتحسب نسبة 30x للجمع ونسبة 16x تقريباً للضرب بين عمليات 32-bit وعمليات 8-bit.
02Explain why multiplier energy grows roughly with the square of the bit-width, adder energy roughly linearly, and why a DRAM access dwarfs both.تشرح لماذا تنمو طاقة الضارب (multiplier) تقريباً مع مربع عدد البتات (bit-width)، وطاقة الجامع (adder) خطياً تقريباً، ولماذا تطغى قراءة واحدة من DRAM على الاثنين.
03Write the n-bit range of unsigned, sign-magnitude and two's complement integers, and evaluate it for n = 8 and n = 4.تكتب نطاق الأعداد الصحيحة ذات n بت بصيغ unsigned و sign-magnitude و two's complement، وتحسبه عند n = 8 و n = 4.
04Encode and decode any 8-bit value in all three integer formats, including -49 by hand.ترمّز وتفك ترميز أي قيمة من 8 بتات بصيغ الأعداد الصحيحة الثلاث، بما في ذلك -49 يدوياً.
05Read a fixed-point number both as a sum of fractional powers of two and as an integer times 2^-4, and state its resolution and range.تقرأ عدد fixed-point بطريقتين: كمجموع لقوى اثنين الكسرية، وكعدد صحيح مضروب في 2^-4، وتذكر دقته (resolution) ونطاقه (range).
Take one multiply-accumulate, the operation a neural network repeats billions of times. In 32-bit floating point it costs a multiply (3.7 pJ) plus an add (0.9 pJ), so 4.6 pJ. In 8-bit integers it costs 0.2 pJ plus 0.03 pJ, so 0.23 pJ. The same arithmetic job, done with fewer bits, is about 20x cheaper. That one number is why this lecture exists.
خذ عملية multiply-accumulate واحدة، وهي العملية التي تكررها الشبكة العصبية مليارات المرات. في الـ floating point بحجم 32-bit تكلف عملية ضرب (3.7 pJ) زائد عملية جمع (0.9 pJ)، أي 4.6 pJ. وفي الأعداد الصحيحة بحجم 8-bit تكلف 0.2 pJ زائد 0.03 pJ، أي 0.23 pJ. المهمة الحسابية نفسها، حين تُنفذ ببتات أقل، أرخص بنحو 20x. هذا الرقم وحده هو سبب وجود هذه المحاضرة.
The table every efficiency lecture quotesالجدول الذي تستشهد به كل محاضرة عن الكفاءة
The figures come from Mark Horowitz's ISSCC 2014 keynote, measured for a 45 nm process at 0.9 V. They are rough by design: the exact numbers change with the process node, but the ratios between them have held for a decade. The slide lists four precisions for each of two operations.
تأتي هذه الأرقام من الكلمة الرئيسية لـ Mark Horowitz في مؤتمر ISSCC 2014، وقد قيست لتقنية تصنيع 45 nm عند جهد 0.9 V. وهي تقريبية عن قصد: الأرقام الدقيقة تتغير مع عقدة التصنيع (process node)، لكن النسب بينها ظلت ثابتة لعقد كامل. تعرض الشريحة أربع دقّات (precisions) لكل عملية من العمليتين.
Operationالعملية
8b int8b int
32b int32b int
16b float16b float
32b float32b float
fp32 / int8fp32 / int8
ADDجمع (ADD)
0.030.03
0.10.1
0.40.4
0.90.9
0.9 / 0.03 = 30x0.9 / 0.03 = 30x
MULTضرب (MULT)
0.20.2
3.13.1
1.11.1
3.73.7
3.7 / 0.2 = 18.5x3.7 / 0.2 = 18.5x
Energy per operation in pJ, 45 nm, 0.9 V (Horowitz, ISSCC 2014). Last column: 32-bit float over 8-bit int.الطاقة لكل عملية بوحدة pJ، بتقنية 45 nm وجهد 0.9 V (Horowitz، ISSCC 2014). العمود الأخير: 32-bit float مقسوماً على 8-bit int.
The eight operations plus one DRAM read on a log axis: 8-bit integer rows in teal, with the 30x add ratio and the 16x multiply ratio drawn as arrowsالعمليات الثماني مع قراءة واحدة من DRAM على محور لوغاريتمي: صفوف الأعداد الصحيحة 8-bit باللون الأزرق المخضر، مع نسبة 30x للجمع ونسبة 16x للضرب مرسومتين كسهمين
Reading the ratiosقراءة النسب
Worked exampleمثال محلول
The two arrows on slide 3السهمان في الشريحة 3
Adds: 32-bit float against 8-bit intالجمع: 32-bit float مقابل 8-bit int
0.03pJ0.9pJ=30
This is the 30x arrow on the slide.
0.03pJ0.9pJ=30
هذا هو سهم 30x في الشريحة.
Multiplies: 32-bit int against 8-bit intالضرب: 32-bit int مقابل 8-bit int
0.2pJ3.1pJ=15.5≈16
This matches the 16x label.
0.2pJ3.1pJ=15.5≈16
هذا يطابق التسمية 16x.
Multiplies: 32-bit float against 8-bit intالضرب: 32-bit float مقابل 8-bit int
0.2pJ3.7pJ=18.5
This is the ratio you get if you read the arrow from the longest bar, which is where the slide's dotted line sits.
0.2pJ3.7pJ=18.5
هذه هي النسبة التي تحصل عليها إذا قرأت السهم من أطول عمود، وهو المكان الذي يقع فيه الخط المنقط في الشريحة.
Resultالنتيجة
Moving from 32 to 8 bits makes an add about 30x cheaper (float to int) and a multiply about 16x to 18.5x cheaper, depending on whether you start from int32 or fp32.
الانتقال من 32 إلى 8 بتات يجعل الجمع أرخص بنحو 30x (من float إلى int)، ويجعل الضرب أرخص بما بين 16x و18.5x تقريباً، بحسب ما إذا كانت نقطة البداية int32 أو fp32.
Why multiplies punish bits more than addsلماذا يعاقب الضرب على البتات أكثر من الجمع
Look at integers only, so the format does not change. Going from 8 to 32 bits is 4x the Bit-width. The add grows from 0.03 to 0.1 pJ, about 3.3x: roughly linear. The multiply grows from 0.2 to 3.1 pJ, about 15.5x, which is close to 4² = 16: roughly quadratic.
انظر إلى الأعداد الصحيحة فقط حتى لا تتغير الصيغة. الانتقال من 8 إلى 32 بتاً يعني 4x في bit-width. يزداد الجمع من 0.03 إلى 0.1 pJ، أي نحو 3.3x: نمو خطي تقريباً. ويزداد الضرب من 0.2 إلى 3.1 pJ، أي نحو 15.5x، وهذا قريب من 4² = 16: نمو تربيعي تقريباً.
The hardware explains the pattern. An n-bit ripple adder is a chain of n full adders, one per bit. An n-bit array multiplier forms n partial products of n bits each and adds them, so it needs on the order of n² cells. Real designs are cleverer, but the growth stays close to these orders.
العتاد يفسر هذا النمط. الجامع المتتابع (ripple adder) بعدد n من البتات هو سلسلة من n جامعات كاملة (full adders)، واحد لكل بت. أما الضارب المصفوفي (array multiplier) بعدد n من البتات فيكوّن n من النواتج الجزئية (partial products) طول كل منها n بت ثم يجمعها، لذلك يحتاج إلى عدد من الخلايا من رتبة n². التصاميم الحقيقية أذكى من ذلك، لكن النمو يبقى قريباً من هذه الرتب.
Eadd(n)∝n,Emult(n)∝n2
Rule of thumb for integer arithmetic energyقاعدة تقريبية لطاقة الحساب بالأعداد الصحيحة
Floating point adds overhead on top: aligning exponents, normalizing and rounding. That is why a 32-bit float ADD (0.9 pJ) costs 9x a 32-bit int ADD (0.1 pJ) even though both handle 32 bits. A 16-bit float multiply (1.1 pJ) is still cheaper than a 32-bit integer one (3.1 pJ), because its significand is only 11 bits wide. Parts 2 and 3 unpack these float formats.
الـ floating point يضيف عبئاً إضافياً فوق ذلك: محاذاة الأُسس (exponents)، والتطبيع (normalizing)، والتقريب (rounding). لهذا يكلف 32-bit float ADD (0.9 pJ) تسعة أضعاف (9x) 32-bit int ADD (0.1 pJ) رغم أن كليهما يتعامل مع 32 بتاً. ومع ذلك فإن ضرب 16-bit float (1.1 pJ) أرخص من ضرب عدد صحيح 32-bit (3.1 pJ)، لأن الجزء المعنوي (significand) فيه عرضه 11 بتاً فقط. الجزءان 2 و3 يشرحان صيغ الـ float هذه بالتفصيل.
Memory dominates bothالذاكرة تطغى على الاثنين
The bottom line of slide 3 says one DRAM access costs 200x or more than an arithmetic operation. Han et al. quote the same Horowitz table: about 640 pJ for a 32-bit DRAM read and about 5 pJ for a 32-bit on-chip SRAM read. Then 640 / 3.1 ≈ 206, so one fetch from DRAM costs as much as about 200 32-bit integer multiplies, and over 20,000 8-bit integer adds. Horowitz's own paper puts a DRAM access at 1 to 2 nJ, a couple of orders of magnitude above a functional operation.
يقول السطر الأخير في الشريحة 3 إن قراءة واحدة من DRAM تكلف 200x أو أكثر من عملية حسابية. ويستشهد Han et al. بجدول Horowitz نفسه: نحو 640 pJ لقراءة 32-bit من DRAM، ونحو 5 pJ لقراءة 32-bit من SRAM على الشريحة (on-chip). إذن 640 / 3.1 ≈ 206، أي أن جلبة واحدة من DRAM تكلف ما يعادل نحو 200 عملية ضرب لأعداد صحيحة 32-bit، وأكثر من 20,000 عملية جمع لأعداد صحيحة 8-bit. وورقة Horowitz نفسها تقدّر الوصول إلى DRAM بما بين 1 و2 nJ، أي أعلى من العملية الوظيفية بمرتبتين عشريتين تقريباً.
This is why fewer bits help twice. Each operation gets cheaper, and each weight or activation is smaller, so fewer bytes cross the expensive path from DRAM. An 8-bit weight is a quarter of the traffic of a 32-bit one, and a model that shrinks enough may fit in on-chip SRAM, which avoids DRAM almost completely. You saw the memory side of this argument in lecture 03 and in Pruning (lecture 04-1). Quantization attacks the same bill from the other direction: instead of fewer weights, fewer bits per weight.
لهذا تفيد البتات الأقل مرتين. كل عملية تصبح أرخص، وكل وزن (weight) أو تنشيط (activation) يصبح أصغر، فتعبر بايتات أقل المسار المكلف من DRAM. الوزن بحجم 8-bit يمثل ربع حركة البيانات التي يحتاجها وزن بحجم 32-bit، والنموذج الذي يصغر بما يكفي قد يتسع في SRAM على الشريحة، فيتجنب DRAM بالكامل تقريباً. رأيت جانب الذاكرة من هذه الحجة في المحاضرة 03 وفي pruning (المحاضرة 04-1). الـ quantization يهاجم الفاتورة نفسها من الاتجاه الآخر: بدلاً من أوزان أقل، بتات أقل لكل وزن.
Recall
Without looking: what are the 8-bit int and 32-bit float energies for ADD and MULT, and which two ratios does slide 3 highlight?دون أن تنظر: ما طاقة ADD و MULT لـ 8-bit int و 32-bit float، وما النسبتان اللتان تبرزهما الشريحة 3؟
ADD: 0.03 pJ (int8) and 0.9 pJ (fp32), ratio 30x. MULT: 0.2 pJ (int8) and 3.7 pJ (fp32), ratio 18.5x; the slide labels its multiply arrow 16x, which matches int32 at 3.1 pJ (15.5x).
Going from 8-bit to 32-bit integers, how does multiply energy grow in the 45 nm table?عند الانتقال من أعداد صحيحة 8-bit إلى 32-bit، كيف تنمو طاقة الضرب في جدول 45 nm؟
Write 49 in binary: 32 + 16 + 1, so 00110001 in eight bits. Now try to store -49. There is no minus sign in a register, only bits, so some bit pattern has to mean "negative". The three classic answers to that question are the three integer formats on slide 5, and each one gives the same pattern a different meaning.
اكتب 49 بالنظام الثنائي: 32 + 16 + 1، أي 00110001 في ثمانية بتات. الآن حاول تخزين -49. لا توجد إشارة سالب داخل المسجل (register)، بل بتات فقط، لذلك لا بد أن يعني نمطٌ ما من البتات "سالب". الإجابات الكلاسيكية الثلاث عن هذا السؤال هي صيغ الأعداد الصحيحة الثلاث في الشريحة 5، وكل منها يعطي النمط نفسه معنى مختلفاً.
Unsigned: every bit is a positive power of twoصيغة unsigned: كل بت قوة موجبة للعدد اثنين
In an Unsigned integer, bit i has weight 2i, and the value is the sum of the weights of the bits that are set. All zeros gives 0; all ones gives 2n−1. There is no way to write a negative number.
في unsigned integer يكون وزن البت i هو 2i، والقيمة هي مجموع أوزان البتات التي قيمتها 1. كل البتات أصفار تعطي 0، وكل البتات آحاد تعطي 2n−1. لا توجد طريقة لكتابة عدد سالب.
vunsigned=i=0∑n−1bi2i,range [0,2n−1]
Sign-magnitude: a sign flag in front of an unsigned numberصيغة sign-magnitude: علامة إشارة أمام عدد unsigned
Sign-magnitude spends the top bit on the sign and keeps the other n - 1 bits as an unsigned magnitude. So -49 is the sign 1 followed by 0110001: 10110001. It is how people write numbers on paper, which makes it easy to read. It has two flaws. Both 00000000 and 10000000 mean zero (plus zero and minus zero), which wastes a code and complicates equality tests. And adding a positive and a negative number needs a different circuit from adding two positives, because the hardware must compare magnitudes and subtract.
صيغة sign-magnitude تخصص البت الأعلى للإشارة وتُبقي البتات الأخرى وعددها n - 1 كمقدار (magnitude) بلا إشارة. إذن -49 هو بت الإشارة 1 يليه 0110001: 10110001. هكذا يكتب الناس الأعداد على الورق، ولذلك يسهل قراءتها. لكن لها عيبين. النمطان 00000000 و10000000 كلاهما يعني الصفر (صفر موجب وصفر سالب)، وهذا يهدر رمزاً ويعقّد اختبارات التساوي. كما أن جمع عدد موجب وعدد سالب يحتاج إلى دائرة مختلفة عن جمع عددين موجبين، لأن العتاد يجب أن يقارن المقدارين ثم يطرح.
Two's complement: the top bit has a negative weightصيغة two's complement: للبت الأعلى وزن سالب
Two's complement changes one thing: the top bit is no longer a flag but a weight, and that weight is negative, −2n−1. All other bits keep their positive weights. For eight bits the weights are -128, 64, 32, 16, 8, 4, 2, 1.
صيغة two's complement تغيّر شيئاً واحداً: البت الأعلى لم يعد علامة بل وزناً، وهذا الوزن سالب، −2n−1. وتحتفظ بقية البتات بأوزانها الموجبة. في حالة ثمانية بتات تكون الأوزان -128, 64, 32, 16, 8, 4, 2, 1.
-49 = 11001111 in two's complement, against 10110001 in sign-magnitude. These are the two lower patterns on slide 5.
-49 = 11001111 بصيغة two's complement، مقابل 10110001 بصيغة sign-magnitude. هذان هما النمطان السفليان في الشريحة 5.
The second check is the deep reason the format works. A negative value -x is stored as the unsigned pattern of 2n−x, which is arithmetic modulo 2n. An ordinary unsigned adder already works modulo 2n, since the carry out of the top bit is simply dropped. So the same adder handles signed and unsigned numbers, subtraction is "add the negation", and there is a single zero. Practically every CPU, DSP and neural accelerator uses two's complement for signed integers for this reason.
التحقق الثاني هو السبب العميق لنجاح هذه الصيغة. القيمة السالبة -x تُخزَّن على شكل النمط unsigned للعدد 2n−x، وهذا حساب بباقي القسمة على 2n (modulo). والجامع العادي للأعداد unsigned يعمل أصلاً بباقي القسمة على 2n، لأن المحمول (carry) الخارج من البت الأعلى يُهمل ببساطة. لذلك يتعامل الجامع نفسه مع الأعداد ذات الإشارة والأعداد بلا إشارة، ويصبح الطرح "أضف السالب"، ويوجد صفر واحد فقط. لهذا السبب يستخدم عملياً كل CPU وDSP ومسرّع للشبكات العصبية صيغة two's complement للأعداد الصحيحة ذات الإشارة.
The 16 patterns of a 4-bit integer on a wheel: counting up from 0000 reaches 7 at 0111, and one more step wraps to -8 at 1000الأنماط الستة عشر لعدد صحيح من 4 بتات على عجلة: العد تصاعدياً من 0000 يصل إلى 7 عند 0111، وخطوة واحدة إضافية تلتف إلى -8 عند 1000
Integer formats side by side. The last column is how -49 is stored in 8 bits.صيغ الأعداد الصحيحة جنباً إلى جنب. العمود الأخير يبيّن كيف يُخزَّن -49 في 8 بتات.
Count the distinct values. Unsigned and two's complement both use all 2n patterns: 256 values for eight bits, 16 for four. Sign-magnitude gets only 2n−1 distinct values, 255 and 15, because two patterns share zero. The pattern 100...0 shows the difference most sharply: minus zero in sign-magnitude, but −2n−1 in two's complement, which is -128 for 8 bits and -8 for 4.
عُدّ القيم المختلفة. صيغتا unsigned وtwo's complement تستخدمان كل الأنماط وعددها 2n: 256 قيمة لثمانية بتات، و16 لأربعة. أما sign-magnitude فلا تحصل إلا على 2n−1 من القيم المختلفة، أي 255 و15، لأن نمطين يتشاركان الصفر. والنمط 100...0 يُظهر الفرق بأوضح صورة: هو صفر سالب في sign-magnitude، لكنه −2n−1 في two's complement، أي -128 لـ 8 بتات و-8 لـ 4 بتات.
ExplorerمستكشفOne bit pattern, four readingsنمط بتات واحد، وأربع قراءات
weights shown are two's complement; in Q3.4 divide each by 16, so the four bits on the right are the fractionالأوزان المعروضة بصيغة two's complement، وفي Q3.4 تُقسم كل منها على 16، فتكون البتات الأربعة على اليمين هي الكسر
Unsigned49range [0, 255]المدى [0, 255]
Sign-magnitude49range [-127, 127], two zerosالمدى [-127, 127]، وفيه صفران
Pattern 00110001. The bits never change between the four readings; only the rule for turning them into a number does. Try 10000000: unsigned 128, sign-magnitude -0, two's complement -128, fixed point -8.النمط 00110001. البتات لا تتغير بين القراءات الأربع، وإنما تتغير القاعدة التي تحولها إلى عدد. جرّب 10000000: بلا إشارة 128، وبالإشارة والمقدار -0، وبـ two's complement -128، وبالنقطة الثابتة -8.
Recall
Give the ranges of 4-bit unsigned, sign-magnitude and two's complement integers, and say what 1000 means in each.اذكر نطاقات الأعداد الصحيحة ذات 4 بتات بصيغ unsigned و sign-magnitude و two's complement، وقل ماذا يعني النمط 1000 في كل منها.
Unsigned [0, 15], where 1000 is 8. Sign-magnitude [-7, 7], where 1000 is minus zero. Two's complement [-8, 7], where 1000 is -8.
unsigned: [0, 15]، والنمط 1000 فيها يساوي 8. sign-magnitude: [-7, 7]، والنمط 1000 فيها صفر سالب. two's complement: [-8, 7]، والنمط 1000 فيها يساوي -8.
Quick checkاختبار سريع
In 8-bit two's complement, which bit pattern encodes -49?في صيغة two's complement ذات 8 بتات، أي نمط بتات يرمّز -49؟
Quick checkاختبار سريع
What is the range of a 4-bit two's complement integer?ما نطاق عدد صحيح بصيغة two's complement ذات 4 بتات؟
Take the same bits as before, 00110001, and draw a dot between the fourth and fifth bit: 0011.0001. The left part reads 3 and the right part 0001 is one sixteenth, so the number is 3.0625. Nothing about the bits changed. Only our agreement about where the point sits did.
خذ البتات نفسها كما في السابق، 00110001، وارسم نقطة بين البت الرابع والبت الخامس: 0011.0001. الجزء الأيسر يُقرأ 3، والجزء الأيمن 0001 يساوي جزءاً من ستة عشر، إذن العدد هو 3.0625. لم يتغير شيء في البتات. الذي تغير فقط هو اتفاقنا على مكان النقطة.
Reading one: fractional powers of twoالقراءة الأولى: قوى اثنين الكسرية
A Fixed-point number format fixes, once and for all, how many bits sit after the binary point. The slide's format uses eight bits in two's complement: a sign bit, three integer bits and four fraction bits. The weights continue past the point into negative powers of two.
صيغة fixed-point تحدد مرة واحدة وإلى الأبد عدد البتات التي تقع بعد النقطة الثنائية (binary point). الصيغة في الشريحة تستخدم ثمانية بتات بنظام two's complement: بت إشارة، وثلاثة بتات للجزء الصحيح، وأربعة بتات للكسر. وتستمر الأوزان بعد النقطة إلى قوى اثنين السالبة.
Reading two: an integer times a fixed scaleالقراءة الثانية: عدد صحيح مضروب في مقياس ثابت
Now ignore the point and read the eight bits as the two's complement integer 49. Every weight in reading one is exactly the reading-two weight times 2−4: −27⋅2−4=−23, 20⋅2−4=2−4, and so on. So the whole value is the integer times one shared scale.
الآن تجاهل النقطة واقرأ البتات الثمانية كعدد صحيح بصيغة two's complement، فتحصل على 49. كل وزن في القراءة الأولى يساوي بالضبط الوزن المقابل في القراءة الثانية مضروباً في 2−4: −27⋅2−4=−23، و20⋅2−4=2−4، وهكذا. إذن القيمة كلها هي العدد الصحيح مضروباً في مقياس (scale) واحد مشترك.
v=q⋅2−f⇒0011.0001=49×2−4=49×0.0625=3.0625
f is the number of fraction bits; q is the stored two's complement integerf عدد بتات الكسر؛ وq العدد الصحيح المخزن بصيغة المتمم الثنائي (two's complement)
The integer 49 and the fixed-point number 3.0625 are the same eight bits; the binary point, and with it the factor 2^-4, lives only in the formatالعدد الصحيح 49 والعدد fixed-point الذي قيمته 3.0625 هما البتات الثمانية نفسها؛ النقطة الثنائية، ومعها العامل 2^-4، موجودة في الصيغة فقط
This second reading is the one to remember. The binary point is never stored. It is a property of the format, which means fixed point is integer arithmetic plus a fixed scale. Adding two numbers in the same format is a plain integer add, because the scale factors out: q12−4+q22−4=(q1+q2)2−4. Multiplying is a plain integer multiply whose result has scale 2−8; shift right by four bits to return to 2−4. A fixed-point unit is just an integer ALU and a shifter, which is why it is cheap.
هذه القراءة الثانية هي التي يجب أن تتذكرها. النقطة الثنائية لا تُخزَّن أبداً. إنها خاصية للصيغة، وهذا يعني أن الـ fixed point هو حساب أعداد صحيحة زائد مقياس ثابت. جمع عددين من الصيغة نفسها هو جمع أعداد صحيحة عادي، لأن المقياس يخرج عاملاً مشتركاً: q12−4+q22−4=(q1+q2)2−4. والضرب هو ضرب أعداد صحيحة عادي يكون مقياس ناتجه 2−8؛ أزِح الناتج إلى اليمين أربعة بتات لتعود إلى 2−4. وحدة الـ fixed-point ليست سوى ALU للأعداد الصحيحة مع مُزيح (shifter)، ولهذا هي رخيصة.
Resolution and rangeالدقة والنطاق
With four fraction bits the gap between neighbouring values, the resolution, is 2^-4 = 0.0625. The range is the two's complement range [-128, 127] times that scale: from -128 / 16 = -8 (pattern 1000.0000) to 127 / 16 = 7.9375 (pattern 0111.1111). Moving the point one place to the left halves both the step and the range; moving it right doubles both. Fixed point can never have fine steps and a wide range at the same time, which is the gap floating point (part 2) was invented to close.
مع أربعة بتات كسرية تكون المسافة بين قيمتين متجاورتين، أي الدقة (resolution)، هي 2^-4 = 0.0625. والنطاق هو نطاق two's complement أي [-128, 127] مضروباً في هذا المقياس: من -128 / 16 = -8 (النمط 1000.0000) إلى 127 / 16 = 7.9375 (النمط 0111.1111). تحريك النقطة خانة واحدة إلى اليسار يُنصّف الخطوة والنطاق معاً، وتحريكها إلى اليمين يضاعفهما معاً. لا يمكن للـ fixed point أبداً أن يجمع بين خطوات دقيقة ونطاق واسع في الوقت نفسه، وهذه هي الفجوة التي اختُرع الـ floating point (الجزء 2) لسدّها.
Worked exampleمثال محلول
Store 2.7 in the same 8-bit formatخزّن 2.7 بالصيغة نفسها ذات 8 بتات
Divide by the scaleاقسم على المقياس
2.7 / 0.0625 = 43.2
2.7 / 0.0625 = 43.2
Round to the nearest integerقرّب إلى أقرب عدد صحيح
q = 43 = 00101011, which reads as 0010.1011.
q = 43 = 00101011، ويُقرأ على أنه 0010.1011.
Decodeفك الترميز
43 x 0.0625 = 2.6875
43 x 0.0625 = 2.6875
Resultالنتيجة
The stored value is 2.6875, off by 0.0125. The error can never exceed half a step, 0.03125. That round-to-the-grid error is your first taste of Quantization error.
القيمة المخزنة هي 2.6875، بفارق 0.0125. لا يمكن أن يتجاوز الخطأ نصف خطوة، أي 0.03125. خطأ التقريب إلى الشبكة هذا هو أول لمحة لك عن quantization error.
Hold on to the equation v=q⋅2−4. It is linear quantization in disguise: Linear quantization writes r=S(q−Z), a real value r recovered from a stored integer q with a scale S and a zero point Z. Fixed point is the special case S=2−4,Z=0. Lecture 05-2 lets S be any real number chosen from the data and lets Z shift the grid, so the 256 levels of an 8-bit integer land where a tensor's values actually are.
احتفظ بالمعادلة v=q⋅2−4. إنها linear quantization متنكّر: linear quantization يكتب r=S(q−Z)، أي قيمة حقيقية r نستعيدها من عدد صحيح مخزن q بمقياس S ونقطة صفر (zero point) Z. الـ fixed point هو الحالة الخاصة S=2−4,Z=0. المحاضرة 05-2 تسمح لـ S أن يكون أي عدد حقيقي يُختار من البيانات، وتسمح لـ Z بإزاحة الشبكة، بحيث تقع المستويات الـ 256 لعدد صحيح 8-bit حيث توجد قيم الـ tensor فعلاً.
Resolution with four fraction bits: 0.0625.الدقة مع أربعة بتات كسرية: 0.0625.
Range of the 8-bit format: [-8, 7.9375].نطاق الصيغة ذات 8 بتات: [-8, 7.9375].
Conversion: q=round(v/2−4), then v≈q⋅2−4.التحويل: q=round(v/2−4)، ثم v≈q⋅2−4.
Recall
Represent -3.0625 in the same 8-bit fixed-point format (sign, 3 integer bits, 4 fraction bits).مثّل -3.0625 بصيغة الـ fixed-point نفسها ذات 8 بتات (إشارة، و3 بتات للجزء الصحيح، و4 بتات للكسر).
-3.0625 / 0.0625 = -49, and -49 in two's complement is 11001111, so the answer is 1100.1111. Check: -8 + 4 + 0.5 + 0.25 + 0.125 + 0.0625 = -3.0625.
Why is fixed-point multiplication followed by a shift, and by how many bits in this format?لماذا يتبع ضربَ الـ fixed-point عمليةُ إزاحة، وبكم بت في هذه الصيغة؟
Each operand carries scale 2^-4, so the integer product carries 2^-8. Shifting the product right by 4 bits (with rounding) brings it back to scale 2^-4, the format of the inputs.
كل معامل يحمل المقياس 2^-4، لذلك يحمل ناتج الضرب الصحيح المقياس 2^-8. إزاحة الناتج إلى اليمين بمقدار 4 بتات (مع التقريب) تعيده إلى المقياس 2^-4، أي صيغة المدخلات.
Quick checkاختبار سريع
In the sign + 3 integer + 4 fraction format, what does 1100.1111 represent?في صيغة إشارة + 3 بتات للجزء الصحيح + 4 بتات للكسر، ماذا يمثل النمط 1100.1111؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
Fewer bits means cheaper arithmetic and less data to move. At 45 nm: 8b int ADD 0.03 pJ against 32b float ADD 0.9 pJ (30x); 8b int MULT 0.2 pJ against 32b int MULT 3.1 pJ (15.5x, about 16x).بتات أقل تعني حساباً أرخص وبيانات أقل تحتاج إلى نقل. عند 45 nm: جمع 8b int يكلف 0.03 pJ مقابل 0.9 pJ لجمع 32b float (30x)، وضرب 8b int يكلف 0.2 pJ مقابل 3.1 pJ لضرب 32b int (15.5x، أي 16x تقريباً).
Multipliers scale roughly with the square of the bit-width (4x the bits, about 16x the energy); adders scale roughly linearly (4x the bits, about 3.3x the energy).تنمو طاقة الضوارب تقريباً مع مربع عدد البتات (4 أضعاف البتات تعطي قرابة 16 ضعف الطاقة)، وتنمو طاقة الجوامع خطياً تقريباً (4 أضعاف البتات تعطي قرابة 3.3 أضعاف الطاقة).
A 32-bit DRAM read costs about 640 pJ, about 200x a 32-bit multiply. Shrinking every weight from 32 to 8 bits cuts that traffic by 4x.قراءة 32-bit من DRAM تكلف نحو 640 pJ، أي نحو 200 ضعف عملية ضرب 32-bit. تقليص كل وزن من 32 إلى 8 بتات يخفض هذه الحركة 4 مرات.
Unsigned n bits: [0, 2^n - 1], so [0, 255] for 8 bits and [0, 15] for 4 bits.صيغة unsigned بعدد n من البتات: [0, 2^n - 1]، أي [0, 255] لـ 8 بتات و [0, 15] لـ 4 بتات.
Sign-magnitude: [-(2^(n-1) - 1), 2^(n-1) - 1], so [-127, 127] and [-7, 7], with two zeros (000...0 and 100...0).صيغة sign-magnitude: [-(2^(n-1) - 1), 2^(n-1) - 1]، أي [-127, 127] و [-7, 7]، مع صفرين (000...0 و 100...0).
Two's complement: [-2^(n-1), 2^(n-1) - 1], so [-128, 127] and INT4 [-8, 7]. One zero; the top bit has weight -2^(n-1). Negate by inverting and adding 1: -49 = 11001111.صيغة two's complement: [-2^(n-1), 2^(n-1) - 1]، أي [-128, 127] و INT4 [-8, 7]. صفر واحد فقط، والبت الأعلى وزنه -2^(n-1). نحصل على السالب بقلب البتات ثم إضافة 1: -49 = 11001111.
Fixed point is an integer plus a fixed power-of-two scale: 0011.0001 = 49 x 2^-4 = 3.0625. With 4 fraction bits the resolution is 0.0625 and the 8-bit range is [-8, 7.9375].الـ fixed point هو عدد صحيح مع مقياس (scale) ثابت من قوى اثنين: 0011.0001 = 49 x 2^-4 = 3.0625. مع 4 بتات كسرية تكون الدقة 0.0625 ويكون نطاق الصيغة ذات 8 بتات [-8, 7.9375].
Fixed point is linear quantization with S = 2^-4 and Z = 0. Lecture 05-2 frees S to be any real number and adds a zero point Z.الـ fixed point هو linear quantization بقيمتي S = 2^-4 و Z = 0. المحاضرة 05-2 تحرر S لتصبح أي عدد حقيقي وتضيف zero point هو Z.
Part 02: IEEE 754 FP32: normals, subnormals, zero, infinity and NaNIEEE 754 FP32: القيم العادية وتحت العادية والصفر واللانهاية وNaN
How a 32-bit float splits into sign, 8-bit biased exponent and 23-bit fraction, how to encode a value, why zero and subnormals need a special rule, the smallest and largest representable values, and the exponent-255 codes for infinity and NaN.كيف ينقسم العدد العائم ذو 32 بت إلى إشارة وأس منحاز (biased exponent) من 8 بت وكسر من 23 بت، وكيف نرمّز قيمة، ولماذا يحتاج الصفر والقيم تحت العادية (subnormals) قاعدة خاصة، وأصغر وأكبر القيم القابلة للتمثيل، ورموز الأس 255 للانهاية وNaN.
4 concepts4 مفاهيم, ، slides 7-15الشرائح 7-15
Why this part mattersلماذا يهمّ هذا الجزء
Every weight in an unquantized network is a 32-bit float. Before you can judge what is lost when you squeeze that weight into 16, 8 or 4 bits, you need to know exactly what the 32 bits were buying. This part takes the FP32 format apart field by field.
The thread runs in four steps. First, how sign, exponent and fraction combine into a value, with a full encoding of 0.265625. Second, why that rule cannot express zero, and the special exponent-0 rule that fixes it. Third, the extreme values at the bottom of the range, which are favourite exam fill-ins. Fourth, the all-ones exponent for infinity and NaN, and the complete map of the format. Every later format in this lecture (FP16, BF16, FP8, FP4) reuses this exact machinery with different field widths, so time spent here pays off three times over.
كل وزن (weight) في شبكة غير مكمَّمة هو عدد عشري (float) من 32 bit. قبل أن تحكم على ما يضيع عندما تضغط هذا الوزن في 16 أو 8 أو 4 bits، عليك أن تعرف بالضبط ما الذي كانت تشتريه الـ 32 bit. هذا الجزء يفكّك صيغة FP32 حقلًا حقلًا.
يسير الخيط في أربع خطوات. أولًا، كيف تجتمع الإشارة (sign) والأس (exponent) والكسر (fraction) لتكوين قيمة، مع ترميز كامل للعدد 0.265625. ثانيًا، لماذا لا تستطيع تلك القاعدة التعبير عن الصفر، والقاعدة الخاصة بالأس 0 التي تحل المشكلة. ثالثًا، القيم القصوى في أسفل المدى، وهي من أسئلة الإكمال المفضلة في الامتحانات. رابعًا، الأس المكوّن من آحاد فقط (all-ones) الخاص بـ infinity وNaN، والخريطة الكاملة للصيغة. كل صيغة لاحقة في هذه المحاضرة (FP16 وBF16 وFP8 وFP4) تعيد استخدام الآلية نفسها تمامًا مع عروض حقول مختلفة، لذلك فإن الوقت الذي تقضيه هنا يعود عليك ثلاثة أضعاف.
By the end you canفي نهاية هذا الجزء ستستطيع
01Split a 32-bit word into sign, 8-bit biased exponent and 23-bit fraction, and state the bias 127 = 2^(8-1) - 1.تقسّم كلمة من 32 bit إلى sign وexponent متحيّز (biased) من 8 bits وfraction من 23 bit، وتذكر أن الـ bias يساوي 127 = 2^(8-1) - 1.
02Encode a decimal value such as 0.265625 or -6.5 into FP32 bits, and decode bits back to a value.تحوّل قيمة عشرية مثل 0.265625 أو -6.5 إلى bits بصيغة FP32، وتفكّ bits وتعيدها إلى قيمة.
03Explain why zero cannot be a normal number and how the exponent-0 rule (subnormals) fixes it.تشرح لماذا لا يمكن تمثيل الصفر كعدد normal، وكيف تحل قاعدة exponent = 0 (أي subnormals) هذه المشكلة.
04Derive the smallest and largest subnormal and the smallest and largest normal, and justify the forced exponent 1 - 127.تشتق أصغر وأكبر subnormal وأصغر وأكبر normal، وتبرّر لماذا يُفرض الأس 1 - 127.
05Read the exponent-class table: 00h, 01h to FEh and FFh, each with fraction zero or nonzero.تقرأ جدول أصناف الـ exponent: 00h، ومن 01h إلى FEh، وFFh، وكل منها مع fraction يساوي صفرًا أو لا يساوي صفرًا.
Take the number 0.265625. In binary it is 0.010001₂, because 0.25 + 0.015625 = 0.265625. Slide the binary point two places to the right and you get 1.0001₂ × 2⁻². That is scientific notation in base 2, and it is all a float stores: a sign, a power of two, and the digits after the leading 1.
خذ العدد 0.265625. في النظام الثنائي هو 0.010001₂، لأن 0.25 + 0.015625 = 0.265625. حرّك الفاصلة الثنائية خانتين إلى اليمين فتحصل على 1.0001₂ × 2⁻². هذا هو الترميز العلمي (scientific notation) بالأساس 2، وهو كل ما يخزّنه الـ float: إشارة، وقوة للعدد 2، والأرقام التي تأتي بعد الـ 1 الأول.
Three fields, one formulaثلاثة حقول، ومعادلة واحدة
A Floating-point number number in the IEEE 754 single precision format splits 32 bits into three fields. Bit 31 is the sign s. Bits 30 to 23 hold an 8-bit exponent field E, read as an unsigned integer from 0 to 255. Bits 22 to 0 hold the 23-bit Fraction (mantissa, significand), read as the binary digits after the point, so its value lies in [0,1−2−23]. For ordinary numbers the value is
عدد floating-point بصيغة الدقة الأحادية (single precision) في معيار IEEE 754 يقسّم الـ 32 bit إلى ثلاثة حقول. الـ bit رقم 31 هو الإشارة s. الـ bits من 30 إلى 23 تحمل حقل أس (exponent) من 8 bits هو E، ويُقرأ كعدد صحيح بلا إشارة (unsigned) من 0 إلى 255. والـ bits من 22 إلى 0 تحمل الـ fraction (mantissa) المكوّن من 23 bit، ويُقرأ على أنه الأرقام الثنائية بعد الفاصلة، لذلك تقع قيمته في [0,1−2−23]. وللأعداد العادية تكون القيمة
x=(−1)sign×(1+Fraction)×2Exponent−127
FP32 normal numbers: Exponent field from 1 to 254أعداد FP32 الطبيعية (normal): حقل الأس من 1 إلى 254
Two design choices hide in that formula. The first is the Exponent bias. The field is unsigned, but real exponents must go negative to reach small numbers. Rather than spend a sign bit, IEEE stores E=e+127, where e is the true exponent. The bias is 28−1−1=127, the middle of the 8-bit range, so true exponents from -126 to +127 fit in stored values 1 to 254. A side effect worth knowing: because bigger exponents are bigger unsigned integers, positive floats sort in the same order as their bit patterns.
في تلك المعادلة قراران تصميميان مخفيّان. الأول هو exponent bias. الحقل بلا إشارة (unsigned)، لكن الأسس الحقيقية يجب أن تصبح سالبة لكي نصل إلى الأعداد الصغيرة. وبدلًا من إنفاق bit للإشارة، يخزّن IEEE القيمة E=e+127، حيث e هو الأس الحقيقي. والـ bias يساوي 28−1−1=127، أي منتصف مدى الـ 8 bits، لذلك تتسع الأسس الحقيقية من -126 إلى +127 في القيم المخزَّنة من 1 إلى 254. وهناك أثر جانبي يستحق المعرفة: لأن الأسس الأكبر تكون أعدادًا صحيحة بلا إشارة أكبر، فإن الأعداد العشرية الموجبة تُرتَّب بالترتيب نفسه الذي تُرتَّب به أنماط الـ bits الخاصة بها.
The second choice is the hidden bit. Any nonzero binary number can be shifted until it reads 1.something, so the leading 1 carries no information. FP32 does not store it, which buys one extra bit of precision for free: 23 stored fraction bits give a 24-bit significand.
القرار الثاني هو الـ bit المخفي (hidden bit). أي عدد ثنائي غير صفري يمكن إزاحته حتى يصبح على الشكل 1.something، لذلك فإن الـ 1 الأول لا يحمل أي معلومة. صيغة FP32 لا تخزّنه، وهذا يمنحها bit إضافيًا من الدقة مجانًا: 23 bit مخزَّنة في الـ fraction تعطي significand من 24 bit.
Worked exampleمثال محلول
Encode 0.265625 (slide 7)ترميز العدد 0.265625 (الشريحة 7)
Convert to binaryالتحويل إلى النظام الثنائي
0.265625 × 2 = 0.53125 gives digit 0, × 2 = 1.0625 gives 1, then 0, 0, 0, and 0.5 × 2 = 1.0 gives the final 1. So 0.265625 = 0.010001₂.
0.265625 × 2 = 0.53125 يعطي الرقم 0، ثم × 2 = 1.0625 يعطي 1، ثم 0 و0 و0، وأخيرًا 0.5 × 2 = 1.0 يعطي الـ 1 الأخير. إذن 0.265625 = 0.010001₂.
Normalizeالتطبيع (Normalize)
Move the point to just after the first 1: 0.010001₂ = 1.0001₂ × 2⁻². True exponent e=−2.
انقل الفاصلة إلى ما بعد أول 1 مباشرة: 0.010001₂ = 1.0001₂ × 2⁻². الأس الحقيقي e=−2.
Bias the exponentإضافة الـ bias إلى الأس
E=−2+127=125=011111012.
E=−2+127=125=011111012.
Read off sign and fractionاستخراج الإشارة والـ fraction
Positive, so S=0. The digits after the point are 0001, padded with zeros to 23 bits: 00010000000000000000000, worth 2−4=0.0625.
العدد موجب، إذن S=0. الأرقام بعد الفاصلة هي 0001، ونكملها بأصفار حتى 23 bit: 00010000000000000000000، وقيمتها 2−4=0.0625.
Resultالنتيجة
0 01111101 00010000000000000000000, which is 0x3E880000. Check: (1+0.0625)×2125−127=1.0625×0.25=0.265625.
0 01111101 00010000000000000000000، أي 0x3E880000. للتحقق: (1+0.0625)×2125−127=1.0625×0.25=0.265625.
Recall
Decode 0 01111101 00010000000000000000000 back to a decimal value without looking at the example.فكّ النمط 0 01111101 00010000000000000000000 وأعده إلى قيمة عشرية دون النظر إلى المثال.
Sign 0, so positive. Exponent field 01111101 = 125, not 0 and not 255, so the number is normal and the true exponent is 125 - 127 = -2. The fraction has only the 4th bit set, worth 2⁻⁴ = 0.0625. Value (1 + 0.0625) × 2⁻² = 0.265625.
الإشارة 0، إذن العدد موجب. حقل الأس 01111101 = 125، وهو ليس 0 وليس 255، لذلك العدد normal والأس الحقيقي هو 125 - 127 = -2. في الـ fraction لا يوجد إلا الـ bit الرابع مضبوطًا على 1، وقيمته 2⁻⁴ = 0.0625. القيمة (1 + 0.0625) × 2⁻² = 0.265625.
Worked exampleمثال محلول
Practice: encode -6.5تمرين: ترميز العدد -6.5
Binary and normalizeالتحويل الثنائي والتطبيع
6.5 = 110.1₂ = 1.101₂ × 2², so e=2.
6.5 = 110.1₂ = 1.101₂ × 2²، إذن e=2.
Fieldsالحقول
Negative, so S=1. E=2+127=129=100000012. Fraction digits 101 then zeros, worth 0.5 + 0.125 = 0.625.
العدد سالب، إذن S=1. E=2+127=129=100000012. أرقام الـ fraction هي 101 ثم أصفار، وقيمتها 0.5 + 0.125 = 0.625.
Try it yourself. Load the 0.265625 and -6.5 presets in the explorer below, then flip single bits and watch which readout moves. Flipping the lowest exponent bit doubles or halves the value; flipping the lowest fraction bit barely moves it.
جرّب بنفسك. حمّل الإعدادين المسبقين 0.265625 و-6.5 في المستكشف أدناه، ثم اقلب bits منفردة وراقب أي قراءة تتغير. قلب أدنى bit في الأس يضاعف القيمة أو ينصّفها؛ أما قلب أدنى bit في الـ fraction فبالكاد يحرّكها.
ExplorerمستكشفClick any bit of an FP32 wordانقر أي بت في كلمة FP32
0 01111101 00010000000000000000000 = 0x3E880000
sign0positiveموجب
stored exponent12501111101
unbiased exponent-2stored minus 127القيمة المخزنة ناقص 127
significand1 + 0.0625hidden bit plus fractionالبت المخفي مضافا إليه الكسر
Slide 8 asks: how should we represent 0 with the formula (-1)^sign x (1 + Fraction) x 2^(Exponent - 127)? Try before revealing.تسأل الشريحة 8: كيف نمثّل 0 بالمعادلة (-1)^sign x (1 + Fraction) x 2^(Exponent - 127)؟ حاول قبل كشف الإجابة.
You cannot. 1 + Fraction is at least 1, and 2^(Exponent - 127) is never 0, so the product is never 0. Setting every bit to 0 gives 1 × 2⁻¹²⁷, a tiny number but not zero. The format needs a separate rule.
لا يمكنك ذلك. 1 + Fraction لا يقل عن 1، و2^(Exponent - 127) لا يساوي 0 أبدًا، لذلك فإن حاصل الضرب لا يساوي 0 أبدًا. وجعل كل الـ bits أصفارًا يعطي 1 × 2⁻¹²⁷، وهو عدد صغير جدًا لكنه ليس صفرًا. تحتاج الصيغة إلى قاعدة منفصلة.
The hidden bit that bought free precision has a price: every normal number starts with 1, so the smallest magnitude the normal rule can reach is 1.0 × 2⁻¹²⁶, about 1.18 × 10⁻³⁸. Zero, and everything between zero and that floor, is out of reach.
الـ bit المخفي الذي منحنا دقة مجانية له ثمن: كل عدد normal يبدأ بـ 1، لذلك فإن أصغر مقدار تستطيع قاعدة الـ normal الوصول إليه هو 1.0 × 2⁻¹²⁶، أي نحو 1.18 × 10⁻³⁸. الصفر، وكل ما بين الصفر وذلك الحد الأدنى، خارج متناولها.
The exponent-0 ruleقاعدة الأس 0
IEEE reserves the exponent field 00000000 for a second rule. When the stored exponent is 0, the hidden bit becomes 0 instead of 1, and the scale is fixed at 21−127:
يحجز IEEE حقل الأس 00000000 لقاعدة ثانية. عندما يكون الأس المخزَّن 0، يصبح الـ bit المخفي 0 بدلًا من 1، ويُثبَّت المقياس عند 21−127:
FP32 subnormal numbers: Exponent field = 0أعداد FP32 دون الطبيعية (subnormal): حقل الأس = 0
Values produced this way are subnormal numbers (older texts say denormals). Everything with exponent field 1 to 254 is a Normal number. With fraction 0 the subnormal rule gives exactly 0×2−126=0. Since the sign bit is still free, there are two zeros: 0 00000000 000...0 is +0 and 1 00000000 000...0 is -0. They compare equal, but 1 / +0 = +∞ while 1 / -0 = -∞, so the sign is not cosmetic. You met the same two-zero situation in Sign-magnitude integers, and for the same reason: a separate sign bit.
القيم الناتجة بهذه الطريقة هي subnormal numbers (وتسميها المراجع الأقدم denormals). وكل ما حقل أسه من 1 إلى 254 هو normal number. ومع fraction يساوي 0 تعطي قاعدة الـ subnormal بالضبط 0×2−126=0. وبما أن bit الإشارة ما زال حرًا، يوجد صفران: 0 00000000 000...0 هو +0 و1 00000000 000...0 هو -0. هما متساويان عند المقارنة، لكن 1 / +0 = +∞ بينما 1 / -0 = -∞، لذلك فالإشارة ليست شكلية. لقد قابلت حالة الصفرين نفسها في الأعداد الصحيحة بتمثيل sign-magnitude، وللسبب نفسه: bit إشارة منفصل.
Why 1 - 127 and not 0 - 127لماذا 1 - 127 وليس 0 - 127
The slide says the exponent “should have been” 0 - 127, “but we force” it to 1 - 127. The reason is continuity. The smallest normal number is 2⁻¹²⁶, and normals in the first binade [2⁻¹²⁶, 2⁻¹²⁵) are spaced 2−23×2−126=2−149 apart. With the forced scale 2⁻¹²⁶, subnormals are k×2−149 for k=0,1,…,223−1: the same step, ending one step below 2⁻¹²⁶. The grid runs straight from 0 into the normals without a seam.
تقول الشريحة إن الأس “كان يجب أن يكون” 0 - 127، “لكننا نفرض” أن يكون 1 - 127. السبب هو الاستمرارية. أصغر عدد normal هو 2⁻¹²⁶، والأعداد normal في أول binade [2⁻¹²⁶, 2⁻¹²⁵) تفصل بينها مسافة 2−23×2−126=2−149. ومع المقياس المفروض 2⁻¹²⁶ تكون الـ subnormals هي k×2−149 حيث k=0,1,…,223−1: الخطوة نفسها، وتنتهي قبل 2⁻¹²⁶ بخطوة واحدة. فتمتد الشبكة مباشرة من 0 إلى الأعداد normal دون أي فاصل.
Had IEEE used 2⁻¹²⁷, subnormals would be spaced 2⁻¹⁵⁰ and stop just below 2⁻¹²⁷. The whole interval from 2⁻¹²⁷ to 2⁻¹²⁶ would contain no representable numbers at all, and the spacing would jump by a factor of 2 at the boundary.
لو استخدم IEEE المقياس 2⁻¹²⁷، لكانت المسافة بين الـ subnormals 2⁻¹⁵⁰ ولتوقفت قبل 2⁻¹²⁷ بقليل. ولأصبحت الفترة كاملة من 2⁻¹²⁷ إلى 2⁻¹²⁶ خالية تمامًا من أي عدد قابل للتمثيل، ولقفزت المسافة بين الأعداد بمعامل 2 عند الحد الفاصل.
Forced scale 2^(1-127): subnormal steps continue straight into the first normal binade. Naive 2^(0-127): half the interval is left emptyالمقياس المفروض 2^(1-127): خطوات الـ subnormals تستمر مباشرة في أول binade من الأعداد normal. أما المقياس الساذج 2^(0-127): فيترك نصف الفترة فارغًا
Quick checkاختبار سريع
Why does an FP32 subnormal use the scale 2^(1 - 127) rather than 2^(0 - 127)?لماذا يستخدم الـ subnormal في FP32 المقياس 2^(1 - 127) بدلًا من 2^(0 - 127)؟
Slide 10 asks: what is the smallest positive subnormal value? Write the bit pattern and the value.تسأل الشريحة 10: ما أصغر قيمة subnormal موجبة؟ اكتب نمط الـ bits والقيمة.
Exponent 0, fraction with only the last bit set: 0 00000000 00000000000000000000001. Fraction = 2⁻²³, so the value is 2⁻²³ × 2⁻¹²⁶ = 2⁻¹⁴⁹, about 1.4 × 10⁻⁴⁵.
الأس 0، والـ fraction لا يحوي إلا الـ bit الأخير مضبوطًا: 0 00000000 00000000000000000000001. الـ Fraction = 2⁻²³، إذن القيمة هي 2⁻²³ × 2⁻¹²⁶ = 2⁻¹⁴⁹، أي نحو 1.4 × 10⁻⁴⁵.
Compare that with the smallest normal, 0 00000001 000...0. Its exponent field is 1, its fraction is 0, so it equals (1+0)×21−127=2−126. The subnormals stretch the bottom of the range by another 23 powers of two, from 2⁻¹²⁶ down to 2⁻¹⁴⁹, one power per fraction bit.
قارن ذلك بأصغر عدد normal، وهو 0 00000001 000...0. حقل أسه 1 والـ fraction فيه 0، لذلك يساوي (1+0)×21−127=2−126. الـ subnormals تمد أسفل المدى بـ 23 قوة أخرى للعدد 2، من 2⁻¹²⁶ نزولًا إلى 2⁻¹⁴⁹، قوة واحدة لكل bit في الـ fraction.
Notice what both patterns have in common: exponent field 1 for the normal and exponent field 0 for the subnormal both mean a true exponent of -126. That is the forced 1 - 127 at work. The only difference between the two cases is the hidden bit.
لاحظ القاسم المشترك بين النمطين: حقل الأس 1 في الـ normal وحقل الأس 0 في الـ subnormal كلاهما يعني أسًا حقيقيًا قدره -126. هذا هو أثر الأس المفروض 1 - 127. والفرق الوحيد بين الحالتين هو الـ bit المخفي.
Recall
Slide 12 asks: what is the largest positive subnormal value? Derive it before revealing.تسأل الشريحة 12: ما أكبر قيمة subnormal موجبة؟ اشتقها قبل كشف الإجابة.
Exponent 0, fraction all ones: 0 00000000 11111111111111111111111. Fraction = 2⁻¹ + 2⁻² + … + 2⁻²³ = 1 - 2⁻²³. Value (1 - 2⁻²³) × 2⁻¹²⁶ = 2⁻¹²⁶ - 2⁻¹⁴⁹, exactly one step of 2⁻¹⁴⁹ below the smallest normal.
الأس 0، والـ fraction كله آحاد: 0 00000000 11111111111111111111111. الـ Fraction = 2⁻¹ + 2⁻² + … + 2⁻²³ = 1 - 2⁻²³. القيمة (1 - 2⁻²³) × 2⁻¹²⁶ = 2⁻¹²⁶ - 2⁻¹⁴⁹، أي أقل من أصغر عدد normal بخطوة واحدة بالضبط مقدارها 2⁻¹⁴⁹.
The geometric sum is the step to remember: a run of n ones after the binary point equals 1−2−n, just as 0.999 is 1 - 10⁻³ in decimal. Apply it to the top of the range and you get the largest normal. Exponent field 11111110 = 254 (255 is reserved) and fraction all ones give
المجموع الهندسي هو الخطوة التي يجب تذكرها: سلسلة من n آحاد بعد الفاصلة الثنائية تساوي 1−2−n، تمامًا كما أن 0.999 تساوي 1 - 10⁻³ في النظام العشري. طبّقها على أعلى المدى فتحصل على أكبر عدد normal. حقل الأس 11111110 = 254 (لأن 255 محجوز) مع fraction كله آحاد يعطيان
(1+1−2−23)×2254−127=(2−2−23)×2127≈3.4×1038
Largest FP32 normal, bit pattern 0x7F7FFFFFأكبر عدد FP32 طبيعي، بنمط البتات 0x7F7FFFFF
FP32 values to know coldقيم FP32 التي يجب أن تحفظها جيدًا
smallest subnormalأصغر subnormal
0 00000000 000...01 = 2−23×2−126=2−149, about 1.4 × 10⁻⁴⁵0 00000000 000...01 = 2−23×2−126=2−149، أي نحو 1.4 × 10⁻⁴⁵
Divide 1.0 by +0, or multiply 3 × 10³⁸ by 10. The true answer is beyond the largest normal, and the hardware still has to return 32 bits. Compute 0 / 0 or √-1 and there is no real answer at all. The all-ones exponent is reserved for exactly these cases.
اقسم 1.0 على +0، أو اضرب 3 × 10³⁸ في 10. الإجابة الحقيقية تتجاوز أكبر عدد normal، ومع ذلك يجب على العتاد أن يعيد 32 bit. واحسب 0 / 0 أو √-1 فلا توجد إجابة حقيقية أصلًا. الأس المكوّن من آحاد فقط محجوز لهذه الحالات بالضبط.
Exponent 255: infinity and NaNالأس 255: اللانهاية (infinity) وNaN
When the exponent field is 11111111 (FFh = 255), the bits no longer encode a number through either formula. With fraction 0 the pattern is infinity: 0 11111111 000...0 is +∞ (0x7F800000) and 1 11111111 000...0 is -∞. With any nonzero fraction it is NaN, “not a number”, and the sign bit is a don’t care, which is why slide 14 draws it as a dash. NaN propagates: any arithmetic with a NaN input yields NaN, so a single bad value in a training run poisons the loss rather than silently turning into a plausible number.
عندما يكون حقل الأس 11111111 (FFh = 255)، لا تعود الـ bits ترمّز عددًا عبر أي من المعادلتين. مع fraction يساوي 0 يكون النمط لانهاية (infinity): 0 11111111 000...0 هو +∞ (0x7F800000) و1 11111111 000...0 هو -∞. ومع أي fraction غير صفري يكون NaN، أي “ليس عددًا” (not a number)، ويكون bit الإشارة غير مهم (don’t care)، ولهذا ترسمه الشريحة 14 على شكل شرطة. وNaN ينتشر: أي عملية حسابية أحد مدخلاتها NaN تعطي NaN، لذلك فإن قيمة واحدة فاسدة أثناء التدريب تُفسد الـ loss بدلًا من أن تتحول بصمت إلى عدد يبدو معقولًا.
The slide’s remark “much waste” is a counting argument. Every nonzero 23-bit fraction is a NaN, so there are 223−1 NaN patterns per sign, 2²⁴ - 2 in total, about 16.8 million codes that name no number. In 32 bits that is under 0.4% of all patterns and nobody minds. In an 8-bit format the same rule would burn a whole exponent row out of only 256 codes, which is why FP8 E4M3 drops infinity and keeps a single NaN mantissa (you will see this in the next part).
ملاحظة الشريحة “much waste” (هدر كبير) هي حجة عدّ. كل fraction غير صفري من 23 bit هو NaN، لذلك يوجد 223−1 نمطًا لـ NaN لكل إشارة، أي 2²⁴ - 2 إجمالًا، وهي نحو 16.8 مليون رمز لا تسمّي أي عدد. في 32 bit يمثل ذلك أقل من 0.4% من كل الأنماط ولا أحد يهتم. أما في صيغة من 8 bits فإن القاعدة نفسها ستحرق صفًا كاملًا من الأس من بين 256 رمزًا فقط، ولهذا تتخلى FP8 E4M3 عن infinity وتحتفظ بـ mantissa واحد فقط لـ NaN (سترى ذلك في الجزء التالي).
The whole format in one tableالصيغة كاملة في جدول واحد
FP32 classes by exponent field and fraction (slide 15)أصناف FP32 بحسب حقل الأس والـ fraction (الشريحة 15)
Read the table as a decision procedure. First look at the exponent field. If it is 0, apply the subnormal formula (and fraction 0 gives a signed zero). If it is 255, the answer is infinity or NaN depending on the fraction. Anything else is normal. Every one of the 2³² bit patterns lands in exactly one cell.
اقرأ الجدول كإجراء لاتخاذ القرار. انظر أولًا إلى حقل الأس. إذا كان 0، فطبّق معادلة الـ subnormal (والـ fraction الذي يساوي 0 يعطي صفرًا بإشارة). وإذا كان 255، فالإجابة infinity أو NaN بحسب الـ fraction. وأي قيمة أخرى تعني normal. وكل نمط من الـ 2³² نمطًا يقع في خلية واحدة بالضبط.
Where the values sit on the number lineأين تقع القيم على خط الأعداد
The bottom of slide 15 places the classes on the positive axis. Subnormals fill [0, 2⁻¹²⁶) with a uniform step of 2⁻¹⁴⁹: in that stretch FP32 behaves like a fixed-point format. From 2⁻¹²⁶ upward the normals take over, and each binade [2^e, 2^(e+1)) holds the same 2²³ values, so the absolute step doubles every time the exponent rises by one while the relative step stays about 2⁻²³. The line ends at (2 - 2⁻²³) × 2¹²⁷, after which comes only +∞.
يضع الجزء السفلي من الشريحة 15 الأصناف على المحور الموجب. الـ subnormals تملأ [0, 2⁻¹²⁶) بخطوة منتظمة قدرها 2⁻¹⁴⁹: في هذا الامتداد تتصرف FP32 مثل صيغة fixed-point. ومن 2⁻¹²⁶ فصاعدًا تتولى الأعداد normal الأمر، وكل binade [2^e, 2^(e+1)) يحوي العدد نفسه من القيم وهو 2²³، لذلك تتضاعف الخطوة المطلقة كلما زاد الأس بواحد، بينما تبقى الخطوة النسبية نحو 2⁻²³. وينتهي الخط عند (2 - 2⁻²³) × 2¹²⁷، ولا يأتي بعده إلا +∞.
Positive FP32 axis: evenly spaced subnormals, normals whose spacing doubles each binade, then infinityالمحور الموجب لصيغة FP32: subnormals متساوية المسافات، ثم أعداد normal تتضاعف المسافة بينها في كل binade، ثم اللانهاية
Recall
How many FP32 bit patterns are NaN, how many are infinities, and how many are zeros?كم نمطًا من أنماط bits في FP32 هو NaN، وكم منها infinity، وكم منها أصفار؟
NaN: exponent 255 with any of the 2²³ - 1 nonzero fractions, for both signs, so 2²⁴ - 2. Infinity: 2 (+∞ and -∞). Zero: 2 (+0 and -0).
NaN: الأس 255 مع أي من الـ 2²³ - 1 fraction غير الصفرية، وللإشارتين معًا، أي 2²⁴ - 2. Infinity: 2 (+∞ و-∞). الصفر: 2 (+0 و-0).
Quick checkاختبار سريع
An FP32 word has exponent field 11111111 and fraction 00000000000000000000001. What does it encode?كلمة FP32 حقل أسها 11111111 والـ fraction فيها 00000000000000000000001. ماذا ترمّز؟
Quick checkاختبار سريع
Decode 0 10000000 01000000000000000000000 into a decimal value.فكّ النمط 0 10000000 01000000000000000000000 إلى قيمة عشرية.
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
Normal (exponent 1 to 254): (-1)^sign x (1 + Fraction) x 2^(Exponent - 127). The leading 1 is implicit and not stored.العدد normal (الأس من 1 إلى 254): (-1)^sign x (1 + Fraction) x 2^(Exponent - 127). الـ 1 في البداية ضمني (implicit) ولا يُخزَّن.
Subnormal (exponent 0): (-1)^sign x Fraction x 2^(1 - 127) = (-1)^sign x Fraction x 2^-126. No implicit 1, so zero becomes encodable.العدد subnormal (الأس 0): (-1)^sign x Fraction x 2^(1 - 127) = (-1)^sign x Fraction x 2^-126. لا يوجد 1 ضمني، لذلك يصبح تمثيل الصفر ممكنًا.
The forced 1 - 127 keeps the step size 2^-149 on both sides of 2^-126, so subnormals meet normals with no gap.الأس المفروض 1 - 127 يُبقي حجم الخطوة 2^-149 على جانبي 2^-126، فتلتقي الـ subnormals بالـ normals بلا أي فجوة.
Smallest subnormal 2^-149; largest subnormal 2^-126 - 2^-149; smallest normal 2^-126; largest normal (2 - 2^-23) x 2^127, about 3.4 x 10^38.أصغر subnormal هو 2^-149؛ وأكبر subnormal هو 2^-126 - 2^-149؛ وأصغر normal هو 2^-126؛ وأكبر normal هو (2 - 2^-23) x 2^127، أي نحو 3.4 x 10^38.
Exponent 255: fraction 0 is plus or minus infinity, any other fraction is NaN, which spends 2^23 - 1 patterns per sign.الأس 255: إذا كان الـ fraction يساوي 0 فهو موجب أو سالب ما لا نهاية (infinity)، وأي fraction آخر هو NaN، وهذا يستهلك 2^23 - 1 نمطًا لكل إشارة.
Zero has two encodings, +0 and -0, both with exponent 0 and fraction 0.للصفر تمثيلان، +0 و-0، وكلاهما بأس 0 وfraction يساوي 0.
Part 03: FP16, BF16, FP8 and FP4: trading range for precisionFP16 وBF16 وFP8 وFP4: مقايضة المدى بالدقة
Exponent width sets range and fraction width sets precision. Compares FP32, FP16 and BF16, works the two conversion examples, then FP8 (E4M3 and E5M2) and the four-bit formats INT4, E1M2, E2M1 and E3M0.عرض الأس يحدد المدى وعرض الكسر يحدد الدقة. يقارن FP32 وFP16 وBF16، ويحل مثالي التحويل، ثم FP8 (E4M3 وE5M2) والصيغ ذات الأربع بتات INT4 وE1M2 وE2M1 وE3M0.
4 concepts4 مفاهيم, ، slides 16-20الشرائح 16-20
Why this part mattersلماذا يهمّ هذا الجزء
Part 2 took FP32 apart. This part shrinks it. Every format here keeps the same recipe of sign, biased exponent and fraction, and only changes how many bits each field gets. Once you see that the exponent field buys range and the fraction field buys precision, every format from 32 bits down to 4 becomes a single design decision you can reason about.
This matters well beyond the exam. Mixed precision training on GPUs and TPUs runs in FP16 or BF16, the newest accelerators train and serve large models in FP8, and FP4 is now a real deployment format for weights. For the midterm, expect three kinds of questions: decode a bit pattern, encode a decimal, and justify which format suits which tensor. All three are worked below.
فكّك الجزء الثاني صيغة FP32، وهذا الجزء يصغّرها. كل صيغة هنا تحتفظ بالوصفة نفسها: بت إشارة، وأس مُزاح (biased exponent)، وكسر (fraction)، ولا يتغير سوى عدد البتات المخصص لكل حقل. حين ترى أن حقل الأس يشتري المدى (range) وأن حقل الكسر يشتري الدقة (precision)، تصبح كل صيغة من 32 بتًا نزولًا إلى 4 بتات قرار تصميم واحدًا تستطيع التفكير فيه.
أهمية هذا تتجاوز الامتحان بكثير. التدريب بالدقة المختلطة (mixed precision training) على وحداتGPU وTPU يعمل بصيغة FP16 أو BF16، وأحدث المسرّعات تدرّب النماذج الكبيرة وتخدمها بصيغة FP8، وأصبحت FP4 صيغة نشر حقيقية للأوزان. في امتحان منتصف الفصل توقّع ثلاثة أنواع من الأسئلة: فك ترميز نمط بتات، وترميز رقم عشري، وتبرير أي صيغة تناسب أي موتّر (tensor). الأنواع الثلاثة محلولة بالتفصيل أدناه.
By the end you canفي نهاية هذا الجزء ستستطيع
01State the rule: exponent width sets range, fraction width sets precision, and use it to rank any float format.تذكر القاعدة: عرض الأس (exponent) يحدد المدى (range)، وعرض الكسر (fraction) يحدد الدقة (precision)، وتستخدمها لترتيب أي صيغة فاصلة عائمة.
02Recall the sign, exponent and fraction widths and the bias of FP32, FP16, BF16, FP8 E4M3 and FP8 E5M2.تتذكر عرض حقول الإشارة والأس والكسر وقيمة الإزاحة (bias) في FP32 وFP16 وBF16 وFP8 E4M3 وFP8 E5M2.
03Decode an FP16 bit pattern to decimal and encode a decimal into BF16 by hand.تفك ترميز نمط بتات FP16 إلى رقم عشري، وترمّز رقمًا عشريًا في BF16 يدويًا.
04Compute the largest normal, smallest normal and smallest subnormal of a format from its widths.تحسب أكبر قيمة عادية (normal) وأصغر قيمة عادية وأصغر قيمة دون عادية (subnormal) لأي صيغة انطلاقًا من عرض حقولها.
05Explain why BF16 is preferred for training, and why E4M3 serves the forward pass and E5M2 the gradients.تشرح لماذا تُفضَّل BF16 في التدريب، ولماذا تخدم E4M3 المرور الأمامي (forward pass) وتخدم E5M2 التدرجات (gradients).
06List the eight positive values of INT4, E1M2, E2M1 and E3M0, and spot the slide's E2M1 mistake.تسرد القيم الموجبة الثماني في INT4 وE1M2 وE2M1 وE3M0، وتكتشف خطأ الشريحة في E2M1.
Try storing 100,000 and 1000.5 in two different 16-bit formats. FP16 cannot hold 100,000 at all: its largest finite value is 65504, so the number overflows to infinity. BF16 stores it easily, rounding it to 99,840. Now flip the test. FP16 stores 1000.5 exactly (its steps near 1000 are 0.5 wide), while BF16 rounds it to 1000 because its steps near 1000 are a full 4 wide. Same 16 bits, opposite strengths.
جرّب تخزين 100,000 و1000.5 في صيغتين مختلفتين بطول 16 بتًا. لا تستطيعFP16 أن تحمل 100,000 أصلًا: أكبر قيمة منتهية فيها هي 65504، فيتجاوز الرقم المدى (overflow) ويصبح ما لا نهاية. أما BF16 فتخزنه بسهولة وتقرّبه إلى 99,840. الآن اعكس الاختبار. تخزن FP16 القيمة 1000.5 بدقة تامة (خطواتها قرب 1000 عرضها 0.5)، بينما تقرّبها BF16 إلى 1000 لأن خطواتها قرب 1000 عرضها 4 كاملة. البتات نفسها، 16 بتًا، ونقاط القوة متعاكسة.
The rule on the slideالقاعدة في الشريحة
Every Floating-point number number is stored the way Part 2 showed for FP32: a sign bit, an exponent field with a bias, and a fraction. A normal value is
كل رقم floating-point يُخزَّن بالطريقة التي عرضها الجزء الثاني لصيغة FP32: بت إشارة، وحقل أس مع إزاحة (bias)، وكسر. والقيمة العادية (normal) هي
v=(−1)S×(1.f)2×2E−bias,bias=2e−1−1
Normal value of any IEEE-style format with e exponent bitsالقيمة الطبيعية لأي صيغة على نمط IEEE ذات e بت للأس
The exponent picks which power of two the number lives near, so more exponent bits reach more powers of two: that is range. The fraction picks a position between two neighbouring powers of two, so more fraction bits slice that interval finer: that is precision. This is the slide headline, Range vs precision: exponent width gives range, fraction width gives precision.
يختار الأس قوة العدد 2 التي يقع الرقم قربها، لذلك تصل بتات الأس الإضافية إلى قوى أكثر للعدد 2: وهذا هو المدى (range). ويختار الكسر موضعًا بين قوتين متجاورتين للعدد 2، لذلك تقسّم بتات الكسر الإضافية هذه الفترة إلى شرائح أدق: وهذه هي الدقة (precision). هذا هو عنوان الشريحة، range vs precision: عرض الأس يعطي المدى، وعرض الكسر يعطي الدقة.
Five layouts drawn to scale: teal sign, bright exponent, faint fraction. The dashed line marks where an 8-bit exponent endsخمسة تخطيطات مرسومة بمقياس حقيقي: الإشارة بلون أخضر مزرق، والأس بلون ساطع، والكسر بلون باهت. الخط المتقطع يحدد أين ينتهي أس من 8 بتات
FP16 and BF16 spend the same 16 bits differentlyصيغتا FP16 وBF16 تنفقان البتات الـ16 نفسها بطريقتين مختلفتين
FP16, the IEEE 754 half precision format, keeps 5 exponent bits and 10 fraction bits with bias 15. BF16 (Brain Float), designed at Google for TPUs, keeps all 8 of FP32’s exponent bits with bias 127 and only 7 fraction bits. The Exponent bias follows the same formula everywhere, 2^(e-1) - 1, so you never need to memorize it: e = 5 gives 15, e = 8 gives 127.
صيغة FP16، وهي صيغة نصف الدقة (half precision) في IEEE 754، تحتفظ بـ5 بتات للأس و10 بتات للكسر مع إزاحة 15. أما BF16، التي صممتها Google لوحدات TPU، فتحتفظ ببتات الأس الثماني كلها من FP32 مع إزاحة 127، و7 بتات فقط للكسر. وتتبع exponent bias الصيغة نفسها في كل مكان، 2^(e-1) - 1، فلا تحتاج إلى حفظها: e = 5 تعطي 15، وe = 8 تعطي 127.
FP32FP32
FP16FP16
BF16BF16
Sign / exponent / fractionالإشارة / الأس / الكسر
1 / 8 / 231 / 8 / 23
1 / 5 / 101 / 5 / 10
1 / 8 / 71 / 8 / 7
Biasالإزاحة (bias)
127127
1515
127127
Largest normalأكبر قيمة عادية
≈ 3.40 × 10^38≈ 3.40 × 10^38
6550465504
≈ 3.39 × 10^38≈ 3.39 × 10^38
Smallest normalأصغر قيمة عادية
2^-126 ≈ 1.18 × 10^-382^-126 ≈ 1.18 × 10^-38
2^-14 ≈ 6.10 × 10^-52^-14 ≈ 6.10 × 10^-5
2^-126 ≈ 1.18 × 10^-382^-126 ≈ 1.18 × 10^-38
Smallest subnormalأصغر قيمة دون عادية
2^-1492^-149
2^-24 ≈ 5.96 × 10^-82^-24 ≈ 5.96 × 10^-8
2^-1332^-133
Gap after 1.0 (2^-fraction bits)الفجوة بعد 1.0 (2^-عدد بتات الكسر)
2^-23 ≈ 1.2 × 10^-72^-23 ≈ 1.2 × 10^-7
2^-10 ≈ 0.000982^-10 ≈ 0.00098
2^-7 ≈ 0.00782^-7 ≈ 0.0078
Gap near 1000الفجوة قرب 1000
≈ 0.00006≈ 0.00006
0.50.5
44
The three formats on slide 16, with the numbers you can derive from themالصيغ الثلاث في الشريحة 16، مع الأرقام التي يمكنك اشتقاقها منها
The FP16 limits come straight from the widths. The largest exponent field that is not reserved is 11110 = 30, so the top power is 2^(30 - 15) = 2^15, and a full fraction of ten ones gives (2 - 2^-10) × 2^15 = 65504. The smallest normal uses exponent field 1: 2^(1 - 15) = 2^-14. The smallest Subnormal number puts a single 1 in the last fraction bit: 2^-10 × 2^-14 = 2^-24.
حدود FP16 تأتي مباشرة من عرض الحقول. أكبر قيمة لحقل الأس غير محجوزة هي 11110 = 30، فتكون أعلى قوة 2^(30 - 15) = 2^15، وكسر كامل من عشرة آحاد يعطي (2 - 2^-10) × 2^15 = 65504. أصغر قيمة عادية تستخدم حقل أس يساوي 1: 2^(1 - 15) = 2^-14. وأصغر subnormal number تضع 1 واحدًا في آخر بت من الكسر: 2^-10 × 2^-14 = 2^-24.
Worked exampleمثال محلول
FP16 range from the bit widthsمدى FP16 انطلاقًا من عرض البتات
Largest normalأكبر قيمة عادية
Exponent field 11110 (all ones is reserved for INF and NaN), fraction all ones: (1 + 1023/1024) × 2^15 = 65504.
حقل الأس 11110 (الآحاد كلها محجوزة لـINF وNaN)، والكسر كله آحاد: (1 + 1023/1024) × 2^15 = 65504.
FP16 spans roughly 6 × 10^-8 to 6.5 × 10^4. FP32 and BF16 span roughly 10^-38 to 3.4 × 10^38 for normals.
تمتد FP16 تقريبًا من 6 × 10^-8 إلى 6.5 × 10^4. أما FP32 وBF16 فتمتدان تقريبًا من 10^-38 إلى 3.4 × 10^38 للقيم العادية.
Why BF16 won for trainingلماذا فازت BF16 في التدريب
Training produces values with a huge dynamic range. Activations can be large, while many gradients are tiny, often below FP16’s 2^-24. NVIDIA reports that for the Multibox SSD detector, 31% of activation gradient values became zero when cast to FP16. The FP16 fix is loss scaling: multiply the loss by a large constant so the gradients shift up into FP16’s range, then divide the update back down, while watching for overflow. BF16 removes the problem at its root. Because its exponent is FP32’s exponent, every FP32 magnitude lands in a BF16 binade too (only a sliver just below FP32’s maximum can round up to infinity), and tiny gradients stay representable. Google describes BF16 as close to a drop-in replacement for FP32 with no loss scaling, and notes that networks are more sensitive to exponent size than to fraction size. The price is precision: about two to three significant decimal digits.
ينتج التدريب قيمًا ذات مدى ديناميكي هائل. قد تكون التنشيطات (activations) كبيرة، بينما كثير من التدرجات (gradients) صغير جدًا، وغالبًا أصغر من 2^-24 في FP16. تذكر NVIDIA أنه في كاشف Multibox SSD أصبحت 31% من قيم تدرجات التنشيط أصفارًا عند تحويلها إلى FP16. الحل في FP16 هو تحجيم الخسارة (loss scaling): تضرب الخسارة في ثابت كبير لترتفع التدرجات إلى داخل مدى FP16، ثم تقسم التحديث ليعود إلى حجمه، مع مراقبة تجاوز المدى (overflow). أما BF16 فتزيل المشكلة من جذورها. لأن أسّها هو أس FP32 نفسه، فكل مقدار في FP32 يقع أيضًا في binade من BF16 (باستثناء شريحة رفيعة تحت أكبر قيمة في FP32 مباشرة قد تُقرَّب إلى ما لا نهاية)، وتبقى التدرجات الصغيرة قابلة للتمثيل. تصف Google صيغة BF16 بأنها بديل شبه مباشر لـFP32 دون الحاجة إلى loss scaling، وتذكر أن الشبكات أكثر حساسية لحجم الأس منها لحجم الكسر. والثمن هو الدقة: نحو رقمين إلى ثلاثة أرقام عشرية معنوية.
BF16 is FP32 with the low 16 fraction bits rounded away. Sign and all 8 exponent bits survive unchangedصيغة BF16 هي FP32 بعد إزالة بتات الكسر الـ16 الدنيا بالتقريب. تبقى الإشارة وبتات الأس الثماني كلها دون تغيير
Recall
Without looking: what are the widths and bias of FP16 and of BF16, and which one can store 100,000?دون أن تنظر: ما عرض الحقول وقيمة الإزاحة في FP16 وفي BF16، وأيهما تستطيع تخزين 100,000؟
FP16 is 1/5/10 with bias 15; BF16 is 1/8/7 with bias 127. Only BF16 can store 100,000, because FP16 tops out at 65504.
FP16 هي 1/5/10 بإزاحة 15؛ وBF16 هي 1/8/7 بإزاحة 127. وحدها BF16 تستطيع تخزين 100,000، لأن أقصى قيمة في FP16 هي 65504.
Quick checkاختبار سريع
Why is BF16 usually preferred over FP16 for training neural networks?لماذا تُفضَّل BF16 عادةً على FP16 في تدريب الشبكات العصبية؟
Exams love two directions: “here are 16 bits, what number is it?” and “here is a number, what are the bits?” Both reuse the FP32 procedure from Part 2. Only the field widths and the bias change.
تحب الامتحانات اتجاهين: «هذه 16 بتًا، ما الرقم الذي تمثله؟» و«هذا رقم، ما بتاته؟» كلاهما يعيد استخدام إجراء FP32 من الجزء الثاني. لا يتغير سوى عرض الحقول وقيمة الإزاحة.
10001₂ = 16 + 1 = 17. It is neither 00000 nor 11111, so this is a Normal number. Unbiased exponent 17 - 15 = 2.
10001₂ = 16 + 1 = 17. ليس 00000 ولا 11111، إذن هذا normal number. الأس بعد إزالة الإزاحة 17 - 15 = 2.
Fractionالكسر
The Fraction (mantissa, significand) bits sit after the binary point: 0.11₂ = 1/2 + 1/4 = 0.75. Add the hidden leading one: 1.75.
بتات fraction (mantissa) تقع بعد الفاصلة الثنائية: 0.11₂ = 1/2 + 1/4 = 0.75. أضف الواحد المخفي في البداية: 1.75.
Combineاجمع النتيجة
-(1 + 0.75) × 2^2 = -1.75 × 4.
-(1 + 0.75) × 2^2 = -1.75 × 4.
Resultالنتيجة
-7.0
-7.0
Decimal to bits: BF16من العشري إلى البتات: BF16
Worked exampleمثال محلول
Encode 2.5 in BF16 (slide 18)ترميز 2.5 في BF16 (الشريحة 18)
Normalizeالتطبيع
Write the value as 1.f × 2^k: 2.5 = 1.25 × 2^1, so k = 1 and f = 0.25.
اكتب القيمة على الصورة 1.f × 2^k: 2.5 = 1.25 × 2^1، إذن k = 1 وf = 0.25.
Signالإشارة
Positive, so the sign bit is 0.
موجب، إذن بت الإشارة 0.
Exponent fieldحقل الأس
Add the bias: 1 + 127 = 128 = 10000000₂ (8 bits).
أضف الإزاحة: 1 + 127 = 128 = 10000000₂ (8 بتات).
Fraction fieldحقل الكسر
0.25 = 0.01₂, so the 7 fraction bits are 0100000.
0.25 = 0.01₂، إذن بتات الكسر السبع هي 0100000.
Resultالنتيجة
0 10000000 0100000, which is 0x4020.
0 10000000 0100000، أي 0x4020.
Compare this with FP32. In FP32, 2.5 is 0 10000000 01000000000000000000000, which is 0x40200000. The BF16 code is exactly the top 16 bits. That is the whole BF16 conversion story: keep the top half of an FP32 word and round the dropped half to nearest, ties to even. The exponent field is copied as is (rounding can only carry into it), which is why conversion from FP32 practically never overflows.
قارن هذا بـFP32. في FP32 تكون 2.5 هي 0 10000000 01000000000000000000000، أي 0x40200000. رمز BF16 هو بالضبط أعلى 16 بتًا. وهذه هي قصة تحويل BF16 كلها: احتفظ بالنصف الأعلى من كلمة FP32 وقرّب النصف المحذوف إلى الأقرب، مع كسر التعادل نحو الزوجي (ties to even). يُنسخ حقل الأس كما هو (التقريب لا يفعل إلا أن يحمل إليه)، ولهذا لا يكاد التحويل من FP32 يتجاوز المدى أبدًا.
SimulatorمحاكيOne decimal, five float formatsعدد عشري واحد، وخمس صيغ للفاصلة العائمة
FP32E8 M23, bias 127
00111101110011001100110011001101
stored0.1000000015error1.490116e-91.49e-6 %
FP16E5 M10, bias 15
0010111001100110
stored0.09997558594error2.441406e-50.0244 %
BF16E8 M7, bias 127
0011110111001101
stored0.1000976563error9.765625e-50.0977 %
FP8 E4M3E4 M3, bias 7
00011101
stored0.1015625error0.00156251.56 %
FP8 E5M2E5 M2, bias 15
00101110
stored0.09375error0.006256.25 %
Bits read sign, exponent, fraction. Rounding is round to nearest, ties to even. Overflow follows each format: IEEE-style formats go to infinity, while E4M3 has no infinity, so it is shown saturating to 448 (the OCP spec also allows mapping it to NaN).تُقرأ البتات بالترتيب: الإشارة ثم الأس ثم الكسر. التقريب إلى الأقرب، وعند التعادل إلى الزوجي (round to nearest, ties to even). ويتبع الفيض overflow قاعدة كل صيغة: الصيغ على نمط IEEE تذهب إلى اللانهاية، أما E4M3 فلا لانهاية فيها، لذلك تظهر وهي تتشبع عند 448 (وتسمح مواصفة OCP أيضا بربطها بـ NaN).
Recall
Encode -7 in BF16 and in FP16. How do the two codes differ?رمّز -7 في BF16 وفي FP16. كيف يختلف الرمزان؟
-7 = -1.75 × 2^2. BF16: sign 1, exponent 2 + 127 = 129 = 10000001, fraction 1100000, so 1 10000001 1100000. FP16: exponent 2 + 15 = 17 = 10001, fraction 1100000000, so 1 10001 1100000000. Same sign and fraction prefix; only the exponent width and bias differ.
-7 = -1.75 × 2^2. في BF16: الإشارة 1، والأس 2 + 127 = 129 = 10000001، والكسر 1100000، فيكون 1 10000001 1100000. وفي FP16: الأس 2 + 15 = 17 = 10001، والكسر 1100000000، فيكون 1 10001 1100000000. الإشارة وبداية الكسر متطابقتان؛ ولا يختلف إلا عرض الأس وقيمة الإزاحة.
Quick checkاختبار سريع
What decimal value does the FP16 pattern 0 10010 0100000000 represent?ما القيمة العشرية التي يمثلها نمط FP16 التالي: 0 10010 0100000000؟
Halve the width again and the range versus precision tension becomes impossible to ignore. With only 8 bits, a single format cannot serve both weights, which want fine steps, and gradients, which swing over many orders of magnitude. So NVIDIA, Arm and Intel proposed two FP8 formats and use each where it fits.
نصّف العرض مرة أخرى فيصبح التوتر بين المدى والدقة مستحيل التجاهل. مع 8 بتات فقط، لا تستطيع صيغة واحدة أن تخدم الأوزان (weights)، التي تريد خطوات دقيقة، والتدرجات، التي تتأرجح عبر رتب كثيرة من المقادير. لذلك اقترحت NVIDIA وArm وIntel صيغتين لـFP8، وتُستخدم كل منهما حيث تناسب.
Two splits of eight bitsتقسيمان للبتات الثماني
FP8 E4M3 spends 4 bits on the exponent and 3 on the mantissa, bias 7. FP8 E5M2 spends 5 on the exponent and 2 on the mantissa, bias 15: it is literally FP16 with the low 8 fraction bits cut off, the same relationship BF16 has with FP32.
تنفق FP8 E4M3 4 بتات على الأس و3 على الجزء العشري (mantissa)، بإزاحة 7. وتنفق FP8 E5M2 5 على الأس و2 على الجزء العشري، بإزاحة 15: إنها حرفيًا FP16 بعد قطع بتات الكسر الثماني الدنيا، وهي العلاقة نفسها التي تربط BF16 بـFP32.
E4M3E4M3
E5M2E5M2
Exponent / mantissa bitsعدد بتات الأس / الجزء العشري
Weights and activations, forward passالأوزان والتنشيطات، المرور الأمامي
Gradients, backward passالتدرجات، المرور الخلفي
The two FP8 formats on slide 19 (values from the OCP specification)صيغتا FP8 في الشريحة 19 (القيم من مواصفة OCP)
E4M3 reclaims the special codesصيغة E4M3 تستعيد الرموز الخاصة
In IEEE style, an exponent field of all ones is reserved for Infinity and NaN. In a format with only 16 exponent codes, losing a whole binade to special values is expensive. This is the waste flagged at the end of Part 2. E4M3 drops infinity entirely and keeps just one NaN pattern per sign, S.1111.111. Every other code with exponent 1111 becomes an ordinary normal number.
على طريقة IEEE، حقل الأس المكون من آحاد كلها محجوز لـINF وNaN. وفي صيغة ليس فيها سوى 16 رمزًا للأس، خسارة binade كامل لصالح القيم الخاصة مكلفة. وهذا هو الهدر الذي أُشير إليه في نهاية الجزء الثاني. تتخلى E4M3 عن ما لا نهاية تمامًا وتحتفظ بنمط NaN واحد فقط لكل إشارة، S.1111.111. وكل رمز آخر أسّه 1111 يصبح رقمًا عاديًا (normal).
Worked exampleمثال محلول
Where 448 and 57344 come fromمن أين تأتي 448 و57344
What IEEE rules would have givenما كانت قواعد IEEE ستعطيه
With exponent 1111 reserved, the top would be S.1110.111 = 1.875 × 2^7 = 240. Reclaiming the codes adds seven magnitudes, 256 through 448, and nearly doubles the range.
لو كان الأس 1111 محجوزًا لكانت القمة S.1110.111 = 1.875 × 2^7 = 240. استعادة هذه الرموز تضيف سبعة مقادير، من 256 إلى 448، وتكاد تضاعف المدى.
E5M2 largest normalأكبر قيمة عادية في E5M2
Exponent 11111 stays reserved, so the top is S.11110.11: exponent 30 - 15 = 15, mantissa 0.75. Value 1.75 × 2^15 = 57344.
E5M2 reaches about 128× further than E4M3 (57344 versus 448) and about 128× smaller on the subnormal side (2^-16 versus 2^-9), but each binade has only 4 steps instead of 8.
تصل E5M2 إلى مدى أبعد بنحو 128× من E4M3 (57344 مقابل 448)، وإلى قيم أصغر بنحو 128× في الجانب دون العادي (2^-16 مقابل 2^-9)، لكن كل binade فيها لا يحوي سوى 4 خطوات بدلًا من 8.
Which tensor gets which formatأي موتّر يأخذ أي صيغة
The FP8 paper by Micikevicius and colleagues recommends E4M3 for weight and activation tensors and E5M2 for gradient tensors. The reasoning follows the rule. In the forward pass, weights and activations of one layer sit in a fairly narrow band and benefit from the extra mantissa bit. In the backward pass, gradients vary over many orders of magnitude, and losing small ones to underflow or large ones to overflow hurts more than coarse steps. In practice each tensor also carries a per-tensor scale factor so its values land inside the format’s range, which is the same idea as loss scaling.
توصي ورقة FP8 التي كتبها Micikevicius وزملاؤه باستخدام E4M3 لموتّرات الأوزان والتنشيطات، وE5M2 لموتّرات التدرجات. والتعليل يتبع القاعدة. في المرور الأمامي (forward pass) تقع أوزان طبقة واحدة وتنشيطاتها في نطاق ضيق نسبيًا وتستفيد من بت الجزء العشري الإضافي. وفي المرور الخلفي (backward pass) تتفاوت التدرجات عبر رتب كثيرة من المقادير، وخسارة الصغيرة منها بسبب underflow أو الكبيرة بسبب overflow تضر أكثر من الخطوات الخشنة. وعمليًا يحمل كل موتّر أيضًا معامل تحجيم خاصًا به (per-tensor scale factor) لتقع قيمه داخل مدى الصيغة، وهي الفكرة نفسها التي يقوم عليها loss scaling.
Recall
Derive the largest E4M3 normal and explain why it is not 240.اشتق أكبر قيمة عادية في E4M3 واشرح لماذا ليست 240.
S.1111.110 = 1.75 × 2^(15 - 7) = 448. It would be 240 under IEEE rules, because the all-ones exponent would be reserved for INF and NaN. E4M3 keeps only S.1111.111 as NaN and uses the rest of that binade for normal values.
S.1111.110 = 1.75 × 2^(15 - 7) = 448. كانت ستكون 240 وفق قواعد IEEE، لأن الأس المكوّن من آحاد كلها كان سيُحجز لـINF وNaN. تحتفظ E4M3 بـS.1111.111 وحده كـNaN وتستخدم بقية ذلك الـbinade للقيم العادية.
Quick checkاختبار سريع
Which FP8 format should store gradients in the backward pass, and why?أي صيغة FP8 يجب أن تخزّن التدرجات في المرور الخلفي، ولماذا؟
With 4 bits there are only 16 codes, 8 of them non-negative. That is small enough to list every value, and the lists make the range versus precision rule visible at a glance.
مع 4 بتات لا يوجد سوى 16 رمزًا، منها 8 غير سالبة. وهذا عدد صغير بما يكفي لسرد كل قيمة، والقوائم تجعل قاعدة المدى مقابل الدقة مرئية من نظرة واحدة.
The same eight codes, four waysالرموز الثمانية نفسها بأربع طرق
INT4 treats the bits as a Two's complement integer: 0 to 7 and -1 to -8, evenly spaced. The FP4 (E1M2, E2M1, E3M0) variants instead keep a sign bit and split the remaining three between exponent and mantissa, using the same bias formula 2^(e-1) - 1, which gives 0 for E1M2, 1 for E2M1 and 3 for E3M0. None of them reserves any code for INF or NaN: with so few codes, every pattern must be a number.
تعامل INT4 البتات كعدد صحيح بنظام two's complement: من 0 إلى 7 ومن -1 إلى -8، بتباعد متساوٍ. أما متغيرات FP4 فتحتفظ ببت إشارة وتقسم البتات الثلاثة الباقية بين الأس والجزء العشري، مستخدمة صيغة الإزاحة نفسها 2^(e-1) - 1، التي تعطي 0 لـE1M2 و1 لـE2M1 و3 لـE3M0. ولا تحجز أي منها رمزًا لـINF أو NaN: مع هذا العدد القليل من الرموز، يجب أن يكون كل نمط رقمًا.
Positive values of the four 4-bit formats on slide 20القيم الموجبة لصيغ الأربع بتات الأربع في الشريحة 20
Each row holds eight codes on a shared 0 to 16 axis. More exponent bits fling the dots outwardكل صف يحمل ثمانية رموز على محور مشترك من 0 إلى 16. بتات الأس الإضافية تقذف النقاط نحو الخارج
Decoding every E2M1 codeفك ترميز كل رمز في E2M1
E2M1 is the one that matters most in practice: it is the FP4 element type in the OCP microscaling (MX) specification and in NVIDIA Blackwell’s FP4. Its fields are one sign bit, two exponent bits and one mantissa bit, with bias 1. Exponent 00 means subnormal, value 0.m × 2^(1 - 1); any other exponent is normal, value 1.m × 2^(E - 1).
E2M1 هي الأهم عمليًا: إنها نوع العنصر في FP4 ضمن مواصفة OCP للتحجيم الدقيق (microscaling, MX) وفي FP4 الخاصة بـNVIDIA Blackwell. حقولها بت إشارة واحد، وبتا أس، وبت واحد للجزء العشري، بإزاحة 1. الأس 00 يعني قيمة دون عادية، قيمتها 0.m × 2^(1 - 1)؛ وأي أس آخر يعني قيمة عادية، قيمتها 1.m × 2^(E - 1).
Codeالرمز
Kindالنوع
Formulaالصيغة الحسابية
Valueالقيمة
0 00 00 00 0
subnormalدون عادية
0.0 × 2^(1-1)0.0 × 2^(1-1)
00
0 00 10 00 1
subnormalدون عادية
0.5 × 2^(1-1)0.5 × 2^(1-1)
0.50.5
0 01 00 01 0
normalعادية
1.0 × 2^(1-1)1.0 × 2^(1-1)
11
0 01 10 01 1
normalعادية
1.5 × 2^(1-1)1.5 × 2^(1-1)
1.51.5
0 10 00 10 0
normalعادية
1.0 × 2^(2-1)1.0 × 2^(2-1)
22
0 10 10 10 1
normalعادية
1.5 × 2^(2-1)1.5 × 2^(2-1)
33
0 11 00 11 0
normalعادية
1.0 × 2^(3-1)1.0 × 2^(3-1)
44
0 11 10 11 1
normalعادية
1.5 × 2^(3-1)1.5 × 2^(3-1)
66
All eight non-negative E2M1 codes (sign, exponent, mantissa)رموز E2M1 الثمانية غير السالبة كلها (الإشارة، الأس، الجزء العشري)
The other two rows on the slide check out. E1M2 with bias 0: 0001 is subnormal, 0.25 × 2^(1 - 0) = 0.5, and 0111 is (1 + 0.75) × 2^(1 - 0) = 3.5. Its values are exactly INT4 times 0.5, so E1M2 is really a fixed-point format in disguise. E3M0 with bias 3 has no mantissa at all: 0001 is 2^(1 - 3) = 0.25 and 0111 is 2^(7 - 3) = 16. Every value is a power of two.
الصفان الآخران في الشريحة صحيحان. E1M2 بإزاحة 0: الرمز 0001 دون عادي، 0.25 × 2^(1 - 0) = 0.5، والرمز 0111 هو (1 + 0.75) × 2^(1 - 0) = 3.5. قيمها هي بالضبط قيم INT4 مضروبة في 0.5، لذلك فإن E1M2 في الحقيقة صيغة فاصلة ثابتة (fixed-point) متنكرة. وE3M0 بإزاحة 3 ليس فيها جزء عشري إطلاقًا: الرمز 0001 هو 2^(1 - 3) = 0.25 والرمز 0111 هو 2^(7 - 3) = 16. كل قيمة فيها قوة للعدد 2.
ExplorerمستكشفSame 16 codes, four different spreadsالرموز الستة عشر نفسها، وأربعة توزيعات مختلفة
00000
00010.5
00101
00111.5
01002
01013
01104
01116
Positive half only; setting the sign bit mirrors every value. Bias: 1. Spacing: step doubles every two codes. Largest value: 6.يظهر النصف الموجب فقط، وتفعيل بت الإشارة يعكس كل قيمة. الانحياز bias: 1. التباعد: تتضاعف الخطوة كل رمزين. أكبر قيمة: 6.
What the four grids teachما الذي تعلّمه الشبكات الأربع
Mantissa bits give even spacing. INT4 and E1M2 are uniform grids; the only difference is the scale.بتات الجزء العشري تعطي تباعدًا متساويًا. INT4 وE1M2 شبكتان منتظمتان؛ والفرق الوحيد بينهما هو المقياس.
Exponent bits give logarithmic spacing. E3M0 doubles at every step, so it reaches 16 but jumps from 8 to 16 with nothing in between.بتات الأس تعطي تباعدًا لوغاريتميًا. E3M0 تتضاعف عند كل خطوة، لذلك تصل إلى 16 لكنها تقفز من 8 إلى 16 دون أي قيمة بينهما.
E2M1 is the compromise: two values per binade, reaching 6, dense near zero and coarse near the top. That shape matches the bell-shaped distribution of neural network weights, which is why it is the practical FP4.E2M1 هي الحل الوسط: قيمتان في كل binade، وتصل إلى 6، كثيفة قرب الصفر وخشنة قرب القمة. هذا الشكل يطابق التوزيع الجرسي لأوزان الشبكات العصبية، ولهذا هي صيغة FP4 العملية.
Recall
List the eight non-negative E2M1 values and say which two are subnormal.اسرد القيم الثماني غير السالبة في E2M1 وحدد أي اثنتين منها دون عادية.
0, 0.5, 1, 1.5, 2, 3, 4, 6. The codes with exponent 00, namely 0 and 0.5, are subnormal.
0, 0.5, 1, 1.5, 2, 3, 4, 6. الرمزان اللذان أسّهما 00، أي 0 و0.5، هما القيمتان دون العاديتين.
Quick checkاختبار سريع
In FP4 E2M1 (bias 1), what value does the code 0111 represent?في صيغة FP4 E2M1 (الإزاحة 1)، ما القيمة التي يمثلها الرمز 0111؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
Exponent width sets range, fraction width sets precision. Total width only says how many codes you get.عرض الأس يحدد المدى، وعرض الكسر يحدد الدقة. أما العرض الكلي فيخبرك فقط بعدد الرموز (codes) المتاحة.
Bias = 2^(e-1) - 1: 127 for FP32 and BF16, 15 for FP16 and E5M2, 7 for E4M3.الإزاحة bias = 2^(e-1) - 1: تساوي 127 في FP32 وBF16، و15 في FP16 وE5M2، و7 في E4M3.
FP16 (5/10): max 65504, min normal 2^-14, min subnormal 2^-24. Small gradients underflow, so FP16 training needs loss scaling.FP16 (5/10): أكبر قيمة 65504، وأصغر قيمة عادية 2^-14، وأصغر قيمة دون عادية 2^-24. التدرجات الصغيرة تنزل تحت المدى (underflow)، لذلك يحتاج تدريب FP16 إلى loss scaling.
BF16 (8/7): same exponent, same range as FP32. It is the top 16 bits of FP32 after rounding, so conversion keeps FP32's range.BF16 (8/7): الأس نفسه والمدى نفسه كما في FP32. هي أعلى 16 بتًا من FP32 بعد التقريب، لذلك يحافظ التحويل على مدى FP32.
Encode: normalize to 1.f × 2^k, store k + bias, store f. 2.5 = 1.25 × 2^1 gives BF16 0 10000000 0100000.الترميز: حوّل الرقم إلى الصورة 1.f × 2^k، واخزن k + bias في الأس، واخزن f في الكسر. 2.5 = 1.25 × 2^1 يعطي في BF16 النمط 0 10000000 0100000.
E4M3 drops INF and keeps a single NaN pattern, reclaiming exponent 1111 for normals: max 1.75 × 2^8 = 448. Forward weights and activations.تتخلى E4M3 عن INF وتحتفظ بنمط NaN واحد فقط، فتستعيد الأس 1111 للقيم العادية: أكبر قيمة 1.75 × 2^8 = 448. تُستخدم للأوزان والتنشيطات في المرور الأمامي.
E5M2 keeps IEEE INF and NaN: max 1.75 × 2^15 = 57344. Backward gradients.تحتفظ E5M2 بقيم INF وNaN على طريقة IEEE: أكبر قيمة 1.75 × 2^15 = 57344. تُستخدم للتدرجات في المرور الخلفي.
FP4 positive grids: INT4 0..7, E1M2 0..3.5 in 0.5 steps, E2M1 {0, 0.5, 1, 1.5, 2, 3, 4, 6}, E3M0 {0, 0.25, ..., 16}. No INF, no NaN.شبكات القيم الموجبة في FP4: INT4 من 0 إلى 7، وE1M2 من 0 إلى 3.5 بخطوة 0.5، وE2M1 هي {0, 0.5, 1, 1.5, 2, 3, 4, 6}، وE3M0 هي {0, 0.25, ..., 16}. لا INF ولا NaN.
Part 04: What quantization is and the three main approachesما التكميم والمناهج الثلاثة الرئيسية
Quantization maps a continuous or large set of values onto a small discrete set, leaving a quantization error. Introduces the three neural network approaches (K-means, linear, binary/ternary) and the storage versus computation table, using the 4x4 running example matrix.التكميم يربط مجموعة قيم متصلة أو كبيرة بمجموعة منفصلة صغيرة، تاركًا خطأ تكميم. يقدم المناهج الثلاثة في الشبكات العصبية (K-means والخطي والثنائي/الثلاثي) وجدول التخزين مقابل الحساب، باستخدام مصفوفة المثال الجاري 4x4.
3 concepts3 مفاهيم, ، slides 21-25الشرائح 21-25
Why this part mattersلماذا يهمّ هذا الجزء
The first three parts of this lecture were about number formats: how many bits a value takes and what those bits can express. This part turns that knowledge into a technique. Quantization is the act of deliberately throwing away precision so that each number fits in fewer bits, and it is the single most widely deployed compression method for neural networks on embedded hardware.
Three ideas build on each other. First, what quantization means in general, and the error it always leaves behind. Second, the three ways the course quantizes a neural network, compared through one table of storage and computation that you will keep filling in until part 8. Third, the 4x4 weight matrix that the rest of the lecture reuses, and the idea of weight sharing it is built to show. For the midterm, expect the definition, the error, the table and the question of why K-means saves memory but not compute.
الأجزاء الثلاثة الأولى من هذه المحاضرة كانت عن صيغ الأعداد: كم بتًا تأخذ القيمة، وماذا تستطيع هذه البتات أن تعبّر عنه. هذا الجزء يحوّل تلك المعرفة إلى تقنية. التكميم (quantization) هو التخلّي المتعمَّد عن جزء من الدقة كي يتسع كل عدد في بتات أقل، وهو أكثر طرق ضغط الشبكات العصبية انتشارًا على العتاد المدمج (embedded hardware).
هناك ثلاث أفكار تُبنى كل واحدة منها على السابقة. أولًا، ما معنى التكميم بشكل عام، والخطأ الذي يتركه دائمًا خلفه. ثانيًا، الطرق الثلاث التي يكمّم بها المقرر الشبكة العصبية، مقارنةً من خلال جدول واحد للتخزين والحساب ستستمر في ملئه حتى الجزء 8. ثالثًا، مصفوفة الأوزان 4x4 التي تعيد بقية المحاضرة استخدامها، وفكرة مشاركة الأوزان (weight sharing) التي صُمّمت لتوضيحها. في الاختبار النصفي، توقّع أسئلة عن التعريف، والخطأ، والجدول، وسؤال لماذا يوفّر K-means في الذاكرة لا في الحساب.
By the end you canفي نهاية هذا الجزء ستستطيع
01State the definition of quantization word for word and define quantization error.تذكر تعريف التكميم (quantization) حرفيًا كما في الشريحة، وتعرّف خطأ التكميم (quantization error).
02Compute the quantization error of a value and say why rounding bounds it by half a step.تحسب خطأ التكميم لقيمة ما، وتشرح لماذا يجعل التقريب إلى أقرب مستوى هذا الخطأ لا يتجاوز نصف خطوة.
03Explain palettization as K-means quantization of colours, with the palette as the codebook.تشرح الـ palettization على أنها تكميم K-means للألوان، حيث تكون لوحة الألوان (palette) هي الـ codebook.
04Name the three neural network quantization approaches and fill the storage and computation table for each.تسمّي الطرق الثلاث لتكميم الشبكات العصبية، وتملأ جدول التخزين والحساب لكل منها.
05Explain why K-means quantization saves memory but leaves the arithmetic in floating point.تشرح لماذا يوفّر تكميم K-means في الذاكرة لكنه يُبقي العمليات الحسابية بالفاصلة العائمة (floating point).
06Apply weight sharing to the 4x4 running example and compute the error of each shared weight.تطبّق مشاركة الأوزان (weight sharing) على المثال المستمر 4x4، وتحسب خطأ كل وزن مُشارَك.
Take a thermometer that reads 23.4718 °C and a display that can only show whole degrees. It shows 23. Anything from 22.5 to just under 23.5 also shows 23. The display has replaced an infinite set of possible temperatures with a short list of integers, and the 0.4718 it dropped is gone for good.
خذ ميزان حرارة يقرأ 23.4718 °C وشاشة لا تعرض إلا الدرجات الكاملة. ستعرض 23. وأي قيمة من 22.5 حتى ما دون 23.5 بقليل ستعرض أيضًا 23. لقد استبدلت الشاشة مجموعة لا نهائية من درجات الحرارة الممكنة بقائمة قصيرة من الأعداد الصحيحة، والجزء 0.4718 الذي حذفته ضاع إلى الأبد.
The definitionالتعريف
That is Quantization, and the lecture defines it in one sentence worth memorizing exactly:
هذا هو quantization (التكميم)، والمحاضرة تعرّفه في جملة واحدة تستحق أن تحفظها بنصّها:
Two phrases carry the meaning. “Continuous or otherwise large” covers both a truly continuous input, such as an analogue voltage, and an input that is already digital but has too many possible values, such as an FP32 weight with about four billion bit patterns. “A discrete set” is the small menu of values the output may take. For neural networks the input is almost always the second kind: weights are already numbers in a computer, just in a format far richer than the network needs.
عبارتان تحملان المعنى. عبارة "متصلة أو كبيرة جدًا" (continuous or otherwise large) تشمل المُدخل المتصل فعلًا، مثل جهد كهربائي تناظري، وتشمل أيضًا المُدخل الرقمي أصلًا لكن له عدد هائل من القيم الممكنة، مثل وزن بصيغة FP32 له قرابة أربعة مليارات نمط بتات. أما "مجموعة منفصلة" (a discrete set) فهي القائمة الصغيرة من القيم التي يُسمح للمُخرج أن يأخذها. في الشبكات العصبية يكون المُدخل دائمًا تقريبًا من النوع الثاني: الأوزان أعداد مخزّنة في الحاسوب أصلًا، لكن بصيغة أغنى بكثير مما تحتاجه الشبكة.
Quantization errorخطأ التكميم
Every quantizer loses something. The lecture names it: the difference between an input value and its quantized value is the Quantization error. For the thermometer it is 23.4718 - 23 = 0.4718. Written as a formula, with Q(x) the quantized value of x:
كل مُكمِّم يفقد شيئًا. والمحاضرة تسمّيه: الفرق بين قيمة المُدخل وقيمته بعد التكميم هو quantization error (خطأ التكميم). في مثال ميزان الحرارة يساوي 23.4718 - 23 = 0.4718. وبصيغة رياضية، حيث Q(x) هي القيمة المكمَّمة لـ x:
e=x−Q(x)
Quantization error: input minus quantized valueخطأ التكميم: المدخل ناقص القيمة المكمَّمة
When the allowed values are evenly spaced with step Δ and you round to the nearest one, an input inside the range can never be more than half a step away from its output, so ∣e∣≤Δ/2. Halve the step and the worst-case error halves. A smaller step needs more levels, and more levels need more bits: that trade between bits and error is the whole subject of this lecture.
عندما تكون القيم المسموح بها متباعدة بانتظام بخطوة Δ وتقرّب إلى أقربها، فإن أي مُدخل داخل المدى لا يمكن أن يبعد عن مُخرجه أكثر من نصف خطوة، لذلك ∣e∣≤Δ/2. إذا نصّفت الخطوة تنصّف أسوأ خطأ ممكن. لكن الخطوة الأصغر تحتاج مستويات أكثر، والمستويات الأكثر تحتاج بتات أكثر: هذه المقايضة بين عدد البتات والخطأ هي موضوع هذه المحاضرة كله.
A continuous sine is sampled and each sample is rounded to the nearest of five levels; the teal bars are the quantization errorsموجة جيبية متصلة تُؤخذ منها عيّنات، وتُقرَّب كل عيّنة إلى أقرب مستوى من خمسة مستويات؛ والأعمدة الخضراء المزرقّة هي أخطاء التكميم
The figure on slide 21 shows this on a signal. The continuous curve can take any height. The quantized signal is drawn as stems that may only stop on the dotted levels. Where the curve passes exactly through a level the error is zero; between levels the stem stops short or overshoots, and that gap is the error. Notice that the error is not random noise added on top: it is fully determined by the input and the grid.
الشكل في الشريحة 21 يوضّح هذا على إشارة. المنحنى المتصل يمكن أن يأخذ أي ارتفاع. أما الإشارة المكمَّمة فمرسومة كسيقان (stems) لا يُسمح لها أن تتوقف إلا على المستويات المنقّطة. حيث يمرّ المنحنى تمامًا عبر مستوى يكون الخطأ صفرًا؛ وبين المستويات تتوقف الساق قبل المنحنى أو تتجاوزه، وتلك الفجوة هي الخطأ. لاحظ أن الخطأ ليس ضجيجًا عشوائيًا يُضاف فوق الإشارة: إنه محدَّد بالكامل بالمُدخل وبالشبكة (grid).
Palettization: the same idea for coloursالـ Palettization: الفكرة نفسها مطبَّقة على الألوان
The right half of slide 21 applies quantization to an image. A normal photo stores each pixel as 24 bits of colour, about 16.7 million possible values. The quantized version may use only 16 colours. Those 16 colours are the palette, and with Palettization each pixel stores only which palette entry it uses: a 4-bit index, since 2⁴ = 16.
النصف الأيمن من الشريحة 21 يطبّق التكميم على صورة. الصورة العادية تخزّن كل بكسل في 24 بتًا من اللون، أي قرابة 16.7 million قيمة ممكنة. أما النسخة المكمَّمة فقد تستخدم 16 لونًا فقط. هذه الألوان الـ 16 هي لوحة الألوان (palette)، ومع palettization يخزّن كل بكسل فقط رقم الخانة التي يستخدمها من اللوحة: فهرس (index) من 4-bit، لأن 2⁴ = 16.
Worked exampleمثال محلول
What palettization saves on a 640 x 480 imageماذا توفّر الـ palettization في صورة بأبعاد 640 x 480
Originalالأصل
640 × 480 = 307,200 pixels at 24 bits each is 7,372,800 bits, about 921.6 kB.
640 × 480 = 307,200 بكسل، كل منها 24 بتًا، يساوي 7,372,800 بت، أي قرابة 921.6 kB.
Indexesالفهارس
Each pixel stores a 4-bit index: 307,200 × 4 = 1,228,800 bits, about 153.6 kB.
كل بكسل يخزّن فهرسًا من 4-bit: 307,200 × 4 = 1,228,800 بت، أي قرابة 153.6 kB.
Paletteلوحة الألوان
16 colours at 24 bits each is 384 bits, just 48 B.
16 لونًا، كل منها 24 بتًا، يساوي 384 بتًا، أي 48 B فقط.
Resultالنتيجة
About 6× smaller (24 / 4), and the palette is almost free. The cost is that every pixel now carries a colour quantization error, which is why the zoomed fur on the slide looks blocky.
أصغر بقرابة 6× (24 / 4)، ولوحة الألوان تكاد تكون بلا تكلفة. الثمن هو أن كل بكسل يحمل الآن خطأ تكميم في لونه، ولهذا يبدو الفرو المكبَّر في الشريحة متكتّلًا (blocky).
This analogy is not loose. The standard way to pick a good 16-colour palette is to run K-means clustering on all the pixel colours and keep the 16 cluster centres. Replace “pixel colours” with “weights” and you have exactly the K-means weight quantization of the next part. Apple’s Core ML tools even call weight clustering “palettization”.
هذا التشبيه ليس تقريبيًا. الطريقة المعتادة لاختيار لوحة جيدة من 16 لونًا هي تشغيل التجميع بـ K-means (K-means clustering) على ألوان كل البكسلات والاحتفاظ بمراكز العناقيد الـ 16. استبدل "ألوان البكسلات" بـ "الأوزان" وستحصل تمامًا على تكميم الأوزان بـ K-means في الجزء التالي. بل إن أدوات Core ML من Apple تسمّي تجميع الأوزان (weight clustering) باسم "palettization".
Quick checkاختبار سريع
A weight of 1.53 is quantized to the shared value 1.50. What is its quantization error?وزن قيمته 1.53 كُمِّم إلى القيمة المُشارَكة 1.50. ما خطأ التكميم له؟
Recall
Without looking: give the slide's definition of quantization, then define quantization error.دون أن تنظر: اذكر تعريف التكميم كما في الشريحة، ثم عرّف خطأ التكميم.
Quantization is the process of constraining an input from a continuous or otherwise large set of values to a discrete set. Quantization error is the difference between an input value and its quantized value.
التكميم هو عملية تقييد مُدخل من مجموعة قيم متصلة أو كبيرة جدًا بطريقة أخرى، إلى مجموعة منفصلة (Quantization is the process of constraining an input from a continuous or otherwise large set of values to a discrete set). وخطأ التكميم هو الفرق بين قيمة المُدخل وقيمته بعد التكميم.
Hand three engineers the same sixteen FP32 weights and ask each to store them in fewer bits. The first lists the four typical values once and stores, for every weight, which of the four it is closest to. The second lays an evenly spaced integer ruler over the range and stores each weight’s position on that ruler. The third keeps only the sign. Those are the three approaches on slide 22.
أعطِ ثلاثة مهندسين الأوزان الستة عشر نفسها بصيغة FP32، واطلب من كل واحد أن يخزّنها في بتات أقل. الأول يكتب القيم النموذجية الأربع مرة واحدة، ثم يخزّن لكل وزن أيّ هذه القيم الأربع هي الأقرب إليه. الثاني يضع مسطرة أعداد صحيحة متساوية التباعد فوق المدى، ويخزّن موقع كل وزن على تلك المسطرة. الثالث يحتفظ بالإشارة فقط. هذه هي الطرق الثلاث في الشريحة 22.
The 4x4 FP32 matrix, then its K-means indexes with a four-entry codebook, its 2-bit linear codes and its 1-bit signsمصفوفة 4x4 بصيغة FP32، ثم فهارس K-means مع codebook من أربع خانات، ثم رموزها الخطية من 2 بت، ثم إشاراتها من بت واحد
K-means-based quantization. Group the weights into clusters, keep one floating-point value per cluster in a Codebook, and store each weight as a small integer index into it. On the slide, four clusters give the codebook {3: 2.00, 2: 1.50, 1: 0.00, 0: -1.00} and 2-bit indexes. This is K-means-based weight quantization, and it is the rest of this lecture.التكميم المعتمد على K-means. اجمع الأوزان في عناقيد (clusters)، واحتفظ بقيمة واحدة بالفاصلة العائمة لكل عنقود في codebook، وخزّن كل وزن كفهرس صحيح صغير يشير إليه. في الشريحة، أربعة عناقيد تعطي الـ codebook {3: 2.00, 2: 1.50, 1: 0.00, 0: -1.00} وفهارس من 2-bit. هذا هو K-means quantization، وهو موضوع بقية هذه المحاضرة.
Linear quantization. Store an integer q per weight and recover the real value with one affine formula shared by the whole tensor. The slide writes (q - (-1)) × 1.07, which is the general form r=S(q−Z) with scale S = 1.07 and zero point Z = -1. This is Linear quantization, the topic of lecture 05-2.التكميم الخطي (Linear quantization). خزّن عددًا صحيحًا q لكل وزن، واسترجع القيمة الحقيقية بصيغة تآلفية (affine) واحدة يشترك فيها الـ tensor كله. الشريحة تكتب (q - (-1)) × 1.07، وهي الصيغة العامة r=S(q−Z) مع scale قيمته S = 1.07 وzero point قيمته Z = -1. هذا هو linear quantization، موضوع المحاضرة 05-2.
Binary or ternary quantization. Push to the extreme: one bit per weight (two values) or three values with zero allowed. This is Binary and ternary quantization, covered in lecture 05-3.التكميم الثنائي أو الثلاثي (Binary or ternary quantization). اذهب إلى أقصى حد: بت واحد لكل وزن (قيمتان)، أو ثلاث قيم مع السماح بالصفر. هذا هو binary/ternary quantization، ويُشرح في المحاضرة 05-3.
r=S(q−Z),S=1.07,Z=−1
Linear quantization preview from slide 22: real value from integer codeلمحة عن التكميم الخطي من الشريحة 22: القيمة الحقيقية من الرمز الصحيح
A quick check makes the linear formula concrete. The top-left weight 2.09 has code q = 1, so it reconstructs as (1 + 1) × 1.07 = 2.14, an error of 2.09 - 2.14 = -0.05. Its codes run from -2 to 1, exactly the range of a 2-bit two’s complement integer from part 1. Leave the derivation of 1.07 and -1 for lecture 05-2; here you only need to recognize the shape.
تحقّق سريع يجعل الصيغة الخطية ملموسة. الوزن في أعلى اليسار 2.09 رمزه q = 1، فيُعاد بناؤه كـ (1 + 1) × 1.07 = 2.14، بخطأ قدره 2.09 - 2.14 = -0.05. رموزه تمتد من -2 إلى 1، وهو تمامًا مدى عدد صحيح من 2-bit بتمثيل المتمم الثنائي (two’s complement) من الجزء 1. اترك اشتقاق 1.07 و-1 للمحاضرة 05-2؛ هنا يكفي أن تتعرّف على شكل الصيغة.
The table that organizes the whole topicالجدول الذي ينظّم الموضوع كله
Slides 22 and 23 do not compare the approaches by accuracy. They ask two engineering questions instead: what is kept in memory (storage), and what kind of arithmetic runs at inference (computation). The baseline network answers “floating-point” to both. Slide 23 fills in the K-means column, and the linear column is filled on slide 43.
الشريحتان 22 و23 لا تقارنان الطرق من حيث الدقة. بل تطرحان سؤالين هندسيين: ماذا يُحفظ في الذاكرة (التخزين، storage)، وما نوع العمليات الحسابية التي تجري أثناء الاستدلال (الحساب، computation). الشبكة الأساسية (baseline) تجيب "فاصلة عائمة" (floating-point) على السؤالين. الشريحة 23 تملأ عمود K-means، والعمود الخطي يُملأ في الشريحة 43.
Integer weights (slide 43, part 8)أوزان صحيحة (الشريحة 43، الجزء 8)
Lecture 05-3 (greyed out here)المحاضرة 05-3 (باهت هنا)
Computationالحساب
Floating-point arithmeticحساب بالفاصلة العائمة
Floating-point arithmeticحساب بالفاصلة العائمة
Integer arithmetic (slide 43, part 8)حساب بأعداد صحيحة (الشريحة 43، الجزء 8)
Lecture 05-3 (greyed out here)المحاضرة 05-3 (باهت هنا)
Storage and computation per approach. Baseline and K-means are slides 22 and 23; linear is slide 43 (part 8); binary/ternary stays greyed out in this lecture.التخزين والحساب لكل طريقة. الأساسي وK-means من الشريحتين 22 و23؛ والخطي من الشريحة 43 (الجزء 8)؛ أما الثنائي/الثلاثي فيبقى باهتًا في هذه المحاضرة.
The K-means column is the surprising one. Its storage really is integer: 2 bits per weight instead of 32. But before a multiply can happen, each index has to be looked up in the codebook, and what comes out is a floating-point number. The multiply-accumulate units therefore still run in floating point. The saving is in memory size and in the bytes moved from DRAM, not in the arithmetic itself. Part 8 shows the lookup step explicitly (slide 42). Linear quantization is the approach that finally changes the second row, because its integers can be multiplied as integers.
عمود K-means هو المفاجئ. تخزينه فعلًا بأعداد صحيحة: 2 بت لكل وزن بدلًا من 32. لكن قبل أن يحدث أي ضرب، يجب البحث عن كل فهرس في الـ codebook، وما يخرج من البحث عدد بالفاصلة العائمة. لذلك تظل وحدات الضرب والجمع التراكمي (multiply-accumulate) تعمل بالفاصلة العائمة. التوفير يكون في حجم الذاكرة وفي عدد البايتات المنقولة من DRAM، لا في العمليات الحسابية نفسها. الجزء 8 يُظهر خطوة البحث صراحةً (الشريحة 42). والتكميم الخطي هو الطريقة التي تغيّر أخيرًا الصف الثاني، لأن أعداده الصحيحة يمكن ضربها كأعداد صحيحة.
Quick checkاختبار سريع
Which entry of the storage and computation table describes K-means-based quantization?أيّ خانة في جدول التخزين والحساب تصف التكميم المعتمد على K-means؟
Recall
Linear quantization on slide 22 uses S = 1.07 and Z = -1. What real value does the code q = -2 represent?التكميم الخطي في الشريحة 22 يستخدم S = 1.07 وZ = -1. ما القيمة الحقيقية التي يمثّلها الرمز q = -2؟
r = 1.07 × (-2 - (-1)) = 1.07 × (-1) = -1.07. That is the reconstruction of -0.98, -1.08, -0.91 and -1.03 in the running example.
r = 1.07 × (-2 - (-1)) = 1.07 × (-1) = -1.07. هذه هي القيمة المُعاد بناؤها للأوزان -0.98 و-1.08 و-0.91 و-1.03 في المثال المستمر.
Here is the matrix the rest of the lecture lives on: sixteen weights of one layer, each stored as a 32-bit float. Look at it for a moment before reading on and ask which numbers are almost the same.
هذه هي المصفوفة التي تدور حولها بقية المحاضرة: ستة عشر وزنًا من طبقة واحدة، كل منها مخزّن كعدد بالفاصلة العائمة من 32-bit. تأمّلها لحظة قبل أن تكمل القراءة، واسأل نفسك: أيّ هذه الأعداد متقاربة جدًا؟
The running example: a 4x4 FP32 weight matrix (slide 24)المثال المستمر: مصفوفة أوزان 4x4 بصيغة FP32 (الشريحة 24)
Sixteen FP32 values cost 16 × 32 = 512 bits, or 64 B. Yet the matrix clearly does not use sixteen independent values. Four of them sit near 2, three near 1.5, four near -1 and five near 0. Slide 25 takes the first group, 2.09, 2.12, 1.92 and 1.87, crosses them out and writes one number in their place: 2.0.
ست عشرة قيمة بصيغة FP32 تكلّف 16 × 32 = 512 بتًا، أي 64 B. ومع ذلك من الواضح أن المصفوفة لا تستخدم ست عشرة قيمة مستقلة. أربع منها قريبة من 2، وثلاث قريبة من 1.5، وأربع قريبة من -1، وخمس قريبة من 0. الشريحة 25 تأخذ المجموعة الأولى، 2.09 و2.12 و1.92 و1.87، وتشطبها وتكتب مكانها عددًا واحدًا: 2.0.
The four weights near 2 light up in the running matrix and collapse into one shared value, 2.0الأوزان الأربعة القريبة من 2 تُضاء في المصفوفة المستمرة ثم تنضمّ في قيمة مُشارَكة واحدة، 2.0
That move is Weight sharing: several weights that are close in value are replaced by one shared value. It is quantization by the definition above, because the four inputs are constrained to a discrete set (here a single value), and each now carries a quantization error.
هذه الخطوة هي weight sharing (مشاركة الأوزان): عدة أوزان متقاربة في القيمة تُستبدل بقيمة واحدة مُشارَكة. إنها تكميم وفق التعريف السابق، لأن المُدخلات الأربعة قُيّدت بمجموعة منفصلة (هنا قيمة واحدة)، وكل منها يحمل الآن خطأ تكميم.
Weightالوزن
Shared valueالقيمة المُشارَكة
Errorالخطأ
2.092.09
2.002.00
+0.09+0.09
2.122.12
2.002.00
+0.12+0.12
1.921.92
2.002.00
-0.08-0.08
1.871.87
2.002.00
-0.13-0.13
Quantization error of each shared weight (input minus quantized value)خطأ التكميم لكل وزن مُشارَك (المُدخل ناقص القيمة المكمَّمة)
Two facts in that table matter later. First, every error is small compared with the weights themselves, at most 0.13 against values near 2. Second, the errors add up to zero: 0.09 + 0.12 - 0.08 - 0.13 = 0. That is no accident. 2.0 is exactly the mean of the four weights, (2.09 + 2.12 + 1.92 + 1.87) / 4 = 8.00 / 4 = 2.00, and the mean is the single value that minimizes the squared error of a group. In part 5 that mean gets its proper name, the Centroid of a K-means cluster.
حقيقتان في هذا الجدول ستهمّان لاحقًا. أولًا، كل خطأ صغير مقارنة بالأوزان نفسها، فهو لا يتجاوز 0.13 أمام قيم قريبة من 2. ثانيًا، مجموع الأخطاء يساوي صفرًا: 0.09 + 0.12 - 0.08 - 0.13 = 0. وهذا ليس صدفة. القيمة 2.0 هي تمامًا متوسط الأوزان الأربعة، (2.09 + 2.12 + 1.92 + 1.87) / 4 = 8.00 / 4 = 2.00، والمتوسط هو القيمة الوحيدة التي تجعل مجموع مربعات الأخطاء في المجموعة أصغر ما يمكن. في الجزء 5 يأخذ هذا المتوسط اسمه الصحيح: centroid (مركز) عنقود K-means.
Do the same for every group and the matrix needs only four distinct values. Four values can be told apart with 2 bits, since 2² = 4, so each weight can be stored as a 2-bit label pointing at its shared value instead of a 32-bit float. Part 5 turns this into the exact storage bill (64 B down to 20 B), and shows how the network is retrained around the shared values.
افعل الشيء نفسه مع كل مجموعة، فلن تحتاج المصفوفة إلا إلى أربع قيم مختلفة. أربع قيم يمكن التمييز بينها بـ 2 بت، لأن 2² = 4، لذلك يمكن تخزين كل وزن كتسمية (label) من 2-bit تشير إلى قيمته المُشارَكة بدلًا من عدد بالفاصلة العائمة من 32-bit. الجزء 5 يحوّل هذا إلى حساب التخزين الدقيق (من 64 B إلى 20 B)، ويوضّح كيف يُعاد تدريب الشبكة حول القيم المُشارَكة.
Quick checkاختبار سريع
Why does K-means weight sharing on this 4x4 matrix not reduce the cost of each multiply at inference?لماذا لا تقلّل مشاركة الأوزان بـ K-means على هذه المصفوفة 4x4 تكلفة كل عملية ضرب أثناء الاستدلال؟
Recall
Group the remaining weights of the running example. Which value would each group share, and what is the error of -1.08?جمّع بقية أوزان المثال المستمر. ما القيمة التي ستتشاركها كل مجموعة، وما خطأ الوزن -1.08؟
Near 1.5: 1.48, 1.53, 1.49, mean 4.50 / 3 = 1.50. Near 0: 0.09, 0.05, -0.14, 0, 0, mean 0.00. Near -1: -0.98, -1.08, -0.91, -1.03, mean -4.00 / 4 = -1.00. The error of -1.08 is -1.08 - (-1.00) = -0.08. These are exactly the codebook values on slide 22.
قرب 1.5: 1.48 و1.53 و1.49، والمتوسط 4.50 / 3 = 1.50. قرب 0: 0.09 و0.05 و-0.14 و0 و0، والمتوسط 0.00. قرب -1: -0.98 و-1.08 و-0.91 و-1.03، والمتوسط -4.00 / 4 = -1.00. خطأ -1.08 هو -1.08 - (-1.00) = -0.08. وهذه بالضبط قيم الـ codebook في الشريحة 22.
Recall
How many bits does the original 4x4 matrix take, and how many bits per weight are needed once only four shared values remain?كم بتًا تأخذ المصفوفة 4x4 الأصلية، وكم بتًا يحتاج كل وزن بعد أن تبقى أربع قيم مُشارَكة فقط؟
16 × 32 = 512 bits (64 B). With four shared values, 2 bits per weight identify which one, plus a small table of the four values themselves.
16 × 32 = 512 بتًا (64 B). مع أربع قيم مُشارَكة، يكفي 2 بت لكل وزن لتحديد أيّها يستخدم، إضافة إلى جدول صغير يحوي القيم الأربع نفسها.
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
Quantization is the process of constraining an input from a continuous or otherwise large set of values to a discrete set.التكميم هو عملية تقييد مُدخل من مجموعة قيم متصلة أو كبيرة جدًا إلى مجموعة منفصلة (discrete).
Quantization error is the difference between an input value and its quantized value. With round-to-nearest on a grid of step Δ it is at most Δ/2.خطأ التكميم هو الفرق بين قيمة المُدخل وقيمته بعد التكميم. مع التقريب إلى الأقرب على شبكة خطوتها Δ، لا يتجاوز الخطأ Δ/2.
Palettization (a 16-colour image) is K-means quantization of colours: the palette is the codebook and each pixel stores a 4-bit index.الـ palettization (صورة بـ 16 لونًا) هي تكميم K-means للألوان: لوحة الألوان هي الـ codebook، وكل بكسل يخزّن فهرسًا (index) من 4 بتات.
Three approaches: K-means-based, linear, binary/ternary. Baseline stores FP weights and computes in FP arithmetic.ثلاث طرق: المعتمدة على K-means، والخطية (linear)، والثنائية/الثلاثية (binary/ternary). النموذج الأساسي (baseline) يخزّن أوزانًا بالفاصلة العائمة ويحسب بحساب الفاصلة العائمة.
K-means stores integer indexes plus an FP codebook, but computes in FP arithmetic: it saves storage, not compute.طريقة K-means تخزّن فهارس صحيحة إضافة إلى codebook بالفاصلة العائمة، لكنها تحسب بحساب الفاصلة العائمة: توفّر في التخزين لا في الحساب.
Linear quantization stores integers and can compute in integers, r = S(q - Z); the slide preview uses S = 1.07, Z = -1. Binary/ternary comes later.التكميم الخطي يخزّن أعدادًا صحيحة ويمكنه الحساب بأعداد صحيحة، r = S(q - Z)؛ ومعاينة الشريحة تستخدم S = 1.07 وZ = -1. أما الثنائي/الثلاثي فيأتي لاحقًا.
Running example: a 4x4 FP32 matrix (64 B). Weight sharing stores 2.09, 2.12, 1.92 and 1.87 all as 2.0, with errors 0.09, 0.12, -0.08 and -0.13.المثال المستمر: مصفوفة 4x4 بصيغة FP32 (64 B). مشاركة الأوزان تخزّن 2.09 و2.12 و1.92 و1.87 كلها بالقيمة 2.0، بأخطاء 0.09 و0.12 و-0.08 و-0.13.
Part 05: K-means weight quantization: codebook, storage and centroid fine-tuningتكميم الأوزان بـK-means: دفتر الترميز والتخزين وضبط المراكز
Cluster weights with K-means, store 2-bit cluster indexes plus a 32-bit codebook, compute the compression ratio, and fine-tune centroids by grouping gradients by cluster index and summing them.جمّع الأوزان بـK-means، وخزّن فهارس عناقيد من 2 بت مع دفتر ترميز (codebook) من 32 بت، واحسب نسبة الضغط، واضبط المراكز (centroids) بتجميع التدرجات حسب فهرس العنقود وجمعها.
4 concepts4 مفاهيم, ، slides 26-29الشرائح 26-29
Why this part mattersلماذا يهمّ هذا الجزء
A trained network stores every weight as a 32-bit float, yet many weights sit so close together that the network would barely notice if they shared one value. This part turns that observation into a working compression method: cluster the weights, keep only a short index per weight and a tiny table of shared values, then retrain the table so the network recovers its accuracy.
Everything here follows Figure 3 of Deep Compression (Han, Mao and Dally, ICLR 2016), the same 4 × 4 example the slides use. For the midterm, expect three kinds of question: the storage bill for given N and M, the fine-tuned centroids for a given gradient matrix and learning rate, and why the index map does not change during fine-tuning. For embedded work, this is the method that lets a model ship at a fraction of its size while the arithmetic stays in floating point.
الشبكة المدرَّبة تخزّن كل وزن كعدد عشري بحجم 32-bit، ومع ذلك فكثير من الأوزان قريبة جدًا من بعضها لدرجة أن الشبكة بالكاد ستلاحظ الفرق لو تشاركت قيمة واحدة. هذا الجزء يحوّل هذه الملاحظة إلى طريقة ضغط عملية: جمّع الأوزان في مجموعات، واحتفظ فقط بفهرس قصير لكل وزن وجدول صغير جدًا من القيم المشتركة، ثم أعد تدريب هذا الجدول حتى تستعيد الشبكة دقتها.
كل ما هنا يتبع الشكل 3 من ورقة Deep Compression (Han, Mao and Dally, ICLR 2016)، وهو نفس مثال 4 × 4 الذي تستخدمه الشرائح. في الاختبار النصفي توقّع ثلاثة أنواع من الأسئلة: حساب التخزين لقيم معطاة من N و M، والمراكز بعد الـ fine-tuning لمصفوفة gradients ومعدل تعلم معطيين، ولماذا لا تتغير خريطة الفهارس أثناء الـ fine-tuning. وفي الأنظمة المدمجة، هذه هي الطريقة التي تسمح بشحن النموذج بجزء صغير من حجمه بينما تبقى العمليات الحسابية بالفاصلة العائمة (floating point).
By the end you canفي نهاية هذا الجزء ستستطيع
01Cluster a small weight matrix with K-means and explain why each centroid is the mean of its cluster.تجميع مصفوفة أوزان صغيرة باستخدام K-means، وشرح لماذا يكون كل مركز (centroid) هو متوسط عناصر مجموعته.
02Turn a clustering into an index matrix plus a codebook, rebuild the weights and read the quantization error.تحويل نتيجة التجميع إلى مصفوفة فهارس (index matrix) زائد دفتر رموز (codebook)، ثم إعادة بناء الأوزان وقراءة خطأ التكميم (quantization error).
03Compute storage before and after for any N and M, and explain why the ratio approaches 32/N only when M is much larger than 2^N.حساب حجم التخزين قبل وبعد لأي N و M، وشرح لماذا تقترب النسبة من 32/N فقط عندما تكون M أكبر بكثير من 2^N.
04Derive the centroid gradient as the sum of the gradients of every weight that shares it.اشتقاق gradient المركز على أنه مجموع gradients كل الأوزان التي تشترك فيه.
05Fine-tune a codebook by hand: group by index, reduce by sum, multiply by the learning rate and subtract.ضبط دفتر الرموز (fine-tuning) يدويًا: جمّع حسب الفهرس، اختزل بالجمع، اضرب في معدل التعلم (learning rate) ثم اطرح.
Look at the 16 weights of the example layer. Four of them are 2.09, 2.12, 1.92 and 1.87. Four more are -0.98, -1.08, -0.91 and -1.03. Three hover around 1.5, and five sit near zero. The matrix holds sixteen numbers, but really only four ideas.
انظر إلى الأوزان الـ 16 في طبقة المثال. أربعة منها هي 2.09 و 2.12 و 1.92 و 1.87. وأربعة أخرى هي -0.98 و -1.08 و -0.91 و -1.03. ثلاثة تحوم حول 1.5، وخمسة تقع قرب الصفر. المصفوفة تحمل ستة عشر رقمًا، لكنها في الحقيقة تحمل أربع أفكار فقط.
From an observation to an algorithmمن ملاحظة إلى خوارزمية
Weight sharing makes that observation official: all weights in one group are replaced by one shared value. The question is how to choose the groups and the values. K-means-based weight quantization answers with one-dimensional K-means. You fix the number of clusters k in advance, then minimise the within-cluster sum of squares, the total squared distance from each weight to the value that will replace it.
Weight sharing (مشاركة الأوزان) تجعل هذه الملاحظة رسمية: كل الأوزان في مجموعة واحدة تُستبدل بقيمة مشتركة واحدة. السؤال هو كيف نختار المجموعات والقيم. K-means-based weight quantization تجيب باستخدام K-means أحادي البعد. تحدد عدد المجموعات k مسبقًا، ثم تقلّل مجموع المربعات داخل المجموعات (within-cluster sum of squares)، أي مجموع مربعات المسافات من كل وزن إلى القيمة التي ستحل محله.
argCmini=1∑kw∈ci∑∣w−ci∣2
Deep Compression, Eq. 2: partition the n weights into k clusters that minimise the within-cluster sum of squaresDeep Compression، المعادلة 2: قسّم الأوزان n إلى k عنقودًا بحيث يُقلَّل مجموع المربعات داخل العناقيد
The standard way to minimise it is Lloyd's algorithm. Start with k guesses for the shared values. Then repeat two steps until nothing changes. First, assign every weight to its nearest guess. Second, move every guess to the mean of the weights assigned to it. Neither step can raise the objective, so the loop always stops, though possibly at a local rather than global minimum, which is why the starting guesses matter.
الطريقة المعيارية لتقليله هي خوارزمية Lloyd. ابدأ بـ k تخمينات للقيم المشتركة. ثم كرّر خطوتين حتى لا يتغير شيء. أولًا، أسند كل وزن إلى أقرب تخمين. ثانيًا، انقل كل تخمين إلى متوسط الأوزان المسندة إليه. لا يمكن لأي من الخطوتين أن ترفع قيمة الهدف، لذلك تتوقف الحلقة دائمًا، لكن ربما عند قيمة صغرى محلية (local minimum) لا عامة (global)، ولهذا تهمّ التخمينات الابتدائية.
Each of the 16 FP32 weights snaps to the nearest of four shared values: -1.00, 0.00, 1.50 and 2.00كل وزن من الأوزان الـ 16 بصيغة FP32 ينجذب إلى أقرب قيمة من أربع قيم مشتركة: -1.00 و 0.00 و 1.50 و 2.00
The representative value of a cluster is its Centroid. Because the second Lloyd step sets it to the mean, you can check the slide by hand. Every centroid on slide 27 is the exact mean of its members:
القيمة الممثِّلة للمجموعة هي centroid (المركز). ولأن خطوة Lloyd الثانية تضعه عند المتوسط، يمكنك التحقق من الشريحة يدويًا. كل مركز في الشريحة 27 هو المتوسط الدقيق لأعضائه:
The k = 4 clustering of slide 26, with the index each colour receives on slide 27تجميع k = 4 من الشريحة 26، مع الفهرس الذي يأخذه كل لون في الشريحة 27
A useful consequence: since a centroid is a mean, the errors inside each cluster cancel. In the blue cluster, 0.09 + 0.12 - 0.08 - 0.13 = 0. That is a quick consistency check in an exam when you are handed a clustering and asked whether it is a converged K-means solution.
نتيجة مفيدة: بما أن المركز متوسط، فإن الأخطاء داخل كل مجموعة يلغي بعضها بعضًا. في المجموعة الزرقاء، 0.09 + 0.12 - 0.08 - 0.13 = 0. هذا فحص سريع للاتساق في الاختبار عندما تُعطى تجميعًا ويُسأل هل هو حل K-means متقارب (converged).
Where the starting guesses come fromمن أين تأتي التخمينات الابتدائية
Han et al. compared three initialisations: random (Forgy), density-based and linear. Linear spaces the starting centroids evenly between the smallest and largest weight. It won, because large-magnitude weights are rare but important, and the other two methods crowd the centroids into the dense middle of the distribution, leaving the few large weights badly represented. For the example, linear initialisation between -1.08 and 2.12 converges in one update to exactly the slide's four centroids.
قارن Han et al. بين ثلاث طرق للتهيئة (initialisation): العشوائية (Forgy)، والمعتمدة على الكثافة (density-based)، والخطية (linear). الطريقة الخطية توزّع المراكز الابتدائية بالتساوي بين أصغر وزن وأكبر وزن. وقد فازت، لأن الأوزان الكبيرة في القيمة المطلقة نادرة لكنها مهمة، والطريقتان الأخريان تحشران المراكز في الوسط الكثيف من التوزيع، فتبقى الأوزان الكبيرة القليلة ممثَّلة بشكل سيئ. في المثال، التهيئة الخطية بين -1.08 و 2.12 تتقارب في تحديث واحد إلى المراكز الأربعة نفسها الموجودة في الشريحة بالضبط.
Recall
State the two alternating steps of Lloyd's algorithm, and explain why the pink centroid is 1.50.اذكر الخطوتين المتناوبتين في خوارزمية Lloyd، واشرح لماذا يساوي المركز الوردي 1.50.
Assign each weight to its nearest centroid, then set each centroid to the mean of its assigned weights. The pink cluster holds 1.48, 1.53 and 1.49, whose mean is 4.50 / 3 = 1.50.
أسند كل وزن إلى أقرب مركز، ثم اجعل كل مركز يساوي متوسط الأوزان المسندة إليه. المجموعة الوردية تضم 1.48 و 1.53 و 1.49، ومتوسطها 4.50 / 3 = 1.50.
Once the clustering is fixed, the original matrix can be thrown away. In its place you store two things: a 4 × 4 matrix of small integers saying which cluster each weight belongs to, and a list of four floats saying what each cluster's value is.
بمجرد تثبيت التجميع يمكن التخلص من المصفوفة الأصلية. وتخزّن مكانها شيئين: مصفوفة 4 × 4 من أعداد صحيحة صغيرة تقول إلى أي مجموعة ينتمي كل وزن، وقائمة من أربعة أعداد عشرية تقول ما قيمة كل مجموعة.
Two tables replace oneجدولان بدلًا من جدول واحد
The integer matrix is the map of Cluster index values. With k=4 clusters an index needs log24=2 bits, so slide 27 labels it 2-bit int. Its first row is 3, 0, 2, 1. The list of floats is the Codebook: 3: 2.00, 2: 1.50, 1: 0.00, 0: -1.00. Notice the indexes are numbered in increasing centroid order, so index 0 is the most negative value.
مصفوفة الأعداد الصحيحة هي خريطة قيم cluster index (فهرس المجموعة). مع k=4 مجموعات يحتاج الفهرس إلى log24=2 بت، ولذلك تسمّيها الشريحة 27 باسم 2-bit int. صفها الأول هو 3, 0, 2, 1. أما قائمة الأعداد العشرية فهي codebook (دفتر الرموز): 3: 2.00 و 2: 1.50 و 1: 0.00 و 0: -1.00. لاحظ أن الفهارس مرقّمة بترتيب تصاعدي للمراكز، فالفهرس 0 هو القيمة الأكثر سالبية.
To use the layer you rebuild each weight by looking up its index in the codebook. Index 3 becomes 2.00, index 0 becomes -1.00, and so on. The rebuilt matrix is:
لاستخدام الطبقة تعيد بناء كل وزن بالبحث عن فهرسه في دفتر الرموز. الفهرس 3 يصبح 2.00، والفهرس 0 يصبح -1.00، وهكذا. المصفوفة المعاد بناؤها هي:
W^=20−12−10201.5−101.502−11.5,W^ij=CIij
Reconstructed weights: each entry is the codebook value at that position's indexالأوزان المعاد بناؤها: كل عنصر هو قيمة دفتر الرموز عند فهرس ذلك الموضع
The rebuilt weights are still 32-bit floats, which is why slide 27 labels them that way. K-means saves storage, not arithmetic: at inference the indexes are decoded through the codebook and the layer runs in floating point, the Decode (lookup) at inference step a later part covers.
الأوزان المعاد بناؤها ما زالت أعدادًا عشرية بحجم 32-bit، ولهذا تسمّيها الشريحة 27 بهذا الاسم. K-means يوفّر في التخزين لا في الحساب: عند الاستدلال (inference) تُفك الفهارس عبر دفتر الرموز وتعمل الطبقة بالفاصلة العائمة، وهي خطوة decode (lookup) التي يشرحها جزء لاحق.
What is lost: the quantization errorما الذي نخسره: خطأ التكميم
Subtracting gives the Quantization error at each position, original minus reconstructed:
الطرح يعطي quantization error (خطأ التكميم) عند كل موضع، أي الأصلي ناقص المعاد بناؤه:
Quantization error matrix from slide 27مصفوفة خطأ التكميم من الشريحة 27
The largest error in magnitude is -0.14, the weight -0.14 forced to 0.00. These small errors are what the network pays for compression, and what the fine-tuning in the next two concepts tries to win back.
أكبر خطأ في القيمة المطلقة هو -0.14، وهو الوزن -0.14 الذي أُجبر على أن يصبح 0.00. هذه الأخطاء الصغيرة هي الثمن الذي تدفعه الشبكة مقابل الضغط، وهي ما يحاول الـ fine-tuning في المفهومين التاليين استعادته.
The storage billفاتورة التخزين
Count bits. The original layer is 16 floats of 32 bits: 32 × 16 = 512 bit = 64 B. The quantized layer stores 16 indexes of 2 bits, 32 bit = 4 B, plus 4 centroids of 32 bits, 128 bit = 16 B. Total 20 B, so the layer is 64 / 20 = 3.2× smaller. That is the Compression ratio on the slide.
عُدّ البتات. الطبقة الأصلية هي 16 عددًا عشريًا كل منها 32 بت: 32 × 16 = 512 bit = 64 B. الطبقة المكمَّمة تخزّن 16 فهرسًا كل منها 2 بت، أي 32 bit = 4 B، زائد 4 مراكز كل منها 32 بت، أي 128 bit = 16 B. المجموع 20 B، فالطبقة أصغر بمقدار 64 / 20 = 3.2×. هذه هي compression ratio (نسبة الضغط) في الشريحة.
64 B of FP32 weights against 4 B of indexes plus 16 B of codebook: the codebook is most of the 20 B64 B من أوزان FP32 مقابل 4 B من الفهارس زائد 16 B من دفتر الرموز: دفتر الرموز هو معظم الـ 20 B
Now generalise. Take N-bit indexes, so k=2N clusters, and M parameters. The original costs 32M bits. The indexes cost NM bits and the codebook 32⋅2N=2N+5 bits.
الآن عمّم. خذ فهارس من N بت، أي k=2N مجموعة، و M معاملًا. الأصل يكلّف 32M بت. الفهارس تكلّف NM بت، ودفتر الرموز 32⋅2N=2N+5 بت.
r=NM+2N+532MM≫2NN32
Compression ratio of N-bit K-means quantization; Han et al. write it as nb / (n log2 k + kb)نسبة الضغط لتكميم K-means بعدد N من البتات؛ ويكتبها Han et al. على الصورة nb / (n log2 k + kb)
The codebook term does not grow with M. In a real layer with M = 1,000,000 and N = 4, the codebook is 16 × 32 = 512 bit against 4,000,000 bit of indexes, about 0.013% of the total. That is why the slide crosses it out.
حدّ دفتر الرموز لا يكبر مع M. في طبقة حقيقية فيها M = 1,000,000 و N = 4، يكون دفتر الرموز 16 × 32 = 512 bit مقابل 4,000,000 bit من الفهارس، أي نحو 0.013% من المجموع. ولهذا تشطبه الشريحة.
The 4 × 4 example misses 32/2 = 16× by a wide margin because its assumption M≫2N fails: with only 16 weights, the 16 B codebook is 80% of the 20 B total. Push it further and the method backfires. At N = 4 on these 16 weights, the indexes cost 64 bit but the codebook costs 512 bit, 72 B in all, larger than the 64 B original.
مثال 4 × 4 يبتعد كثيرًا عن 32/2 = 16× لأن افتراضه M≫2N لا يتحقق: مع 16 وزنًا فقط، يمثّل دفتر الرموز البالغ 16 B نسبة 80% من المجموع 20 B. وإذا ذهبت أبعد تنقلب الطريقة ضدك. عند N = 4 على هذه الأوزان الـ 16، تكلّف الفهارس 64 bit لكن دفتر الرموز يكلّف 512 bit، أي 72 B إجمالًا، وهذا أكبر من الأصل البالغ 64 B.
Itemالعنصر
Formulaالصيغة
Slide: N = 2, M = 16الشريحة: N = 2، M = 16
Layer: N = 4, M = 10^6طبقة: N = 4، M = 10^6
Original weightsالأوزان الأصلية
32 bit x M32 bit x M
32 x 16 = 512 bit = 64 B32 x 16 = 512 bit = 64 B
32,000,000 bit32,000,000 bit
Indexesالفهارس
N bit x MN bit x M
2 x 16 = 32 bit = 4 B2 x 16 = 32 bit = 4 B
4,000,000 bit4,000,000 bit
Codebookدفتر الرموز (codebook)
32 bit x 2^N = 2^(N+5) bit32 bit x 2^N = 2^(N+5) bit
32 x 4 = 128 bit = 16 B32 x 4 = 128 bit = 16 B
32 x 16 = 512 bit32 x 16 = 512 bit
Ratioالنسبة
32M / (NM + 2^(N+5))32M / (NM + 2^(N+5))
64 / 20 = 3.2x64 / 20 = 3.2x
≈ 8.0x (32/N = 8)≈ 8.0x (32/N = 8)
The same three formulas applied to the slide example and to a realistic layerالصيغ الثلاث نفسها مطبّقة على مثال الشريحة وعلى طبقة واقعية
The simulator runs K-means on the slide's weights. At k = 4 it reproduces slide 27 exactly. Switch to k = 2: the ratio rises to 6.4× but the errors grow to about 0.6. Switch to k = 8: the errors barely improve, three centroids own no weight at all, and the ratio falls to 1.68× because the codebook doubles.
المحاكي يشغّل K-means على أوزان الشريحة. عند k = 4 يعيد إنتاج الشريحة 27 بالضبط. انتقل إلى k = 2: ترتفع النسبة إلى 6.4× لكن الأخطاء تكبر إلى نحو 0.6. انتقل إلى k = 8: الأخطاء بالكاد تتحسن، وثلاثة مراكز لا يملك أي منها أي وزن، وتنخفض النسبة إلى 1.68× لأن دفتر الرموز يتضاعف.
SimulatorمحاكيK-means on the 16 slide weights: indexes, codebook and storageK-means على أوزان الشريحة الستة عشر: الفهارس ودفتر الرموز والتخزين
Weights, coloured by clusterالأوزان ملوّنة حسب العنقود32-bit float
Lloyd iterations from linear initialisation: 1. Mean absolute error 0.061. Every centroid is the mean of the weights that point to it, so within each cluster the errors cancel (exactly at k = 4, up to display rounding otherwise). With only 16 weights the codebook is a large share of the bill, which is why the ratio here sits far below 32/2 = 16.0x.عدد تكرارات Lloyd بدءا من التهيئة الخطية: 1. متوسط الخطأ المطلق 0.061. كل مركز هو متوسط الأوزان التي تشير إليه، لذلك تتلاشى الأخطاء داخل كل عنقود (تماما عند k = 4، وفي غيرها بقدر تقريب العرض). مع 16 وزنا فقط يشغل دفتر الرموز حصة كبيرة من الفاتورة، ولهذا تبقى النسبة هنا أقل بكثير من 32/2 = 16.0x.
Centroids start evenly spaced between the smallest and largest weight (the linear initialisation Han et al. found best) and are rounded to two decimals for display. At k = 4 the result is exactly the slide: codebook -1.00, 0.00, 1.50, 2.00, 20 B, 3.2x.تبدأ المراكز موزعة بالتساوي بين أصغر وزن وأكبر وزن (وهي التهيئة الخطية التي وجدها Han et al. الأفضل)، وتُقرَّب إلى منزلتين عشريتين للعرض. عند k = 4 تطابق النتيجة الشريحة تماما: دفتر الرموز -1.00, 0.00, 1.50, 2.00، و20 B، و3.2x.
Quick checkاختبار سريع
A layer with one million weights is quantized with 4-bit K-means and an FP32 codebook. About how much smaller does it become?طبقة فيها مليون وزن تُكمَّم باستخدام K-means بـ 4 بت مع دفتر رموز (codebook) بصيغة FP32. بكم مرة تقريبًا يصغر حجمها؟
Recall
Why does the 4 × 4 example reach only 3.2× when 32/N predicts 16×?لماذا يصل مثال 4 × 4 إلى 3.2× فقط بينما تتوقع 32/N قيمة 16×؟
The formula 32/N assumes the codebook is negligible (M ≫ 2^N). Here the codebook is 16 B out of 20 B. Without it, 64 / 4 = 16×; with it, 64 / 20 = 3.2×.
الصيغة 32/N تفترض أن دفتر الرموز مهمل (M ≫ 2^N). هنا دفتر الرموز 16 B من أصل 20 B. بدونه تكون النسبة 64 / 4 = 16×، ومعه 64 / 20 = 3.2×.
Quantizing a trained network nudges every weight by its quantization error, and the accuracy usually drops a little. The fix is to keep training. But what exactly is there to train, now that the weights no longer exist as sixteen independent numbers?
تكميم شبكة مدرَّبة يزيح كل وزن بمقدار خطأ التكميم الخاص به، وعادة تنخفض الدقة قليلًا. والحل هو مواصلة التدريب. لكن ما الذي يمكن تدريبه بالضبط، بعد أن لم تعد الأوزان موجودة كستة عشر رقمًا مستقلًا؟
Only the codebook is free to moveدفتر الرموز وحده حرّ في الحركة
After quantization the layer is described by the index map and the codebook. The index map is a grid of integers: there is no meaningful small step from index 2 to index 2.01, so it has no gradient. The four centroids are ordinary floats, and the forward pass uses them through W^ij=CIij. So Centroid fine-tuning trains the codebook and keeps every index exactly where K-means put it. The Deep Compression paper describes this as a level of indirection in both the forward and backward pass.
بعد التكميم توصف الطبقة بخريطة الفهارس ودفتر الرموز. خريطة الفهارس شبكة من الأعداد الصحيحة: لا توجد خطوة صغيرة ذات معنى من الفهرس 2 إلى الفهرس 2.01، لذلك ليس لها gradient. أما المراكز الأربعة فهي أعداد عشرية عادية، والتمرير الأمامي (forward pass) يستخدمها عبر W^ij=CIij. ولذلك فإن centroid fine-tuning يدرّب دفتر الرموز ويُبقي كل فهرس بالضبط حيث وضعه K-means. وتصف ورقة Deep Compression ذلك بأنه مستوى من الإحالة غير المباشرة (indirection) في التمرير الأمامي والخلفي معًا.
Backpropagation still produces one gradient per weightالـ backpropagation ما زال ينتج gradient واحدًا لكل وزن
The forward pass runs with the reconstructed weights, so ordinary backpropagation returns the usual 4 × 4 matrix ∂L/∂Wij, one number per position. Slide 28 shows it: first row -0.03, -0.01, 0.03, 0.02, and the largest entry is 0.12 at row 2, column 4. These numbers are gradients for positions, but the parameters are centroids. The chain rule connects the two.
التمرير الأمامي يعمل بالأوزان المعاد بناؤها، لذلك يعيد الـ backpropagation العادي مصفوفة 4 × 4 المعتادة ∂L/∂Wij، رقمًا واحدًا لكل موضع. تعرضها الشريحة 28: الصف الأول -0.03, -0.01, 0.03, 0.02، وأكبر عنصر هو 0.12 في الصف 2 والعمود 4. هذه الأرقام gradients للمواضع، لكن المعاملات هي المراكز. وقاعدة السلسلة (chain rule) تربط بين الاثنين.
Centroid Ck appears in every position whose index is k, and nowhere else. So ∂Wij/∂Ck is 1 when Iij=k and 0 otherwise. Summing over all positions:
المركز Ck يظهر في كل موضع فهرسه k، ولا يظهر في أي مكان آخر. لذلك فإن ∂Wij/∂Ck تساوي 1 عندما Iij=k و 0 في غير ذلك. وبالجمع على كل المواضع:
Deep Compression, Eq. 3: the centroid gradient is the sum of the gradients of all weights that use itDeep Compression، المعادلة 3: تدرّج المركز هو مجموع تدرجات كل الأوزان التي تستخدمه
This is the same rule that governs any shared parameter, such as one convolution filter used at every image position: a parameter used in several places receives the sum of the gradients from all of them.
هذه هي نفس القاعدة التي تحكم أي معامل مشترك، مثل مرشّح convolution واحد يُستخدم في كل موضع من الصورة: المعامل المستخدم في عدة أماكن يتلقى مجموع الـ gradients من كل تلك الأماكن.
Recall
Why is the index map not trained during fine-tuning? Give two reasons.لماذا لا تُدرَّب خريطة الفهارس أثناء الـ fine-tuning؟ اذكر سببين.
Indexes are discrete integers, so they have no gradient: a tiny change has no meaning. And keeping them fixed keeps the stored compressed format (the 2-bit map and its storage cost) valid throughout training; changing them would amount to re-clustering.
الفهارس أعداد صحيحة منفصلة (discrete)، لذلك ليس لها gradient: التغيير الصغير جدًا لا معنى له. كما أن تثبيتها يُبقي الصيغة المضغوطة المخزّنة (خريطة 2-bit وكلفة تخزينها) صالحة طوال التدريب؛ وتغييرها يعادل إعادة التجميع.
Slide 29 turns the formula into three mechanical moves you can do with a pencil: group the gradients by colour, reduce each group to one number, then take a gradient-descent step on each centroid.
الشريحة 29 تحوّل الصيغة إلى ثلاث حركات آلية يمكنك تنفيذها بالقلم: جمّع الـ gradients حسب اللون، واختزل كل مجموعة إلى رقم واحد، ثم خذ خطوة gradient descent على كل مركز.
Group, reduce, updateجمّع، اختزل، حدّث
Group by index. Lay the gradient matrix over the index map. Every gradient joins the group of the index at the same position. Read in row-major order, blue (index 3) collects -0.03, 0.12, 0.02, -0.07.التجميع حسب الفهرس (group by index). ضع مصفوفة الـ gradients فوق خريطة الفهارس. كل gradient ينضم إلى مجموعة الفهرس الموجود في الموضع نفسه. بالقراءة صفًا بعد صف (row-major)، يجمع الأزرق (الفهرس 3) القيم -0.03, 0.12, 0.02, -0.07.
Reduce by sum. Add up each group. The result is ∂L/∂Ck.الاختزال بالجمع (reduce by sum). اجمع كل مجموعة. الناتج هو ∂L/∂Ck.
Update. Multiply by the learning rate and subtract from the old centroid.التحديث (update). اضرب في معدل التعلم واطرح الناتج من المركز القديم.
Ck←Ck−lr⋅Iij=k∑∂Wij∂L
Centroid updateتحديث المركز (centroid)
Sixteen gradients flow into four sums, and each sum moves one centroid: 2.00 to 1.96, 1.50 to 1.48, 0.00 to -0.04, -1.00 to -0.97ستة عشر gradient تتدفق إلى أربعة مجاميع، وكل مجموع يحرّك مركزًا واحدًا: 2.00 إلى 1.96، و 1.50 إلى 1.48، و 0.00 إلى -0.04، و -1.00 إلى -0.97
Slide 29 grouped and reduced, then updated with lr = 1الشريحة 29 بعد التجميع والاختزال، ثم التحديث مع lr = 1
Watch the signs. A positive summed gradient means the loss rises as the centroid rises, so the centroid moves down: blue falls from 2.00 to 1.96. Green's sum is negative, so it moves up, from -1.00 to -0.97. Step through it with a different learning rate below.
انتبه للإشارات. الـ gradient المجموع الموجب يعني أن الخسارة ترتفع عندما يرتفع المركز، لذلك يتحرك المركز إلى الأسفل: الأزرق ينخفض من 2.00 إلى 1.96. مجموع الأخضر سالب، لذلك يتحرك إلى الأعلى، من -1.00 إلى -0.97. جرّب الخطوات بمعدل تعلم مختلف في الأسفل.
SimulatorمحاكيCentroid fine-tuning: group, reduce, then step against the gradientالضبط الدقيق للمراكز: جمّع، اختزل، ثم خذ خطوة عكس التدرّج
1. Gradient1. التدرّج
2. Group by index2. التجميع حسب الفهرس
3. Reduce (sum)3. الاختزال (الجمع)
4. Centroid - lr x sum4. المركز - lr x المجموع
Gradient dL/dW, coloured by indexالتدرّج dL/dW ملوّنا حسب الفهرسfrom backprop
Cluster index (frozen)فهرس العنقود (مجمّد)2-bit uint
3021110303103122
index 3-0.03 + 0.12 + 0.02 - 0.07= 0.042.00 - 1 x 0.04 = 1.96
index 20.03 + 0.01 - 0.02= 0.021.50 - 1 x 0.02 = 1.48
index 10.02 - 0.01 + 0.01 + 0.04 - 0.02= 0.040.00 - 1 x 0.04 = -0.04
index 0-0.01 - 0.02 - 0.01 + 0.01= -0.03-1.00 - 1 x -0.03 = -0.97
Backpropagation gives one gradient per weight position, the 4 x 4 matrix on the left. The index map beside it is frozen.يعطي الانتشار العكسي backpropagation تدرّجا واحدا لكل موضع وزن، وهو المصفوفة 4 x 4 على اليسار. أما خريطة الفهارس بجانبها فمجمّدة.
Gradients and centroids are the slide 28 and 29 values from Han et al., Figure 3. The slide prints x lr without a value; its fine-tuned centroids only follow with lr = 1. Try lr = 0.1 to see the realistic, much smaller step.التدرّجات والمراكز هي قيم الشريحتين 28 و29 المأخوذة من Han et al.، الشكل 3. تكتب الشريحة x lr دون قيمة، ولا تتحقق مراكزها بعد الضبط الدقيق إلا مع lr = 1. جرّب lr = 0.1 لترى الخطوة الواقعية الأصغر بكثير.
Worked exampleمثال محلول
The same gradients with lr = 0.5نفس الـ gradients مع lr = 0.5
Centroid 0 is -1.00 and its gradients sum to -0.03. With lr = 0.5, what is the fine-tuned centroid?المركز 0 قيمته -1.00 ومجموع gradients الخاصة به -0.03. مع lr = 0.5، ما قيمة المركز بعد الـ fine-tuning؟
Quick checkاختبار سريع
During centroid fine-tuning, what happens to the 2-bit index matrix?أثناء الـ fine-tuning للمراكز، ماذا يحدث لمصفوفة الفهارس ذات الـ 2 بت؟
Recall
Without looking, reduce the slide 29 gradients for cluster 1 (orange) and give its new centroid at lr = 1.دون أن تنظر، اختزل gradients الشريحة 29 للمجموعة 1 (البرتقالية) وأعطِ مركزها الجديد عند lr = 1.
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
K-means (Lloyd's algorithm) alternates two steps: assign each weight to its nearest centroid, then move each centroid to the mean of its members.خوارزمية K-means (خوارزمية Lloyd) تتناوب بين خطوتين: أسند كل وزن إلى أقرب مركز، ثم انقل كل مركز إلى متوسط أعضائه.
On the slide example, k = 4 gives centroids -1.00, 0.00, 1.50 and 2.00, each the exact mean of its 4, 5, 3 and 4 weights.في مثال الشريحة، k = 4 يعطي المراكز -1.00 و 0.00 و 1.50 و 2.00، وكل منها هو المتوسط الدقيق لأوزانه البالغ عددها 4 و 5 و 3 و 4 على الترتيب.
Store an N-bit index per weight plus a codebook of 2^N FP32 centroids. Reconstructed weight = codebook[index].خزّن فهرسًا من N بت لكل وزن، زائد دفتر رموز (codebook) فيه 2^N مركزًا بصيغة FP32. الوزن المُعاد بناؤه = codebook[index].
Storage: 32M bits before, NM + 32 x 2^N bits after. The example drops 64 B to 4 B + 16 B = 20 B, a 3.2x saving.التخزين: 32M بت قبل، و NM + 32 x 2^N بت بعد. في المثال ينخفض الحجم من 64 B إلى 4 B + 16 B = 20 B، أي توفير بمقدار 3.2x.
When M is much larger than 2^N the codebook is negligible and the ratio tends to 32/N (8.0x for N = 4 and a million weights).عندما تكون M أكبر بكثير من 2^N يصبح دفتر الرموز مهملًا وتقترب النسبة من 32/N (أي 8.0x عند N = 4 ومليون وزن).
The index map is frozen during fine-tuning. Only the centroids train, with dL/dC_k = sum of dL/dW over the weights whose index is k.خريطة الفهارس مجمّدة أثناء الـ fine-tuning. المراكز وحدها تتدرّب، مع dL/dC_k = مجموع dL/dW على كل الأوزان التي فهرسها k.
Slide 29: sums 0.04, 0.02, 0.04, -0.03 give fine-tuned centroids 1.96, 1.48, -0.04, -0.97, which implies lr = 1.الشريحة 29: المجاميع 0.04 و 0.02 و 0.04 و -0.03 تعطي مراكز بعد الضبط 1.96 و 1.48 و -0.04 و -0.97، وهذا يعني أن lr = 1.
Part 06: How far can we compress: accuracy curves, weight histograms and bit choiceإلى أي حد نضغط: منحنيات الدقة ومدرجات الأوزان واختيار البتات
Reads the AlexNet accuracy versus model-size curves for pruning only, quantization only and both combined, shows weights becoming discrete after quantization and shifting slightly after retraining, and how many bits conv and FC layers need.يقرأ منحنيات الدقة مقابل حجم النموذج في AlexNet للتقليم وحده والتكميم وحده والاثنين معًا، ويبين أن الأوزان تصبح منفصلة بعد التكميم وتنزاح قليلًا بعد إعادة التدريب، وكم بتًا تحتاج طبقات الالتفاف (conv) والطبقات المتصلة كليًا (FC).
3 concepts3 مفاهيم, ، slides 30-36الشرائح 30-36
Why this part mattersلماذا يهمّ هذا الجزء
The previous parts showed how K-means quantization stores each weight as a short index into a codebook. This part asks the engineering question that follows: how far can you push it before the model breaks, and does it combine with pruning? Every number here comes from one paper, Han, Mao and Dally's Deep Compression (ICLR 2016), using AlexNet on ImageNet.
Three pictures carry the argument. First, accuracy versus size curves, which show that pruning and quantization are complementary. Second, weight histograms, which show what quantization physically does to the weights and what retraining changes. Third, a sweep over bits per weight, which shows that conv and FC layers need very different precision. For the midterm, expect to read a plot like these and to explain the FC versus conv difference. For a real embedded deployment, these are the curves you sketch before choosing a bit-width for each layer of your own model.
الأجزاء السابقة أوضحت كيف يخزّن K-means quantization كل وزن على شكل index قصير يشير إلى codebook. هذا الجزء يطرح السؤال الهندسي الذي يليه مباشرة: إلى أي حد يمكنك أن تضغط قبل أن ينهار النموذج، وهل يمكن دمج ذلك مع الـ pruning؟ كل رقم هنا مأخوذ من ورقة واحدة، ورقة Deep Compression لـ Han وMao وDally (ICLR 2016)، باستخدام AlexNet على ImageNet.
ثلاث صور تحمل الفكرة كاملة. الأولى: منحنيات الدقة مقابل الحجم، وهي تبيّن أن الـ pruningوالـ quantization متكاملان. الثانية: الـ histograms الخاصة بالأوزان، وهي تبيّن ما يفعله الـ quantization بالأوزان فعليًا وما الذي يغيّره الـ retraining. الثالثة: مسح على عدد الـ bits لكل وزن، ويبيّن أن طبقات الـ conv وطبقات الـ FC تحتاج دقة مختلفة جدًا. في الـ midterm توقّع أن يُطلب منك قراءة رسم مثل هذه الرسوم وشرح الفرق بين FC وconv. وفي أي نشر حقيقي على جهاز مدمج (embedded)، هذه هي المنحنيات التي ترسمها قبل أن تختار الـ bit-width لكل طبقة في نموذجك.
By the end you canفي نهاية هذا الجزء ستستطيع
01Read an accuracy-loss versus model-size-ratio plot and locate where each method falls off its cliff.تقرأ رسمًا بيانيًا لفقدان الدقة مقابل نسبة حجم النموذج وتحدد أين تسقط كل طريقة من حافة الجرف الخاصة بها.
02Explain why pruning plus quantization reaches about 3% of AlexNet's size with no loss, while each alone stalls near 8%.تشرح لماذا يصل الـ pruning مع الـ quantization إلى نحو 3% من حجم AlexNet بلا أي فقدان، بينما يتوقف كل منهما وحده عند نحو 8%.
03Estimate a compressed size ratio from the fraction of weights kept and the bits per weight and per index.تقدّر نسبة الحجم بعد الضغط من نسبة الأوزان المُبقاة وعدد الـ bits لكل وزن ولكل index.
04Describe how the weight histogram changes from continuous, to discrete spikes, to slightly shifted spikes after retraining.تصف كيف يتغير الـ histogram الخاص بالأوزان من توزيع متصل، إلى قمم منفصلة، إلى قمم منزاحة قليلًا بعد الـ retraining.
05State the bit-width knees (conv 4 bits, FC 2 bits) and explain why FC layers tolerate fewer bits.تذكر نقاط الانكسار (knees) في عدد الـ bits (الـ conv عند 4 bits والـ FC عند 2 bits) وتشرح لماذا تتحمل طبقات الـ FC عددًا أقل من الـ bits.
Suppose you must fit AlexNet, about 240 MB of FP32 weights, onto a microcontroller-class device with a few megabytes of flash. You need the model at roughly 3% of its size. Slide 32 answers whether that is possible without losing accuracy, and which tool gets you there.
لنفترض أنك مطالب بوضع AlexNet، أي نحو 240 MB من أوزان FP32، على جهاز من فئة الـ microcontroller لا تتجاوز ذاكرة الـ flash فيه بضعة ميغابايتات. أنت تحتاج النموذج بنحو 3% من حجمه. الشريحة 32 تجيب عن سؤالين: هل هذا ممكن دون فقدان في الدقة، وأي أداة توصلك إلى هناك.
How to read the plotكيف تقرأ الرسم
The x-axis is the model size ratio after compression: compressed size divided by original size, so 20% means a model five times smaller and 2% means fifty times smaller. Moving left means more compression. The y-axis is accuracy loss relative to the uncompressed model, so 0% is "as good as the original" and lower is worse. A good method is a curve that stays flat at the top while it travels as far left as possible, then drops. The place where it drops is the method's cliff.
المحور الأفقي هو نسبة حجم النموذج بعد الضغط (model size ratio after compression): الحجم بعد الضغط مقسومًا على الحجم الأصلي، فـ 20% تعني نموذجًا أصغر بخمس مرات و2% تعني نموذجًا أصغر بخمسين مرة. التحرك يسارًا يعني ضغطًا أكبر. المحور الرأسي هو فقدان الدقة (accuracy loss) مقارنةً بالنموذج غير المضغوط، فـ 0% تعني "بجودة النموذج الأصلي نفسها"، وكلما نزلت كانت النتيجة أسوأ. الطريقة الجيدة منحنى يبقى مسطحًا في الأعلى وهو يتحرك يسارًا أبعد ما يمكن، ثم يهبط. المكان الذي يهبط فيه هو حافة الجرف (cliff) الخاصة بتلك الطريقة.
Accuracy loss versus model size for AlexNet on ImageNet. Points are read approximately from the Deep Compression figure on slide 32, not from raw data.فقدان الدقة مقابل حجم النموذج لـ AlexNet على ImageNet. النقاط مقروءة تقريبيًا من شكل Deep Compression في الشريحة 32، وليست من بيانات خام.
Three curves, three cliffsثلاثة منحنيات وثلاث حواف جرف
Quantization only (slide 30). K-means quantization alone stays within about 0.5% of the original down to about 8% of the size. Below about 7% it falls almost vertically, past -3.5% at about 6.5%.الـ quantization وحده (الشريحة 30). الـ K-means quantization وحده يبقى في حدود نحو 0.5% من النموذج الأصلي حتى نحو 8% من الحجم. وتحت نحو 7% يهبط بشكل شبه عمودي، فيتجاوز -3.5% عند نحو 6.5%.
Pruning only (slide 31). Pruning alone holds near 0% down to about 10% of the size, then degrades more gradually: about -1% at 6.3%, about -2% at 5.3% and about -4.2% near 4.3%.الـ pruning وحده (الشريحة 31). الـ pruning وحده يبقى قريبًا من 0% حتى نحو 10% من الحجم، ثم يتدهور بشكل أكثر تدرجًا: نحو -1% عند 6.3%، ونحو -2% عند 5.3%، ونحو -4.2% قرب 4.3%.
Pruning plus quantization (slide 32). The combined curve sits at 0% (even slightly above) all the way down to about 3% of the original size, and only collapses below about 2.8%.الـ pruning مع الـ quantization (الشريحة 32). المنحنى المدمج يبقى عند 0% (بل أعلى قليلًا) طوال الطريق حتى نحو 3% من الحجم الأصلي، ولا ينهار إلا تحت نحو 2.8%.
The paper states it plainly: each method alone "begins to drop significantly when compressed below 8% of its original size", but combined, "the network can be compressed to 3% of original size with no loss of accuracy."
الورقة تقولها بوضوح: كل طريقة وحدها "تبدأ دقتها بالهبوط بشكل ملحوظ عند ضغطها إلى أقل من 8% من حجمها الأصلي"، لكن عند دمجهما "يمكن ضغط الشبكة إلى 3% من حجمها الأصلي دون أي فقدان في الدقة".
Why combining wins: they shrink different factorsلماذا يفوز الدمج: كل منهما يقلّص عاملًا مختلفًا
The stored size of a layer is a product of two factors: how many weights you keep, and how many bits each kept weight costs. Pruning attacks the first factor. Quantization attacks the second. Because they multiply, pushing each one only to its comfortable zone, far from its own cliff, already gives a product far smaller than either can reach alone.
الحجم المخزّن لأي طبقة هو حاصل ضرب عاملين: كم وزنًا تُبقي، وكم bit يكلّف كل وزن مُبقى. الـ pruning يهاجم العامل الأول، والـ quantization يهاجم العامل الثاني. ولأن العاملين يُضربان ببعضهما، فإن دفع كل منهما فقط إلى منطقته المريحة، بعيدًا عن حافة الجرف الخاصة به، يعطي بالفعل حاصل ضرب أصغر بكثير مما يصل إليه أي منهما وحده.
size ratio≈p×32bw+bi
p = fraction of weights kept, b_w = bits per kept weight (the cluster index), b_i = bits for the sparse position index, 32 = bits of an FP32 weight. Codebooks add a small extra.p = نسبة الأوزان الباقية، وb_w = البتات لكل وزن باقٍ (فهرس العنقود)، وb_i = بتات فهرس الموضع المتناثر، و32 = بتات وزن FP32. وتضيف دفاتر الرموز زيادة صغيرة.
Worked exampleمثال محلول
Estimating the three cliffs for AlexNetتقدير حواف الجرف الثلاث لـ AlexNet
Quantization only: everything is in b_wالـ quantization وحده: كل شيء في b_w
With nothing pruned, p = 1 and there is no position index, so the ratio is just b_w / 32. At 8 bits that is 25%, at 4 bits it is 12.5%, at 2 bits it is 6.25%. FC layers hold about 96% of the weights, so the average is set almost entirely by them. FC at 2 bits and conv at 4 bits gives 0.96 x 2 + 0.04 x 4 ≈ 2.1 bits, about 6.5%: exactly where the cliff is. Going further left needs 1-bit FC layers or sub-4-bit conv layers, and the third concept shows both collapse.
بلا أي pruning تكون p = 1 ولا يوجد index للمواقع، فالنسبة هي ببساطة b_w / 32. عند 8 bits تساوي 25%، وعند 4 bits تساوي 12.5%، وعند 2 bits تساوي 6.25%. طبقات الـ FC تحمل نحو 96% من الأوزان، لذلك يكاد المتوسط يتحدد بها وحدها. الـ FC عند 2 bits مع الـ conv عند 4 bits يعطي 0.96 x 2 + 0.04 x 4 ≈ 2.1 bits، أي نحو 6.5%: وهذا بالضبط موقع حافة الجرف. التقدم أكثر نحو اليسار يتطلب طبقات FC بـ 1-bit أو طبقات conv بأقل من 4-bit، والمفهوم الثالث يبيّن أن كليهما ينهار.
Pruning only: everything is in pالـ pruning وحده: كل شيء في p
Deep Compression keeps 11% of AlexNet's weights (a 9x reduction). Kept weights are still FP32 and each needs a position index of about 4 bits: 0.11 x (32 + 4) / 32 ≈ 12%. Pushing pruning much further than this is what bends the pruning-only curve down.
ورقة Deep Compression تُبقي 11% من أوزان AlexNet (تقليل بمقدار 9x). الأوزان المُبقاة ما زالت FP32 وكل منها يحتاج index للموقع بنحو 4 bits: 0.11 x (32 + 4) / 32 ≈ 12%. دفع الـ pruning إلى أبعد من هذا بكثير هو ما يجعل منحنى الـ pruning وحده ينحني إلى الأسفل.
Both together: p and b_w are moderate at the same timeالاثنان معًا: p وb_w معتدلان في الوقت نفسه
Keep 11% of the weights, quantize them to an average of 5.4 bits, and use 4-bit position indexes: 0.11 x (5.4 + 4) / 32 ≈ 3.2%. Neither factor is anywhere near its own cliff.
أبقِ 11% من الأوزان، وحوّلها بالـ quantization إلى متوسط 5.4 bits، واستخدم index للمواقع بـ 4-bit: 0.11 x (5.4 + 4) / 32 ≈ 3.2%. لا يقترب أي من العاملين من حافة الجرف الخاصة به.
Resultالنتيجة
The paper's Table 4 reports 3.7% (27x) for pruning plus quantization, a little above the estimate because of codebooks and filler entries for long index gaps, and 2.88% (35x) once Huffman coding is added. That is 240 MB down to about 6.9 MB.
الجدول 4 في الورقة يذكر 3.7% (27x) للـ pruning مع الـ quantization، وهي أعلى قليلًا من التقدير بسبب الـ codebooks والمدخلات الحشوية (filler entries) للفجوات الطويلة بين الـ indexes، و2.88% (35x) بعد إضافة Huffman coding. أي من 240 MB إلى نحو 6.9 MB.
There is a second, subtler reason the combination works. After pruning, far fewer weights share the same number of centroids: pruned AlexNet has about 6.7M weights to cluster instead of about 60M, so for the same Codebook size the Quantization error is smaller. Pruning does not just coexist with quantization; it makes the quantizer's job slightly easier.
هناك سبب ثانٍ أدق يجعل الدمج ناجحًا. بعد الـ pruning يصبح عدد الأوزان التي تتشارك العدد نفسه من الـ centroids أقل بكثير: AlexNet بعد الـ pruning فيه نحو 6.7M وزن يجب تجميعها بدلًا من نحو 60M، لذلك يكون الـ quantization error أصغر عند حجم codebook نفسه. الـ pruning لا يتعايش مع الـ quantization فحسب، بل يجعل مهمة الـ quantizer أسهل قليلًا.
Recall
Using the size-ratio formula, why does quantization alone hit a wall near 6% to 7% of the original size?باستخدام معادلة نسبة الحجم، لماذا يصطدم الـ quantization وحده بجدار عند نحو 6% إلى 7% من الحجم الأصلي؟
With no pruning the ratio is about b_w / 32, so 6.5% is an average of about 2.1 bits. Because FC layers hold about 96% of the weights, that is FC at 2 bits with conv at 4 bits, both sitting on their knees. Going further left forces FC to 1 bit or conv below 4 bits, and either one collapses accuracy.
بلا pruning تكون النسبة نحو b_w / 32، إذن 6.5% تعني متوسطًا قدره نحو 2.1 bits. ولأن طبقات الـ FC تحمل نحو 96% من الأوزان، فهذا يعني FC عند 2 bits مع conv عند 4 bits، وكلاهما يقف تمامًا على نقطة الانكسار (knee) الخاصة به. التقدم أكثر نحو اليسار يجبر الـ FC على 1 bit أو الـ conv على أقل من 4 bits، وأي منهما يدمّر الدقة.
Quick checkاختبار سريع
Why does pruning plus quantization reach a much smaller lossless size than either technique alone?لماذا يصل الـ pruning مع الـ quantization إلى حجم بلا فقدان أصغر بكثير مما تصل إليه كل تقنية وحدها؟
Take one pruned layer and count how many of its weights fall into each small interval of value. Before quantization you get a smooth landscape. After K-means you get a picket fence. After retraining the fence posts move, but only a little. Slides 33 to 35 are these three pictures.
خذ طبقة واحدة بعد الـ pruning واحسب كم وزنًا من أوزانها يقع في كل فترة صغيرة من القيم. قبل الـ quantization تحصل على تضاريس ناعمة. بعد K-means تحصل على ما يشبه سياجًا من الأوتاد. بعد الـ retraining تتحرك أوتاد السياج، لكن قليلًا فقط. الشرائح من 33 إلى 35 هي هذه الصور الثلاث.
Before quantization: a continuous, bimodal spread with peaks near -0.025 and +0.025 and a hole at 0 left by pruning. Counts are per narrow bin, in thousands. Shapes redrawn approximately from Han et al., ICLR 2016, as shown on slides 33 to 35.قبل التكميم: توزيع متصل ثنائي القمة، قمتاه قرب -0.025 و+0.025، وفيه فجوة عند 0 خلّفها التقليم. الأعداد لكل فئة ضيقة، بالآلاف. الأشكال معاد رسمها تقريبيا من Han et al., ICLR 2016، كما تظهر في الشرائح 33 إلى 35.
Before: continuous and bimodal, with a hole at zeroقبل: توزيع متصل ثنائي القمة، مع فجوة عند الصفر
On slide 33 the weights spread continuously over roughly -0.1 to +0.1, with a tall peak near -0.025 (about 3,300 weights per bin) and a lower one near +0.025 (about 1,400). Between them, around 0, the count nearly vanishes. A freshly trained layer does not look like this; its weights pile up around zero. The hole is there because pruning removed exactly the small-magnitude weights, leaving two humps on either side. Deep Compression notes this bimodal shape directly and uses it to argue for linearly spaced initial centroids, which do not ignore the rare large weights in the tails.
في الشريحة 33 تنتشر الأوزان بشكل متصل تقريبًا من -0.1 إلى +0.1، مع قمة عالية قرب -0.025 (نحو 3,300 وزن في كل bin) وقمة أقل قرب +0.025 (نحو 1,400). بينهما، حول 0، يكاد العدد يختفي. الطبقة المدرّبة حديثًا لا تبدو هكذا، فأوزانها تتكدس حول الصفر. الفجوة موجودة لأن الـ pruning أزال بالضبط الأوزان ذات القيمة المطلقة الصغيرة، فبقيت حدبتان على جانبي الصفر. ورقة Deep Compression تلاحظ هذا الشكل ثنائي القمة (bimodal) صراحةً، وتستخدمه لتبرير تهيئة الـ centroids الابتدائية بتباعد خطي (linear initialization)، لأنها لا تتجاهل الأوزان الكبيرة النادرة الموجودة في الأطراف.
After quantization: a handful of spikesبعد الـ quantization: حفنة من القمم المنفصلة
On slide 34 every weight has been replaced by the centroid of its cluster, so the histogram can only have as many non-empty bins as there are centroids. You can make out about fifteen spikes, which fits a codebook of 2^4 = 16 entries, that is, a 4-bit Cluster index (one spike may be too short to see). Notice the count axis: it changed from x10^3 to x10^4. No weights were added. Before, a cluster's weights were spread over many narrow bins; now they all land in a single bin, so each spike is tall. The spikes are dense around the two old peaks and sparse in the tails, which is exactly where the weights were.
في الشريحة 34 استُبدل كل وزن بالـ centroid الخاص بالـ cluster الذي ينتمي إليه، لذلك لا يمكن أن يحتوي الـ histogram على bins غير فارغة أكثر من عدد الـ centroids. يمكنك أن تميّز نحو خمس عشرة قمة، وهذا يتوافق مع codebook فيه 2^4 = 16 مدخلًا، أي cluster index بـ 4-bit (قد تكون إحدى القمم أقصر من أن تُرى). لاحظ محور العدد: تغيّر من x10^3 إلى x10^4. لم تُضَف أي أوزان. في السابق كانت أوزان الـ cluster الواحد موزعة على bins ضيقة كثيرة، أما الآن فهي كلها تقع في bin واحد، لذلك تكون كل قمة طويلة. القمم كثيفة حول القمتين القديمتين ومتباعدة في الأطراف، وهذا بالضبط حيث كانت الأوزان.
After retraining: same heights, slightly moved positionsبعد الـ retraining: الارتفاعات نفسها، والمواقع تحركت قليلًا
Put slides 34 and 35 side by side and they look identical. That is the point worth noticing. In Centroid fine-tuning, the index of every weight is frozen; only the shared centroid values are updated, by summing the gradients of all weights in each cluster. So:
ضع الشريحتين 34 و35 جنبًا إلى جنب وستبدوان متطابقتين. وهذه بالضبط النقطة الجديرة بالملاحظة. في الـ centroid fine-tuning يكون الـ index لكل وزن مجمّدًا، ولا تُحدَّث إلا قيم الـ centroids المشتركة، وذلك بجمع الـ gradients لكل الأوزان في كل cluster. لذلك:
Heights do not change. A spike's height is the number of weights in that cluster, and no weight changes cluster.الارتفاعات لا تتغير. ارتفاع القمة هو عدد الأوزان في ذلك الـ cluster، ولا يغيّر أي وزن الـ cluster الذي ينتمي إليه.
Positions shift slightly. Each centroid moves by a small amount (on the order of 0.001) toward a value that lowers the training loss. Compare, for example, the spike near +0.015, which moves slightly left, or the one near +0.057.المواقع تنزاح قليلًا. كل centroid يتحرك بمقدار صغير (في حدود 0.001) نحو قيمة تخفّض الـ training loss. قارن مثلًا القمة القريبة من +0.015 التي تتحرك قليلًا إلى اليسار، أو القمة القريبة من +0.057.
Storage does not change. The indexes are the same and the codebook still has the same number of FP32 entries, so retraining recovers accuracy for free in terms of size.التخزين لا يتغير. الـ indexes هي نفسها، والـ codebook ما زال يحتوي العدد نفسه من مدخلات FP32، لذلك يستعيد الـ retraining الدقة مجانًا من ناحية الحجم.
Recall
Why does the y-axis jump from thousands (slide 33) to tens of thousands (slide 34) even though the layer has the same number of weights?لماذا يقفز المحور الرأسي من الآلاف (الشريحة 33) إلى عشرات الآلاف (الشريحة 34) مع أن الطبقة فيها العدد نفسه من الأوزان؟
A histogram counts weights per bin. Before quantization a cluster's weights are spread over many narrow bins; after quantization they all share one value, so the whole cluster lands in a single bin. The tallest bar grows from about 3,300 to about 19,500, roughly six times taller, so the axis needs the larger unit.
الـ histogram يعدّ الأوزان في كل bin. قبل الـ quantization تكون أوزان الـ cluster الواحد موزعة على bins ضيقة كثيرة، وبعده تتشارك كلها قيمة واحدة، فيقع الـ cluster كله في bin واحد. أطول عمود يكبر من نحو 3,300 إلى نحو 19,500، أي أطول بنحو ست مرات، لذلك يحتاج المحور إلى وحدة أكبر.
Recall
What is the only visible difference between slides 34 and 35, and why is that the only one?ما الفرق الوحيد المرئي بين الشريحتين 34 و35، ولماذا هو الفرق الوحيد؟
The spikes shift slightly sideways; their heights stay the same. Fine-tuning updates only the centroids while the cluster indexes, and therefore the number of weights per cluster, are frozen.
القمم تنزاح قليلًا إلى الجانبين، وارتفاعاتها تبقى كما هي. الـ fine-tuning يحدّث الـ centroids فقط، بينما الـ cluster indexes، وبالتالي عدد الأوزان في كل cluster، تكون مجمّدة.
Quick checkاختبار سريع
Comparing the histograms on slides 34 and 35, what does retraining change?بمقارنة الـ histograms في الشريحتين 34 و35، ما الذي يغيّره الـ retraining؟
You have decided to quantize AlexNet. One question remains: how many bits should each layer's Cluster index get? Slide 36 sweeps Bit-width from 1 to 8 bits, once for all conv layers and once for all FC layers, and plots top-1 and top-5 accuracy.
لقد قررت تطبيق الـ quantization على AlexNet. يبقى سؤال واحد: كم bit يجب أن يأخذ الـ cluster index في كل طبقة؟ الشريحة 36 تمسح الـ bit-width من 1 إلى 8 bits، مرة لكل طبقات الـ conv ومرة لكل طبقات الـ FC، وترسم دقة الـ top-1 والـ top-5.
Top-1 accuracy (bars) and top-5 accuracy (line) versus bits per effective weight, pruned plus quantized AlexNet. Values read approximately from the figure on slide 36.دقة top-1 (الأعمدة) ودقة top-5 (الخط) مقابل عدد الـ bits لكل وزن فعّال، لـ AlexNet بعد الـ pruning والـ quantization. القيم مقروءة تقريبيًا من الشكل في الشريحة 36.
The two kneesنقطتا الانكسار (knees)
Conv layers saturate at 4 bits. From 4 to 8 bits top-1 sits around 53% to 57% and top-5 around 76% to 80%. At 3 bits top-1 drops to about 25%, and at 2 bits it is near 0%.طبقات الـ conv تتشبّع عند 4 bits. من 4 إلى 8 bits تبقى دقة الـ top-1 بين نحو 53% و57%، ودقة الـ top-5 بين نحو 76% و80%. عند 3 bits تهبط الـ top-1 إلى نحو 25%، وعند 2 bits تقترب من 0%.
FC layers saturate at 2 bits. With only 4 centroids per layer they already reach about 55% top-1 and 79% top-5. Only at 1 bit do they collapse.طبقات الـ FC تتشبّع عند 2 bits. بـ 4 centroids فقط لكل طبقة تصل بالفعل إلى نحو 55% في الـ top-1 و79% في الـ top-5. ولا تنهار إلا عند 1 bit.
Pruning does not hurt quantization. The "pruned + quantized" and "quantized only" curves lie on top of each other. The paper's caption: accuracy "begins to drop at the same number of quantization bits whether or not the network has been pruned", and at 3 bits on conv the pruned network is even slightly better.الـ pruning لا يضرّ الـ quantization. منحنى "pruned + quantized" ومنحنى "quantized only" يقعان فوق بعضهما. تعليق الورقة على الشكل: الدقة "تبدأ بالهبوط عند العدد نفسه من quantization bits سواء مرّت الشبكة بالـ pruning أم لا"، وعند 3 bits في الـ conv تكون الشبكة بعد الـ pruning أفضل قليلًا.
"Bits per effective weight" means bits per surviving, shared weight index, not bits per original FP32 weight. A 2-bit FC layer has a codebook of 2^2 = 4 values and each kept connection points to one of them.
"Bits per effective weight" (عدد الـ bits لكل وزن فعّال) تعني عدد الـ bits لكل index لوزن باقٍ ومشترك، لا عدد الـ bits لكل وزن FP32 أصلي. طبقة FC بـ 2-bit لها codebook من 2^2 = 4 قيم، وكل اتصال مُبقى يشير إلى واحدة منها.
Why FC layers tolerate fewer bitsلماذا تتحمل طبقات الـ FC عددًا أقل من الـ bits
The paper reports the difference but does not explain it. The standard explanation combines three facts about AlexNet:
الورقة تذكر الفرق لكنها لا تشرحه. التفسير المعتاد يجمع ثلاث حقائق عن AlexNet:
FC layers are heavily over-parameterized. They hold about 59M of the 61M weights (about 96%). The pruning paper shows they can be cut to 9% of their weights, while conv layers keep 35% to 84% and are reported as "more sensitive to pruning". That much redundancy means many weights carry overlapping information, so rounding any one of them hard costs little.طبقات الـ FC فيها عدد معاملات أكبر بكثير من اللازم (over-parameterized). فهي تحمل نحو 59M من أصل 61M وزن (نحو 96%). ورقة الـ pruning تبيّن أنه يمكن تقليصها إلى 9% من أوزانها، بينما تُبقي طبقات الـ conv من 35% إلى 84% وتوصف بأنها "أكثر حساسية للـ pruning". هذا القدر من التكرار (redundancy) يعني أن أوزانًا كثيرة تحمل معلومات متداخلة، لذلك فإن تقريب أي واحد منها بقسوة لا يكلّف إلا القليل.
Each conv weight carries more information. A conv layer has few weights (a small kernel per filter), and they encode the low-level features every later layer depends on.كل وزن في الـ conv يحمل معلومات أكثر. طبقة الـ conv فيها أوزان قليلة (kernel صغير لكل filter)، وهي ترمّز الخصائص منخفضة المستوى (low-level features) التي تعتمد عليها كل الطبقات اللاحقة.
Conv weights are reused everywhere. Through weight sharing in space, one kernel weight multiplies the input at every output position, hundreds to thousands of times per image. A rounding error in it is repeated across the whole feature map and then propagates through all the later layers. An FC weight is used once per input.أوزان الـ conv يُعاد استخدامها في كل مكان. بسبب الـ weight sharing في الفضاء المكاني، يضرب وزن واحد من الـ kernel المدخل عند كل موقع في المخرج، أي مئات إلى آلاف المرات لكل صورة. خطأ التقريب فيه يتكرر عبر الـ feature map كلها ثم ينتشر في كل الطبقات اللاحقة. أما وزن الـ FC فيُستخدم مرة واحدة لكل مدخل.
Conv layersطبقات الـ conv
FC layersطبقات الـ FC
Weights in AlexNetعدد الأوزان في AlexNet
about 2.3M (5 layers)نحو 2.3M (5 طبقات)
about 59M (3 layers)نحو 59M (3 طبقات)
Weights kept after pruningالأوزان المُبقاة بعد الـ pruning
35% to 84% per layerمن 35% إلى 84% لكل طبقة
9% to 25% per layerمن 9% إلى 25% لكل طبقة
Times each weight is used per imageعدد مرات استخدام كل وزن لكل صورة
Once per output position (169 to 3,025 times)مرة لكل موقع في المخرج (من 169 إلى 3,025 مرة)
Onceمرة واحدة
Knee on slide 36نقطة الانكسار في الشريحة 36
4 bits4 bits
2 bits2 bits
Accuracy one step below the kneeالدقة عند خطوة واحدة تحت نقطة الانكسار
top-1 about 25% at 3 bitstop-1 نحو 25% عند 3 bits
near 0% at 1 bitقرب 0% عند 1 bit
Bits Deep Compression actually usedعدد الـ bits الذي استخدمته Deep Compression فعليًا
8 bits (256 centroids)8 bits (256 centroid)
5 bits (32 centroids)5 bits (32 centroid)
Conv versus FC layers in AlexNet (counts from the pruning and Deep Compression papers)طبقات الـ conv مقابل طبقات الـ FC في AlexNet (الأعداد من ورقة الـ pruning وورقة Deep Compression)
Recall
From slide 36, what happens to conv-layer top-1 accuracy at 4, 3 and 2 bits, and to FC-layer top-1 at 2 and 1 bits?من الشريحة 36، ماذا يحدث لدقة top-1 في طبقات الـ conv عند 4 و3 و2 bits، ولدقة top-1 في طبقات الـ FC عند 2 و1 bit؟
Conv: about 53% at 4 bits (near the full 57%), about 25% at 3 bits, near 0% at 2 bits. FC: about 55% at 2 bits, near 0% at 1 bit.
الـ conv: نحو 53% عند 4 bits (قريب من الدقة الكاملة 57%)، ونحو 25% عند 3 bits، وقرب 0% عند 2 bits. الـ FC: نحو 55% عند 2 bits، وقرب 0% عند 1 bit.
Quick checkاختبار سريع
In the Deep Compression bit sweep, below which bit-widths does accuracy collapse?في مسح عدد الـ bits في Deep Compression، تحت أي bit-width تنهار الدقة؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
The x-axis is model size after compression as a percent of the original; the y-axis is accuracy loss. Further left is smaller, lower is worse.المحور الأفقي هو حجم النموذج بعد الضغط كنسبة مئوية من الحجم الأصلي، والمحور الرأسي هو فقدان الدقة (accuracy loss). كلما اتجهت يسارًا كان النموذج أصغر، وكلما اتجهت للأسفل كانت الدقة أسوأ.
Quantization only and pruning only each hold close to 0% loss down to roughly 8% to 10% of the original size, then fall off a cliff.الـ quantization وحده والـ pruning وحده يحافظ كل منهما على فقدان قريب من 0% حتى نحو 8% إلى 10% من الحجم الأصلي، ثم يسقط كل منهما من حافة الجرف (cliff).
Pruning plus quantization holds about 0% loss down to about 3% of the original size (Deep Compression reports 3.7% before Huffman coding and 2.88% after).الـ pruning مع الـ quantization معًا يحافظان على فقدان يقارب 0% حتى نحو 3% من الحجم الأصلي (ورقة Deep Compression تذكر 3.7% قبل Huffman coding و2.88% بعده).
They are complementary because they shrink different factors: pruning cuts how many weights are stored, quantization cuts how many bits each one costs.هما متكاملان لأن كلًا منهما يقلّص عاملًا مختلفًا: الـ pruning يقلّل عدد الأوزان المخزّنة، والـ quantization يقلّل عدد الـ bits التي يكلّفها كل وزن.
Size ratio is roughly (fraction kept) x (weight bits + index bits) / 32, e.g. 0.11 x 9.4 / 32, about 3.2% for AlexNet.نسبة الحجم تقريبًا = (نسبة الأوزان المُبقاة) × (bits الوزن + bits الـ index) / 32، مثلًا 0.11 × 9.4 / 32، أي نحو 3.2% لـ AlexNet.
Before quantization the weights form a continuous bimodal histogram with a hole at 0 from pruning. After K-means they collapse into at most 2^b spikes.قبل الـ quantization تشكّل الأوزان histogram متصلًا ثنائي القمة (bimodal) فيه فجوة عند الصفر بسبب الـ pruning. بعد K-means تنهار إلى 2^b قمة منفصلة (spikes) على الأكثر.
Retraining moves the centroids slightly but never the cluster membership, so spike heights stay fixed and only spike positions shift.الـ retraining يحرّك الـ centroids قليلًا لكنه لا يغيّر انتماء الأوزان للـ clusters أبدًا، لذلك تبقى ارتفاعات القمم ثابتة وتتغيّر مواقعها فقط.
Accuracy saturates at 4 bits for conv layers and at 2 bits for FC layers (top-1 about 57%, top-5 about 80%); conv at 2 bits collapses to near 0%.الدقة تتشبّع عند 4 bits لطبقات الـ conv وعند 2 bits لطبقات الـ FC (top-1 نحو 57% وtop-5 نحو 80%)، أما الـ conv عند 2 bits فتنهار دقتها إلى ما يقارب 0%.
Pruned plus quantized and quantized only give the same curves, so pruning does not hurt quantization.منحنى pruned + quantized ومنحنى quantized only متطابقان، إذن الـ pruning لا يضرّ الـ quantization.
FC layers hold about 96% of AlexNet's weights and are highly redundant; conv weights are few and each is reused across every spatial position, so each carries more information.طبقات الـ FC تحمل نحو 96% من أوزان AlexNet وفيها تكرار (redundancy) كبير، أما أوزان الـ conv فقليلة وكل وزن منها يُعاد استخدامه في كل موقع مكاني، لذلك يحمل كل وزن معلومات أكثر.
Part 07: Huffman coding, the Deep Compression pipeline and SqueezeNetترميز Huffman وخط عمل Deep Compression وSqueezeNet
Variable-length Huffman codes exploit the uneven usage of the 32 effective weights. Deep Compression chains pruning, K-means quantization and Huffman coding for 35x to 49x reduction with no accuracy loss, and stacks on SqueezeNet for a 510x smaller model than AlexNet.رموز Huffman متغيرة الطول تستغل الاستخدام غير المتساوي للأوزان الفعلية الـ32. يربط Deep Compression التقليم وتكميم K-means وترميز Huffman لتخفيض من 35x إلى 49x دون فقدان في الدقة، ويُطبَّق فوق SqueezeNet لنموذج أصغر بـ510x من AlexNet.
5 concepts5 مفاهيم, ، slides 37-41الشرائح 37-41
Why this part mattersلماذا يهمّ هذا الجزء
Parts 05 and 06 turned every FP32 weight into a short cluster index that points into a small codebook. That already gives roughly 32/N compression for N-bit indexes. This part asks what is left to squeeze, and answers it three ways: encode the indexes more cleverly, chain quantization with pruning into one pipeline, and start from an architecture that needs fewer weights in the first place.
The pipeline is Deep Compression (Han, Mao and Dally, ICLR 2016), and its stage order, what each stage reduces and the headline ratios are the most examinable facts in this lecture. SqueezeNet then shows that a compact design and compression stack on top of each other, which is exactly the reasoning you need when a model has to fit in the on-chip memory of an embedded device.
حوّل الجزآن 05 و06 كل وزن FP32 إلى فهرس عنقود (cluster index) قصير يشير إلى codebook صغير. وهذا وحده يعطي ضغطاً بنحو 32/N عندما تكون الفهارس بطول N بت. يسأل هذا الجزء: ماذا بقي لنضغطه؟ ويجيب بثلاث طرق: ترميز الفهارس بذكاء أكبر، وربط الـ quantization مع الـ pruning في خط معالجة واحد، والبدء من معمارية تحتاج إلى أوزان أقل من الأساس.
خط المعالجة هذا اسمه Deep Compression (Han, Mao and Dally, ICLR 2016)، وترتيب مراحله، وما الذي تقلّله كل مرحلة، والنسب الرئيسية، هي أكثر الحقائق احتمالاً للظهور في الاختبار من هذه المحاضرة. ثم يبيّن SqueezeNet أن التصميم المدمج والضغط يتراكمان فوق بعضهما، وهذا بالضبط نوع التفكير الذي تحتاجه عندما يجب أن يتسع النموذج في الذاكرة الموجودة على الشريحة (on-chip memory) لجهاز مدمج.
By the end you canفي نهاية هذا الجزء ستستطيع
01Build a Huffman code by hand for a small alphabet and compute its average code length against a fixed-length code.أن تبني رمز Huffman يدوياً لأبجدية صغيرة، وتحسب متوسط طول الرمز مقارنةً برمز ثابت الطول.
02Explain why Huffman coding helps on quantized weights and sparse indexes, and why it is lossless.أن تشرح لماذا يفيد ترميز Huffman مع الأوزان المكمّاة (quantized) ومع الفهارس المتناثرة (sparse indexes)، ولماذا هو بلا فقد (lossless).
03Name the three Deep Compression stages in order, what each one reduces, and the cumulative 9x to 13x, 27x to 31x and 35x to 49x ranges.أن تسمّي مراحل Deep Compression الثلاث بالترتيب، وما الذي تقلّله كل مرحلة، والنطاقات التراكمية 9x إلى 13x ثم 27x إلى 31x ثم 35x إلى 49x.
04Read the six-network results table and explain why GoogleNet and ResNet-18 compress only 10x to 11x.أن تقرأ جدول نتائج الشبكات الست، وتشرح لماذا لا يتجاوز ضغط GoogleNet وResNet-18 ما بين 10x و11x.
05Count the weights in a SqueezeNet fire module and compare them with a plain 3x3 convolution.أن تعدّ الأوزان في fire module الخاصة بـ SqueezeNet وتقارنها بطبقة convolution عادية بحجم 3x3.
06Explain why SqueezeNet plus Deep Compression reaches 510x: architecture and compression multiply.أن تشرح لماذا يصل SqueezeNet مع Deep Compression إلى 510x: لأن أثر المعمارية وأثر الضغط يتضاعفان (يُضرب أحدهما في الآخر).
Take the last fully connected layer of AlexNet after K-means quantization with 32 clusters. Every surviving weight is now stored as a 5-bit Cluster index, because 2^5 = 32. The histogram on slide 37 counts how often each of the 32 indexes appears, and it is far from flat: two peaks near index 10 and index 19 each collect around 90,000 to 100,000 weights, while the indexes at both ends are used almost never. Yet a fixed-length code spends the same 5 bits on the index used 100,000 times as on the one used twice.
خذ آخر طبقة fully connected في AlexNet بعد K-means quantization بـ 32 عنقوداً. كل وزن باقٍ يُخزَّن الآن على شكل cluster index بطول 5 بتات، لأن 2^5 = 32. يعدّ الـ histogram في الشريحة 37 كم مرة يظهر كل فهرس من الفهارس الـ 32، والتوزيع بعيد جداً عن أن يكون مسطحاً: هناك قمّتان قرب الفهرس 10 والفهرس 19 تجمع كل منهما نحو 90,000 إلى 100,000 وزن، بينما الفهارس في الطرفين لا تكاد تُستخدم. ومع ذلك فإن الرمز ثابت الطول يصرف 5 بتات نفسها على الفهرس المستخدم 100,000 مرة وعلى الفهرس المستخدم مرتين فقط.
The bimodal index histogram (top) and the approximate code length, about log2(1/p) bits, that Huffman assigns each index (bottom). Peaks get codes shorter than the fixed 5 bits; the tails get longer ones.الـ histogram ثنائي القمة للفهارس (في الأعلى)، وطول الرمز التقريبي، نحو log2(1/p) بت، الذي يعطيه Huffman لكل فهرس (في الأسفل). القمم تحصل على رموز أقصر من الـ 5 بتات الثابتة، والأطراف تحصل على رموز أطول.
Huffman coding fixes that mismatch. It is the slide's two bullets made precise: infrequent weights get more bits, frequent weights get fewer bits, and the code lengths are chosen to minimise the average number of bits per symbol.
Huffman coding يعالج هذا التفاوت. هو صياغة دقيقة لنقطتَي الشريحة: الأوزان القليلة الظهور تأخذ بتات أكثر، والأوزان الكثيرة الظهور تأخذ بتات أقل، وتُختار أطوال الرموز بحيث يكون متوسط عدد البتات لكل رمز أصغر ما يمكن.
Worked exampleمثال محلول
Huffman code for four cluster indexesرمز Huffman لأربعة فهارس عناقيد
Start with the probabilitiesابدأ بالاحتمالات
Four indexes A, B, C, D occur with probabilities 0.5, 0.25, 0.125 and 0.125. A fixed code needs log2(4) = 2 bits for each.
أربعة فهارس A, B, C, D تظهر باحتمالات 0.5 و0.25 و0.125 و0.125. الرمز الثابت يحتاج إلى log2(4) = 2 bits لكل منها.
Merge the two least likelyادمج الرمزين الأقل احتمالاً
Join C (0.125) and D (0.125) into a node of weight 0.25. The forest is now A 0.5, B 0.25, CD 0.25.
اجمع C (0.125) وD (0.125) في عقدة وزنها 0.25. تصبح الغابة الآن A 0.5 وB 0.25 وCD 0.25.
Repeat until one tree remainsكرّر حتى تبقى شجرة واحدة
Merge B and CD into 0.5, then merge that with A into the root, 1.0. Three merges for four symbols.
ادمج B وCD في 0.5، ثم ادمج الناتج مع A لتحصل على الجذر 1.0. ثلاث عمليات دمج لأربعة رموز.
Read the codes off the treeاقرأ الرموز من الشجرة
Label one branch 0 and the other 1 at each node, then read the path from the root: A = 0, B = 10, C = 110, D = 111.
عند كل عقدة سمِّ أحد الفرعين 0 والآخر 1، ثم اقرأ المسار من الجذر: A = 0 وB = 10 وC = 110 وD = 111.
Average lengthمتوسط الطول
Lˉ=0.5(1)+0.25(2)+0.125(3)+0.125(3)=1.75 bits
Lˉ=0.5(1)+0.25(2)+0.125(3)+0.125(3)=1.75 bits
Resultالنتيجة
1.75 bits per symbol instead of 2, a 12.5% saving, with no information lost.
1.75 bits لكل رمز بدلاً من 2، أي توفير بنسبة 12.5%، دون فقد أي معلومة.
The general rule behind the example: the expected code length is the probability-weighted sum of the code lengths, and no prefix code can beat the entropy of the source. Huffman's greedy merge of the two least likely nodes is provably optimal among prefix codes and always lands within one bit of entropy.
القاعدة العامة وراء المثال: طول الرمز المتوقع هو مجموع أطوال الرموز موزوناً باحتمالاتها، ولا يمكن لأي prefix code أن يتفوق على الـ entropy الخاصة بالمصدر. والدمج الجشع (greedy) الذي يقوم به Huffman لأقل عقدتين احتمالاً مُثبَت أنه الأمثل بين كل الـ prefix codes، ويقع دائماً ضمن بت واحد من الـ entropy.
Lˉ=i∑piℓi,H=−i∑pilog2pi≤LˉHuffman<H+1
Average code length and the entropy bound for an optimal prefix codeمتوسط طول الرمز وحد الإنتروبيا لرمز بادئة (prefix code) أمثل
In the worked example the probabilities are powers of two, so the entropy is exactly 1.75 bits and Huffman meets the bound with equality. The code is also prefix-free: no codeword is the start of another, so the decoder needs no separators. The bit string 0110100 can only be read as 0 | 110 | 10 | 0, that is A C B A.
في المثال المحلول الاحتمالات قوى للعدد اثنين، لذلك تساوي الـ entropy بالضبط 1.75 bits، ويبلغ Huffman الحد بالتساوي التام. والرمز أيضاً خالٍ من البادئات (prefix-free): لا توجد كلمة رمز هي بداية لكلمة أخرى، لذلك لا يحتاج فك الترميز إلى فواصل. سلسلة البتات 0110100 لا يمكن قراءتها إلا على أنها 0 | 110 | 10 | 0، أي A C B A.
InteractiveتفاعليBuild a Huffman tree one merge at a timeابنِ شجرة Huffman دمجًا بعد دمج
merge 0 of 3الدمج 0 من 3
Huffman average1.75bits / symbolsum of probability times code lengthمجموع حاصل ضرب الاحتمال في طول الرمز
Fixed length2bits / symbolsaves 12.5 percent with Huffmanيوفّر Huffman نسبة 12.5 بالمئة
Entropy1.75bits / symbolno prefix code can average below thisلا يمكن لأي رمز بادئة أن يكون متوسطه أقل من هذا
Two streams get encoded, not oneيُرمَّز تياران لا تيار واحد
The dashed box on slide 37 has two entries, and both matter. Encode Weights Huffman-codes the cluster indexes. Encode Index Huffman-codes the sparse index: after pruning, each surviving weight also stores its position as a small relative offset from the previous nonzero, and small offsets are far more common than large ones, so that stream is skewed too. Han et al. report that Huffman coding these two non-uniform streams saves 20% to 30% of network storage. On AlexNet the average weight code falls from 5.4 to 4 bits and the index code from 4 to 3.2 bits.
المربع المنقّط في الشريحة 37 فيه بندان، وكلاهما مهم. Encode Weights يرمّز فهارس العناقيد بطريقة Huffman. وEncode Index يرمّز الفهرس المتناثر (sparse index) بطريقة Huffman: بعد الـ pruning يخزّن كل وزن باقٍ موقعه أيضاً على شكل إزاحة نسبية صغيرة عن آخر قيمة غير صفرية، والإزاحات الصغيرة أكثر شيوعاً بكثير من الكبيرة، فيكون هذا التيار منحازاً أيضاً. يذكر Han وزملاؤه أن ترميز هذين التيارين غير المنتظمين بطريقة Huffman يوفّر من 20% إلى 30% من مساحة تخزين الشبكة. وفي AlexNet ينخفض متوسط رمز الوزن من 5.4 إلى 4 بتات، ورمز الفهرس من 4 إلى 3.2 بت.
Recall
Four cluster indexes are each used exactly 25 percent of the time. How much does Huffman coding save over a 2-bit fixed code?أربعة فهارس عناقيد يُستخدم كل منها 25 بالمئة من الوقت بالضبط. كم يوفّر ترميز Huffman مقارنةً برمز ثابت بطول 2 بت؟
Nothing. Every merge pairs equal weights, every code has length 2, and the average stays 2 bits, which already equals the entropy log2(4). Huffman only helps when the distribution is skewed.
لا شيء. كل عملية دمج تجمع وزنين متساويين، فيكون طول كل رمز 2، ويبقى المتوسط 2 bits، وهو يساوي أصلاً الـ entropy أي log2(4). Huffman لا يفيد إلا عندما يكون التوزيع منحازاً.
Quick checkاختبار سريع
Four cluster indexes have probabilities 0.5, 0.25, 0.125 and 0.125. What is the average Huffman code length?أربعة فهارس عناقيد احتمالاتها 0.5 و0.25 و0.125 و0.125. ما متوسط طول رمز Huffman؟
Follow AlexNet through the whole pipeline. It starts with 61M weights, each a 32-bit float, for 240 MB. Three different things can shrink that number, and Deep Compression attacks each one with its own stage.
تتبّع AlexNet عبر خط المعالجة كله. تبدأ الشبكة بـ 61M وزن، كل منها عدد عشري بطول 32 بت، أي 240 MB. هناك ثلاثة أشياء مختلفة يمكنها تقليص هذا الرقم، وDeep Compression يهاجم كل واحد منها بمرحلة خاصة به.
AlexNet through the three stages (Han et al., ICLR 2016, Table 4)AlexNet عبر المراحل الثلاث (Han et al., ICLR 2016, Table 4)
Originalالأصل
61M weights at 32 bits, 240 MB61M وزن بطول 32 بت، أي 240 MB
After pruningبعد الـ pruning
11% of the weights survive, a 9x cut in the weight countيبقى 11% من الأوزان، أي تخفيض عدد الأوزان بمقدار 9x
After quantizationبعد الـ quantization
conv layers use 256 shared values (8 bits), FC layers 32 (5 bits), average 5.4 bits per weight plus a 4-bit relative index; 27x including index and codebook overheadطبقات conv تستخدم 256 قيمة مشتركة (8 بتات)، وطبقات FC تستخدم 32 (5 بتات)، بمتوسط 5.4 بت لكل وزن إضافةً إلى فهرس نسبي بطول 4 بتات؛ والنتيجة 27x شاملةً كلفة الفهارس والـ codebook
After Huffman codingبعد ترميز Huffman
average weight code falls to 4 bits and index code to 3.2 bits, about 22% more saving; 6.9 MB, 35xينخفض متوسط رمز الوزن إلى 4 بتات ورمز الفهرس إلى 3.2 بت، أي توفير إضافي بنحو 22%؛ والحجم 6.9 MB، بنسبة 35x
The stored size is roughly the number of surviving weights times the bits each one costs, so the stages line up with the factors of a product:
الحجم المخزَّن يساوي تقريباً عدد الأوزان الباقية مضروباً في عدد البتات التي يكلّفها كل منها، لذلك تتطابق المراحل مع عوامل حاصل ضرب:
size≈pruning#weights×(quantizationbits per weight+index bits)Huffmanaverage code length
Each stage of Deep Compression shrinks a different factor of the storage costكل مرحلة في Deep Compression تقلص عاملًا مختلفًا من كلفة التخزين
Pruning, fewer weights.Pruning trains to learn which connections matter, removes the small ones, retrains the rest, and iterates. Result: 9x to 13x.الـ pruning، أوزان أقل. يدرّب pruning الشبكة ليعرف أي الاتصالات مهمة، ثم يزيل الصغيرة منها، ويعيد تدريب الباقي، ويكرر ذلك. النتيجة: 9x إلى 13x.
Quantization, fewer bits per weight. Cluster the surviving weights, build the Codebook, replace each weight by its cluster index, then retrain the codebook with Centroid fine-tuning, and iterate. Cumulative: 27x to 31x.الـ quantization، بتات أقل لكل وزن. جمّع الأوزان الباقية في عناقيد، وابنِ الـ codebook، واستبدل كل وزن بفهرس عنقوده، ثم أعد تدريب الـ codebook باستخدام centroid fine-tuning، وكرّر. النسبة التراكمية: 27x إلى 31x.
Huffman encoding. Encode the weight indexes and the sparse index with variable-length codes. Cumulative: 35x to 49x. No training at all.ترميز Huffman. رمّز فهارس الأوزان والفهرس المتناثر برموز متغيرة الطول. النسبة التراكمية: 35x إلى 49x. دون أي تدريب على الإطلاق.
Stageالمرحلة
Reducesما الذي تقلّله
Sub-stepsالخطوات الفرعية
Cumulative ratioالنسبة التراكمية
Retraining?إعادة تدريب؟
PruningPruning
Number of weightsعدد الأوزان
Train connectivity, prune connections, train weights, iterateدرّب الاتصالات، ثم قلّم الاتصالات، ثم درّب الأوزان، وكرّر
9x to 13x9x to 13x
Yes, prune and retrain loopنعم، حلقة pruning ثم إعادة تدريب
QuantizationQuantization
Bits per weightعدد البتات لكل وزن
Cluster weights, generate codebook, quantize with codebook, retrain codebook, iterateجمّع الأوزان في عناقيد، وولّد الـ codebook، وكمّم باستخدامه، وأعد تدريب الـ codebook، وكرّر
The three stages of slide 38المراحل الثلاث في الشريحة 38
InteractiveتفاعليStep through the Deep Compression pipelineتتبّع خط معالجة Deep Compression خطوة بخطوة
bar length is the stored size relative to the original 240 MBطول الشريط هو الحجم المخزّن نسبة إلى الأصل 240 MB
Original shrinks nothing yet. Slide range for this stage: 1x, same accuracy.الأصل لا يقلّص شيئا بعد. مدى الشريحة لهذه المرحلة: 1x، بالدقة نفسها.
dense FP32 network, every weight stored in 32 bitsشبكة FP32 كثيفة، كل وزن فيها مخزّن في 32 bit
Cumulative1xsmaller
Size240MBAlexNet, original 240 MBAlexNet، الأصل 240 MB
Weights kept100%of original
Bits per weight32avgindex bits: noneبتات الفهرس: none
The order is not arbitrary. Pruning goes first so that K-means clusters only the weights that will actually be stored, and the codebook is fitted to the weights that survive. Quantization must come before Huffman because Huffman needs a small alphabet with repeated symbols: on raw FP32 values almost every weight is unique, there is no skew to exploit, and the code would be useless. After quantization there are only 32 or 256 symbols, used very unevenly, which is exactly what Huffman feeds on.
الترتيب ليس اعتباطياً. يأتي الـ pruning أولاً حتى لا يجمّع K-means إلا الأوزان التي ستُخزَّن فعلاً، فيُضبط الـ codebook على الأوزان الباقية. ويجب أن يسبق الـ quantization ترميزَ Huffman لأن Huffman يحتاج إلى أبجدية صغيرة فيها رموز متكررة: مع قيم FP32 الخام يكون كل وزن تقريباً فريداً، فلا يوجد انحياز يمكن استغلاله، ويصبح الرمز عديم الفائدة. بعد الـ quantization لا يبقى إلا 32 أو 256 رمزاً، تُستخدم بشكل متفاوت جداً، وهذا بالضبط ما يتغذى عليه Huffman.
Recall
Which Deep Compression stage needs no retraining, and why?أي مرحلة من مراحل Deep Compression لا تحتاج إلى إعادة تدريب، ولماذا؟
Huffman coding. It is a lossless re-encoding of indexes that already exist, so every weight decodes to exactly the same value and the network's output cannot change.
ترميز Huffman. فهو إعادة ترميز بلا فقد لفهارس موجودة أصلاً، لذلك يُفك كل وزن إلى القيمة نفسها تماماً، ولا يمكن أن يتغير خرج الشبكة.
Quick checkاختبار سريع
Slide 38 labels one stage 'less bits per weight'. Which stage is it, and how does it work?تصف الشريحة 38 إحدى المراحل بأنها 'less bits per weight' (بتات أقل لكل وزن). أي مرحلة هي، وكيف تعمل؟
Check two rows of slide 39 yourself: AlexNet goes from 240 MB to 6.9 MB, and 240 / 6.9 = 34.8, which rounds to 35x. GoogleNet goes from 28 MB to 2.8 MB, exactly 10x. Same method, a 3.5x difference in outcome. The table is about why.
تحقّق بنفسك من صفّين في الشريحة 39: ينتقل AlexNet من 240 MB إلى 6.9 MB، و240 / 6.9 = 34.8، وتُقرَّب إلى 35x. وينتقل GoogleNet من 28 MB إلى 2.8 MB، أي 10x بالضبط. الطريقة نفسها، وفرق في النتيجة بمقدار 3.5x. والجدول يدور حول سبب ذلك.
InteractiveتفاعليDeep Compression results, click a header to sortنتائج Deep Compression، انقر عنوان عمود للترتيب
VGGNetImageNet, top-5
550 MB
11.3 MB
49x
88.68%
+0.41 pts
LeNet-300MNIST, top-1
1070 KB
27 KB
40x
98.36%
+0.06 pts
LeNet-5MNIST, top-1
1720 KB
44 KB
39x
99.20%
+0.06 pts
AlexNetImageNet, top-5
240 MB
6.9 MB
35x
80.27%
+0.03 pts
ResNet-18ImageNet, top-5
44.6 MB
4.0 MB
11x
89.24%
+0.04 pts
GoogleNetImageNet, top-5
28 MB
2.8 MB
10x
88.90%
+0.02 pts
Shaded rows are the compact modern networks. Sort by ratio and they fall to the bottom: less redundancy to remove.الصفوف المظلّلة هي الشبكات الحديثة المدمجة. رتّب حسب النسبة فتنزل إلى الأسفل: فيها تكرار أقل يمكن إزالته.
First, accuracy. Every row keeps or slightly improves its accuracy, by 0.02 to 0.41 percentage points. The gains are small enough to read as "no loss"; they come from the retraining in the pruning and quantization loops acting as a mild regulariser. The Compression ratio column is where the networks differ.
أولاً، الدقة. كل صف يحافظ على دقته أو يحسّنها قليلاً، بمقدار 0.02 إلى 0.41 نقطة مئوية. هذه المكاسب صغيرة بما يكفي لتُقرأ على أنها "لا خسارة"، ومصدرها إعادة التدريب في حلقتي الـ pruning والـ quantization التي تعمل كـ regularizer خفيف. أما عمود compression ratio فهو المكان الذي تختلف فيه الشبكات.
The networks that compress best, LeNet-300, AlexNet and VGGNet, spend most of their weights in huge fully connected layers. In AlexNet the three FC layers hold about 59M of the 61M weights, and Deep Compression prunes the two largest (fc6, fc7) to 9% of their weights and codes every FC layer with 5 bits. GoogleNet and ResNet-18 were designed to be compact: they replace the big FC layers with global average pooling and put almost all their weights in convolutions, which tolerate less pruning (AlexNet's conv layers keep 35% to 84% of their weights) and need more bits (8 for AlexNet's convs against 5 for its FC layers). There is simply less redundancy to remove, so they stop at 10x to 11x.
الشبكات الأفضل ضغطاً، LeNet-300 وAlexNet وVGGNet، تصرف معظم أوزانها في طبقات fully connected ضخمة. في AlexNet تحمل طبقات FC الثلاث نحو 59M من أصل 61M وزن، ويقلّم Deep Compression أكبر طبقتين منها (fc6 وfc7) إلى 9% من أوزانهما، ويرمّز كل طبقة FC بـ 5 بتات. أما GoogleNet وResNet-18 فقد صُمّمتا لتكونا مدمجتين: تستبدلان طبقات FC الكبيرة بـ global average pooling وتضعان معظم أوزانهما في طبقات convolution، وهذه تتحمل pruning أقل (طبقات الـ conv في AlexNet تحتفظ بـ 35% إلى 84% من أوزانها) وتحتاج إلى بتات أكثر (8 لطبقات conv في AlexNet مقابل 5 لطبقات FC). ببساطة فيهما تكرار (redundancy) أقل يمكن إزالته، فتتوقفان عند 10x إلى 11x.
Recall
Which two networks on slide 39 compress least, and what do they have in common?ما الشبكتان الأقل ضغطاً في الشريحة 39، وما المشترك بينهما؟
GoogleNet (10x) and ResNet-18 (11x). Both are modern compact designs without large fully connected layers, so they have far less redundant weight to prune and quantize than AlexNet or VGGNet.
GoogleNet (10x) وResNet-18 (11x). كلتاهما تصميم حديث مدمج بلا طبقات fully connected كبيرة، لذلك فيهما أوزان زائدة أقل بكثير يمكن تقليمها وتكميمها مقارنةً بـ AlexNet أو VGGNet.
Quick checkاختبار سريع
Why does Deep Compression shrink ResNet-18 only 11x but VGGNet 49x?لماذا يقلّص Deep Compression حجم ResNet-18 بنسبة 11x فقط بينما يقلّص VGGNet بنسبة 49x؟
Suppose a layer must turn 64 input channels into 128 output channels. A plain 3x3 convolution needs 64 x 128 x 9 = 73,728 weights. SqueezeNet gets the same 128 output channels from a Fire module with about a sixth of that.
افترض أن طبقة يجب أن تحوّل 64 قناة دخل إلى 128 قناة خرج. طبقة convolution عادية بحجم 3x3 تحتاج إلى 64 x 128 x 9 = 73,728 وزناً. أما SqueezeNet فيحصل على قنوات الخرج نفسها، 128، من fire module بنحو سدس هذا العدد.
Fire module from slide 40: 64 channels squeezed to 16 by a 1x1 conv, expanded by parallel 1x1 and 3x3 convs to 64 each, concatenated to 128.الـ fire module من الشريحة 40: تُضغط 64 قناة إلى 16 بطبقة conv بحجم 1x1، ثم تُوسَّع بطبقتي conv متوازيتين 1x1 و3x3 إلى 64 لكل منهما، وتُدمجان (concatenate) إلى 128.
The module has two layers. The squeeze layer is a 1x1 convolution that compresses the 64 input channels to 16. The expand layer runs a 1x1 convolution and a 3x3 convolution side by side on those 16 channels, 64 filters each, and concatenates the results into 128 channels. A convolution layer has C_in x C_out x k x k weights, so the expensive 3x3 filters now see 16 input channels instead of 64, and half of the outputs come from cheap 1x1 filters.
للوحدة طبقتان. طبقة squeeze هي convolution بحجم 1x1 تضغط قنوات الدخل الـ 64 إلى 16. وطبقة expand تشغّل convolution بحجم 1x1 وأخرى بحجم 3x3 جنباً إلى جنب على هذه القنوات الـ 16، بـ 64 مرشحاً لكل منهما، وتدمج النتائج (concatenate) في 128 قناة. طبقة الـ convolution فيها C_in x C_out x k x k وزناً، لذلك أصبحت المرشحات المكلفة 3x3 ترى 16 قناة دخل بدلاً من 64، ونصف المخرجات يأتي من مرشحات 1x1 رخيصة.
Layerالطبقة
C_in x C_out x k x kC_in x C_out x k x k
Weightsالأوزان
3x3 conv, 64 to 128طبقة 3x3 conv من 64 إلى 128
64 x 128 x 964 x 128 x 9
73,72873,728
1x1 squeeze, 64 to 16طبقة 1x1 squeeze من 64 إلى 16
64 x 16 x 164 x 16 x 1
1,0241,024
1x1 expand, 16 to 64طبقة 1x1 expand من 16 إلى 64
16 x 64 x 116 x 64 x 1
1,0241,024
3x3 expand, 16 to 64طبقة 3x3 expand من 16 إلى 64
16 x 64 x 916 x 64 x 9
9,2169,216
Fire module totalمجموع الـ fire module
1,024 + 1,024 + 9,2161,024 + 1,024 + 9,216
11,26411,264
Weights in a direct 3x3 convolution versus the slide's fire module (biases ignored)الأوزان في طبقة convolution مباشرة بحجم 3x3 مقابل الـ fire module في الشريحة (مع إهمال قيم الـ bias)
73,728 / 11,264 = 6.5, so the fire module uses about 6.5x fewer weights for the same output width. The SqueezeNet paper names the three ideas behind the design: replace 3x3 filters with 1x1 filters (each has 9x fewer weights), decrease the number of input channels to the 3x3 filters (that is the squeeze), and downsample late so the layers work on large activation maps, which protects accuracy. The squeeze width is always kept below the total expand width, s1x1 < e1x1 + e3x3.
73,728 / 11,264 = 6.5، إذن تستخدم الـ fire module أوزاناً أقل بنحو 6.5x لعرض الخرج نفسه. تسمّي ورقة SqueezeNet الأفكار الثلاث وراء التصميم: استبدال مرشحات 3x3 بمرشحات 1x1 (كل واحد منها أقل بـ 9x في الأوزان)، وتقليل عدد قنوات الدخل إلى مرشحات 3x3 (وهذا هو الـ squeeze)، وتأخير الـ downsampling حتى تعمل الطبقات على خرائط تنشيط (activation maps) كبيرة، مما يحمي الدقة. ويبقى عرض الـ squeeze دائماً أقل من مجموع عرض الـ expand، أي s1x1 < e1x1 + e3x3.
Recall
Recount the fire module with a squeeze width of 32 instead of 16, keeping 64 + 64 expand filters. How many weights?أعد عدّ أوزان الـ fire module بعرض squeeze يساوي 32 بدلاً من 16، مع الإبقاء على 64 + 64 مرشح expand. كم عدد الأوزان؟
64 x 32 + 32 x 64 + 32 x 64 x 9 = 2,048 + 2,048 + 18,432 = 22,528. Doubling the squeeze width doubles every term, which is why the squeeze is kept narrow.
64 x 32 + 32 x 64 + 32 x 64 x 9 = 2,048 + 2,048 + 18,432 = 22,528. مضاعفة عرض الـ squeeze تضاعف كل حد، ولهذا يُبقى الـ squeeze ضيقاً.
Quick checkاختبار سريع
A direct 3x3 conv maps 64 channels to 128. The slide's fire module also outputs 128. Roughly how many times fewer weights does it need?طبقة 3x3 conv مباشرة تحوّل 64 قناة إلى 128. والـ fire module في الشريحة تُخرج 128 قناة أيضاً. بكم مرة تقريباً تقل الأوزان التي تحتاجها؟
Slide 41 lines up five ways to get an ImageNet classifier at AlexNet accuracy. Read the size column from top to bottom: 240 MB, 48 MB, 6.9 MB, 4.8 MB and finally 0.47 MB, less than half a megabyte.
تصفّ الشريحة 41 خمس طرق للحصول على مصنّف ImageNet بدقة AlexNet. اقرأ عمود الحجم من الأعلى إلى الأسفل: 240 MB و48 MB و6.9 MB و4.8 MB وأخيراً 0.47 MB، أي أقل من نصف ميغابايت.
Networkالشبكة
Approachالطريقة
Sizeالحجم
Ratio vs AlexNetالنسبة مقارنةً بـ AlexNet
Top-1Top-1
Top-5Top-5
AlexNetAlexNet
noneبلا ضغط
240 MB240 MB
1x1x
57.2%57.2%
80.3%80.3%
AlexNetAlexNet
SVDSVD
48 MB48 MB
5x5x
56.0%56.0%
79.4%79.4%
AlexNetAlexNet
Deep CompressionDeep Compression
6.9 MB6.9 MB
35x35x
57.2%57.2%
80.3%80.3%
SqueezeNetSqueezeNet
noneبلا ضغط
4.8 MB4.8 MB
50x50x
57.5%57.5%
80.3%80.3%
SqueezeNetSqueezeNet
Deep CompressionDeep Compression
0.47 MB0.47 MB
510x510x
57.5%57.5%
80.3%80.3%
Slide 41: compression and compact design on ImageNet (Iandola et al., 2016)الشريحة 41: الضغط والتصميم المدمج على ImageNet (Iandola et al., 2016)
Model size on a log scale. Deep Compression and SqueezeNet each cut about one and a half decades; together they cut more than two and a half.حجم النموذج على مقياس لوغاريتمي. كل من Deep Compression وSqueezeNet يقتطع نحو مرتبة عشرية ونصف، ومعاً يقتطعان أكثر من مرتبتين ونصف.
Three lessons sit in this table. First, not all compression is equal: a low-rank SVD factorisation buys only 5x and already costs 1.2 points of top-1 accuracy (57.2% to 56.0%), while Deep Compression buys 35x at no cost. Second, a better architecture can beat compression on its own: SqueezeNet is 50x smaller than AlexNet by design and even slightly more accurate in top-1. Third, and most important, the two are orthogonal.
في هذا الجدول ثلاثة دروس. أولاً، ليس كل ضغط متساوياً: تحليل SVD منخفض الرتبة (low-rank) لا يكسب إلا 5x ويكلّف أصلاً 1.2 نقطة من دقة top-1 (من 57.2% إلى 56.0%)، بينما يكسب Deep Compression نسبة 35x دون أي كلفة. ثانياً، المعمارية الأفضل قد تتفوق على الضغط وحده: SqueezeNet أصغر من AlexNet بـ 50x بحكم تصميمه، بل وأدق قليلاً في top-1. ثالثاً، وهو الأهم، أن الاثنين متعامدان (orthogonal)، أي مستقلان عن بعضهما.
Architecture and compression multiplyالمعمارية والضغط يتضاعفان معًا
SqueezeNet decides how many parameters the network needs; Deep Compression decides how many bits each surviving parameter costs. Because they act on different factors, their ratios multiply. The paper used 6-bit quantization and light pruning on SqueezeNet. Notice that compression gave only about 10x here, against 35x on AlexNet: exactly the lesson of the previous concept, since a compact network carries less redundancy.
SqueezeNet يحدد كم معاملاً تحتاج الشبكة، وDeep Compression يحدد كم بتاً يكلّف كل معامل باقٍ. ولأنهما يعملان على عوامل مختلفة، فإن نسبتيهما تُضربان. استخدمت الورقة quantization بـ 6 بتات وpruning خفيفاً على SqueezeNet. لاحظ أن الضغط أعطى هنا نحو 10x فقط، مقابل 35x على AlexNet: وهذا بالضبط درس المفهوم السابق، لأن الشبكة المدمجة تحمل تكراراً أقل.
Recall
Why is 510x not 50 x 35 = 1750x?لماذا النسبة 510x وليست 50 x 35 = 1750x؟
The 35x was measured on AlexNet, which is full of redundant FC weights. Applied to the already compact SqueezeNet, Deep Compression achieves only about 10x, and 50 x 10.2 = 510.
نسبة 35x قيست على AlexNet، وهو مليء بأوزان FC زائدة. وعند تطبيق Deep Compression على SqueezeNet المدمج أصلاً لا يحقق إلا نحو 10x، و50 x 10.2 = 510.
Quick checkاختبار سريع
SqueezeNet is 50x smaller than AlexNet, and Deep Compression shrinks SqueezeNet another 10x. What does that show?SqueezeNet أصغر من AlexNet بـ 50x، ويقلّص Deep Compression حجم SqueezeNet بـ 10x إضافية. ماذا يبيّن ذلك؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
Huffman coding gives frequent symbols short codes and rare symbols long codes. It is a prefix code, so it decodes without separators, and it is lossless.ترميز Huffman يعطي الرموز المتكررة رموزاً قصيرة والرموز النادرة رموزاً طويلة. وهو prefix code، لذلك يُفك دون فواصل، وهو بلا فقد (lossless).
Worked case: probabilities 0.5, 0.25, 0.125, 0.125 give codes 0, 10, 110, 111 and an average of 1.75 bits against 2 bits fixed.المثال المحلول: الاحتمالات 0.5 و0.25 و0.125 و0.125 تعطي الرموز 0 و10 و110 و111، بمتوسط 1.75 بت مقابل 2 بت للرمز الثابت.
Deep Compression Huffman-codes two streams: the cluster indexes of the quantized weights and the relative sparse indexes left by pruning. It saves 20 to 30 percent of storage with no retraining.يرمّز Deep Compression بطريقة Huffman تيارين: فهارس العناقيد (cluster indexes) للأوزان المكمّاة، والفهارس النسبية المتناثرة التي يتركها الـ pruning. ويوفّر 20 إلى 30 بالمئة من مساحة التخزين دون أي إعادة تدريب.
Pipeline order: pruning (fewer weights, 9x to 13x), then K-means quantization (fewer bits per weight, 27x to 31x cumulative), then Huffman coding (shorter average code, 35x to 49x cumulative), each at the same accuracy.ترتيب خط المعالجة: الـ pruning (أوزان أقل، 9x إلى 13x)، ثم K-means quantization (بتات أقل لكل وزن، 27x إلى 31x تراكمياً)، ثم ترميز Huffman (متوسط رمز أقصر، 35x إلى 49x تراكمياً)، وكل ذلك بالدقة نفسها.
AlexNet 240 MB to 6.9 MB (35x), VGGNet 550 MB to 11.3 MB (49x), GoogleNet 10x, ResNet-18 11x. FC-heavy networks hold the most redundancy.AlexNet من 240 MB إلى 6.9 MB (35x)، وVGGNet من 550 MB إلى 11.3 MB (49x)، وGoogleNet بنسبة 10x، وResNet-18 بنسبة 11x. الشبكات التي تغلب عليها طبقات FC تحمل أكبر قدر من التكرار (redundancy).
Fire module: 1x1 squeeze to 16 channels, then parallel 1x1 and 3x3 expands of 64 each, concatenated to 128. 11,264 weights against 73,728 for a direct 3x3 conv, about 6.5x fewer.الـ fire module: طبقة squeeze بحجم 1x1 إلى 16 قناة، ثم طبقتا expand متوازيتان 1x1 و3x3 بـ 64 مرشحاً لكل منهما، تُدمجان (concatenate) إلى 128. أي 11,264 وزناً مقابل 73,728 لطبقة 3x3 مباشرة، أقل بنحو 6.5x.
SqueezeNet is 4.8 MB (50x smaller than AlexNet); Deep Compression takes it to 0.47 MB, 510x smaller than AlexNet, with the same 57.5 percent top-1 and 80.3 percent top-5.حجم SqueezeNet هو 4.8 MB (أصغر من AlexNet بـ 50x)، ويوصله Deep Compression إلى 0.47 MB، أي أصغر من AlexNet بـ 510x، بالدقة نفسها: 57.5 بالمئة top-1 و80.3 بالمئة top-5.
Part 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 التخزين فقط؛ أما الحساب والوصول إلى الذاكرة فيبقيان بالفاصلة العائمة. التكميم الخطي يخزّن أعدادًا صحيحة ويحسب بأعداد صحيحة، وهو موضوع المحاضرة التالية.
3 concepts3 مفاهيم, ، slides 42-45الشرائح 42-45
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في نهاية هذا الجزء ستستطيع
01Trace 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 في كل مكان بعده.
02Answer 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 تبقى بالفاصلة العائمة.
03Fill in the full storage and computation table of slide 43 for floating point, K-means and linear quantization.تملأ جدول التخزين والحساب الكامل في الشريحة 43 لكل من الفاصلة العائمة و K-means والتكميم الخطي.
04Reconstruct 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.
05Name 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 يوفّر كلفة تخزين النموذج فقط، لأن كل الحسابات والوصول إلى الذاكرة ما زالت بالفاصلة العائمة.
Only the bottom edge carries integers. Decode turns every 2-bit index into an FP32 weight, and from there the convolution, bias add and ReLU are pure floating point.الحافة السفلية وحدها تحمل أعدادًا صحيحة. يحوّل decode كل فهرس ذي 2-bit إلى وزن FP32، ومن هناك يكون الالتفاف وإضافة الـ bias و ReLU بالفاصلة العائمة بالكامل.
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 قراءة صغيرة إضافية على الشريحة
Where the energy goes, using EIE Table I numbers (45 nm)أين تذهب الطاقة، بأرقام الجدول I في EIE (45 nm)
Per weight, K-means cuts the bits fetched by 16x, leaves the FP32 multiply-add exactly as it was, and adds one codebook lookup.لكل وزن، يقلّص K-means عدد البتات المجلوبة بمقدار 16x، ويترك عملية الضرب والجمع بـ FP32 كما هي تمامًا، ويضيف بحثًا واحدًا في الـ codebook.
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، من التخزين حتى الخرج.
Quantized weights (uint) and codebook (float) into decode; float weights out of decode; float inputs; float Conv output into the adder; float bias; float into ReLU; float outputs. Exactly one edge carries integers.
الأوزان المكمَّمة (uint) والـ codebook (float) داخلة إلى decode؛ أوزان float خارجة من decode؛ مدخلات float؛ خرج Conv بصيغة float داخل إلى الجامع؛ bias بصيغة float؛ float داخل إلى ReLU؛ مخرجات float. حافة واحدة بالضبط تحمل أعدادًا صحيحة.
Recall
Why can't the hardware multiply directly with the 2-bit K-means indexes?لماذا لا يستطيع العتاد الضرب مباشرة بفهارس K-means ذات 2-bit؟
Because an index is a label, not a value. The centroids -1.00, 0.00, 1.50, 2.00 are learned and unevenly spaced, so there is no linear relation between index and value. The only way to get the value is the table lookup, and the value it returns is FP32.
لأن الفهرس تسمية، وليس قيمة. المراكز -1.00, 0.00, 1.50, 2.00 متعلَّمة وغير متساوية التباعد، فلا توجد علاقة خطية بين الفهرس والقيمة. الطريقة الوحيدة للحصول على القيمة هي البحث في الجدول، والقيمة التي يعيدها بصيغة FP32.
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:
r=S(q−Z),S=1.07,Z=−1
Linear (affine) quantization, as previewed on slide 43التكميم الخطي (affine) كما لُمِّح إليه في الشريحة 43
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الأوزان الأصلية التي تُربط هنا
Decoding the slide 43 integers with S = 1.07 and Z = -1فك الأعداد الصحيحة في الشريحة 43 باستخدام S = 1.07 و Z = -1
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.
i∑rw,irx,i=SwSxi∑(qw,i−Zw)(qx,i−Zx)
Preview only: the integer sum on the right is what integer MAC units computeلمحة فقط: المجموع الصحيح على اليمين هو ما تحسبه وحدات MAC الصحيحة
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
Reconstruction of selected weights by each method (computed from slides 27 and 43)إعادة بناء أوزان مختارة بكل طريقة (محسوبة من الشريحتين 27 و 43)
Each weight drops to its nearest level. K-means levels sit on the clusters; the evenly spaced linear grid leaves the 1.5 cluster stranded and pulls it down to 1.07 (the long highlighted connectors).كل وزن ينزل إلى أقرب مستوى له. مستويات K-means تقع على المجموعات؛ أما الشبكة الخطية متساوية التباعد فتترك مجموعة 1.5 معزولة وتسحبها للأسفل إلى 1.07 (الوصلات الطويلة المميَّزة).
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 هنا يضخّم الخطأ ليجعل شكل الشبكة مرئيًا.
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
Slide 43 completed: storage and computation for the three columns it fillsالشريحة 43 مكتملة: التخزين والحساب للأعمدة الثلاثة التي تملؤها
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، وقل أي الأوزان الأصلية تقع على كل منهما.
q = 0: (0 + 1) x 1.07 = 1.07, holding 1.48, 1.53 and 1.49. q = -1: (-1 + 1) x 1.07 = 0, holding 0.09, 0.05, -0.14 and the two zeros. Note that real zero is exactly representable, which is what the zero point guarantees.
q = 0: (0 + 1) x 1.07 = 1.07، وتحمل 1.48 و 1.53 و 1.49. q = -1: (-1 + 1) x 1.07 = 0، وتحمل 0.09 و 0.05 و -0.14 والصفرين. لاحظ أن الصفر الحقيقي يمكن تمثيله بدقة تامة، وهذا ما تضمنه نقطة الصفر.
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 (Han, Mao and Dally, ICLR 2016): prune, K-means quantize, Huffman code, giving 35x on AlexNet (240 MB to 6.9 MB) and 49x on VGG-16 with no accuracy loss. SqueezeNet (Iandola et al., 2016): AlexNet-level accuracy with 50x fewer parameters, and under 0.5 MB (510x smaller than AlexNet) after Deep Compression.
Deep Compression (Han, Mao and Dally, ICLR 2016): تقليم، ثم تكميم K-means، ثم ترميز Huffman، مما يعطي 35x على AlexNet (من 240 MB إلى 6.9 MB) و 49x على VGG-16 دون فقدان في الدقة. SqueezeNet (Iandola et al., 2016): دقة بمستوى AlexNet بمعاملات أقل بمقدار 50x، وأقل من 0.5 MB (أصغر من AlexNet بمقدار 510x) بعد Deep Compression.
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 فارغة.