COE 592Lecture 5.1المحاضرة 5.1Part 06الجزء 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).
- Conceptsالمفاهيم
- 3
- Slidesالشرائح
- 30-36
- Readingمدة القراءة
- 18 min18 دقيقة
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في نهاية هذا الجزء ستستطيع
- Read an accuracy-loss versus model-size-ratio plot and locate where each method falls off its cliff.تقرأ رسمًا بيانيًا لفقدان الدقة مقابل نسبة حجم النموذج وتحدد أين تسقط كل طريقة من حافة الجرف الخاصة بها.
- Explain 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%.
- Estimate a compressed size ratio from the fraction of weights kept and the bits per weight and per index.تقدّر نسبة الحجم بعد الضغط من نسبة الأوزان المُبقاة وعدد الـ bits لكل وزن ولكل index.
- Describe how the weight histogram changes from continuous, to discrete spikes, to slightly shifted spikes after retraining.تصف كيف يتغير الـ histogram الخاص بالأوزان من توزيع متصل، إلى قمم منفصلة، إلى قمم منزاحة قليلًا بعد الـ retraining.
- State 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) الخاصة بتلك الطريقة.
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 يهاجم العامل الثاني. ولأن العاملين يُضربان ببعضهما، فإن دفع كل منهما فقط إلى منطقته المريحة، بعيدًا عن حافة الجرف الخاصة به، يعطي بالفعل حاصل ضرب أصغر بكثير مما يصل إليه أي منهما وحده.
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% من الحجم الأصلي؟
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: 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) مع أن الطبقة فيها العدد نفسه من الأوزان؟
Recall
What is the only visible difference between slides 34 and 35, and why is that the only one?ما الفرق الوحيد المرئي بين الشريحتين 34 و35، ولماذا هو الفرق الوحيد؟
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.
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) |
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؟
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 فقليلة وكل وزن منها يُعاد استخدامه في كل موقع مكاني، لذلك يحمل كل وزن معلومات أكثر.
Sourcesالمصادر
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman CodingPaperHan, Mao and Dally, ICLR 2016Section 6.1 and Figures 6 and 7: each method alone drops below 8%, combined reaches 3% with no loss; conv needs 4 bits, FC 2 bits; Table 4 gives per-layer bits and the 3.7% and 2.88% ratios.القسم 6.1 والشكلان 6 و7: كل طريقة وحدها تهبط دقتها تحت 8%، والدمج يصل إلى 3% بلا فقدان؛ الـ conv تحتاج 4 bits والـ FC تحتاج 2 bits؛ والجدول 4 يعطي عدد الـ bits لكل طبقة والنسبتين 3.7% و2.88%.(opens in a new tab)(يفتح في تبويب جديد)
- Learning both Weights and Connections for Efficient Neural NetworksPaperHan, Pool, Tran and Dally, NeurIPS 2015Per-layer AlexNet weight counts and pruning ratios; conv layers are more sensitive to pruning than FC layers.أعداد الأوزان ونسب الـ pruning لكل طبقة في AlexNet؛ طبقات الـ conv أكثر حساسية للـ pruning من طبقات الـ FC.(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 5: Quantization (Part I)DocsMIT HAN LabThe course these slides follow; lecture videos and slides on K-means quantization.المقرر الذي تتبعه هذه الشرائح؛ فيه فيديوهات المحاضرات والشرائح عن الـ K-means quantization.(opens in a new tab)(يفتح في تبويب جديد)