COE 592Lecture 4.1المحاضرة 4.1Full guideالشرح الكامل
Pruning and sparsity Iالتقليم (Pruning) والتناثر (Sparsity) الجزء الأول
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الأجزاء
- 6
- Conceptsالمفاهيم
- 29
- Slidesالشرائح
- 43
- Readingمدة القراءة
- 174 min174 دقيقة
Part 01: Why prune: energy, definition and formulationلماذا نقلّم: الطاقة والتعريف والصياغة
Memory access dominates the energy bill of deep learning, so fewer weights means less data movement; pruning removes synapses and neurons and is posed as minimizing loss under an L0 budget, echoing synaptic pruning in the human brain.الوصول إلى الذاكرة يهيمن على فاتورة الطاقة في التعلم العميق، لذا فإن أوزانًا أقل تعني نقل بيانات أقل؛ التقليم يزيل المشابك (synapses) والعصبونات ويُصاغ بوصفه تقليلًا للخسارة تحت ميزانية L0، على غرار التقليم المشبكي في الدماغ البشري.
5 concepts5 مفاهيم, ، slides 1-6الشرائح 1-6
Why this part mattersلماذا يهمّ هذا الجزء
Every model you want on an embedded board is limited first by how many weights must be moved, not by how many multiplies the chip can do. One number from this part, 640 pJ for a DRAM access against 3.1 pJ for an integer multiply, justifies the pruning, quantization and sparse-hardware lectures that follow.
This part gives you three tools. A roadmap of the pruning pipeline, which doubles as the checklist for any pruning experiment in your research. The energy argument, which is the answer to the exam question "why is memory rather than arithmetic the bottleneck?". And the formulation of pruning as constrained optimization, which is the standard way to write down what pruning optimizes and why it cannot be solved by gradient descent alone. The part closes with the biological curve that inspired the whole idea.
كل نموذج تريد تشغيله على لوحة مدمجة (embedded board) يحدّه أولًا عدد الأوزان التي يجب نقلها، لا عدد عمليات الضرب التي تستطيع الشريحة تنفيذها. رقم واحد من هذا الجزء، 640 pJ للوصول إلى DRAM مقابل 3.1 pJ لعملية ضرب أعداد صحيحة، يبرّر محاضرات الـ pruning والـ quantization والعتاد المخصص للمصفوفات المتناثرة (sparse hardware) التي تأتي بعده.
يمنحك هذا الجزء ثلاث أدوات. الأولى خريطة طريق لسلسلة الـ pruning، وهي في الوقت نفسه قائمة التحقق لأي تجربة pruning في بحثك. الثانية حجة الطاقة، وهي إجابة سؤال الامتحان «لماذا تكون الذاكرة، لا العمليات الحسابية، هي عنق الزجاجة؟». الثالثة صياغة الـ pruning كمسألة تحسين مقيّدة (constrained optimization)، وهي الطريقة القياسية لكتابة ما يحسّنه الـ pruning ولماذا لا يمكن حلّه بالـ gradient descent وحده. ويُختتم الجزء بالمنحنى البيولوجي الذي ألهم الفكرة كلها.
By the end you canفي نهاية هذا الجزء ستستطيع
- Name the four decisions of the pruning pipeline and say which ones this lecture covers.سمِّ القرارات الأربعة في سلسلة الـ pruning، وحدّد أيها تغطيه هذه المحاضرة.
- Reproduce the 45 nm energy ladder and argue with numbers why DRAM traffic, not arithmetic, dominates.أعِد بناء سُلّم الطاقة لتقنية 45 nm، وبرهن بالأرقام لماذا تهيمن حركة البيانات من DRAM، لا العمليات الحسابية.
- Distinguish synapse pruning from neuron pruning and state what each does to a layer's weight matrix.ميّز بين pruning الوصلات (synapse pruning) وpruning العصبونات (neuron pruning)، واذكر ما يفعله كلٌّ منهما بمصفوفة أوزان الطبقة.
- Write the pruning formulation with a less-or-equal budget, name every symbol, and explain why the L0 constraint forces heuristic criteria.اكتب صياغة الـ pruning بميزانية «أصغر من أو يساوي»، وسمِّ كل رمز فيها، واشرح لماذا يفرض قيد L0 اللجوء إلى معايير تقريبية (heuristic criteria).
- Describe the brain's overprovision-then-prune curve and use it as motivation, not as proof, for network pruning.صِف منحنى الدماغ «بناء فائض ثم تقليم»، واستخدمه دافعًا لـ pruning الشبكات العصبية، لا دليلًا عليه.
Suppose you have a trained object detector that is accurate on your validation set but will not fit on the board you are targeting. Before you touch a single weight, four questions need answers, and the outline slide of this lecture is exactly that checklist. It reappears on slides 14 and 26 as a progress marker, so treat it as the map you return to as each section closes.
افترض أن لديك نموذج كشف أجسام (object detector) مدرّبًا ودقيقًا على مجموعة التحقق (validation set)، لكنه لا يتسع على اللوحة التي تستهدفها. قبل أن تلمس وزنًا واحدًا، هناك أربعة أسئلة تحتاج إلى إجابة، وشريحة المخطط العام (outline) في هذه المحاضرة هي قائمة التحقق هذه بالضبط. تعود الشريحة للظهور في الشريحتين 14 و26 كمؤشر للتقدم، فتعامل معها كالخريطة التي ترجع إليها كلما انتهى قسم.
Pruning makes a network smaller by removing the synapses and neurons whose removal hurts performance least. That one sentence hides a sequence of design decisions. First you must formulate the problem: what exactly is being minimized, and under what budget. Then you choose the granularity, the pattern in which weights are removed, from single scattered weights up to whole channels. Then a criterion, the rule that scores which synapses or neurons are least important. Then a ratio, the target sparsity for each layer. Finally you fine-tune or retrain the pruned network so the accuracy you lost comes back.
الـ Pruning (التقليم) يصغّر الشبكة بإزالة الوصلات (synapses) والعصبونات (neurons) التي يضرّ حذفها بالأداء أقل ما يمكن. هذه الجملة الواحدة تخفي سلسلة من قرارات التصميم. أولًا يجب أن تصوغ المسألة: ما الذي نقلّله بالضبط، وتحت أي ميزانية. ثم تختار الـ granularity (درجة التفصيل)، أي النمط الذي تُزال به الأوزان، من أوزان منفردة متفرقة إلى قنوات (channels) كاملة. ثم تختار criterion (معيارًا)، أي القاعدة التي تعطي درجة لكل وصلة أو عصبون لتحديد الأقل أهمية. ثم تختار ratio (نسبة)، أي الـ sparsity المستهدفة لكل طبقة. وأخيرًا تُجري fine-tune أو تعيد تدريب الشبكة بعد التقليم حتى تعود الدقة التي فقدتها.
Loss under an L0 budget
الخسارة تحت ميزانية L0
What pattern to remove
أي نمط نزيل
Which synapses or neurons
أي المشابك أو العصبونات
Sparsity per layer
التناثرية لكل طبقة
Recover the accuracy
استعادة الدقة
| Decisionالقرار | Question the slide asksالسؤال الذي تطرحه الشريحة | Where it is taughtأين يُدرَّس |
|---|---|---|
| Formulateالصياغة (Formulate) | What is pruning? How should we formulate pruning?ما الـ pruning؟ وكيف نصوغ مسألة الـ pruning؟ | This partهذا الجزء |
| Granularityدرجة التفصيل (Granularity) | In what pattern should we prune the neural network?بأي نمط نقلّم الشبكة العصبية؟ | Parts 03 and 04الجزءان 03 و04 |
| Criterionالمعيار (Criterion) | What synapses or neurons should we prune?أي الوصلات (synapses) أو العصبونات (neurons) نقلّم؟ | Parts 05 and 06الجزءان 05 و06 |
| Ratioالنسبة (Ratio) | What should target sparsity be for each layer?ما الـ sparsity المستهدفة لكل طبقة؟ | Lecture 04-2المحاضرة 04-2 |
| Fine-tune or trainالـ fine-tuning أو التدريب | How should we improve performance of pruned models?كيف نحسّن أداء النماذج بعد الـ pruning؟ | Part 02 previews it; Lecture 04-2يمهّد له الجزء 02؛ والمحاضرة 04-2 |
This lecture, Pruning and Sparsity I, covers the formulation, the granularity and the criteria. The ratio and the fine-tuning belong to Pruning and Sparsity II, the next lecture. The split mirrors the two pruning lectures of the MIT course the deck is built on, and it explains why the outline slide is highlighted only at the top: the yellow marker moves down as the lecture proceeds.
هذه المحاضرة، Pruning and Sparsity I، تغطي الصياغة والـ granularity والمعايير. أما النسبة (ratio) والـ fine-tuning فينتميان إلى Pruning and Sparsity II، أي المحاضرة التالية. هذا التقسيم يطابق محاضرتي الـ pruning في مقرر MIT الذي بُني عليه هذا العرض، وهو يفسّر لماذا تكون شريحة المخطط العام مظلّلة في أعلاها فقط: العلامة الصفراء تنزل للأسفل كلما تقدمت المحاضرة.
Recall
What are the four decisions that follow the formulation of pruning, and which of them belong to Lecture 04-2?ما القرارات الأربعة التي تلي صياغة الـ pruning، وأيّها ينتمي إلى المحاضرة 04-2؟
Take one weight of a fully connected layer. It is fetched from off-chip DRAM and multiplied by an activation. The fetch costs 640 pJ. The 32-bit integer multiply costs 3.1 pJ. Divide them: 640 / 3.1 ≈ 206. Fetching the weight costs as much energy as about two hundred multiplies. That single ratio is the reason this lecture exists.
خذ وزنًا واحدًا من طبقة متصلة بالكامل (fully connected). يُجلب هذا الوزن من ذاكرة DRAM خارج الشريحة ثم يُضرب في قيمة تنشيط (activation). عملية الجلب تكلّف 640 pJ. أما عملية ضرب الأعداد الصحيحة بعرض 32-bit فتكلّف 3.1 pJ. اقسم أحدهما على الآخر: 640 / 3.1 ≈ 206. جلب الوزن يكلّف من الطاقة ما يعادل نحو مئتي عملية ضرب. هذه النسبة الواحدة هي سبب وجود هذه المحاضرة.
The numbers come from Mark Horowitz's ISSCC 2014 keynote, measured for a 45 nm process at 0.9 V, and reproduced in Han et al. (2015), which the slide follows. The full ladder is worth knowing by heart, because it is the quantitative case for every compression technique in this course. Read it top to bottom as an ordering of operations by cost, and notice that the four arithmetic rows and the register file all sit below 4 pJ while the two memory rows, SRAM and DRAM, close the table at 5 pJ and 640 pJ.
هذه الأرقام مأخوذة من الكلمة الرئيسية التي ألقاها Mark Horowitz في ISSCC 2014، وهي مقيسة لتقنية تصنيع 45 nm عند جهد 0.9 V، وأعاد نشرها Han et al. (2015)، وهي الورقة التي تتبعها الشريحة. يستحق السُّلّم كاملًا أن تحفظه عن ظهر قلب، لأنه الحجة الكمية لكل تقنية ضغط في هذا المقرر. اقرأه من الأعلى إلى الأسفل على أنه ترتيب للعمليات بحسب كلفتها، ولاحظ أن صفوف العمليات الحسابية الأربعة وملف المسجلات (register file) كلها أقل من 4 pJ، بينما يُختتم الجدول بصفّي الذاكرة، SRAM وDRAM، عند 5 pJ و640 pJ.
| Operationالعملية | Energyالطاقة | Relative to int ADDنسبةً إلى جمع الأعداد الصحيحة int ADD |
|---|---|---|
| 32-bit int ADDجمع أعداد صحيحة 32-bit int ADD | 0.1 pJ0.1 pJ | 1x1x |
| 32-bit float ADDجمع بالفاصلة العائمة 32-bit float ADD | 0.9 pJ0.9 pJ | 9x9x |
| 32-bit register fileملف المسجلات 32-bit register file | 1 pJ1 pJ | 10x10x |
| 32-bit int MULTضرب أعداد صحيحة 32-bit int MULT | 3.1 pJ3.1 pJ | 31x31x |
| 32-bit float MULTضرب بالفاصلة العائمة 32-bit float MULT | 3.7 pJ3.7 pJ | 37x37x |
| 32-bit SRAM cacheذاكرة 32-bit SRAM cache | 5 pJ5 pJ | 50x50x |
| 32-bit DRAM memoryذاكرة 32-bit DRAM memory | 640 pJ640 pJ | 6400x6400x |
Han et al. summarize the ladder in one sentence: memory access is three orders of magnitude more energy expensive than simple arithmetic. Sze et al. make the same point in their survey: DRAM accesses require up to several orders of magnitude more energy than computation, and DRAM consumes two orders of magnitude more energy per access than a small on-chip memory of a few kilobytes. Measured against the rows of the ladder, one DRAM access costs as much as each of the following.
يلخّص Han et al. السُّلّم في جملة واحدة: الوصول إلى الذاكرة أغلى من العمليات الحسابية البسيطة بثلاث رتب عشرية (orders of magnitude) من حيث الطاقة. ويطرح Sze et al. الفكرة نفسها في مسحهم البحثي: الوصول إلى DRAM يتطلب طاقة أكبر من الحساب بما يصل إلى عدة رتب عشرية، وDRAM تستهلك لكل وصول طاقة أكبر برتبتين عشريتين من ذاكرة صغيرة داخل الشريحة حجمها بضعة كيلوبايتات. وبالمقارنة مع صفوف السُّلّم، فإن وصولًا واحدًا إلى DRAM يكلّف ما يعادل كل واحدة مما يلي.
One 640 pJ DRAM access costs as much as one...وصول واحد إلى DRAM بكلفة 640 pJ يكلّف ما يعادل...
- One 32-bit int ADDعملية جمع واحدة لأعداد صحيحة بعرض 32-bit
- 6400x6400x
- One register file readقراءة واحدة من ملف المسجلات (register file)
- 640x640x
- One SRAM cache readقراءة واحدة من ذاكرة SRAM cache
- 128x128x
- One 32-bit int MULTعملية ضرب واحدة لأعداد صحيحة بعرض 32-bit
- 206x206x
The slide's icon line, one DRAM stick equals 200 ×+, rounds the chart's arrow: that arrow runs from the DRAM bar to the 32-bit int MULT bar, so the 200 is 640 / 3.1 ≈ 206 rounded down. Pricing one MAC instead (3.1 + 0.1 = 3.2 pJ) gives 640 / 3.2 = 200. Either way the answer is about two hundred.
سطر الأيقونات في الشريحة، حيث شريحة DRAM واحدة تساوي 200 ×+، هو تقريب لسهم المخطط: ذلك السهم يمتد من عمود DRAM إلى عمود ضرب الأعداد الصحيحة 32-bit int MULT، لذا فإن الـ 200 هي 640 / 3.1 ≈ 206 مقرّبة إلى الأسفل. وإذا حسبت كلفة MAC واحدة بدلًا من ذلك (3.1 + 0.1 = 3.2 pJ) تحصل على 640 / 3.2 = 200. في الحالتين الجواب نحو مئتين.
The chain from weights to wattsالسلسلة من الأوزان إلى الواط
The slide states the consequence as a chain: data movement, more memory references, more energy. Every weight that does not fit on chip is a DRAM reference on every inference. A network with more weights moves more bytes, more bytes mean more DRAM references, and each reference costs 640 pJ. The compute, the MACs that the earlier lectures counted so carefully, turns out to be the cheap part. This is the memory access energy problem, and pruning attacks it at the root by reducing the number of weights that have to move at all.
تعرض الشريحة النتيجة على شكل سلسلة: حركة البيانات، فمزيد من مرات الوصول إلى الذاكرة، فمزيد من الطاقة. كل وزن لا يتسع داخل الشريحة يعني وصولًا إلى DRAM في كل عملية استدلال (inference). الشبكة ذات الأوزان الأكثر تنقل بايتات أكثر، والبايتات الأكثر تعني مرات وصول أكثر إلى DRAM، وكل وصول يكلّف 640 pJ. أما الحساب، أي عمليات الـ MAC التي عددناها بعناية في المحاضرات السابقة، فيتضح أنه الجزء الرخيص. هذه هي مشكلة memory access energy (طاقة الوصول إلى الذاكرة)، والـ pruning يعالجها من جذورها بتقليل عدد الأوزان التي يجب نقلها أصلًا.
Worked exampleمثال محلول
A billion connections at 20 frames per second (Han et al. 2015)مليار وصلة بمعدل 20 إطارًا في الثانية (Han et al. 2015)
Count the fetchesعُدّ عمليات الجلب
A network with 1,000,000,000 connections run at 20 Hz fetches every weight twenty times a second: 2 × 10^10 DRAM references per second.شبكة فيها 1,000,000,000 وصلة تعمل بتردد 20 Hz تجلب كل وزن عشرين مرة في الثانية: أي 2 × 10^10 وصول إلى DRAM في الثانية.Price each fetchاحسب كلفة كل عملية جلب
2 × 10^10 × 640 pJ = 12.8 J every second, so 12.8 W.2 × 10^10 × 640 pJ = 12.8 J في كل ثانية، أي 12.8 W.Resultالنتيجة
12.8 W for DRAM traffic alone, before a single multiply is counted. Han et al. call this well beyond the power envelope of a typical mobile device.12.8 W لحركة البيانات من DRAM وحدها، قبل احتساب عملية ضرب واحدة. ويصف Han et al. هذا الرقم بأنه يتجاوز بكثير حدود الطاقة المتاحة لجهاز محمول نموذجي.
Worked exampleمثال محلول
One layer of a million fp32 weights, before and after 90 percent pruningطبقة واحدة بمليون وزن fp32، قبل pruning بنسبة 90 بالمئة وبعده
Dense: memoryالكثيفة (dense): الذاكرة
10^6 weights fetched once each from DRAM: 10^6 × 640 pJ = 640 µJ.10^6 وزن يُجلب كل منها مرة واحدة من DRAM: 10^6 × 640 pJ = 640 µJ.Dense: arithmeticالكثيفة (dense): الحساب
One float multiply and one float add per weight: 10^6 × (3.7 + 0.9) pJ = 4.6 µJ.عملية ضرب واحدة وعملية جمع واحدة بالفاصلة العائمة (float) لكل وزن: 10^6 × (3.7 + 0.9) pJ = 4.6 µJ.Dense: shareالكثيفة (dense): الحصة
640 / 644.6 ≈ 0.993. Memory is 99.3% of the layer's energy, and the ratio of memory to arithmetic is 640 / 4.6 ≈ 139.640 / 644.6 ≈ 0.993. الذاكرة تمثّل 99.3% من طاقة الطبقة، ونسبة الذاكرة إلى الحساب هي 640 / 4.6 ≈ 139.Pruned: keep 100,000 weightsبعد الـ pruning: نُبقي 100,000 وزن
Fetch 10^5 × 640 pJ = 64 µJ, compute 10^5 × 4.6 pJ = 0.46 µJ.الجلب 10^5 × 640 pJ = 64 µJ، والحساب 10^5 × 4.6 pJ = 0.46 µJ.Resultالنتيجة
Total drops from 644.6 µJ to 64.46 µJ, about 10x, ignoring the index overhead of a sparse format, which Part 03 reintroduces.ينخفض المجموع من 644.6 µJ إلى 64.46 µJ، أي نحو 10x، مع تجاهل كلفة الفهارس (index overhead) في صيغة التخزين المتناثرة (sparse format)، وهي كلفة يعيد الجزء 03 إدخالها.
| Quantityالكمية | Dense, 10^6 weightsكثيفة، 10^6 وزن | Pruned, 10^5 weightsبعد الـ pruning، 10^5 وزن |
|---|---|---|
| DRAM fetch energyطاقة الجلب من DRAM | 640 µJ640 µJ | 64 µJ64 µJ |
| MAC energyطاقة عمليات الـ MAC | 4.6 µJ4.6 µJ | 0.46 µJ0.46 µJ |
| Total per inferenceالمجموع لكل عملية استدلال | 644.6 µJ644.6 µJ | 64.46 µJ64.46 µJ |
| Share from memoryحصة الذاكرة | 99.3%99.3% | 99.3%99.3% |
There is a second payoff hiding in the ladder. Once a pruned model is small enough, its weights stop living in DRAM at all and sit in on-chip SRAM, where an access costs 5 pJ instead of 640 pJ. That is the argument of Deep Compression: pruning plus quantization shrinks both networks to a few megabytes, small enough to fit in on-chip SRAM cache rather than off-chip DRAM.
هناك مكسب ثانٍ مخفي في السُّلّم. حين يصبح النموذج بعد الـ pruning صغيرًا بما يكفي، تتوقف أوزانه عن الإقامة في DRAM أصلًا وتستقر في ذاكرة SRAM داخل الشريحة، حيث يكلّف الوصول 5 pJ بدلًا من 640 pJ. هذه هي حجة Deep Compression: الـ pruning مع الـ quantization يقلّصان كلتا الشبكتين إلى بضعة ميغابايتات، وهو حجم صغير بما يكفي ليتسع في ذاكرة SRAM cache داخل الشريحة بدلًا من DRAM خارجها.
| Modelالنموذج | Beforeقبل | Afterبعد | Ratioالنسبة |
|---|---|---|---|
| AlexNetAlexNet | 240 MB240 MB | 6.9 MB6.9 MB | 35x35x |
| VGG-16VGG-16 | 552 MB552 MB | 11.3 MB11.3 MB | 49x49x |
Separately, benchmarking the pruned fully connected layers on CPU, GPU and mobile GPU measured 3x to 7x less energy per layer. Fewer weights is the first win; crossing the SRAM boundary is the second.
وبشكل منفصل، أظهر قياس أداء الطبقات المتصلة بالكامل بعد الـ pruning على CPU وGPU وGPU المحمول انخفاضًا في الطاقة لكل طبقة بين 3x و7x. تقليل الأوزان هو المكسب الأول؛ وعبور حد SRAM هو المكسب الثاني.
Figures are the slide's 45 nm, 0.9 V numbers from 2014 and ignore activation traffic and the index overhead of storing a sparse matrix. The 1 B at 20 Hz preset reproduces Han et al.'s memory-only estimate of 12.8 W (the total adds 0.09 W of MACs).الأرقام هي أرقام الشريحة لتقنية 45 nm عند 0.9 V من عام 2014، وهي تتجاهل حركة بيانات الـ activations وكلفة الفهارس الإضافية لتخزين مصفوفة متناثرة. الإعداد المسبق 1 B at 20 Hz يعيد إنتاج تقدير Han et al. للذاكرة وحدها وهو 12.8 W (ويضيف الإجمالي 0.09 W لعمليات MAC).
Quick checkاختبار سريع
Using the slide's 45 nm figures, about how many 32-bit integer multiplies cost the same energy as one 32-bit DRAM access?باستخدام أرقام الشريحة لتقنية 45 nm، كم عملية ضرب لأعداد صحيحة بعرض 32-bit تكلّف تقريبًا الطاقة نفسها التي يكلّفها وصول واحد إلى DRAM بعرض 32-bit؟
Quick checkاختبار سريع
According to slide 3, what is the primary motivation for pruning a network?بحسب الشريحة 3، ما الدافع الأساسي لتقليم (pruning) شبكة عصبية؟
Recall
One DRAM access versus one 32-bit integer multiply in 45 nm: give the two energies and the ratio. What is the ratio against an integer add?وصول واحد إلى DRAM مقابل ضرب واحد لأعداد صحيحة بعرض 32-bit في تقنية 45 nm: اذكر الطاقتين والنسبة. وما النسبة مقارنة بجمع الأعداد الصحيحة؟
The slide's before-and-after picture, taken from Han et al. (2015), is a small fully connected network with layers of 5, 4, 3 and 2 nodes. Count the edges: 5 × 4 + 4 × 3 + 3 × 2 = 20 + 12 + 6 = 38 synapses and 14 neurons. After pruning the layers read 5, 3, 2, 2. One hidden neuron is gone from the second layer, one from the third, and most of the remaining edges have vanished. Two different things were removed, and the slide labels them with two different arrows.
صورة «قبل وبعد» في الشريحة، المأخوذة من Han et al. (2015)، هي شبكة صغيرة متصلة بالكامل طبقاتها فيها 5, 4, 3 و2 عقد. عُدّ الحواف: 5 × 4 + 4 × 3 + 3 × 2 = 20 + 12 + 6 = 38 وصلة (synapse) و14 عصبونًا. بعد الـ pruning تصبح الطبقات 5, 3, 2, 2. اختفى عصبون مخفي واحد من الطبقة الثانية، وآخر من الثالثة، واختفت معظم الحواف المتبقية. أُزيل شيئان مختلفان، والشريحة تسمّيهما بسهمين مختلفين.
A synapse is one weight w_ij, one edge between neuron j of one layer and neuron i of the next. Synapse pruning sets that single entry to zero, and the neurons at both ends survive with one fewer connection. A neuron is a node. Neuron pruning removes the node and therefore every edge incident to it at once: all of its incoming weights and all of its outgoing weights. Nothing about the neuron remains, so nothing that fed it or read from it needs to exist either.
الوصلة (synapse) هي وزن واحد w_ij، أي حافة واحدة بين العصبون j في طبقة والعصبون i في الطبقة التالية. الـ Synapse pruning يجعل هذا العنصر الواحد صفرًا، ويبقى العصبونان على طرفيه مع وصلة أقل بواحدة. أما العصبون فهو عقدة. الـ Neuron pruning يزيل العقدة، وبالتالي يزيل دفعة واحدة كل حافة متصلة بها: كل أوزانها الداخلة وكل أوزانها الخارجة. لا يبقى شيء من العصبون، لذا لا حاجة لوجود أي شيء كان يغذّيه أو يقرأ منه.
The matrix view makes the difference concrete. A linear layer holds its weights in a matrix W of shape [out, in], one row per output neuron and one column per input neuron. Synapse pruning zeroes scattered entries of that matrix, and the matrix keeps its shape; the result is a sparse matrix that must be stored with indices to say where the survivors are. Neuron pruning deletes a whole row of this layer's W(the neuron's inputs) and the matching column of the next layer's W (its outputs); both matrices become smaller dense matrices with no bookkeeping at all. This is the seed of the granularity spectrum in Part 03: fine-grained pruning lives at the synapse end and coarse-grained pruning at the neuron end.
النظر إلى المصفوفات يجعل الفرق ملموسًا. الطبقة الخطية (linear layer) تحفظ أوزانها في مصفوفة W شكلها [out, in]، صف لكل عصبون خرج وعمود لكل عصبون دخل. الـ synapse pruning يصفّر عناصر متفرقة من هذه المصفوفة، وتحتفظ المصفوفة بشكلها؛ والنتيجة مصفوفة متناثرة (sparse) يجب تخزينها مع indices (فهارس) توضّح أين توجد القيم الباقية. أما الـ neuron pruning فيحذف صفًا كاملًا من W في هذه الطبقة (مداخل العصبون) والعمود المقابل من W في الطبقة التالية (مخارجه)؛ فتصبح المصفوفتان مصفوفتين كثيفتين (dense) أصغر دون أي حسابات إضافية لتتبع المواقع. هذه هي بذرة طيف الـ granularity في الجزء 03: الـ fine-grained pruning يقع عند طرف الوصلات، والـ coarse-grained pruning عند طرف العصبونات.
Worked exampleمثال محلول
Same number of weights removed, two different resultsالعدد نفسه من الأوزان المحذوفة، ونتيجتان مختلفتان
The setupالإعداد
Layer one has 4 inputs and 3 outputs, so W_1 is 3 × 4 = 12 weights. Layer two takes those 3 outputs to 2, so W_2 is 2 × 3 = 6 weights.الطبقة الأولى لها 4 مداخل و3 مخارج، إذن W_1 فيها 3 × 4 = 12 وزنًا. الطبقة الثانية تأخذ هذه المخارج الـ 3 إلى 2، إذن W_2 فيها 2 × 3 = 6 أوزان.Option A: prune 6 synapsesالخيار A: تقليم 6 وصلات
Zero six entries of W_1. It still has 3 rows and 4 columns, with six zeros scattered inside. Every neuron still exists.صفّر ستة عناصر من W_1. تبقى فيها 3 صفوف و4 أعمدة، مع ستة أصفار متفرقة بداخلها. كل عصبون ما زال موجودًا.Option B: prune neuron 2 of layer oneالخيار B: تقليم العصبون 2 من الطبقة الأولى
Delete row 2 of W_1 (4 weights) and column 2 of W_2 (2 weights): 4 + 2 = 6 weights gone.احذف الصف 2 من W_1 (4 أوزان) والعمود 2 من W_2 (وزنان، 2): 4 + 2 = 6 أوزان حُذفت.Resultالنتيجة
Both options remove six weights. Option A leaves a sparse 3 × 4 matrix. Option B leaves dense 2 × 4 and 2 × 2 matrices that any hardware multiplies at full speed.كلا الخيارين يزيل ستة أوزان. الخيار A يترك مصفوفة متناثرة 3 × 4. الخيار B يترك مصفوفتين كثيفتين 2 × 4 و2 × 2 يضربهما أي عتاد بسرعته الكاملة.
| Choiceالخيار | Weights removedالأوزان المزالة | Shapes afterالأشكال بعد ذلك | Sparse or denseمتناثرة أم كثيفة |
|---|---|---|---|
| Prune 6 synapsesتقليم 6 وصلات | 66 | 3 × 4 and 2 × 3, unchanged3 × 4 و2 × 3، دون تغيير | Sparse: 6 zeros scattered inside a 3 × 4 matrixمتناثرة (sparse): 6 أصفار متفرقة داخل مصفوفة 3 × 4 |
| Prune neuron 2تقليم العصبون 2 | 4 + 2 = 64 + 2 = 6 | 2 × 4 and 2 × 22 × 4 and 2 × 2 | Dense: both matrices simply got smallerكثيفة (dense): المصفوفتان صغرتا ببساطة |
Han et al. describe the effect of synapse pruning on a layer in one line: this pruning converts a dense, fully-connected layer to a sparse layer. They also stress that retraining the surviving weights is critical, because zeroing connections drops accuracy immediately. Part 02 shows that curve and how fine-tuning recovers it.
يصف Han et al. أثر الـ synapse pruning على الطبقة في سطر واحد: هذا الـ pruning يحوّل الطبقة الكثيفة المتصلة بالكامل إلى طبقة متناثرة. ويؤكدون أيضًا أن إعادة تدريب الأوزان الباقية أمر حاسم، لأن تصفير الوصلات يُسقط الدقة فورًا. الجزء 02 يعرض هذا المنحنى وكيف يستعيده الـ fine-tuning.
- Synapse pruning: unit is one weight, neurons survive, the matrix keeps its shape but becomes sparse.Synapse pruning: الوحدة وزن واحد، والعصبونات تبقى، والمصفوفة تحتفظ بشكلها لكنها تصبح متناثرة.
- Neuron pruning: unit is one node, all incident weights go, a row and a column disappear, matrices stay dense.Neuron pruning: الوحدة عقدة واحدة، وكل الأوزان المتصلة بها تُحذف، ويختفي صف وعمود، وتبقى المصفوفات كثيفة.
- Both reduce the number of weights that must be fetched; only the second reduces it in a shape hardware likes.كلاهما يقلّل عدد الأوزان التي يجب جلبها؛ لكن الثاني وحده يقلّله بشكل يناسب العتاد.
Quick checkاختبار سريع
Which statement about pruning one hidden neuron is correct?أي العبارات التالية صحيحة بشأن تقليم عصبون مخفي واحد؟
Recall
A 3 × 4 linear layer feeds a 2 × 3 layer. You prune neuron 2 of the first layer. How many weights vanish, and what shapes remain?طبقة خطية 3 × 4 تغذّي طبقة 2 × 3. قلّمت العصبون 2 من الطبقة الأولى. كم وزنًا يختفي، وما الأشكال المتبقية؟
Start with a weight vector small enough to see whole: W = [0.8, -0.05, 0.3, -0.01]. It has four nonzero entries. Give yourself a budget of two. One candidate is W_P = [0.8, 0, 0.3, 0], which has exactly two nonzeros. Is it the best candidate? That depends on the training loss it produces, and the pruning formulation on the slide is precisely the question: among all weight vectors with at most two nonzeros, which one makes the loss smallest?
ابدأ بمتجه أوزان صغير بما يكفي لتراه كاملًا: W = [0.8, -0.05, 0.3, -0.01]. فيه أربعة عناصر غير صفرية. ضع لنفسك ميزانية من عنصرين. أحد المرشحين هو W_P = [0.8, 0, 0.3, 0]، وفيه عنصران غير صفريين بالضبط. هل هو أفضل مرشح؟ يعتمد ذلك على قيمة دالة الخسارة (loss) التي ينتجها في التدريب، وpruning formulation (صياغة الـ pruning) في الشريحة هي هذا السؤال بالضبط: من بين كل متجهات الأوزان التي فيها عنصران غير صفريين على الأكثر، أيّها يجعل الخسارة أصغر ما يمكن؟
The left half of the slide figure is ordinary training: pick W to minimize L, with the whole dense network available. The right half adds one line. The search variable becomes W_P, the pruned weights, and a constraint limits how many of its entries may be nonzero. Everything else, the loss, the data, the architecture, is unchanged. Pruning is training with a budget.
النصف الأيسر من شكل الشريحة هو التدريب العادي: اختر W بحيث تقلّل L، والشبكة الكثيفة كلها متاحة. النصف الأيمن يضيف سطرًا واحدًا. يصبح متغير البحث W_P، أي الأوزان بعد الـ pruning، ويحدّ قيدٌ عدد عناصره التي يُسمح أن تكون غير صفرية. كل ما عدا ذلك، أي الخسارة والبيانات والمعمارية، يبقى دون تغيير. الـ pruning هو تدريب بميزانية.
Every symbol in the formulationكل رمز في الصياغة
- L
- The training objective (the loss), unchanged from ordinary trainingهدف التدريب (دالة الخسارة loss)، دون تغيير عن التدريب العادي
- x
- The input data the loss is evaluated onبيانات الدخل التي تُحسب عليها الخسارة
- W
- The original dense weights the network was trained withالأوزان الكثيفة (dense) الأصلية التي دُرّبت بها الشبكة
- W_P
- The pruned weights, the thing we search overالأوزان بعد الـ pruning، وهي ما نبحث فيه
- ||W_P||_0
- The count of nonzero entries in W_P, the L0 pseudo-normعدد العناصر غير الصفرية في W_P، أي الـ L0 pseudo-norm (شبه المعيار)
- N
- The target number of nonzeros, the budget the pruned model must respectالعدد المستهدف من العناصر غير الصفرية، أي الميزانية التي يجب أن يلتزم بها النموذج بعد الـ pruning
Why the constraint needs heuristicsلماذا يحتاج القيد إلى حلول تقريبية (heuristics)
The L0 norm counts nonzeros, and despite its name it is not a norm at all. A norm must scale with its argument, so that doubling the vector doubles the norm. Doubling our example gives ||2W||_0 = 4 = ||W||_0, not 8. Worse, as a function of the weights it is piecewise constant: nudge any nonzero weight and the count does not change, so the gradient is zero almost everywhere and undefined exactly at zero. Louizos, Welling and Kingma state it plainly: the L0 norm of weights is non-differentiable, so it cannot be incorporated directly as a regularization term. Gradient descent, the only tool that scales to millions of weights, gets no signal from the constraint.
الـ L0 norm يعدّ العناصر غير الصفرية، ورغم اسمه فهو ليس norm أصلًا. يجب أن يتناسب الـ norm مع مدخله، بحيث يتضاعف عند مضاعفة المتجه. لكن مضاعفة مثالنا تعطي ||2W||_0 = 4 = ||W||_0، لا 8. والأسوأ أنه كدالة في الأوزان ثابت على فترات (piecewise constant): حرّك أي وزن غير صفري قليلًا ولن يتغير العدد، لذا فالـ gradient صفر في كل مكان تقريبًا وغير معرّف عند الصفر بالضبط. ويقولها Louizos وWelling وKingma بوضوح: الـ L0 norm للأوزان غير قابل للاشتقاق، لذا لا يمكن إدخاله مباشرة كحد regularization. والـ gradient descent، وهو الأداة الوحيدة التي تتوسع لملايين الأوزان، لا يتلقى أي إشارة من هذا القيد.
The constraint is also combinatorial. Choosing which N of the |W| entries survive is a subset selection. With 16 weights and a budget of 8 there are C(16, 8) = 12,870 masks to compare, each requiring a retrained loss to evaluate. With a million weights and a budget of a hundred thousand the count is astronomically large. Exact search is out of the question.
والقيد أيضًا توافقي (combinatorial). اختيار أي N من بين |W| عنصرًا سيبقى هو مسألة اختيار مجموعة جزئية (subset selection). مع 16 وزنًا وميزانية 8 هناك C(16, 8) = 12,870 من الـ masks (الأقنعة) للمقارنة، وكل منها يتطلب حساب الخسارة بعد إعادة التدريب لتقييمه. ومع مليون وزن وميزانية مئة ألف يصبح العدد ضخمًا بشكل فلكي. البحث الدقيق غير وارد إطلاقًا.
So the field replaces the exact problem by the pipeline of the first concept. A criterion assigns each weight or neuron an importance score, such as its magnitude |w|, and the least important are zeroed; that is a greedy stand-in for the search over masks. A ratio fixes N for each layer; that is the budget. Fine-tuning then re-minimizes L over the surviving entries, which is the only part gradient descent can do. The formulation is exact; everything after it is an approximation, and the quality of the approximation is what the rest of this lecture and the next are about.
لذلك يستبدل المجال المسألة الدقيقة بسلسلة الخطوات في المفهوم الأول. الـ criterion (المعيار) يعطي كل وزن أو عصبون درجة أهمية، مثل مقداره |w|، ويُصفَّر الأقل أهمية؛ وهذا بديل جشع (greedy) للبحث في كل الأقنعة. والـ ratio (النسبة) يحدد N لكل طبقة؛ وهذه هي الميزانية. ثم يعيد الـ fine-tuning تقليل L على العناصر الباقية، وهو الجزء الوحيد الذي يستطيع الـ gradient descent القيام به. الصياغة دقيقة؛ وكل ما بعدها تقريب، وجودة هذا التقريب هي موضوع بقية هذه المحاضرة والمحاضرة التالية.
From N to sparsityمن N إلى الـ sparsity
Worked exampleمثال محلول
AlexNet under Han et al. (2015)AlexNet وفق Han et al. (2015)
Countالعدّ
AlexNet has |W| = 61 M parameters. Han et al. prune it to N = 6.7 M.في AlexNet عدد |W| = 61 M من المعاملات. يقلّمها Han et al. إلى N = 6.7 M.Sparsityالـ sparsity
1 - 6.7 / 61 = 1 - 0.11 = 0.89, so 89% of the weights are zero.1 - 6.7 / 61 = 1 - 0.11 = 0.89، إذن 89% من الأوزان أصفار.
In the tiny example, keeping 2 of 4 entries is 50% sparsity; the mask visual above keeps 8 of 24, which is 67%. The glossary defines the pruning ratio as the percentage of parameters pruned away, and when every zero comes from pruning the two quantities coincide.
في المثال الصغير، إبقاء 2 من 4 عناصر يعني sparsity بنسبة 50%؛ والشكل التوضيحي للقناع أعلاه يُبقي 8 من 24، أي 67%. يعرّف المسرد (glossary) نسبة الـ pruning بأنها النسبة المئوية للمعاملات التي أُزيلت، وحين يكون كل صفر ناتجًا عن الـ pruning تتطابق الكميتان.
Quick checkاختبار سريع
In argmin over W_P of L(x; W_P) subject to ||W_P||_0 <= N, what does N stand for?في الصياغة argmin على W_P للدالة L(x; W_P) بشرط ||W_P||_0 <= N، إلامَ يرمز N؟
Recall
Why can gradient descent not handle the L0 constraint directly, and what replaces it in practice?لماذا لا يستطيع الـ gradient descent التعامل مع قيد L0 مباشرة، وما الذي يحل محله عمليًا؟
Recall
Write the pruning formulation and name each symbol.اكتب صياغة الـ pruning وسمِّ كل رمز.
A newborn's cortical neuron carries about 2,500 synapses. By the age of two to four the figure is near 15,000. An adult settles around 7,000. The brain grows to six times its newborn connection count, then removes more than half of that peak. Growth to a peak, then elimination: the curve on the slide is the shape of train-dense-then-prune, drawn by biology decades before anyone pruned a neural network.
يحمل العصبون القشري لدى المولود نحو 2,500 وصلة (synapse). وبين عمر سنتين وأربع سنوات يقترب الرقم من 15,000. ثم يستقر لدى البالغ عند نحو 7,000. ينمو الدماغ حتى يصل إلى ستة أضعاف عدد وصلاته عند الولادة، ثم يزيل أكثر من نصف تلك القمة. نمو حتى قمة، ثم إزالة: المنحنى في الشريحة هو شكل «درّب الشبكة كثيفة ثم قلّمها»، رسمته البيولوجيا قبل عقود من أن يقلّم أحد شبكة عصبية.
The three numbers on the slideالأرقام الثلاثة في الشريحة
- Newbornالمولود
- about 2,500 synapses per neuronنحو 2,500 وصلة لكل عصبون
- 2 to 4 yearsمن سنتين إلى أربع سنوات
- peak, about 15,000 synapses per neuronالقمة، نحو 15,000 وصلة لكل عصبون
- Adultالبالغ
- about 7,000 synapses per neuronنحو 7,000 وصلة لكل عصبون
Worked exampleمثال محلول
How much the brain overprovisions and removesكم يبني الدماغ من فائض، وكم يزيل
Growthالنمو
15,000 / 2,500 = 6x more synapses per neuron at the peak than at birth.15,000 / 2,500 = 6x وصلات أكثر لكل عصبون عند القمة مقارنة بالولادة.Eliminationالإزالة
(15,000 - 7,000) / 15,000 = 8,000 / 15,000 ≈ 0.53, so about 53% of the peak is pruned away.(15,000 - 7,000) / 15,000 = 8,000 / 15,000 ≈ 0.53، إذن يُزال نحو 53% من القمة.Resultالنتيجة
Adults keep roughly 47% of their peak synapses. Using the slide's illustrative figures, in the vocabulary of the previous concept the brain runs at about 53% sparsity relative to its own dense peak.يحتفظ البالغون بنحو 47% من وصلاتهم عند القمة. وباستخدام أرقام الشريحة التوضيحية، وبمصطلحات المفهوم السابق، يعمل الدماغ بـ sparsity تقارب 53% مقارنة بقمته الكثيفة الخاصة.
This is synaptic pruning, and Han et al. invoke it in the introduction of the paper the slide follows: their method learns the network connectivity in addition to the weights, much as in the mammalian brain, where synapses are created in the first few months of a child's development, followed by gradual pruning of little-used connections, falling to typical adult values. The parallel to the pipeline is exact in shape. Overprovision (train a large dense network), score by use (the criterion), remove the weak connections (prune), and let the remaining ones strengthen (fine-tune).
هذا هو synaptic pruning (التقليم المشبكي)، ويستشهد به Han et al. في مقدمة الورقة التي تتبعها الشريحة: طريقتهم تتعلم بنية اتصال الشبكة إضافة إلى الأوزان، تمامًا كما في دماغ الثدييات، حيث تُنشأ الوصلات في الأشهر الأولى من نمو الطفل، ثم يتبعها تقليم تدريجي للوصلات قليلة الاستخدام، فتنخفض إلى القيم المعتادة لدى البالغين. والتوازي مع سلسلة الخطوات دقيق في شكله. بناء فائض (درّب شبكة كثيفة كبيرة)، ثم تقييم بحسب الاستخدام (المعيار)، ثم إزالة الوصلات الضعيفة (الـ pruning)، ثم ترك الوصلات الباقية تتقوّى (fine-tune).
Quick checkاختبار سريع
Using slide 6's figures, roughly what fraction of the peak synapses per neuron is eliminated by adulthood?باستخدام أرقام الشريحة 6، ما الكسر التقريبي من وصلات القمة لكل عصبون الذي يُزال بحلول البلوغ؟
Recall
Give the synapses per neuron at birth, at the peak and in adulthood from slide 6, and the fraction eliminated between peak and adult.اذكر عدد الوصلات لكل عصبون عند الولادة وعند القمة وفي البلوغ بحسب الشريحة 6، والنسبة التي تُزال بين القمة والبلوغ.
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- Pruning is a pipeline: formulate, choose granularity, choose criterion, choose ratio, fine-tune. This lecture covers the first three, Lecture 04-2 the last two.الـ pruning سلسلة خطوات: الصياغة، ثم اختيار الـ granularity، ثم اختيار المعيار (criterion)، ثم اختيار النسبة (ratio)، ثم الـ fine-tuning. تغطي هذه المحاضرة الثلاث الأولى، وتغطي المحاضرة 04-2 الأخيرتين.
- In 45 nm at 0.9 V a 32-bit DRAM access costs 640 pJ against 3.1 pJ for an int multiply and 0.1 pJ for an int add: about 200x and 6400x.في تقنية 45 nm وعند 0.9 V يكلّف الوصول إلى DRAM بعرض 32-bit مقدار 640 pJ، مقابل 3.1 pJ لضرب أعداد صحيحة و0.1 pJ لجمع أعداد صحيحة: أي نحو 200x و6400x.
- Data movement drives memory references, memory references drive energy, so fewer weights means fewer fetches and, once the model fits SRAM, 128x cheaper accesses.حركة البيانات تولّد مرات الوصول إلى الذاكرة، ومرات الوصول تولّد استهلاك الطاقة، لذا فإن أوزانًا أقل تعني عمليات جلب أقل، وما إن يتسع النموذج داخل SRAM يصبح كل وصول أرخص بـ 128x.
- A 1-billion-connection network at 20 Hz spends 12.8 W on DRAM fetches alone.شبكة بمليار وصلة تعمل بتردد 20 Hz تستهلك 12.8 W على جلب البيانات من DRAM وحده.
- Synapse pruning zeroes single weights and leaves neurons in place; neuron pruning deletes a node with all incident edges, a row here and a column in the next layer.pruning الوصلات يصفّر أوزانًا منفردة ويُبقي العصبونات في مكانها؛ أما pruning العصبونات فيحذف العقدة مع كل الحواف المتصلة بها، أي صفًا في هذه الطبقة وعمودًا في الطبقة التالية.
- Pruning is argmin over W_P of L(x; W_P) subject to ||W_P||_0 <= N; the slide bullet's strict less-than is a typo inherited from the MIT deck.الـ pruning هو argmin على W_P للدالة L(x; W_P) بشرط ||W_P||_0 <= N؛ وعلامة «أصغر تمامًا» في نقطة الشريحة خطأ مطبعي موروث من عرض MIT.
- ||.||_0 counts nonzeros, is not a true norm and has no useful gradient, so practical pruning uses importance criteria and per-layer ratios.الرمز ||.||_0 يعدّ القيم غير الصفرية، وليس norm حقيقيًا، وليس له gradient مفيد، لذا يعتمد الـ pruning العملي على معايير الأهمية (importance criteria) وعلى نسب مختلفة لكل طبقة.
- Sparsity equals 1 - N/|W|; AlexNet at 61 M to 6.7 M parameters is 89 percent sparsity, 9x fewer weights.الـ sparsity تساوي 1 - N/|W|؛ وتقليص AlexNet من 61 M إلى 6.7 M معامل يعني sparsity بنسبة 89 بالمئة، أي أوزانًا أقل بـ 9x.
- The brain grows from about 2,500 to 15,000 synapses per neuron and prunes to about 7,000: overprovision, then remove the little-used.ينمو الدماغ من نحو 2,500 إلى 15,000 وصلة (synapse) لكل عصبون، ثم يقلّمها إلى نحو 7,000: يبني فائضًا أولًا، ثم يزيل الوصلات قليلة الاستخدام.
Sourcesالمصادر
- Learning both Weights and Connections for Efficient Neural NetworksPaperNeurIPS 2015, Han, Pool, Tran and DallyEnergy table (0.1 to 640 pJ, relative 1 to 6400), the 12.8 W example, Figure 3 synapses and neurons, 9x AlexNet, the brain analogy.جدول الطاقة (من 0.1 إلى 640 pJ، ونسبيًا من 1 إلى 6400)، ومثال 12.8 W، والشكل 3 عن الوصلات والعصبونات، وتصغير AlexNet بـ 9x، وتشبيه الدماغ.(opens in a new tab)(يفتح في تبويب جديد)
- 1.1 Computing's energy problem (and what we can do about it)PaperIEEE ISSCC 2014, M. HorowitzOrigin of the 45 nm, 0.9 V energy per operation figures.مصدر أرقام الطاقة لكل عملية بتقنية 45 nm وجهد 0.9 V.(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 3: Pruning and Sparsity Part IDocsMIT HAN Lab, Song HanUpstream deck with the same outline, the same strict-inequality typo and the same brain slide.العرض الأصلي الذي يحمل المخطط العام نفسه، وخطأ المتباينة الصارمة نفسه، وشريحة الدماغ نفسها.(opens in a new tab)(يفتح في تبويب جديد)
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman CodingPaperICLR 2016, Han, Mao and DallyAlexNet 240 MB to 6.9 MB, VGG-16 552 MB to 11.3 MB, fitting in on-chip SRAM; 3x to 7x less energy per pruned FC layer on CPU, GPU and mobile GPU.AlexNet من 240 MB إلى 6.9 MB، وVGG-16 من 552 MB إلى 11.3 MB، بما يتسع في ذاكرة SRAM داخل الشريحة؛ وطاقة أقل بين 3x و7x لكل طبقة FC بعد الـ pruning على CPU وGPU وGPU المحمول.(opens in a new tab)(يفتح في تبويب جديد)
- Efficient Processing of Deep Neural Networks: A Tutorial and SurveyPaperProceedings of the IEEE 2017, Sze, Chen, Yang and EmerDRAM accesses cost several orders of magnitude more energy than computation; two orders more than small on-chip memory.الوصول إلى DRAM يكلّف طاقة أكبر من الحساب بعدة رتب عشرية، وأكبر برتبتين عشريتين من ذاكرة صغيرة داخل الشريحة.(opens in a new tab)(يفتح في تبويب جديد)
- Learning Sparse Neural Networks through L0 RegularizationPaperICLR 2018, Louizos, Welling and KingmaThe L0 norm of weights is non-differentiable and cannot be used directly as a regularizer.الـ L0 norm للأوزان غير قابل للاشتقاق، ولا يمكن استخدامه مباشرة كحد regularization.(opens in a new tab)(يفتح في تبويب جديد)
- What is the State of Neural Network Pruning?PaperMLSys 2020, Blalock, Gonzalez Ortiz, Frankle and GuttagSurvey of 81 pruning papers; lack of standardized benchmarks across pruning choices.مسح لـ 81 ورقة عن الـ pruning؛ وغياب معايير قياس (benchmarks) موحدة عبر خيارات الـ pruning المختلفة.(opens in a new tab)(يفتح في تبويب جديد)
- Synaptic density in human frontal cortex: developmental changes and effects of agingPaperBrain Research 163, 1979, P. R. HuttenlocherPeak at one to two years about 50 percent above the adult mean; decline from two to sixteen years.قمة بين سنة وسنتين أعلى بنحو 50 بالمئة من متوسط البالغين؛ ثم انخفاض من عمر سنتين إلى ستة عشر عامًا.(opens in a new tab)(يفتح في تبويب جديد)
- Regional differences in synaptogenesis in human cerebral cortexPaperJournal of Comparative Neurology 387, 1997, Huttenlocher and DabholkarPrefrontal peak after fifteen months; elimination into mid-adolescence.قمة القشرة الجبهية الأمامية بعد خمسة عشر شهرًا؛ واستمرار الإزالة حتى منتصف المراهقة.(opens in a new tab)(يفتح في تبويب جديد)
- Do we have brain to spare?PaperNeurology 64(12), 2005, D. A. DrachmanAbout 20 billion neocortical neurons averaging 7,000 synapses each; the slide's 2004 is the page number.نحو 20 مليار عصبون في القشرة الحديثة (neocortex) بمتوسط 7,000 وصلة لكل منها؛ والرقم 2004 في الشريحة هو رقم الصفحة.(opens in a new tab)(يفتح في تبويب جديد)
- Peter Huttenlocher (1931 to 2013)ArticleNature 502, 2013, C. A. WalshObituary cited on slide 6; synapse formation and pruning in child development.نعي مُستشهد به في الشريحة 6؛ عن تكوّن الوصلات وتقليمها في نمو الطفل.(opens in a new tab)(يفتح في تبويب جديد)
Part 02: Train, prune, fine-tune: what pruning achievesتدريب ثم تقليم ثم ضبط دقيق: ماذا يحقق التقليم
The Han et al. pipeline of training connectivity, pruning and retraining, how iterative pruning pushes the pruning ratio past 90 percent without accuracy loss, the resulting parameter and MAC reductions, and hardware support for sparsity.خط عمل Han et al.: تدريب الاتصالات ثم التقليم ثم إعادة التدريب، وكيف يدفع التقليم التكراري نسبة التقليم إلى ما يتجاوز 90 بالمئة دون فقدان في الدقة، والتخفيضات الناتجة في المعاملات وعمليات MAC، ودعم العتاد للتناثر.
6 concepts6 مفاهيم, ، slides 7-13الشرائح 7-13
Why this part mattersلماذا يهمّ هذا الجزء
Part 01 ended with the reason to prune: a 32-bit DRAM access costs about 640 pJ, roughly 200 times a multiply, so a model that fits in on-chip memory wins on energy before it wins on anything else. This part is where the lecture proves that pruning actually delivers: AlexNet loses 9x of its parameters and VGG-16 loses 12x with no accuracy loss at all.
The proof comes as one chart built up over four slides, a five-row reduction table, a set of image captions and a slide of hardware. Along the way it exposes the two traps that catch most first attempts: pruning without retraining, which throws away several percent of accuracy for nothing, and assuming that fewer parameters means faster inference, which is only true when the hardware knows how to skip zeros. The pipeline chart and the reduction table are classic exam material, and the hardware slide is the bridge to the granularity discussion in Part 03.
انتهى الجزء 01 بسبب التقليم: الوصول إلى ذاكرة DRAM لقراءة كلمة بطول 32-bit يكلّف نحو 640 pJ، أي ما يقارب 200 ضعف عملية ضرب واحدة، لذلك فالنموذج الذي يتسع في الذاكرة الموجودة على الشريحة (on-chip) يكسب في الطاقة قبل أن يكسب في أي شيء آخر. في هذا الجزء تثبت المحاضرة أن التقليم يحقق ذلك فعلاً: يفقد AlexNet ما مقداره 9x من معاملاته، ويفقد VGG-16 ما مقداره 12x، دون أي فقدان في الدقة على الإطلاق.
يأتي الإثبات في صورة مخطط واحد يُبنى تدريجياً عبر أربع شرائح، وجدول تخفيض من خمسة صفوف، ومجموعة من الأوصاف النصية للصور (captions)، وشريحة عن العتاد. وفي الطريق يكشف الفخين اللذين يقع فيهما معظم من يجرّب لأول مرة: التقليم دون إعادة تدريب، وهو ما يضيّع عدة نقاط مئوية من الدقة بلا مقابل، وافتراض أن قلة المعاملات تعني استدلالاً أسرع، وهذا لا يصح إلا إذا كان العتاد يعرف كيف يتخطى الأصفار. مخطط المسار وجدول التخفيض مادة امتحانية كلاسيكية، وشريحة العتاد هي الجسر إلى نقاش الدقة الحبيبية (granularity) في الجزء 03.
By the end you canفي نهاية هذا الجزء ستستطيع
- Explain the train, prune, retrain pipeline and why retraining is the step the paper calls critical.تشرح مسار التدريب ثم التقليم ثم إعادة التدريب، ولماذا تصف الورقة إعادة التدريب بأنها الخطوة الحاسمة.
- Read accuracy loss and reduction factor off the pruning-ratio chart for one-shot, retrained and iterative pruning.تقرأ فقدان الدقة ومعامل التخفيض من مخطط نسبة التقليم (pruning ratio) لكل من التقليم دفعة واحدة، والتقليم مع إعادة التدريب، والتقليم التكراري.
- Explain from layer tables why parameter reduction and MAC reduction differ across AlexNet, VGG-16, GoogleNet, ResNet-50 and SqueezeNet.تشرح من جداول الطبقات لماذا يختلف تخفيض المعاملات عن تخفيض عمليات MAC في AlexNet وVGG-16 وGoogleNet وResNet-50 وSqueezeNet.
- State what hardware needs, a 2:4 pattern or a sparse engine, before sparsity turns into speed.تحدد ما يحتاجه العتاد، نمط 2:4 أو محركاً مخصصاً للمصفوفات المتفرقة، قبل أن تتحول الندرة (sparsity) إلى سرعة.
Take AlexNet as Han, Pool, Tran and Dally trained it for their NeurIPS 2015 paper: 57.2% top-1 and 80.3% top-5 on ImageNet. Its first fully connected layer alone holds 38 million weights, and if you histogram them you get a narrow bell centered on zero, almost all of it inside [-0.015, 0.015] by the paper's own account. Now pick a threshold that removes the smallest half of every layer. Nothing happens to accuracy. Remove three quarters, and top-5 accuracy falls by about 2.2%. Remove four fifths, and it falls by about 4%. That single experiment is the whole of slides 7 and 8.
خذ AlexNet كما درّبه Han وPool وTran وDally في ورقتهم في NeurIPS 2015: دقة top-1 قدرها 57.2% وtop-5 قدرها 80.3% على ImageNet. طبقته الأولى المتصلة بالكامل (fully connected) وحدها تحمل 38 million وزن، وإذا رسمت مدرجها التكراري (histogram) حصلت على جرس ضيق متمركز عند الصفر، يقع معظمه داخل [-0.015, 0.015] بحسب الورقة نفسها. الآن اختر عتبة تحذف النصف الأصغر من كل طبقة. لا يحدث شيء للدقة. احذف ثلاثة أرباع الأوزان، فتنخفض دقة top-5 بنحو 2.2%. احذف أربعة أخماسها، فتنخفض بنحو 4%. هذه التجربة الواحدة هي كل محتوى الشريحتين 7 و8.
The rule behind it is a two-step recipe. Step one is ordinary training, but Han reads it differently: the dense network is not trained to learn final weights, it is trained to learn which connections are important. Step two removes every weight whose magnitude falls below a threshold, which the paper sets as a quality parameter times the standard deviation of that layer's weights. A dense layer becomes a sparse layer. This is Pruning at its simplest, Synapse pruning in the vocabulary of Part 01, and it is the plainest form of Magnitude-based pruning: importance is |w| and nothing else. Once connections are gone, some neurons are left with no surviving input or no surviving output. Those neurons contribute nothing and are removed too, so Neuron pruning falls out of synapse pruning for free.
القاعدة وراء ذلك وصفة من خطوتين. الخطوة الأولى تدريب عادي، لكن Han يقرؤه بطريقة مختلفة: الشبكة الكثيفة لا تُدرَّب لتتعلم أوزانها النهائية، بل لتتعلم أي الوصلات مهمة. الخطوة الثانية تحذف كل وزن تقل قيمته المطلقة عن threshold (عتبة)، وتحددها الورقة بأنها معامل جودة مضروب في الانحراف المعياري لأوزان تلك الطبقة. هكذا تتحول الطبقة الكثيفة إلى طبقة متفرقة (sparse). هذا هو pruning في أبسط صوره، وهو Synapse pruning بمصطلحات الجزء 01، وأوضح أشكال Magnitude-based pruning: الأهمية هي |w| ولا شيء غيرها. وبعد حذف الوصلات تبقى بعض العصبونات بلا أي مدخل باقٍ أو بلا أي مخرج باقٍ. هذه العصبونات لا تساهم بشيء فتُحذف هي أيضاً، فيأتي Neuron pruning نتيجة مجانية لتقليم الوصلات.
The right-hand inset of slide 8 shows exactly that gap: the same bell with its center cut out, a hole of width 2t around zero, and nothing else changed. The paper's discussion of its Figure 7 describes the distribution as "centered around zero with tails dropping off quickly" before pruning, then "the center of the distribution" removed. The weights that survive have not moved. They will move in the next concept, and that movement is what retraining does.
الرسم المصغر على يمين الشريحة 8 يُظهر تلك الفجوة بالضبط: الجرس نفسه وقد قُطع مركزه، أي ثقب عرضه 2t حول الصفر، ولم يتغير أي شيء آخر. تصف الورقة في نقاشها لشكلها 7 التوزيع قبل التقليم بأنه «متمركز حول الصفر وأطرافه تهبط بسرعة»، ثم بأن «مركز التوزيع» قد أُزيل. الأوزان الباقية لم تتحرك. ستتحرك في المفهوم التالي، وهذه الحركة هي ما تفعله إعادة التدريب.
Reading the prune-only curveقراءة منحنى التقليم وحده
The chart on slide 8 plots top-5 accuracy loss against the Pruning ratio, the fraction of parameters pruned away, from 40% to 100% on the x axis and from +0.5% to -4.5% on the y axis. The dashed purple curve is what happens with no retraining. It sits at zero up to 50%, which the paper calls a "free lunch of reducing 2x the connections without losing accuracy even without retraining". It reaches about -1% at 67%, about -2.2% at 75%, about -4% at 80%, and leaves the chart just past 82%. Without retraining, the paper says, accuracy "begins dropping much sooner", once only a third of the connections remain.
يرسم مخطط الشريحة 8 فقدان دقة top-5 مقابل Pruning ratio (نسبة التقليم)، أي نسبة المعاملات المحذوفة، من 40% إلى 100% على المحور الأفقي ومن +0.5% إلى -4.5% على المحور الرأسي. المنحنى البنفسجي المتقطع هو ما يحدث دون إعادة تدريب. يبقى عند الصفر حتى 50%، وهو ما تسميه الورقة «وجبة مجانية تخفض الوصلات 2x دون فقدان في الدقة حتى بلا إعادة تدريب». ثم يصل إلى نحو -1% عند 67%، ونحو -2.2% عند 75%، ونحو -4% عند 80%، ويخرج من المخطط بعد 82% بقليل. وتقول الورقة إنه بدون إعادة تدريب «تبدأ الدقة في الانخفاض أبكر بكثير»، أي بمجرد أن يبقى ثلث الوصلات فقط.
The x axis counts what is removed, so you have to translate it into a reduction factor before you can compare with a table that reports "9x". Keeping a fraction 1 - r of the weights makes the model 1 / (1 - r) times smaller.
المحور الأفقي يعدّ ما حُذف، لذلك عليك أن تحوّله إلى reduction factor (معامل التخفيض) قبل أن تقارن بجدول يذكر «9x». الاحتفاظ بنسبة 1 - r من الأوزان يجعل النموذج أصغر بمقدار 1 / (1 - r) مرة.
Anchor points to memorizeنقاط مرجعية للحفظ
- 50% prunedتقليم 50%
- 2x2x
- 67% prunedتقليم 67%
- 3x3x
- 75% prunedتقليم 75%
- 4x4x
- 80% prunedتقليم 80%
- 5x5x
- 87.5% prunedتقليم 87.5%
- 8x8x
- 88.9% prunedتقليم 88.9%
- 9x9x
- 90% prunedتقليم 90%
- 10x10x
Where the threshold comes fromمن أين تأتي العتبة
Because the criterion is magnitude, the threshold and the pruning ratio are two views of the same cut. If the weights of a layer are roughly Gaussian with standard deviation sigma, removing a fraction r means removing everything inside ±t where the Gaussian mass inside ±t equals r. That is an inverse normal lookup: t = sigma × z with z = 0.674 for 50%, z = 1.282 for 80% and z = 1.645 for 90%.
بما أن المعيار هو القيمة المطلقة، فالعتبة ونسبة التقليم وجهان للقطع نفسه. إذا كانت أوزان الطبقة قريبة من التوزيع الطبيعي (Gaussian) بانحراف معياري sigma، فإن حذف نسبة r يعني حذف كل ما يقع داخل ±t بحيث تساوي كتلة التوزيع داخل ±t القيمة r. هذا بحث في معكوس التوزيع الطبيعي: t = sigma × z حيث z = 0.674 لنسبة 50%، وz = 1.282 لنسبة 80%، وz = 1.645 لنسبة 90%.
Worked exampleمثال محلول
Threshold for a Gaussian layer with sigma = 0.03العتبة لطبقة أوزانها طبيعية التوزيع بانحراف sigma = 0.03
Half the weightsنصف الأوزان
t = 0.03 × 0.674 = 0.020. Everything with |w| < 0.020 goes. The model is 2x smaller and, on AlexNet, loses nothing.t = 0.03 × 0.674 = 0.020. يُحذف كل وزن يحقق |w| < 0.020. النموذج أصغر بـ 2x، وفي AlexNet لا يخسر شيئاً.Four fifthsأربعة أخماس
t = 0.03 × 1.282 = 0.038. This is the cut in the visual above: 5x smaller, about -4% top-5 without retraining.t = 0.03 × 1.282 = 0.038. هذا هو القطع في الرسم أعلاه: أصغر بـ 5x، ونحو -4% في top-5 دون إعادة تدريب.Nine tenthsتسعة أعشار
t = 0.03 × 1.645 = 0.049. 10x smaller. Prune-only is off the chart here, one-shot retraining loses about 1.7%, and only the iterative recipe of the third concept holds zero loss.t = 0.03 × 1.645 = 0.049. أصغر بـ 10x. منحنى التقليم وحده خارج المخطط هنا، وإعادة التدريب لمرة واحدة تخسر نحو 1.7%، والوصفة التكرارية في المفهوم الثالث وحدها تحافظ على فقدان صفري.The threshold scales with sigma, the ratio does notالعتبة تتغير مع sigma، أما النسبة فلا
Han sets t per layer as a quality parameter times that layer's standard deviation, so a layer with wider weights gets a proportionally wider cut and the same share removed.يحدد Han العتبة t لكل طبقة على حدة بأنها معامل جودة مضروب في الانحراف المعياري لتلك الطبقة، فالطبقة ذات الأوزان الأوسع تحصل على قطع أوسع بالتناسب، وتُحذف منها الحصة نفسها.
Recall
What does the x axis of the pruning chart measure, and how do you turn 80 percent into a reduction factor?ماذا يقيس المحور الأفقي في مخطط التقليم، وكيف تحوّل 80 بالمئة إلى معامل تخفيض؟
Return to the AlexNet that lost 4% at 80% pruned. Keep the mask fixed, so the removed weights stay at zero, and train the survivors again with a learning rate one hundredth of the original. The loss comes back to 0.0%. That run took 173 hours on a Titan X against 75 hours for the original training, which is why the paper says pruning is "not used when iteratively prototyping the model, but rather used for model reduction when the model is ready for deployment".
عُد إلى AlexNet الذي خسر 4% عند تقليم 80%. ثبّت mask (القناع) بحيث تبقى الأوزان المحذوفة عند الصفر، ثم درّب الأوزان الباقية من جديد بمعدل تعلم يساوي جزءاً من مئة من المعدل الأصلي. يعود الفقدان إلى 0.0%. استغرقت تلك الجولة 173 hours على بطاقة Titan X مقابل 75 hours للتدريب الأصلي، ولهذا تقول الورقة إن التقليم «لا يُستخدم أثناء بناء النموذج وتجريبه بشكل متكرر، بل يُستخدم لتصغير النموذج عندما يكون جاهزاً للنشر».
This is step three of the pipeline, and the paper is blunt about its status: retraining "learns the final weights for the remaining sparse connections. This step is critical. If the pruned network is used without retraining, accuracy is significantly impacted." The lecture calls it Fine-tuning. The green curve on slide 9 shows what it buys. It stays at zero, or a hair above, all the way to 80%, then bends: about -0.25% at 84%, about -0.9% at 88%, about -1.7% at 90%, about -4% at 93%. The paper summarizes the same curve as "with retraining we are able to reduce connections by 9x".
هذه هي الخطوة الثالثة في المسار، والورقة صريحة في وصف مكانتها: إعادة التدريب «تتعلم الأوزان النهائية للوصلات المتفرقة الباقية. هذه الخطوة حاسمة. إذا استُخدمت الشبكة المقلّمة دون إعادة تدريب، تتأثر الدقة بشكل كبير». وتسميها المحاضرة Fine-tuning (الضبط الدقيق). المنحنى الأخضر في الشريحة 9 يُظهر ما تشتريه. يبقى عند الصفر، أو فوقه بشعرة، حتى 80%، ثم ينحني: نحو -0.25% عند 84%، ونحو -0.9% عند 88%، ونحو -1.7% عند 90%، ونحو -4% عند 93%. وتلخص الورقة المنحنى نفسه بقولها «مع إعادة التدريب نستطيع تقليل الوصلات بمقدار 9x».
Two of the green points sit slightly above zero. The authors do not treat that as noise: "We believe this accuracy improvement is due to pruning finding the right capacity of the network and hence reducing overfitting." In other words, Pruning behaves like a regularizer, and an over-parameterized network can lose most of its weights and generalize a little better for it.
نقطتان من النقاط الخضراء تقعان فوق الصفر بقليل. لا يعدّ المؤلفون ذلك ضجيجاً: «نعتقد أن هذا التحسن في الدقة سببه أن التقليم يجد السعة المناسبة للشبكة، وبالتالي يقلل الإفراط في التخصيص (overfitting)». بعبارة أخرى، يتصرف pruning كأداة تنظيم (regularizer)، ويمكن لشبكة ذات معاملات زائدة أن تفقد معظم أوزانها وتعمّم أفضل قليلاً بسبب ذلك.
What retraining does to the weightsماذا تفعل إعادة التدريب بالأوزان
The third inset on slide 9 is the most informative picture in this part. After pruning, the histogram was a bell with a hole. After retraining it is two smooth lobes, one on each side of zero, and the whole distribution is wider. The paper's text on Figure 7 states the numbers: the original weights lived inside [-0.015, 0.015]; after retraining "the parameters form a bimodal distribution and become more spread across the x-axis, between [-0.025, 0.025]". The survivors have grown in magnitude to take over the work of the connections that were removed. Nothing has been restored; the mask still holds the pruned weights at zero.
الرسم المصغر الثالث في الشريحة 9 هو أغنى صورة في هذا الجزء. بعد التقليم كان المدرج التكراري جرساً فيه ثقب. وبعد إعادة التدريب أصبح فصّين ناعمين، واحداً على كل جانب من الصفر، والتوزيع كله أعرض. نص الورقة عن الشكل 7 يذكر الأرقام: الأوزان الأصلية كانت تعيش داخل [-0.015, 0.015]؛ وبعد إعادة التدريب «تشكل المعاملات توزيعاً ثنائي القمة (bimodal) وتصبح أكثر انتشاراً على المحور الأفقي، بين [-0.025, 0.025]». الأوزان الباقية كبرت في قيمتها المطلقة لتتولى عمل الوصلات التي حُذفت. لم يُستعَد أي شيء؛ القناع ما زال يُبقي الأوزان المقلّمة عند الصفر.
Three rules the paper gives for retrainingثلاث قواعد تعطيها الورقة لإعادة التدريب
- Keep the surviving weights; do not reinitialize them. The paper argues that networks contain "fragile co-adapted features" that gradient descent finds when the network is first trained but cannot find again from scratch on a sparse layout.احتفظ بالأوزان الباقية؛ لا تُعِد تهيئتها. تحتج الورقة بأن الشبكات تحتوي على «سمات هشة متكيفة فيما بينها» (fragile co-adapted features) يجدها الانحدار التدرجي (gradient descent) عند تدريب الشبكة أول مرة، لكنه لا يستطيع إيجادها مجدداً من الصفر على بنية متفرقة.
- Shrink dropout. Pruning has already removed capacity, so the retraining dropout D_r is scaled from the original D_o by the square root of the fraction of connections kept.قلّل الـ dropout. التقليم أزال جزءاً من السعة أصلاً، لذلك يُحسب dropout إعادة التدريب D_r من القيمة الأصلية D_o بضربها في الجذر التربيعي لنسبة الوصلات المحتفَظ بها.
- Choose the regularizer for the stage. L1 pushes more weights toward zero and gives better accuracy straight after pruning, but L2 gives better accuracy once the survivors are retrained, so the paper uses L2 for the curves on these slides.اختر أداة التنظيم المناسبة للمرحلة. L1 يدفع أوزاناً أكثر نحو الصفر ويعطي دقة أفضل مباشرة بعد التقليم، لكن L2 يعطي دقة أفضل بعد إعادة تدريب الأوزان الباقية، لذلك تستخدم الورقة L2 في منحنيات هذه الشرائح.
Worked exampleمثال محلول
Dropout for a fully connected layer kept at 9 percentقيمة dropout لطبقة متصلة بالكامل بقي منها 9 بالمئة
Fraction of connections keptنسبة الوصلات المحتفَظ بها
AlexNet's fc6 keeps 9% of its weights, so C_ir / C_io = 0.09.طبقة fc6 في AlexNet تحتفظ بـ 9% من أوزانها، إذن C_ir / C_io = 0.09.Scale the original dropoutاضرب قيمة dropout الأصلية في المعامل
With D_o = 0.5: D_r = 0.5 × sqrt(0.09) = 0.5 × 0.3 = 0.15.مع D_o = 0.5: D_r = 0.5 × sqrt(0.09) = 0.5 × 0.3 = 0.15.Resultالنتيجة
Retrain with dropout 0.15, not 0.5. A sparse layer already regularizes itself.أعد التدريب بـ dropout قدره 0.15، لا 0.5. الطبقة المتفرقة تنظّم نفسها بنفسها أصلاً.
One more observation from the paper's sensitivity study (Figure 6) matters for your own experiments: convolutional layers are more sensitive to pruning than fully connected ones, and the first convolutional layer is the most sensitive of all, because its input has only three channels and there is little redundancy to remove. That is why the per-layer keep rates in the next concepts are so uneven.
ملاحظة أخرى من دراسة الحساسية في الورقة (الشكل 6) تهمك في تجاربك الخاصة: الطبقات الالتفافية أكثر حساسية للتقليم من الطبقات المتصلة بالكامل، والطبقة الالتفافية الأولى هي الأكثر حساسية على الإطلاق، لأن مدخلها له ثلاث قنوات فقط ولا يوجد فيه إلا القليل من التكرار القابل للحذف. ولهذا السبب تتفاوت نسب الاحتفاظ لكل طبقة في المفاهيم التالية تفاوتاً كبيراً.
Quick checkاختبار سريع
In Han's three-step pipeline, which step does the paper call critical because skipping it makes accuracy drop significantly?في مسار Han ذي الخطوات الثلاث، أي خطوة تصفها الورقة بأنها حاسمة لأن تخطيها يجعل الدقة تنخفض بشكل كبير؟
Recall
State the three steps of Han's pipeline and say which one the paper calls critical.اذكر الخطوات الثلاث في مسار Han، وحدد أيها تصفه الورقة بأنه حاسم.
Start from the retrained network at 80% pruned, the last green point still on the zero line, a 5x model with no loss. Now prune it again, using the retrained magnitudes, and fine-tune again. The paper describes what happens: "The leftmost dot on this curve corresponds to the point on the green line at 80% (5x pruning) pruned to 8x. There's no accuracy loss at 9x. Not until 10x does the accuracy begin to drop sharply." The red curve on slide 10 is that experiment: flat through 90%, about -0.5% at 92%, -1% at 93%, -2% at 94%, and about -4% between 95% and 96%.
ابدأ من الشبكة المعاد تدريبها عند تقليم 80%، وهي آخر نقطة خضراء ما زالت على خط الصفر، نموذج أصغر بـ 5x بلا أي فقدان. الآن قلّمها مرة أخرى باستخدام القيم المطلقة بعد إعادة التدريب، ثم طبّق fine-tune مرة أخرى. تصف الورقة ما يحدث: «النقطة الأولى من اليسار على هذا المنحنى تقابل النقطة على الخط الأخضر عند 80% (تقليم 5x) بعد تقليمها إلى 8x. لا يوجد فقدان في الدقة عند 9x. ولا تبدأ الدقة في الانخفاض الحاد إلا عند 10x». المنحنى الأحمر في الشريحة 10 هو تلك التجربة: مستوٍ حتى 90%، ثم نحو -0.5% عند 92%، و-1% عند 93%، و-2% عند 94%، ونحو -4% بين 95% و96%.
This is Iterative pruning, and the paper states the rule and the payoff in one breath: "Pruning followed by a retraining is one iteration, after many such iterations the minimum number connections could be found. Without loss of accuracy, this method can boost pruning rate from 5x to 9x on AlexNet compared with single-step aggressive pruning." Each iteration is a greedy search. VGG-16 used five rounds; ResNet-50 in Han's thesis used three. The left side of slide 10 draws the loop: train connectivity, prune connections, train weights, and an arrow from train weights back to prune.
هذا هو Iterative pruning (التقليم التكراري)، والورقة تذكر القاعدة والمكسب في نَفَس واحد: «التقليم متبوعاً بإعادة تدريب يمثل تكراراً واحداً، وبعد تكرارات كثيرة من هذا النوع يمكن إيجاد أقل عدد من الوصلات. ودون فقدان في الدقة، يمكن لهذه الطريقة أن ترفع معدل التقليم من 5x إلى 9x على AlexNet مقارنة بالتقليم الحاد بخطوة واحدة». كل تكرار هو بحث جشع (greedy search). استخدم VGG-16 خمس جولات؛ واستخدم ResNet-50 في أطروحة Han ثلاث جولات. الجانب الأيسر من الشريحة 10 يرسم الحلقة: تدريب بنية الوصلات، ثم تقليم الوصلات، ثم تدريب الأوزان، مع سهم يعود من تدريب الأوزان إلى التقليم.
Learn which connections matter.
تعلّم أي الاتصالات مهمة.
Cut a fraction of the survivors.
اقطع جزءًا من الأوزان الباقية.
Survivors redistribute, then loop back to prune.
تعيد الأوزان الباقية توزيع نفسها، ثم نعود إلى التقليم.
Why several small cuts beat one big cutلماذا تتفوق عدة قطعات صغيرة على قطعة واحدة كبيرة
A single cut to 90% judges every weight by the magnitude it had in the dense network. But the previous concept showed that retraining changes those magnitudes: the survivors grow and the distribution becomes bimodal. Weights that looked expendable in the dense network may become load-bearing after the first round, and weights that looked important may shrink once their neighbours take over. Iterating lets each cut use the freshest evidence. Frankle and Carbin reach the same conclusion in a different setting: iterative pruning over n rounds, each removing p^(1/n) of what remains, "finds winning tickets that match the accuracy of the original network at smaller sizes than does one-shot pruning". The price, which they also state, is that repeated retraining is expensive.
القطع الواحد إلى 90% يحكم على كل وزن بالقيمة المطلقة التي كانت له في الشبكة الكثيفة. لكن المفهوم السابق بيّن أن إعادة التدريب تغيّر هذه القيم: الأوزان الباقية تكبر والتوزيع يصبح ثنائي القمة. أوزان بدت قابلة للاستغناء في الشبكة الكثيفة قد تصبح حاملة للحمل بعد الجولة الأولى، وأوزان بدت مهمة قد تصغر بعد أن تتولى جاراتها عملها. التكرار يتيح لكل قطع أن يعتمد على أحدث دليل. ويصل Frankle وCarbin إلى الاستنتاج نفسه في سياق مختلف: التقليم التكراري على n جولة، تحذف كل منها p^(1/n) مما تبقى، «يجد تذاكر رابحة (winning tickets) تطابق دقة الشبكة الأصلية بأحجام أصغر مما يجده التقليم دفعة واحدة». والثمن، الذي يذكرانه أيضاً، أن إعادة التدريب المتكررة مكلفة.
Worked exampleمثال محلول
Compounding a pruning scheduleتراكم جدول التقليم عبر الجولات
Equal halvesأنصاف متساوية
Three rounds that each remove half of the survivors leave 0.5 × 0.5 × 0.5 = 12.5%, an 8x model. Four rounds leave 6.25%, which is 16x.ثلاث جولات تحذف كل منها نصف الأوزان الباقية تترك 0.5 × 0.5 × 0.5 = 12.5%، أي نموذجاً أصغر بـ 8x. وأربع جولات تترك 6.25%، أي 16x.Hitting a target in equal roundsالوصول إلى هدف بجولات متساوية
To reach 90% overall in three equal rounds, each round must keep 0.1^(1/3) = 0.464 of what remains, so it removes 53.6% of the current survivors.للوصول إلى 90% إجمالاً في ثلاث جولات متساوية، يجب أن تحتفظ كل جولة بـ 0.1^(1/3) = 0.464 مما تبقى، أي أنها تحذف 53.6% من الأوزان الباقية حالياً.Han's actual pathالمسار الفعلي عند Han
80% in one round (5x), then re-pruned to 8x, then 9x, all at zero loss. The drop only starts past 10x.80% في جولة واحدة (5x)، ثم إعادة تقليم إلى 8x، ثم 9x، وكل ذلك بلا فقدان. ولا يبدأ الهبوط إلا بعد 10x.
| Pruning ratioنسبة التقليم | Prune onlyالتقليم وحده | Prune + fine-tuneالتقليم مع الضبط الدقيق | Iterativeالتكراري |
|---|---|---|---|
| 80% (5x)80% (5x) | about -4%نحو -4% | 0%0% | starting point: the retrained 80% modelنقطة البداية: نموذج 80% المعاد تدريبه |
| 90% (10x)90% (10x) | off the chartخارج المخطط | about -1.7%نحو -1.7% | about 0%نحو 0% |
| 93% (14x)93% (14x) | off the chartخارج المخطط | about -4%نحو -4% | about -1%نحو -1% |
Slide to 80% and switch recipes: prune-only sits near -4%, both retrained recipes sit at zero. Slide to 90%: only the iterative loop is still at zero. The red curve begins at the 80% retrained model, as on slide 10, so below that it has no data. The histogram is a model, not the paper's data: a zero-mean Gaussian with sigma = 0.03, cut at the threshold that removes the chosen share, then redrawn as two lobes once retraining lets the survivors grow.حرّك المنزلق إلى 80% وبدّل بين الطرق: التقليم وحده يقف قرب -4%، والطريقتان المعاد تدريبهما تقفان عند الصفر. حرّكه إلى 90%: الحلقة التكرارية وحدها ما زالت عند الصفر. يبدأ المنحنى الأحمر من النموذج المعاد تدريبه عند 80%، كما في الشريحة 10، لذلك لا بيانات له تحت هذه القيمة. المدرج التكراري نموذج تقريبي وليس بيانات الورقة: توزيع غاوسي متوسطه صفر مع sigma = 0.03، يُقطع عند العتبة التي تزيل النسبة المختارة، ثم يُعاد رسمه على هيئة فصّين بعد أن تسمح إعادة التدريب للأوزان الباقية بالنمو.
Quick checkاختبار سريع
Reading slide 10, roughly how far can iterative prune-and-retrain go before top-5 loss exceeds half a percent?بقراءة الشريحة 10، إلى أي حد تقريباً يمكن أن يصل التقليم وإعادة التدريب بالتكرار قبل أن يتجاوز فقدان top-5 نصف نقطة مئوية؟
Recall
At 80 percent pruned, what top-5 loss do prune-only and prune-plus-retrain give, where does the iterative curve begin, and what reduction factor is that?عند تقليم 80 بالمئة، ما فقدان top-5 الذي يعطيه التقليم وحده والتقليم مع إعادة التدريب، وأين يبدأ المنحنى التكراري، وما معامل التخفيض المقابل؟
Recall
Why did iterative pruning lift AlexNet from 5x to 9x with no loss?لماذا رفع التقليم التكراري AlexNet من 5x إلى 9x دون فقدان؟
Look at AlexNet layer by layer, as the paper's Table 4 does. Its first fully connected layer, fc6, holds 38 M weights but costs only 75 M FLOPs, because each weight is used once per image. Its second convolutional layer, conv2, holds 307 K weights but costs 448 M FLOPs, because each weight is reused at every spatial position. Add the layers up and the network splits into two worlds: the three FC layers hold 58.6 M of the 61 M parameters (96.2%, which the paper rounds to 59 M) but only about 117 M of 1.45 G FLOPs (8%), while the five conv layers hold 2.3 M parameters (3.8%) but 1.33 G FLOPs (92%).
انظر إلى AlexNet طبقة طبقة كما يفعل الجدول 4 في الورقة. طبقته الأولى المتصلة بالكامل، fc6، تحمل 38 M وزن لكنها تكلف 75 M عملية FLOP فقط، لأن كل وزن يُستخدم مرة واحدة لكل صورة. وطبقته الالتفافية الثانية، conv2، تحمل 307 K وزن لكنها تكلف 448 M عملية FLOP، لأن كل وزن يُعاد استخدامه في كل موضع مكاني. اجمع الطبقات فتنقسم الشبكة إلى عالمين: طبقات FC الثلاث تحمل 58.6 M من أصل 61 M معامل (96.2%، وتقرّبها الورقة إلى 59 M) لكنها لا تكلف إلا نحو 117 M من أصل 1.45 G عملية FLOP (8%)، بينما تحمل الطبقات الالتفافية الخمس 2.3 M معامل (3.8%) لكنها تكلف 1.33 G عملية FLOP (92%).
That split explains the table on slide 11 before you read it. Pruning fc6 to 9% deletes 34.6 M parameters but only 68 M FLOPs by weight count (73 M once zero activations are skipped as well, which is how Han counts). Pruning conv2 to 38% deletes only 190 K parameters but 278 M FLOPs by weight count (300 M by Han's count). Parameter reduction is a story about FC layers; MAC reduction is a story about conv layers, and the two are pruned to very different depths.
هذا الانقسام يفسر جدول الشريحة 11 قبل أن تقرأه. تقليم fc6 إلى 9% يحذف 34.6 M معامل لكنه لا يحذف إلا 68 M عملية FLOP بحساب عدد الأوزان (73 M إذا تخطينا التفعيلات الصفرية أيضاً، وهي طريقة Han في العدّ). وتقليم conv2 إلى 38% لا يحذف إلا 190 K معامل لكنه يحذف 278 M عملية FLOP بحساب عدد الأوزان (300 M بطريقة Han). تخفيض المعاملات قصة طبقات FC؛ وتخفيض MAC قصة الطبقات الالتفافية، والنوعان يُقلَّمان إلى أعماق مختلفة جداً.
| Networkالشبكة | Parameters beforeالمعاملات قبل التقليم | Afterبعده | Parameter reductionتخفيض المعاملات | MAC reductionتخفيض MAC | FC share of parametersحصة طبقات FC من المعاملات |
|---|---|---|---|---|---|
| AlexNetAlexNet | 61 M61 M | 6.7 M6.7 M | 9x9x | 3x3x | 96.2%96.2% |
| VGG-16VGG-16 | 138 M138 M | 10.3 M10.3 M | 12x12x | 5x5x | 89.9%89.9% |
| GoogleNetGoogleNet | 7 M7 M | 2.0 M2.0 M | 3.5x3.5x | 5x5x | about 14%نحو 14% |
| ResNet-50ResNet-50 | 26 M26 M | 7.47 M7.47 M | 3.4x3.4x | 6.3x6.3x | about 8%نحو 8% |
| SqueezeNetSqueezeNet | 1 M1 M | 0.38 M0.38 M | 3.2x3.2x | 3.5x3.5x | 0%0% |
Why the over-parameterized nets compress moreلماذا تنضغط الشبكات ذات المعاملات الزائدة أكثر
AlexNet and VGG-16 get 9x and 12x; GoogleNet, ResNet-50 and SqueezeNet get about 3.2x to 3.5x. The extra column is the reason. VGG-16's fc6 alone holds 103 M of its 138 M weights, and the paper prunes fc6 and fc7 to 4% of their size while conv layers keep 22% to 58%. GoogleNet has one FC layer of about 1 M in 7 M, ResNet-50 one of about 2 M in 25.5 M, and SqueezeNet has none at all, ending in global average pooling. Han's thesis says it directly: the pruning ratio of GoogleNet is smaller than AlexNet and VGG-16 "because convolutional layers dominate GoogleNet, and convolutional layers are much more efficient than fully connected layers". The three conv-dominated networks land in the same place, about 30% of parameters nonzero (GoogleNet 29%, SqueezeNet 31%, ResNet 29%), which is the 3.4x in the table. Their FC rows, where Neuron pruning would delete whole rows of a weight matrix, are too small to matter.
يحصل AlexNet وVGG-16 على 9x و12x؛ بينما يحصل GoogleNet وResNet-50 وSqueezeNet على نحو 3.2x إلى 3.5x. العمود الإضافي هو السبب. طبقة fc6 في VGG-16 وحدها تحمل 103 M من أصل 138 M وزن، والورقة تقلّم fc6 وfc7 إلى 4% من حجمهما بينما تحتفظ الطبقات الالتفافية بما بين 22% و58%. أما GoogleNet فله طبقة FC واحدة بنحو 1 M من أصل 7 M، وResNet-50 طبقة واحدة بنحو 2 M من أصل 25.5 M، وSqueezeNet ليس فيه أي طبقة FC، إذ ينتهي بـ global average pooling. وأطروحة Han تقولها صراحة: نسبة تقليم GoogleNet أصغر من AlexNet وVGG-16 «لأن الطبقات الالتفافية تهيمن على GoogleNet، والطبقات الالتفافية أكفأ بكثير من الطبقات المتصلة بالكامل». الشبكات الثلاث التي تهيمن عليها الطبقات الالتفافية تنتهي في المكان نفسه، نحو 30% من المعاملات غير صفرية (GoogleNet 29%، وSqueezeNet 31%، وResNet 29%)، وهذا هو الـ 3.4x في الجدول. أما صفوف طبقات FC فيها، حيث يحذف Neuron pruning صفوفاً كاملة من مصفوفة الأوزان، فهي أصغر من أن تُحدث فرقاً.
Why MAC reduction is not parameter reductionلماذا لا يساوي تخفيض MAC تخفيض المعاملات
Two mechanisms separate the two columns. The first is the split above: parameters concentrate in FC layers, which are pruned hardest, and MACs concentrate in conv layers, which are pruned least. That is how AlexNet gets 9x on parameters but 3x on MACs, and VGG-16 12x against 5x. The second is how Han counts. A multiply-accumulate is only counted as saved when it is really skipped, and it is skipped when either the weight or the input activation is zero. ReLU produces plenty of zero activations, so the FLOP column in Table 4 is roughly the weight density times the density of the layer's input activations.
آليتان تفصلان العمودين. الأولى هي الانقسام المذكور أعلاه: المعاملات تتركز في طبقات FC، وهي التي تُقلَّم بأشد قدر، وعمليات MAC تتركز في الطبقات الالتفافية، وهي التي تُقلَّم بأقل قدر. وهكذا يحصل AlexNet على 9x في المعاملات لكن 3x فقط في عمليات MAC، ويحصل VGG-16 على 12x مقابل 5x. والثانية هي طريقة Han في العدّ. لا تُحسب عملية الضرب والجمع التراكمي (multiply-accumulate) موفَّرة إلا إذا تُخطّيت فعلاً، وهي تُتخطى عندما يكون الوزن أو تفعيل المدخل صفراً. ودالة ReLU تنتج كثيراً من zero activations (التفعيلات الصفرية)، لذلك فعمود FLOP في الجدول 4 يساوي تقريباً كثافة الأوزان مضروبة في كثافة تفعيلات مدخل الطبقة.
Worked exampleمثال محلول
Checking the rule against AlexNet's Table 4التحقق من القاعدة مقابل الجدول 4 لـ AlexNet
conv2conv2
Weights kept 38%, input activations (the output of conv1) 88% nonzero: 0.38 × 0.88 = 33%. The table says 33%.الأوزان المحتفَظ بها 38%، وتفعيلات المدخل (أي مخرج conv1) غير صفرية بنسبة 88%: 0.38 × 0.88 = 33%. والجدول يقول 33%.fc6fc6
Weights kept 9%, input activations (the output of conv5) 34% nonzero: 0.09 × 0.34 = 3%. The table says 3%.الأوزان المحتفَظ بها 9%، وتفعيلات المدخل (أي مخرج conv5) غير صفرية بنسبة 34%: 0.09 × 0.34 = 3%. والجدول يقول 3%.ResNet-50, whole network, run backwardsResNet-50، الشبكة كاملة، بالاتجاه المعاكس
The thesis reports 29% of weights kept (3.4x) and about 16% of FLOPs remaining (6.25x, rounded to 6.3x on the slide). The rule then implies an average input activation density near 0.16 / 0.29 = 55%, which is a plausible ReLU figure. This step derives the density from the two reported numbers rather than checking a third.تذكر الأطروحة أن 29% من الأوزان محتفَظ بها (3.4x) وأن نحو 16% من عمليات FLOP متبقية (6.25x، مقرّبة إلى 6.3x في الشريحة). عندئذ تستلزم القاعدة أن متوسط كثافة تفعيلات المدخل قريب من 0.16 / 0.29 = 55%، وهو رقم معقول لـ ReLU. هذه الخطوة تستنتج الكثافة من الرقمين المذكورين بدلاً من التحقق من رقم ثالث.Compute can fall faster than parametersالحساب قد ينخفض أسرع من المعاملات
For conv-heavy networks the activation zeros from ReLU are a second source of Sparsity, which is why ResNet-50 and GoogleNet cut MACs by more than they cut parameters.في الشبكات التي تغلب عليها الطبقات الالتفافية، تكون التفعيلات الصفرية الناتجة عن ReLU مصدراً ثانياً لـ sparsity، ولهذا يخفض ResNet-50 وGoogleNet عمليات MAC بأكثر مما يخفضان المعاملات.
Even where MACs barely fall, the parameter count is worth cutting. A 6.7 M parameter AlexNet fits in on-chip SRAM, and the paper's point from Part 01 stands: at 640 pJ per DRAM access, the energy of fetching weights dominates the energy of multiplying them.
حتى حيث تكاد عمليات MAC لا تنخفض، يستحق عدد المعاملات أن يُخفَّض. نموذج AlexNet بـ 6.7 M معامل يتسع في ذاكرة SRAM على الشريحة، وتبقى فكرة الورقة من الجزء 01 قائمة: عند 640 pJ لكل وصول إلى DRAM، فإن energy of fetching weights (طاقة جلب الأوزان) تطغى على طاقة ضربها.
Quick checkاختبار سريع
AlexNet's parameters fall 9x after pruning but its MACs fall only 3x. Why?تنخفض معاملات AlexNet بمقدار 9x بعد التقليم لكن عمليات MAC فيه لا تنخفض إلا بمقدار 3x. لماذا؟
Recall
AlexNet: 9x fewer parameters but only 3x fewer MACs. Give both reasons.AlexNet: معاملات أقل بـ 9x لكن عمليات MAC أقل بـ 3x فقط. اذكر السببين.
Everything so far was an image classifier with a huge fully connected tail. NeuralTalk, Karpathy and Fei-Fei's image captioner, is a different animal: a CNN feature extractor feeding an LSTM that writes a sentence one word at a time. Han froze the CNN, pruned every LSTM weight matrix except the word-embedding table to 10% nonzeros, retrained with the original weight decay and batch size, and measured BLEU-1 to BLEU-4 on Flickr-8K. The thesis reports: "Not until pruning away 90% of the parameters does the BLEU score begin to drop sharply."
كل ما سبق كان مصنّفات صور بذيل ضخم من الطبقات المتصلة بالكامل. أما NeuralTalk، مولّد الأوصاف النصية للصور الذي بناه Karpathy وFei-Fei، فهو كائن مختلف: مستخرج سمات من نوع CNN يغذي شبكة LSTM تكتب جملة كلمةً كلمة. جمّد Han شبكة CNN، وقلّم كل مصفوفات أوزان LSTM ما عدا جدول تضمين الكلمات (word embedding) إلى 10% من القيم غير الصفرية، وأعاد التدريب بمعامل اضمحلال الأوزان (weight decay) وحجم الدفعة الأصليين، وقاس BLEU-1 إلى BLEU-4 على Flickr-8K. تقول الأطروحة: «لا تبدأ درجة BLEU في الانخفاض الحاد إلا بعد تقليم 90% من المعاملات».
The recipe did not change. Train, cut the small weights, retrain the survivors: the same three steps, the same knee near 90%, and the same dependence on Fine-tuning, which the thesis says "plays a very important role" when it compares the retrained curve with the one that skips retraining. Slide 12 shows the qualitative check that a BLEU number cannot: the captions themselves.
الوصفة لم تتغير. درّب، اقطع الأوزان الصغيرة، أعد تدريب الباقي: الخطوات الثلاث نفسها، والانحناءة نفسها قرب 90%، والاعتماد نفسه على Fine-tuning، الذي تقول الأطروحة إنه «يؤدي دوراً مهماً جداً» حين تقارن المنحنى المعاد تدريبه بالمنحنى الذي يتخطى إعادة التدريب. وتعرض الشريحة 12 التحقق النوعي الذي لا يستطيعه رقم BLEU: الأوصاف نفسها.
| Imageالصورة | Baselineالنموذج الأساسي | Prunedالنموذج المقلّم | Pruning ratioنسبة التقليم | Verdictالحكم |
|---|---|---|---|---|
| Basketballكرة السلة | a basketball player in a white uniform is playing with a ballلاعب كرة سلة بزي أبيض يلعب بالكرة | a basketball player in a white uniform is playing with a basketballلاعب كرة سلة بزي أبيض يلعب بكرة السلة | 90%90% | Same meaning, more specific nounالمعنى نفسه، باسم أكثر تحديداً |
| Dogالكلب | a brown dog is running through a grassy fieldكلب بني يركض عبر حقل معشب | a brown dog is running through a grassy areaكلب بني يركض عبر منطقة معشبة | 90%90% | Synonymمرادف |
| Surferراكب الأمواج | a man is riding a surfboard on a waveرجل يركب لوح تزلج على موجة | a man in a wetsuit is riding a wave on a beachرجل يرتدي بدلة غوص يركب موجة على شاطئ | 90%90% | Different but valid descriptionوصف مختلف لكنه صحيح |
| Soccerكرة القدم | a soccer player in red is running in the fieldلاعب كرة قدم بالأحمر يركض في الملعب | a man in a red shirt and black and white black shirt is running through a fieldرجل بقميص أحمر وقميص أسود وأبيض أسود يركض عبر حقل | 95%95% | Drift: repeated phrase, lost the word soccerانحراف: عبارة مكررة، وضاعت كلمة كرة القدم |
At 90% the pruned model "sometimes produces the same caption, sometimes produces a different word to describe the same thing", and sometimes describes the scene differently but still correctly. Replacing "ball" with "basketball" is arguably an improvement. The fourth image is the warning. At 95% pruned, a 20x model, the sentence starts to stutter: "a red shirt and black and white black shirt" repeats a phrase and loses the word "soccer". That is what crossing the knee of the Pruning ratio curve looks like in a language model: not silence, but drift.
عند 90% فإن النموذج المقلّم «يُنتج أحياناً الوصف نفسه، وأحياناً كلمة مختلفة لوصف الشيء نفسه»، وأحياناً يصف المشهد بطريقة مختلفة لكنها تبقى صحيحة. واستبدال «ball» بـ «basketball» يمكن اعتباره تحسناً. الصورة الرابعة هي التحذير. عند تقليم 95%، أي نموذج أصغر بـ 20x، تبدأ الجملة في التلعثم: «a red shirt and black and white black shirt» تكرر عبارة وتفقد كلمة «soccer». هذا هو شكل تجاوز انحناءة منحنى Pruning ratio في نموذج لغوي: ليس صمتاً، بل انحرافاً.
Recall
Name a non-CNN case where the prune-and-retrain recipe worked, and give its pruning ratio.اذكر حالة من غير شبكات CNN نجحت فيها وصفة التقليم وإعادة التدريب، واذكر نسبة تقليمها.
Take fc6 of AlexNet pruned to 9% and run it with an ordinary dense matrix kernel on a GPU. The kernel does not know the zeros are zeros. It multiplies all 38 M weight-activation pairs, 34.6 M of them by zero, and finishes in exactly the time the dense layer took. Nine times fewer parameters, zero speedup. The reduction table of two concepts ago counted what could be skipped; it did not promise that anything would be. Skipping needs either a custom engine that understands sparse formats or a sparsity pattern that commodity hardware is built for. Slide 13 shows both.
خذ fc6 من AlexNet بعد تقليمها إلى 9% وشغّلها بنواة ضرب مصفوفات كثيفة عادية (dense kernel) على GPU. النواة لا تعرف أن الأصفار أصفار. فهي تضرب كل أزواج الوزن والتفعيل البالغة 38 M، منها 34.6 M مضروبة في صفر، وتنتهي في الزمن نفسه تماماً الذي استغرقته الطبقة الكثيفة. معاملات أقل بتسع مرات، وتسريع صفري. جدول التخفيض قبل مفهومين عدّ ما يمكن تخطيه؛ لم يعد بأن شيئاً سيُتخطى فعلاً. والتخطي يحتاج إما محركاً مخصصاً يفهم الصيغ المتفرقة، وإما نمط ندرة صُمم العتاد التجاري الشائع من أجله. والشريحة 13 تعرض الاثنين.
The commodity route: NVIDIA A100 and 2:4الطريق التجاري: NVIDIA A100 ونمط 2:4
The Ampere whitepaper defines 2:4 sparsity as a structure "that allows two non-zero values in every four-entry vector". Every group of four contiguous weights along a row keeps at most two, so the matrix is exactly half zeros, stored as the nonzero values plus a 2-bit index per survivor. That compression cuts storage and bandwidth "by almost 2x", and the Sparse Tensor Core has a matrix multiply instruction that reads the indices, gathers only the matching activations, and finishes a tile in N/2 cycles instead of N: "a 2x speedup". This is the special case N = 2, M = 4 of N:M sparsity.
تعرّف الورقة البيضاء لمعمارية Ampere 2:4 sparsity بأنها بنية «تسمح بقيمتين غير صفريتين في كل متجه من أربعة عناصر». كل مجموعة من أربعة أوزان متجاورة على طول الصف تحتفظ بوزنين على الأكثر، فتكون المصفوفة نصفها أصفار بالضبط، وتُخزَّن على شكل القيم غير الصفرية مع 2-bit index (فهرس من بتّين) لكل وزن باقٍ. هذا الضغط يخفض التخزين وعرض النطاق «بما يقارب 2x»، ولدى Sparse Tensor Core تعليمة ضرب مصفوفات تقرأ الفهارس، وتجمع التفعيلات المطابقة فقط، وتُنهي البلاطة (tile) في N/2 دورة بدلاً من N: «تسريع 2x». هذه هي الحالة الخاصة N = 2, M = 4 من N:M sparsity.
How does a model get into that pattern? The whitepaper's recipe is the pipeline of this part with one constraint added: the network is "first trained using dense weights, then fine-grained structured pruning is applied, and finally the remaining non-zero weights are fine-tuned". NVIDIA's developer blog reports BERT-Large keeping its SQuAD F1 of 91.9 dense and sparse. The magnitude criterion, the mask and the retraining are all Han's; the only change is that the two smallest of every four are cut instead of the smallest 50% of the layer.
كيف يصل النموذج إلى هذا النمط؟ وصفة الورقة البيضاء هي مسار هذا الجزء مع قيد واحد إضافي: الشبكة «تُدرَّب أولاً بأوزان كثيفة، ثم يُطبَّق تقليم منظم دقيق الحبيبات (fine-grained structured pruning)، وأخيراً تخضع الأوزان غير الصفرية الباقية للضبط الدقيق». وتذكر مدونة المطورين في NVIDIA أن BERT-Large يحافظ على درجة SQuAD F1 البالغة 91.9 في النسختين الكثيفة والمتفرقة. معيار القيمة المطلقة والقناع وإعادة التدريب كلها من Han؛ والتغيير الوحيد أنك تقطع أصغر وزنين من كل أربعة بدلاً من أصغر 50% من الطبقة.
What the A100 asks for and what it deliversما يطلبه A100 وما يقدّمه
- Pattern requiredالنمط المطلوب
- 2 nonzeros in every 4 contiguous weights (50% sparsity)قيمتان غير صفريتين في كل 4 أوزان متجاورة (ندرة 50%)
- Storage and bandwidthالتخزين وعرض النطاق
- almost 2x smaller: half the values plus 2-bit indicesأصغر بما يقارب 2x: نصف القيم مع فهارس من 2-bit
- Peak Tensor Core throughputإنتاجية Tensor Core في الذروة
- up to 2x: Sparse MMA finishes a tile in N/2 cyclesحتى 2x: تعليمة Sparse MMA تُنهي البلاطة في N/2 دورة
- Measured, BERT-Large GEMM layers (cuSPARSELt on A100)المقيس على طبقات GEMM في BERT-Large (cuSPARSELt على A100)
- 1.3x (projection), 1.4x (QKV, FC1), 1.6x (FC2)1.3x (الإسقاط projection)، 1.4x (QKV وFC1)، 1.6x (FC2)
- Slide's summaryتلخيص الشريحة
- 1.5x measured BERT speedupتسريع مقيس قدره 1.5x على BERT
The gap between 2x and 1.5x is the gap between a peak instruction rate and a whole layer. The whitepaper says "up to 2x". NVIDIA's cuSPARSELt measurements on BERT-Large GEMM layers on an A100 give 1.3x for the projection, 1.4x for QKV and FC1, and 1.6x for FC2 over dense cuBLAS, because memory traffic for activations, the non-GEMM parts of the layer and kernel launch costs do not halve. The slide's "1.5X measured BERT speedup" is Han's summary of those numbers. Treat 1.5x as the realistic middle and 2x as the ceiling.
الفجوة بين 2x و1.5x هي الفجوة بين معدل تعليمة في الذروة وطبقة كاملة. الورقة البيضاء تقول «حتى 2x». وقياسات NVIDIA باستخدام cuSPARSELt على طبقات GEMM في BERT-Large على A100 تعطي 1.3x لطبقة الإسقاط (projection)، و1.4x لـ QKV وFC1، و1.6x لـ FC2 مقارنة بـ cuBLAS الكثيف، لأن حركة الذاكرة الخاصة بالتفعيلات والأجزاء غير المتعلقة بـ GEMM في الطبقة وتكاليف إطلاق النوى لا تنخفض إلى النصف. وعبارة الشريحة «1.5X measured BERT speedup» هي تلخيص Han لهذه الأرقام. اعتبر 1.5x القيمة الواقعية في المنتصف و2x السقف.
The custom route: engines built to skip zerosالطريق المخصص: محركات مبنية لتخطي الأصفار
Before 2:4 existed, the way to profit from unstructured sparsity was to build the hardware yourself. The four papers cited on slide 13 are all from Han and his students, and each makes a different thing sparse. EIE, the Efficient Inference Engine, holds the compressed model in on-chip SRAM, so the 640 pJ DRAM access from Part 01 disappears, and it skips both zero weights and the zero activations that ReLU produces, which its authors say "saves another 3x". ESE moves the same idea onto an FPGA for pruned speech-recognition LSTMs, the same recipe the previous concept applied to NeuralTalk. SpArch accelerates multiplying two sparse matrices, and SpAtten prunes tokens and attention heads at run time instead of weights.
قبل ظهور نمط 2:4، كانت طريقة الاستفادة من الندرة غير المنتظمة أن تبني العتاد بنفسك. الأوراق الأربع المذكورة في الشريحة 13 كلها من Han وطلابه، وكل منها يجعل شيئاً مختلفاً متفرقاً. EIE، أي Efficient Inference Engine، يحتفظ بالنموذج المضغوط في ذاكرة SRAM على الشريحة، فيختفي وصول DRAM بتكلفة 640 pJ المذكور في الجزء 01، ويتخطى الأوزان الصفرية وzero activations (التفعيلات الصفرية) التي تنتجها ReLU معاً، وهو ما يقول مؤلفوه إنه «يوفر 3x أخرى». وينقل ESE الفكرة نفسها إلى FPGA لشبكات LSTM المقلّمة الخاصة بالتعرف على الكلام، وهي الوصفة نفسها التي طبقها المفهوم السابق على NeuralTalk. ويسرّع SpArch ضرب مصفوفتين متفرقتين، بينما يقلّم SpAtten الرموز (tokens) ورؤوس الانتباه (attention heads) أثناء التشغيل بدلاً من الأوزان.
| Systemالنظام | Venueمكان النشر | What is sparseما الذي يكون متفرقاً | Headlineالادعاء الرئيسي |
|---|---|---|---|
| EIEEIE | ISCA 2016ISCA 2016 | Weights and activations of pruned FC layers, model held in on-chip SRAMأوزان وتفعيلات طبقات FC المقلّمة، والنموذج محفوظ في SRAM على الشريحة | 189x faster than CPU, 13x faster than GPU, 24000x more energy efficient than CPUأسرع بـ 189x من CPU، وأسرع بـ 13x من GPU، وأكفأ في الطاقة بـ 24000x من CPU |
| ESEESE | FPGA 2017FPGA 2017 | Pruned LSTM weights for speech recognitionأوزان LSTM المقلّمة للتعرف على الكلام | 43x faster than a Core i7, 3x faster than a Pascal Titan X, 282 GOPS on the compressed modelأسرع بـ 43x من Core i7، وأسرع بـ 3x من Pascal Titan X، و282 GOPS على النموذج المضغوط |
| SpArchSpArch | HPCA 2020HPCA 2020 | Sparse matrix times sparse matrix (outer product with merge)ضرب مصفوفة متفرقة في مصفوفة متفرقة (الضرب الخارجي مع الدمج) | 2.8x fewer DRAM accesses, 4x over OuterSPACEوصول إلى DRAM أقل بـ 2.8x، و4x مقارنة بـ OuterSPACE |
| SpAttenSpAtten | HPCA 2021HPCA 2021 | Tokens and heads of attention, pruned in a cascadeالرموز (tokens) ورؤوس الانتباه، مقلّمة على مراحل متتالية | 10x less DRAM traffic, 162x over a Titan Xpحركة بيانات مع DRAM أقل بـ 10x، و162x مقارنة بـ Titan Xp |
| A100 Sparse Tensor CoreA100 Sparse Tensor Core | NVIDIA 2020NVIDIA 2020 | Any weight matrix in the 2:4 patternأي مصفوفة أوزان بنمط 2:4 | up to 2x peak, 1.3x to 1.6x measured per BERT-Large layerحتى 2x في الذروة، و1.3x إلى 1.6x مقيسة لكل طبقة في BERT-Large |
Worked exampleمثال محلول
The same pruned layer on three targetsالطبقة المقلّمة نفسها على ثلاثة أنواع من العتاد
Dense GPU kernelنواة GPU كثيفة
fc6 at 9% density still executes all 38 M MACs (75 M FLOPs). Speedup 1x. Memory footprint is smaller only if you store it sparse and decompress it, which costs time too.طبقة fc6 بكثافة 9% ما زالت تنفّذ كل عمليات MAC البالغة 38 M (75 M عملية FLOP). التسريع 1x. ولا تصغر مساحة الذاكرة إلا إذا خزّنتها بصيغة متفرقة ثم فككت ضغطها، وهذا يكلّف وقتاً أيضاً.EIEEIE
Work is proportional to nonzero weight times nonzero activation pairs, roughly 3% of the dense count for fc6, and the weights never leave SRAM. This is where the MAC column of the reduction table becomes real time and real energy.العمل يتناسب مع عدد أزواج الوزن غير الصفري والتفعيل غير الصفري، أي نحو 3% من العدد الكثيف في fc6، والأوزان لا تغادر SRAM أبداً. هنا يتحول عمود MAC في جدول التخفيض إلى وقت حقيقي وطاقة حقيقية.A100 Sparse Tensor CoreSparse Tensor Core في A100
You must prune exactly half in the 2:4 pattern, no more and no less, and you get at most 2x. The 9% density of fc6 cannot be expressed, so you either settle for 50% or lose the hardware path.يجب أن تقلّم النصف بالضبط بنمط 2:4، لا أكثر ولا أقل، وتحصل على 2x على الأكثر. كثافة fc6 البالغة 9% لا يمكن التعبير عنها، فإما أن تقبل بـ 50% وإما أن تخسر مسار العتاد.Speed is a property of the pairالسرعة خاصية للزوج: المصفوفة والعتاد معاً
The same sparse matrix is a 1x, a 2x or a 30x win depending on what executes it. Parameter count alone predicts none of those.المصفوفة المتفرقة نفسها مكسب بمقدار 1x أو 2x أو 30x بحسب ما ينفّذها. وعدد المعاملات وحده لا يتنبأ بأي من هذه القيم.
Quick checkاختبار سريع
What must a weight matrix satisfy before A100 sparse Tensor Cores can double its throughput?ما الشرط الذي يجب أن تحققه مصفوفة الأوزان قبل أن تستطيع Sparse Tensor Cores في A100 مضاعفة إنتاجيتها؟
Recall
What does the A100 require of a pruned matrix, and what does it deliver?ماذا يتطلب A100 من المصفوفة المقلّمة، وماذا يقدّم؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- Train, prune below a magnitude threshold, retrain the survivors. The retraining step is critical.درّب، ثم قلّم الأوزان التي تقل قيمتها المطلقة عن العتبة، ثم أعد تدريب الأوزان الباقية. خطوة إعادة التدريب حاسمة.
- Prune-only: free lunch at 50 percent, about -1 percent at 67 percent, about -4 percent at 80 percent pruned.التقليم وحده: مكسب مجاني عند 50 بالمئة، ونحو -1 بالمئة عند 67 بالمئة، ونحو -4 بالمئة عند تقليم 80 بالمئة.
- Prune plus retrain: zero loss to about 80 percent, 9x on AlexNet. Weights become bimodal and spread from ±0.015 to ±0.025.التقليم مع إعادة التدريب: لا فقدان حتى نحو 80 بالمئة، أي 9x على AlexNet. تصبح الأوزان ثنائية القمة (bimodal) وتتسع من ±0.015 إلى ±0.025.
- Iterative prune and retrain: zero loss to about 90 percent, 5x lifted to 9x, sharp drop only past 10x.التقليم وإعادة التدريب بالتكرار: لا فقدان حتى نحو 90 بالمئة، فيرتفع التخفيض من 5x إلى 9x، ولا يحدث الهبوط الحاد إلا بعد 10x.
- Reduction factor = 1 / (1 - pruning ratio): 80 percent is 5x, 90 percent is 10x.معامل التخفيض = 1 / (1 - نسبة التقليم): تقليم 80 بالمئة يعني 5x، و90 بالمئة يعني 10x.
- AlexNet is 9x smaller but only 3x cheaper: FC layers hold 96.2 percent of parameters, conv layers hold 92 percent of MACs. FLOP% ≈ weight density × input activation density.AlexNet أصغر بـ 9x لكنه أرخص حساباً بـ 3x فقط: طبقات FC تحمل 96.2 بالمئة من المعاملات، وطبقات الالتفاف (conv) تحمل 92 بالمئة من عمليات MAC. نسبة FLOP المتبقية ≈ كثافة الأوزان × كثافة تفعيلات المدخل.
- Fully convolutional nets (GoogleNet, ResNet-50, SqueezeNet) all keep about 30 percent, so about 3.4x.الشبكات الالتفافية بالكامل (GoogleNet وResNet-50 وSqueezeNet) تحتفظ كلها بنحو 30 بالمئة من أوزانها، أي نحو 3.4x.
- The NeuralTalk LSTM pruned 90 percent keeps BLEU flat and captions nearly identical. 95 percent starts to drift.LSTM الخاص بـ NeuralTalk بعد تقليم 90 بالمئة يبقي BLEU ثابتاً والأوصاف (captions) شبه متطابقة. عند 95 بالمئة يبدأ الانحراف.
- Sparsity is speed only with hardware support: EIE, ESE, SpArch, SpAtten, or the A100 2:4 pattern (up to 2x peak, about 1.3x to 1.6x measured on BERT-Large layers).الندرة لا تصبح سرعة إلا بدعم من العتاد: EIE أو ESE أو SpArch أو SpAtten، أو نمط 2:4 في A100 (حتى 2x في الذروة، ونحو 1.3x إلى 1.6x مقيسة على طبقات BERT-Large).
Sourcesالمصادر
- Learning both Weights and Connections for Efficient Neural NetworksPaperHan, Pool, Tran and Dally, NeurIPS 2015Three-step pipeline, retraining is critical, Figure 5 curves, Table 4 layer statistics, Figure 7 bimodal weights, dropout equation 2, 9x and 13x.المسار ذو الخطوات الثلاث، وإعادة التدريب حاسمة، ومنحنيات الشكل 5، وإحصاءات الطبقات في الجدول 4، والأوزان ثنائية القمة في الشكل 7، ومعادلة dropout رقم 2، و9x و13x.(opens in a new tab)(يفتح في تبويب جديد)
- Efficient Methods and Hardware for Deep LearningPaperSong Han, PhD thesis, Stanford University, 2017Tables 3.4 to 3.8 (GoogleNet, ResNet-50, SqueezeNet rows), about 30 percent nonzero in conv-dominated networks, NeuralTalk pruning and captions (section 3.4.3).الجداول 3.4 إلى 3.8 (صفوف GoogleNet وResNet-50 وSqueezeNet)، ونحو 30 بالمئة قيم غير صفرية في الشبكات التي تغلب عليها الطبقات الالتفافية، وتقليم NeuralTalk وأوصافه (القسم 3.4.3).(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 3: Pruning and Sparsity (Part I)DocsMIT HAN LabThe deck these slides reproduce, including the reduction table, the four captions and the A100 line.مجموعة الشرائح التي تعيد هذه الشرائح إنتاجها، ومنها جدول التخفيض والأوصاف الأربعة وسطر A100.(opens in a new tab)(يفتح في تبويب جديد)
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman CodingPaperHan, Mao and Dally, ICLR 2016Pruning as the first stage (9x to 13x) of a 35x to 49x compression pipeline.التقليم بوصفه المرحلة الأولى (9x إلى 13x) في مسار ضغط يحقق 35x إلى 49x.(opens in a new tab)(يفتح في تبويب جديد)
- The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural NetworksPaperFrankle and Carbin, ICLR 2019Iterative pruning over n rounds finds smaller networks than one-shot pruning; each round prunes p^(1/n) of survivors.التقليم التكراري على n جولة يجد شبكات أصغر مما يجده التقليم دفعة واحدة؛ كل جولة تقلّم p^(1/n) من الأوزان الباقية.(opens in a new tab)(يفتح في تبويب جديد)
- EIE: Efficient Inference Engine on Compressed Deep Neural NetworkPaperHan et al., ISCA 2016189x and 13x faster than CPU and GPU, 24000x and 3400x more energy efficient, skipping zero activations saves 3x.أسرع بـ 189x و13x من CPU وGPU، وأكفأ في الطاقة بـ 24000x و3400x، وتخطي التفعيلات الصفرية يوفر 3x.(opens in a new tab)(يفتح في تبويب جديد)
- ESE: Efficient Speech Recognition Engine with Sparse LSTM on FPGAPaperHan et al., FPGA 201720x model compression (10x pruning, 2x quantization), 43x over a Core i7, 3x over a Pascal Titan X, 282 GOPS.ضغط النموذج بمقدار 20x (تقليم 10x وتكميم 2x)، و43x مقارنة بـ Core i7، و3x مقارنة بـ Pascal Titan X، و282 GOPS.(opens in a new tab)(يفتح في تبويب جديد)
- SpArch: Efficient Architecture for Sparse Matrix MultiplicationPaperZhang et al., HPCA 20202.8x fewer DRAM accesses, 4x over OuterSPACE.وصول إلى DRAM أقل بـ 2.8x، و4x مقارنة بـ OuterSPACE.(opens in a new tab)(يفتح في تبويب جديد)
- SpAtten: Efficient Sparse Attention Architecture with Cascade Token and Head PruningPaperWang, Zhang and Han, HPCA 202110x DRAM access reduction, 162x over a Titan Xp.تخفيض الوصول إلى DRAM بمقدار 10x، و162x مقارنة بـ Titan Xp.(opens in a new tab)(يفتح في تبويب جديد)
- NVIDIA A100 Tensor Core GPU Architecture whitepaperDocsNVIDIA2:4 definition, almost 2x storage and bandwidth, N/2 cycles, dense-prune-finetune recipe (pages 31 to 32).تعريف 2:4، وتوفير يقارب 2x في التخزين وعرض النطاق، وN/2 دورة، ووصفة التدريب الكثيف ثم التقليم ثم الضبط الدقيق (الصفحتان 31 و32).(opens in a new tab)(يفتح في تبويب جديد)
- Accelerating Inference with Sparsity Using the NVIDIA Ampere Architecture and NVIDIA TensorRTArticleNVIDIA Developer Blog2:4 recipe and BERT-Large SQuAD F1 of 91.9 dense and sparse.وصفة 2:4، ودرجة SQuAD F1 البالغة 91.9 لـ BERT-Large في النسختين الكثيفة والمتفرقة.(opens in a new tab)(يفتح في تبويب جديد)
- Exploiting NVIDIA Ampere Structured Sparsity with cuSPARSELtArticleNVIDIA Developer BlogMeasured 1.3x to 1.6x speedups on BERT-Large GEMM layers on an A100.تسريع مقيس من 1.3x إلى 1.6x على طبقات GEMM في BERT-Large على A100.(opens in a new tab)(يفتح في تبويب جديد)
- Accelerating Sparse Deep Neural NetworksPaperMishra et al., NVIDIA, 2021Twice the math throughput for 2:4 sparse matrices and the training recipe that preserves accuracy.ضعف إنتاجية العمليات الحسابية للمصفوفات المتفرقة بنمط 2:4، ووصفة التدريب التي تحافظ على الدقة.(opens in a new tab)(يفتح في تبويب جديد)
Part 03: Pruning granularity: from irregular to regularدقة التقليم (Granularity): من غير المنتظم إلى المنتظم
Fine-grained versus coarse-grained pruning on a 2D weight matrix, the four dimensions of a convolution weight tensor, and the five commonly used granularities from fine-grained to channel-level.التقليم الدقيق (fine-grained) مقابل الخشن (coarse-grained) على مصفوفة أوزان ثنائية الأبعاد، والأبعاد الأربعة لموتر أوزان الالتفاف، ومستويات الدقة الخمسة الشائعة من الدقيق إلى مستوى القنوات.
3 concepts3 مفاهيم, ، slides 14-18الشرائح 14-18
Why this part mattersلماذا يهمّ هذا الجزء
Sooner or later your embedded project will hit this moment: a network that is 90% zeros runs no faster on the target MCU or GPU than the dense one did. Nothing is wrong with the pruning. What is wrong is the shape of the holes, and that shape is what this part is about.
Part 02 showed that pruning can remove most of a network's weights without hurting accuracy. The next question on the lecture's outline is in what pattern to remove them. We start with a single 8 x 8 matrix and two ways of cutting it, then open up a convolution weight to see that it has four dimensions and therefore many more ways to be cut, and finish with a ladder of five granularities adapted from Mao et al., who studied four. Exams ask you to order that ladder, to count the weights a given unit removes and to argue the trade between flexibility and acceleration. The same ladder returns in the next part as NVIDIA 2:4 sparsity, channel pruning and AMC, and again in lecture 04-2.
عاجلًا أو آجلًا سيصل مشروعك المدمج إلى هذه اللحظة: شبكة 90% من أوزانها أصفار لا تعمل على المتحكم الدقيق (MCU) أو الـGPU المستهدف أسرع مما كانت تعمل الشبكة الكثيفة. لا خطأ في التقليم نفسه. الخطأ في شكل الثقوب، وهذا الشكل هو موضوع هذا الجزء.
أوضح الجزء 02 أن التقليم يستطيع حذف معظم أوزان الشبكة دون الإضرار بالدقة. السؤال التالي في مخطط المحاضرة هو: بأي نمط نحذفها؟ نبدأ بمصفوفة واحدة حجمها 8 x 8 وطريقتين لقطعها، ثم نفتح وزن الالتفاف (convolution) لنرى أن له أربعة أبعاد وبالتالي طرقًا أكثر بكثير للقطع، ونختم بسلّم من خمس درجات للدقة (granularity) مقتبس من Mao et al. الذين درسوا أربعًا منها. تطلب منك الاختبارات ترتيب هذا السلّم، وعدّ الأوزان التي تحذفها وحدة معيّنة، ومناقشة المقايضة بين المرونة والتسريع. ويعود السلّم نفسه في الجزء التالي في صورة تفرّغ 2:4 من NVIDIA وتقليم القنوات وAMC، ثم مرة أخرى في المحاضرة 04-2.
By the end you canفي نهاية هذا الجزء ستستطيع
- Define pruning granularity and place fine-grained and coarse-grained pruning at its two ends.تعرّف دقة التقليم (pruning granularity) وتضع التقليم الدقيق (fine-grained) والتقليم الخشن (coarse-grained) عند طرفيها.
- Explain why coarse-grained choices are a subset of fine-grained ones and what that does to attainable sparsity at equal accuracy.تشرح لماذا تكون خيارات التقليم الخشن مجموعة جزئية من خيارات التقليم الدقيق، وما أثر ذلك على نسبة التفرّغ (sparsity) الممكن بلوغها عند الدقة نفسها.
- Read a convolution weight as [c_o, c_i, k_h, k_w] and count the weights in a filter, an input channel, a kernel and a row.تقرأ وزن الالتفاف (convolution) على أنه [c_o, c_i, k_h, k_w] وتعدّ الأوزان في المرشّح (filter) وفي قناة الإدخال (input channel) وفي النواة (kernel) وفي الصف.
- Order fine-grained, pattern-based, vector-level, kernel-level and channel-level from irregular to regular and say what hardware each maps onto.ترتّب المستويات fine-grained وpattern-based وvector-level وkernel-level وchannel-level من غير المنتظم إلى المنتظم، وتذكر العتاد الذي يناسب كلًّا منها.
- Compute the sparsity and the surviving shape after removing a given unit.تحسب نسبة التفرّغ والشكل المتبقي بعد حذف وحدة معيّنة.
Take a weight matrix with eight rows and eight columns, 64 weights in all, and decide to remove 24 of them. One way is to cross out rows 3, 4 and 7 completely. Another is to cross out 24 individual entries wherever the magnitude criterion of part 05 says they matter least. Both leave 40 weights and both reach a Sparsity of 24 / 64 = 37.5%. Everything else about them is different.
خذ مصفوفة أوزان من ثمانية صفوف وثمانية أعمدة، أي 64 وزنًا في المجموع، وقرّر حذف 24 منها. إحدى الطرق أن تشطب الصفوف 3 و4 و7 بالكامل. وطريقة أخرى أن تشطب 24 عنصرًا منفردًا أينما قال معيار المقدار (magnitude) في الجزء 05 إنها الأقل أهمية. كلتا الطريقتين تُبقي 40 وزنًا وكلتاهما تبلغ نسبة تفرّغ (sparsity) قدرها 24 / 64 = 37.5%. وكل ما عدا ذلك مختلف بينهما.
The unit you delete is the Pruning granularity. Deleting single weights is fine-grained, or unstructured, pruning. Deleting whole rows, columns, kernels or channels is coarse-grained, or structured, pruning. Two consequences pull in opposite directions as the unit grows. The number of masks you may choose from falls, which costs accuracy at a given Pruning ratio. The regularity of what survives rises, which is what lets ordinary hardware run the pruned layer faster.
الوحدة التي تحذفها هي دقة التقليم (pruning granularity). حذف أوزان منفردة هو التقليم الدقيق أو غير المنظَّم (fine-grained / unstructured pruning). وحذف صفوف أو أعمدة أو أنوية (kernels) أو قنوات كاملة هو التقليم الخشن أو المنظَّم (coarse-grained / structured pruning). كلما كبرت الوحدة ظهرت نتيجتان تشدّان في اتجاهين متعاكسين. عدد الأقنعة التي يمكنك الاختيار منها يقلّ، وهذا يكلّف دقة عند نسبة تقليم (pruning ratio) معيّنة. وانتظام ما يبقى يزداد، وهذا ما يسمح للعتاد العادي بتشغيل الطبقة المقلَّمة أسرع.
Counting the choicesعدّ الخيارات
The slide calls fine-grained pruning "more flexible" and coarse-grained pruning "a subset of the fine-grained case". Both statements can be made exact by counting masks. A mask is the set of positions you zero, and the pruning problem of part 01 searches over masks for the one with the lowest loss.
تصف الشريحة التقليم الدقيق بأنه "أكثر مرونة" والتقليم الخشن بأنه "مجموعة جزئية من حالة التقليم الدقيق". يمكن جعل العبارتين دقيقتين بعدّ الأقنعة. القناع (mask) هو مجموعة المواضع التي تصفّرها، ومسألة التقليم (pruning) في الجزء 01 تبحث بين الأقنعة عن القناع ذي أقل خسارة (loss).
Worked exampleمثال محلول
How many masks remove 24 of 64 weightsكم قناعًا يحذف 24 وزنًا من 64
Fine-grainedالتقليم الدقيق (Fine-grained)
Any 24 of the 64 positions may go, so there are C(64, 24) = 250,649,105,469,666,120 masks, about 2.5 x 10^17.يمكن حذف أي 24 موضعًا من المواضع الـ64، لذلك يوجد C(64, 24) = 250,649,105,469,666,120 قناعًا، أي نحو 2.5 x 10^17.Row-structuredالتقليم المنظَّم بالصفوف (Row-structured)
Any 3 of the 8 rows may go, so there are C(8, 3) = 56 masks.يمكن حذف أي 3 صفوف من الصفوف الـ8، لذلك يوجد C(8, 3) = 56 قناعًا.Nest one inside the otherضع إحداهما داخل الأخرى
Every one of the 56 row masks is also a set of 24 individual positions, so it is one of the 2.5 x 10^17 fine-grained masks. The structured menu sits strictly inside the unstructured menu.كل قناع من أقنعة الصفوف الـ56 هو أيضًا مجموعة من 24 موضعًا منفردًا، فهو إذن أحد أقنعة التقليم الدقيق البالغة 2.5 x 10^17. قائمة الخيارات المنظَّمة تقع بالكامل داخل قائمة الخيارات غير المنظَّمة.Consequence for accuracyالنتيجة على الدقة
The best row mask can at most tie the best fine-grained mask on the loss. It can never beat it. At a fixed accuracy target, structured pruning therefore reaches equal or lower sparsity, never higher, for the best achievable mask under the same retraining.أفضل قناع صفوف يمكنه في أحسن الأحوال أن يعادل أفضل قناع دقيق في قيمة الخسارة، ولا يمكنه أبدًا أن يتفوق عليه. لذلك عند هدف دقة ثابت يبلغ التقليم المنظَّم نسبة تفرّغ مساوية أو أقل، لا أعلى أبدًا، وذلك لأفضل قناع ممكن تحت إعادة التدريب نفسها.
Same sparsity, different search spacesنسبة التفرّغ نفسها، وفضاءات بحث مختلفة
- Weights removedالأوزان المحذوفة
- 24 of 64 (37.5%)24 من 64 (37.5%)
- Fine-grained masksأقنعة التقليم الدقيق
- C(64, 24) ≈ 2.5 x 10^17C(64, 24) ≈ 2.5 x 10^17
- Row-structured masksأقنعة حذف الصفوف الكاملة
- C(8, 3) = 56C(8, 3) = 56
- Surviving shape, fine-grainedالشكل المتبقي، التقليم الدقيق
- 8 x 8 with 24 holes8 x 8 مع 24 ثقبًا
- Surviving shape, row-structuredالشكل المتبقي، حذف الصفوف
- 5 x 8 dense5 x 8 كثيفة
Why irregular means hard to accelerateلماذا يعني عدم الانتظام صعوبة التسريع
Multiply a vector by the 5 x 8 survivor and nothing special happens. It is just a smaller dense matrix, and every BLAS routine, every tensor core and every microcontroller loop handles it at full speed. That is the slide's "easy to accelerate (just a smaller matrix!)". Now multiply by the 8 x 8 matrix with 24 holes. A dense routine still performs all 64 multiplies, 24 of them by zero, and gains nothing. To gain, you must store the 40 surviving values together with their positions, in a compressed sparse format, and let the hardware skip the zeros one by one. Mao et al. draw the same line: fine-grained sparsity scatters the tensor into isolated weights and needs custom accelerators such as EIE or SCNN to exploit it, while filter and channel sparsity is simple to accelerate on general-purpose processors because it "is equivalent to obtaining a smaller dense model" (Mao et al., 2017, section 2).
اضرب متجهًا في المصفوفة الباقية 5 x 8 ولن يحدث شيء خاص. إنها ببساطة مصفوفة كثيفة أصغر، وكل دالة BLAS وكل tensor core وكل حلقة على متحكم دقيق تعالجها بالسرعة الكاملة. هذا ما تعنيه الشريحة بعبارة "سهل التسريع (مجرد مصفوفة أصغر!)". الآن اضرب في المصفوفة 8 x 8 التي فيها 24 ثقبًا. الدالة الكثيفة ما زالت تنفّذ عمليات الضرب الـ64 كلها، منها 24 ضربًا في صفر، ولا تكسب شيئًا. لكي تكسب، يجب أن تخزّن القيم الـ40 الباقية مع مواضعها في صيغة متفرّغة مضغوطة (compressed sparse format)، وأن تدع العتاد يتخطى الأصفار واحدًا واحدًا. يرسم Mao et al. الخط نفسه: التفرّغ الدقيق يبعثر الموتّر إلى أوزان معزولة ويحتاج إلى مسرّعات مخصّصة مثل EIE أو SCNN للاستفادة منه، بينما تفرّغ المرشّحات والقنوات سهل التسريع على المعالجات العامة لأنه "يكافئ الحصول على نموذج كثيف أصغر" (Mao et al., 2017، القسم 2).
The gap is measurable. Wen et al. trained AlexNet with structured sparsity and reported average layer-wise speedups of the convolutional layers of 5.1x on CPU and 3.1x on GPU with off-the-shelf libraries, against 3.0x and 0.9x for non-structured l1 sparsity (Wen et al., 2016, Table 4). The fine-grained model had more zeros. The structured model ran faster.
الفجوة قابلة للقياس. درّب Wen et al. شبكة AlexNet بتفرّغ منظَّم وأبلغوا عن متوسط تسريع لكل طبقة في الطبقات الالتفافية قدره 5.1x على الـCPU و3.1x على الـGPU باستخدام مكتبات جاهزة، مقابل 3.0x و0.9x للتفرّغ غير المنظَّم بـl1 (Wen et al., 2016، الجدول 4). النموذج الدقيق كان فيه أصفار أكثر، لكن النموذج المنظَّم كان أسرع.
What the accuracy price looks likeكيف يبدو ثمن الدقة
Because coarse units search a smaller space, they lose a little accuracy at the same density (the fraction of weights kept). Mao et al. measured this on ImageNet with the same pipeline at every granularity. The differences are small between fine and vector grains and grow as the grain reaches whole kernels; pruning entire filters "loses nearly 1% validation accuracy at the very first pruning stage" on AlexNet (Mao et al., 2017).
لأن الوحدات الخشنة تبحث في فضاء أصغر، فإنها تخسر قليلًا من الدقة عند الكثافة نفسها (density، أي نسبة الأوزان المُبقاة). قاس Mao et al. ذلك على ImageNet بخط المعالجة نفسه عند كل مستوى دقة. الفروق صغيرة بين المستوى الدقيق ومستوى المتجهات وتكبر حين تصل الوحدة إلى أنوية كاملة؛ وتقليم مرشّحات كاملة "يخسر قرابة 1% من دقة التحقق في أول مرحلة تقليم" على AlexNet (Mao et al., 2017).
| Networkالشبكة | Density keptالكثافة المُبقاة | Fine-grainedدقيق (Fine-grained) | Vector-levelمستوى المتجه (Vector-level) | Kernel-levelمستوى النواة (Kernel-level) |
|---|---|---|---|---|
| AlexNetAlexNet | 24.8%24.8% | 80.41%80.41% | 79.94%79.94% | 79.20%79.20% |
| VGG-16VGG-16 | 23.5%23.5% | 90.56%90.56% | 90.48%90.48% | 89.70%89.70% |
| ResNet-50ResNet-50 | 40.0%40.0% | 92.34%92.34% | 92.26%92.26% | 92.07%92.07% |
| Granularityمستوى الدقة | Density keptالكثافة المُبقاة | Storage relative to denseالتخزين نسبةً إلى الشبكة الكثيفة |
|---|---|---|
| Fine-grainedدقيق (Fine-grained) | 22.1%22.1% | 33.0%33.0% |
| Vector-levelمستوى المتجه (Vector-level) | 29.9%29.9% | 34.5%34.5% |
| Kernel-levelمستوى النواة (Kernel-level) | 37.8%37.8% | 39.7%39.7% |
Recall
Rows 3, 4 and 7 of an 8 x 8 weight matrix are pruned. What is the sparsity, and what shape survives?قُلِّمت الصفوف 3 و4 و7 من مصفوفة أوزان 8 x 8. ما نسبة التفرّغ، وما الشكل الذي يبقى؟
Recall
Why does the slide call coarse-grained choices a subset of the fine-grained case, and what does that imply for compression?لماذا تسمّي الشريحة خيارات التقليم الخشن مجموعة جزئية من حالة التقليم الدقيق، وماذا يعني ذلك للضغط؟
Quick checkاختبار سريع
Why is fine-grained pruning hard to accelerate on an ordinary GPU?لماذا يصعب تسريع التقليم الدقيق (fine-grained) على GPU عادي؟
Quick checkاختبار سريع
Which statement about coarse-grained pruning matches slide 15?أي عبارة عن التقليم الخشن (coarse-grained) تطابق الشريحة 15؟
A linear layer's weight is a matrix, so its only structured units are rows and columns. A convolution weight is richer. Slide 17 draws one: three rows of kernels stacked vertically, two columns of kernels side by side, and each kernel a 3 x 3 grid. Count the cells and you get 3 x 2 x 3 x 3 = 54 weights.
وزن الطبقة الخطية مصفوفة، لذلك وحداته المنظَّمة الوحيدة هي الصفوف والأعمدة. أما وزن الالتفاف فأغنى. ترسم الشريحة 17 واحدًا منه: ثلاثة صفوف من الأنوية مكدّسة عموديًا، وعمودان من الأنوية متجاوران، وكل نواة شبكة 3 x 3. عُدّ الخلايا تحصل على 3 x 2 x 3 x 3 = 54 وزنًا.
Those four factors are the four dimensions of a convolution weight. The tensor has shape [c_o, c_i, k_h, k_w]: c_o output channels, also called filters; c_i input channels; and a kernel of height k_h and width k_w. Goodfellow, Bengio and Courville write the same object as a 4-D kernel tensor K whose element K[i, j, k, l] is the connection strength between output channel i and input channel j at a row offset of k and a column offset of l (Goodfellow et al., 2016, section 9.5). PyTorch stores Conv2d.weight with exactly the slide's ordering, (out_channels, in_channels / groups, kernel_size[0], kernel_size[1]) (PyTorch documentation).
هذه العوامل الأربعة هي الأبعاد الأربعة لوزن الالتفاف (dimensions of a convolution weight). شكل الموتّر [c_o, c_i, k_h, k_w]: c_o قنوات الإخراج، وتسمّى أيضًا المرشّحات (filters)؛ وc_i قنوات الإدخال؛ ونواة ارتفاعها k_h وعرضها k_w. يكتب Goodfellow وBengio وCourville الشيء نفسه على أنه موتّر نواة رباعي الأبعاد (4-D) اسمه K، عنصره K[i, j, k, l] هو قوة الاتصال بين قناة الإخراج i وقناة الإدخال j عند إزاحة صف قدرها k وإزاحة عمود قدرها l (Goodfellow et al., 2016، القسم 9.5). ويخزّن PyTorch Conv2d.weight بترتيب الشريحة نفسه تمامًا، (out_channels, in_channels / groups, kernel_size[0], kernel_size[1]) (توثيق PyTorch).
Slicing the tensor into unitsتقطيع الموتّر إلى وحدات
The reason the lecture stops to name the dimensions is that each way of slicing the tensor is a candidate pruning unit. Mao et al. name the slices with array notation, and reading them that way makes the counts automatic. Fix the output channel and you have a filter, a 3-D slab. Fix the output and input channel and you have one kernel, a 2-D grid. Fix a row inside that kernel and you have a 1-D vector. Fix everything and you have a single scalar weight (Mao et al., 2017, section 3.2).
السبب الذي يجعل المحاضرة تتوقف لتسمية الأبعاد هو أن كل طريقة لتقطيع الموتّر هي وحدة تقليم مرشّحة. يسمّي Mao et al. الشرائح بترميز المصفوفات، وقراءتها بهذه الطريقة تجعل العدّ تلقائيًا. ثبّت قناة الإخراج تحصل على مرشّح، وهو لوح ثلاثي الأبعاد (3-D). ثبّت قناتَي الإخراج والإدخال تحصل على نواة واحدة، وهي شبكة ثنائية الأبعاد (2-D). ثبّت صفًا داخل تلك النواة تحصل على متجه أحادي البعد (1-D). ثبّت كل شيء تحصل على وزن عددي واحد (Mao et al., 2017، القسم 3.2).
| Unitالوحدة | Sliceالمقطع | Weightsالأوزان | Share of 54النسبة من 54 |
|---|---|---|---|
| Single weightوزن مفرد | W[o, i, r, c]W[o, i, r, c] | 11 | 1.9%1.9% |
| Row inside a kernelصف داخل نواة | W[o, i, r, :]W[o, i, r, :] | k_w = 3k_w = 3 | 5.6%5.6% |
| Kernelنواة (kernel) | W[o, i, :, :]W[o, i, :, :] | k_h x k_w = 9k_h x k_w = 9 | 16.7%16.7% |
| Filter (output channel)مرشّح (filter)، أي قناة إخراج | W[o, :, :, :]W[o, :, :, :] | c_i x k_h x k_w = 18c_i x k_h x k_w = 18 | 33.3%33.3% |
| Input channelقناة إدخال (input channel) | W[:, i, :, :]W[:, i, :, :] | c_o x k_h x k_w = 27c_o x k_h x k_w = 27 | 50.0%50.0% |
Two formulas do all the work. A filter holds c_i · k_h · k_w weights, because it has one kernel per input channel. An input channel holds c_o · k_h · k_w weights, because every filter has a kernel that reads it. In the slide these are 18 and 27, and it is easy to mix them up, so picture the grid: a filter is a row of kernels, an input channel is a column of kernels.
صيغتان تؤديان كل العمل. المرشّح يحوي c_i · k_h · k_w وزنًا، لأن فيه نواة واحدة لكل قناة إدخال. وقناة الإدخال تحوي c_o · k_h · k_w وزنًا، لأن كل مرشّح فيه نواة تقرأها. في الشريحة تساويان 18 و27، ومن السهل الخلط بينهما، لذلك تخيّل الشبكة: المرشّح صف من الأنوية، وقناة الإدخال عمود من الأنوية.
The same counts at a realistic scaleالعدّ نفسه على مقياس واقعي
Slide 17 is a toy so the picture fits. A VGG-style layer with 64 input and 64 output channels and 3 x 3 kernels has 64 x 64 x 9 = 36,864 weights, and the same slicing rules apply.
الشريحة 17 مثال مصغّر لكي تتسع الصورة. طبقة على نمط VGG فيها 64 قناة إدخال و64 قناة إخراج وأنوية 3 x 3 تحوي 64 x 64 x 9 = 36,864 وزنًا، وقواعد التقطيع نفسها تنطبق.
| Unit removedالوحدة المحذوفة | Weights removedالأوزان المحذوفة | Shareالنسبة | Surviving shapeالشكل المتبقي |
|---|---|---|---|
| One kernelنواة واحدة | 99 | 0.024%0.024% | Still [64, 64, 3, 3] with holesيبقى [64, 64, 3, 3] مع ثقوب |
| One filterمرشّح واحد | 64 x 9 = 57664 x 9 = 576 | 1.56%1.56% | [63, 64, 3, 3][63, 64, 3, 3] |
| One input channelقناة إدخال واحدة | 64 x 9 = 57664 x 9 = 576 | 1.56%1.56% | [64, 63, 3, 3][64, 63, 3, 3] |
| Sixteen input channelsست عشرة قناة إدخال | 16 x 576 = 9,21616 x 576 = 9,216 | 25%25% | [64, 48, 3, 3][64, 48, 3, 3] |
Removing a whole filter has a second effect that Li et al. spell out. The filter's output feature map disappears, so the next layer no longer receives that channel, and the corresponding kernels in the next layer's weight tensor disappear too. Pruning m of the n filters of a layer removes m / n of the compute in that layer and in the one after it (Li et al., 2017).
لحذف مرشّح كامل (filter pruning) أثر ثانٍ يوضّحه Li et al.. خريطة الخصائص (feature map) التي يخرجها المرشّح تختفي، فلا تعود الطبقة التالية تستقبل تلك القناة، وتختفي أيضًا الأنوية المقابلة لها في موتّر أوزان الطبقة التالية. تقليم m من المرشّحات الـn في طبقة يحذف m / n من الحساب في تلك الطبقة وفي التي تليها (Li et al., 2017).
Recall
Name the four dimensions of a convolution weight in the slide's order, and give the weight count for c_o = 3, c_i = 2 and 3 x 3 kernels.سمِّ الأبعاد الأربعة لوزن الالتفاف بترتيب الشريحة، وأعطِ عدد الأوزان عندما c_o = 3 وc_i = 2 والأنوية 3 x 3.
Recall
How many weights go when you remove one kernel, one input channel and one filter from the 54-weight tensor?كم وزنًا يُحذف عندما تحذف نواة واحدة، وقناة إدخال واحدة، ومرشّحًا واحدًا من الموتّر ذي الـ 54 وزنًا؟
Quick checkاختبار سريع
A convolution layer has c_o = 3, c_i = 2 and 3 x 3 kernels. Channel-level pruning removes one input channel. How many weights are removed?طبقة التفاف فيها c_o = 3 وc_i = 2 ونوى بحجم 3 x 3. يحذف التقليم على مستوى القنوات (channel-level) قناة إدخال واحدة. كم وزنًا يُحذف؟
Put the two previous ideas together and the lecture's central figure appears. Slide 18 takes the same 54-weight tensor and prunes it five times, once per unit, arranging the results on an axis from irregular to regular. Read from left to right, the holes grow from single cells, to fixed shapes inside kernels, to whole rows, to whole kernels, to an entire column of kernels.
اجمع الفكرتين السابقتين يظهر الشكل المركزي في المحاضرة. تأخذ الشريحة 18 الموتّر نفسه ذا الـ54 وزنًا وتقلّمه خمس مرات، مرة لكل وحدة، وترتّب النتائج على محور من غير المنتظم إلى المنتظم. اقرأ من اليسار إلى اليمين: تكبر الثقوب من خلايا منفردة، إلى أشكال ثابتة داخل الأنوية، إلى صفوف كاملة، إلى أنوية كاملة، إلى عمود كامل من الأنوية.
Every panel can be counted, and counting them shows something the picture hides: every panel removes between a third and two thirds of the weights, so the real difference between them is not how much Sparsity they reach but how the zeros are arranged. The fine-grained panel keeps 23 scattered weights. The pattern-based panel keeps exactly four cells in every kernel, and each kept shape is a Tetris piece (a T or an L of four cells). The vector-level panel keeps seven of the eighteen kernel rows. The kernel-level panel drops the first filter's right kernel and the second filter's left kernel. The channel-level panel drops the whole second input channel across all three filters, and what survives is a dense [3, 1, 3, 3] tensor.
كل لوحة يمكن عدّها، والعدّ يكشف شيئًا تخفيه الصورة: كل لوحة تحذف ما بين ثلث الأوزان وثلثيها، لذلك الفرق الحقيقي بينها ليس مقدار نسبة التفرّغ (sparsity) التي تبلغها بل طريقة ترتيب الأصفار. لوحة التقليم الدقيق (fine-grained) تُبقي 23 وزنًا متناثرًا. لوحة التقليم بالأنماط (pattern-based) تُبقي أربع خلايا بالضبط في كل نواة، وكل شكل مُبقى قطعة Tetris (حرف T أو L من أربع خلايا). لوحة مستوى المتجهات (vector-level) تُبقي سبعة من صفوف الأنوية الثمانية عشر. لوحة مستوى النواة (kernel-level) تُسقط النواة اليمنى للمرشّح الأول والنواة اليسرى للمرشّح الثاني. لوحة مستوى القناة (channel-level) تُسقط قناة الإدخال الثانية كاملة عبر المرشّحات الثلاثة، وما يبقى موتّر كثيف [3, 1, 3, 3].
| Panelاللوحة | What was removedما حُذف | Weights removedالأوزان المحذوفة | Sparsityنسبة التفرّغ | Survivorما يبقى |
|---|---|---|---|---|
| Fine-grainedدقيق (Fine-grained) | 31 single weights31 وزنًا مفردًا | 3131 | 57.4%57.4% | 54 slots with holes54 موضعًا مع ثقوب |
| Pattern-basedقائم على الأنماط (Pattern-based) | 5 of 9 cells in each of 6 kernels5 من 9 خلايا في كل نواة من النوى الست | 6 x 5 = 306 x 5 = 30 | 55.6%55.6% | 54 slots, one shape per kernel54 موضعًا، وشكل واحد لكل نواة |
| Vector-levelمستوى المتجه (Vector-level) | 11 of 18 kernel rows11 من 18 صفًّا من صفوف النوى | 11 x 3 = 3311 x 3 = 33 | 61.1%61.1% | 54 slots with empty rows54 موضعًا مع صفوف فارغة |
| Kernel-levelمستوى النواة (Kernel-level) | 2 of 6 kernels2 من 6 نوى | 2 x 9 = 182 x 9 = 18 | 33.3%33.3% | 54 slots with empty kernels54 موضعًا مع نوى فارغة |
| Channel-levelمستوى القنوات (Channel-level) | 1 of 2 input channels1 من قناتَي الإدخال | 3 x 9 = 273 x 9 = 27 | 50.0%50.0% | dense [3, 1, 3, 3]موتّر كثيف [3, 1, 3, 3] |
The ladder, rung by rungالسلّم درجةً درجة
Mao et al. organise four grains (fine, vector, kernel, filter) by how many dimensions each unit spans. The slide keeps their order, inserts pattern-based pruning between fine-grained and vector-level, and shows the 3-D rung as an input channel instead of Mao's filter (Mao et al., 2017, section 3.2). At the bottom, fine-grained pruning removes 0-D scalars anywhere. Pattern-based pruning keeps a small catalogue of fixed shapes inside each kernel, which the slide calls "like Tetris": the hardware knows the finite set of masks in advance instead of facing arbitrary holes. Niu et al. describe it as "fine-grained pruning patterns inside the coarse-grained structures" and, by compiling specialised code per pattern, ran networks on mobile CPUs and GPUs up to 44.5x faster than TensorFlow Lite and up to 11.4x faster than TVM with no accuracy loss (Niu et al., 2020). Vector-level pruning removes 1-D rows, W[o, i, r, :], of a kernel. Kernel-level pruning removes 2-D kernels, W[o, i, :, :]. At the top, channel pruning removes a 3-D slab: on the slide, an input channel W[:, i, :, :] across every filter.
يرتّب Mao et al. أربعة مستويات (الدقيق، والمتجه، والنواة، والمرشّح) بحسب عدد الأبعاد التي تمتد عليها كل وحدة. تحافظ الشريحة على ترتيبهم، وتُدخل التقليم بالأنماط (pattern-based) بين المستوى الدقيق ومستوى المتجه، وتعرض الدرجة ثلاثية الأبعاد (3-D) على أنها قناة إدخال بدلًا من المرشّح عند Mao (Mao et al., 2017، القسم 3.2). في الأسفل، يحذف التقليم الدقيق قيمًا عددية 0-D في أي مكان. التقليم بالأنماط يحتفظ بفهرس صغير من الأشكال الثابتة داخل كل نواة، وتصفه الشريحة بأنه "مثل Tetris": يعرف العتاد مسبقًا المجموعة المحدودة من الأقنعة بدلًا من مواجهة ثقوب عشوائية. يصفه Niu et al. بأنه "أنماط تقليم دقيقة داخل البنى الخشنة"، وبتوليد شيفرة مخصّصة لكل نمط شغّلوا الشبكات على معالجات CPU وGPU في الهواتف أسرع بما يصل إلى 44.5x من TensorFlow Lite وبما يصل إلى 11.4x من TVM دون أي خسارة في الدقة (Niu et al., 2020). تقليم مستوى المتجه يحذف صفوفًا أحادية البعد (1-D) من النواة، W[o, i, r, :]. وتقليم مستوى النواة يحذف أنوية ثنائية الأبعاد (2-D)، W[o, i, :, :]. وفي الأعلى، يحذف تقليم القنوات لوحًا ثلاثي الأبعاد (3-D): في الشريحة هو قناة إدخال W[:, i, :, :] عبر كل المرشّحات.
| Granularityمستوى الدقة | Unitالوحدة | Weights per unitالأوزان في الوحدة | Index costكلفة الفهارس | Runs efficiently onيعمل بكفاءة على |
|---|---|---|---|---|
| Fine-grainedدقيق (Fine-grained) | Any single weight (0-D)أي وزن مفرد (0-D) | 11 | One index per surviving weightفهرس واحد لكل وزن باقٍ | Custom sparse engines such as EIE or SCNNمحرّكات تفرّغ مخصّصة مثل EIE أو SCNN |
| Pattern-basedقائم على الأنماط (Pattern-based) | A fixed mask inside each kernelقناع ثابت داخل كل نواة | 5 per kernel5 لكل نواة | One pattern id per kernelمعرّف نمط واحد لكل نواة | Compilers that specialize code per pattern (PatDNN)مترجمات (compilers) تخصّص الشيفرة لكل نمط (PatDNN) |
| Vector-levelمستوى المتجه (Vector-level) | A row of a kernel (1-D)صف من نواة (1-D) | k_w = 3k_w = 3 | One index per surviving rowفهرس واحد لكل صف باقٍ | Custom 1-D convolution hardware such as Eyerissعتاد التفاف 1-D مخصّص مثل Eyeriss |
| Kernel-levelمستوى النواة (Kernel-level) | A whole k_h x k_w kernel (2-D)نواة كاملة k_h x k_w (2-D) | 99 | One index per surviving kernelفهرس واحد لكل نواة باقية | Custom 2-D convolution hardware (not stock dense libraries)عتاد التفاف 2-D مخصّص (وليس مكتبات الحساب الكثيف الجاهزة) |
| Channel-levelمستوى القنوات (Channel-level) | An input channel across all filters (3-D)قناة إدخال عبر جميع المرشّحات (3-D) | 2727 | None: the tensor shrinksلا شيء: الموتّر نفسه يصغر | Any dense CPU or GPU libraryأي مكتبة حساب كثيف على CPU أو GPU |
The right-hand column is the practical half of the story. Only the channel and filter rungs run faster on unmodified dense libraries, because the tensor simply shrinks. Kernel and vector sparsity line up with 2-D and 1-D convolution primitives (Winograd, Eyeriss-style 1-D units), which makes custom hardware simpler, but Mao et al. note they are still hard to accelerate on general-purpose processors. Pattern-based pruning needs compiler support (PatDNN) or dedicated support such as NVIDIA's 2:4 sparse tensor cores, and fine-grained sparsity needs accelerators such as EIE (Mao et al., 2017, section 6).
العمود الأيمن هو النصف العملي من القصة. درجتا القناة والمرشّح فقط تعملان أسرع على المكتبات الكثيفة دون تعديل، لأن الموتّر يصغر ببساطة. تفرّغ النواة وتفرّغ المتجه يتوافقان مع عمليات الالتفاف الأساسية 2-D و1-D (Winograd، ووحدات 1-D على نمط Eyeriss)، وهذا يبسّط العتاد المخصّص، لكن Mao et al. يلاحظون أنهما ما زالا صعبَي التسريع على المعالجات العامة. التقليم بالأنماط يحتاج إلى دعم من المترجم (PatDNN) أو دعم مخصّص مثل نوى الموتّرات المتفرّغة (sparse tensor cores) بنمط 2:4 من NVIDIA، والتفرّغ الدقيق يحتاج إلى مسرّعات مثل EIE (Mao et al., 2017، القسم 6).
Try every rung on one tensorجرّب كل درجة على موتّر واحد
The simulator below holds a random [3, 2, 3, 3] tensor and lets you prune it with any of the six units, including the filter unit that Mao et al. list alongside channels. It groups the weights by the chosen unit, scores each group with the L1 or L2 magnitude that part 05 develops, zeros the weakest groups until the target is met, and reports what survives. Watch three things as you switch units: the achieved sparsity snaps to coarser steps, the index count collapses as units grow, and only the channel and filter units ever produce a smaller dense tensor.
المحاكي أدناه يحمل موتّرًا عشوائيًا [3, 2, 3, 3] ويسمح لك بتقليمه بأي من الوحدات الست، ومنها وحدة المرشّح التي يذكرها Mao et al. إلى جانب القنوات. يجمّع الأوزان بحسب الوحدة المختارة، ويقيّم كل مجموعة بمقدار L1 أو L2 الذي يطوّره الجزء 05، ويصفّر المجموعات الأضعف حتى يبلغ الهدف، ثم يعرض ما يبقى. راقب ثلاثة أشياء وأنت تبدّل الوحدات: نسبة التفرّغ المحقّقة تقفز بخطوات أخشن، وعدد الفهارس ينهار كلما كبرت الوحدات، ووحدتا القناة والمرشّح وحدهما تنتجان موتّرًا كثيفًا أصغر.
- Unit
- Individual weight
- Weights per unit
- 1
- Slice
- W[o, i, r, c]
- Units removed
- 19 of 54
Units are ranked by the L1 norm of the weights they would remove, lowest first, and pruned until at least 19 of 54 weights are zero. Achieved sparsity snaps to whole units.تُرتَّب الوحدات حسب معيار L1 للأوزان التي ستزيلها، من الأصغر إلى الأكبر، وتُقلَّم حتى يصبح 19 وزنًا على الأقل من أصل 54أصفارًا. وتقفز التناثرية المحققة إلى مضاعفات الوحدات الكاملة.
The energy argument from part 01 also runs along this axis. Mao et al. simulated the SCNN sparse accelerator on VGG-16 and found that, at the same density, vector-level sparsity needs 30 to 35% fewer output memory references than fine-grained sparsity. Neighbouring surviving weights in a row write to the same output address, so SCNN can skip the repeated read and write of that address (Mao et al., 2017, section 6 and Table 4). Since a DRAM access costs about two hundred times a multiply, fewer memory references is where the energy goes, not fewer multiplies.
حجة الطاقة من الجزء 01 تسري أيضًا على هذا المحور. حاكى Mao et al. المسرّع المتفرّغ SCNN على VGG-16 ووجدوا أنه عند الكثافة نفسها يحتاج تفرّغ مستوى المتجه إلى مراجع ذاكرة للمخرجات أقل بنسبة 30 إلى 35% من التفرّغ الدقيق. الأوزان الباقية المتجاورة في صف واحد تكتب إلى عنوان المخرج نفسه، فيستطيع SCNN تخطّي القراءة والكتابة المكررة لذلك العنوان (Mao et al., 2017، القسم 6 والجدول 4). وبما أن الوصول إلى DRAM يكلّف نحو مئتي ضعف عملية الضرب، فإن تقليل مراجع الذاكرة هو حيث تذهب الطاقة، لا تقليل عمليات الضرب.
Recall
Order fine-grained, kernel-level, pattern-based, channel-level and vector-level pruning from irregular to regular.رتّب التقليم fine-grained وkernel-level وpattern-based وchannel-level وvector-level من غير المنتظم إلى المنتظم.
Quick checkاختبار سريع
Which granularity turns the weight tensor into a smaller dense tensor that needs no index storage at all?أي مستوى للدقة يحوّل موتّر الأوزان إلى موتّر كثيف أصغر لا يحتاج إلى تخزين أي فهارس على الإطلاق؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- Granularity is the unit you delete. Smaller units give more index choices, larger units give regular structure.الدقة (granularity) هي الوحدة التي تحذفها. الوحدات الأصغر تعطي خيارات أكثر لمواضع الحذف، والوحدات الأكبر تعطي بنية منتظمة.
- Coarse-grained masks are a subset of fine-grained masks, so at equal accuracy structured pruning reaches equal or lower sparsity, never higher, for the best achievable mask under the same retraining.أقنعة التقليم الخشن مجموعة جزئية من أقنعة التقليم الدقيق، لذلك عند الدقة نفسها يبلغ التقليم المنظَّم (structured) نسبة تفرّغ مساوية أو أقل، لا أعلى أبدًا، وذلك لأفضل قناع ممكن تحت إعادة التدريب نفسها.
- Fine-grained pruning is hard to accelerate because zeros sit anywhere. Channel or filter pruning yields a smaller dense tensor that any library runs.يصعب تسريع التقليم الدقيق لأن الأصفار قد تقع في أي مكان. أما تقليم القنوات أو المرشّحات فينتج موتّرًا (tensor) كثيفًا أصغر تشغّله أي مكتبة.
- Convolution weights are [c_o, c_i, k_h, k_w]. Slide 17's example holds 3 x 2 x 3 x 3 = 54 weights.أوزان الالتفاف بالشكل [c_o, c_i, k_h, k_w]. مثال الشريحة 17 يحوي 3 x 2 x 3 x 3 = 54 وزنًا.
- From irregular to regular: fine-grained, pattern-based, vector-level, kernel-level, channel-level.من غير المنتظم إلى المنتظم: fine-grained ثم pattern-based ثم vector-level ثم kernel-level ثم channel-level.
- Removing one kernel drops k_h x k_w weights, one input channel drops c_o x k_h x k_w, one filter drops c_i x k_h x k_w.حذف نواة واحدة يُسقط k_h x k_w من الأوزان، وحذف قناة إدخال واحدة يُسقط c_o x k_h x k_w، وحذف مرشّح واحد يُسقط c_i x k_h x k_w.
- Coarser grains share indices, so their storage penalty is smaller than their sparsity penalty (Mao et al.).الوحدات الأخشن تتشارك الفهارس، لذلك تكون خسارتها في التخزين أصغر من خسارتها في نسبة التفرّغ (Mao et al.).
Sourcesالمصادر
- Exploring the Granularity of Sparsity in Convolutional Neural NetworksPaperCVPR Workshops 2017, Mao, Han, Pool, Li, Liu, Wang and DallySource of the slide's figure, which adds a pattern-based rung and uses channel-level where the paper uses filter-level. Grain definitions in 3.2, accuracy at equal density in Table 1, storage with 4-bit indices in Table 2, hardware mapping and SCNN memory reference savings in section 6.مصدر شكل الشريحة، الذي يضيف درجة pattern-based ويستخدم channel-level حيث تستخدم الورقة filter-level. تعريفات مستويات الدقة في القسم 3.2، والدقة عند الكثافة نفسها في الجدول 1، والتخزين بفهارس 4-bit في الجدول 2، وربط المستويات بالعتاد ووفورات مراجع الذاكرة في SCNN في القسم 6.(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 EfficientML.ai, Lecture 3: Pruning and Sparsity (Part I)DocsMIT HAN LabThe course from which this lecture's slides are adapted.المقرر الذي اقتُبست منه شرائح هذه المحاضرة.(opens in a new tab)(يفتح في تبويب جديد)
- Learning Structured Sparsity in Deep Neural NetworksPaperNIPS 2016, Wen, Wu, Wang, Chen and LiStructured sparsity gives average layer-wise convolution speedups of 5.1x on CPU and 3.1x on GPU with standard libraries, against 3.0x and 0.9x for non-structured l1 sparsity (Table 4).يعطي التفرّغ المنظَّم متوسط تسريع لطبقات الالتفاف قدره 5.1x على CPU و3.1x على GPU باستخدام المكتبات القياسية، مقابل 3.0x و0.9x للتفرّغ غير المنظَّم بمعيار l1 (الجدول 4).(opens in a new tab)(يفتح في تبويب جديد)
- Pruning Filters for Efficient ConvNetsPaperICLR 2017, Li, Kadav, Durdanovic, Samet and GrafFilter pruning removes the feature map and the next layer's kernels; pruning m of n filters cuts m/n of the compute in both layers.تقليم المرشّحات يحذف خريطة الخصائص (feature map) ونوى الطبقة التالية المرتبطة بها، وتقليم m من n مرشّحًا يخفض m/n من الحساب في الطبقتين كلتيهما.(opens in a new tab)(يفتح في تبويب جديد)
- PatDNN: Achieving Real-Time DNN Execution on Mobile Devices with Pattern-based Weight PruningPaperASPLOS 2020, Niu et al.Pattern-based pruning as fine-grained patterns inside coarse-grained structures, up to 44.5x over TensorFlow Lite and up to 11.4x over TVM.التقليم القائم على الأنماط بوصفه أنماطًا دقيقة داخل بنى خشنة، بتسريع يصل إلى 44.5x مقارنة بـ TensorFlow Lite وإلى 11.4x مقارنة بـ TVM.(opens in a new tab)(يفتح في تبويب جديد)
- Structured Pruning of Deep Convolutional Neural NetworksPaperAnwar, Hwang and Sung, 2015Channel-wise, kernel-wise and intra-kernel strided sparsity, an early version of the ladder.تفرّغ على مستوى القنوات وعلى مستوى النوى وتفرّغ متخطٍّ (strided) داخل النواة، وهي نسخة مبكرة من السلّم.(opens in a new tab)(يفتح في تبويب جديد)
- Deep Learning, chapter 9: Convolutional NetworksBookGoodfellow, Bengio and Courville, MIT Press 2016Section 9.5 defines the 4-D kernel tensor K with output channel, input channel, row offset and column offset.يعرّف القسم 9.5 موتّر النواة رباعي الأبعاد K بقناة الإخراج وقناة الإدخال وإزاحة الصف وإزاحة العمود.(opens in a new tab)(يفتح في تبويب جديد)
- torch.nn.Conv2dDocsPyTorch documentationWeight shape (out_channels, in_channels / groups, kernel_size[0], kernel_size[1]).شكل الأوزان هو (out_channels, in_channels / groups, kernel_size[0], kernel_size[1]).(opens in a new tab)(يفتح في تبويب جديد)
- Learning both Weights and Connections for Efficient Neural NetworksPaperNIPS 2015, Han, Pool, Tran and DallyFine-grained magnitude pruning, the left end of the ladder.التقليم الدقيق بحسب مقدار الأوزان (magnitude pruning)، وهو الطرف الأيسر من السلّم.(opens in a new tab)(يفتح في تبويب جديد)
Part 04: Fine-grained, N:M and channel pruning in practiceالتقليم الدقيق وN:M وتقليم القنوات عمليًا
Trade-offs of each granularity with real numbers: fine-grained compression ratios, NVIDIA 2:4 pattern sparsity with its compressed format and accuracy table, and channel pruning with non-uniform per-layer sparsity versus uniform shrinking.مقايضات كل مستوى دقة بأرقام حقيقية: نسب الضغط في التقليم الدقيق، وتناثر النمط 2:4 من NVIDIA مع صيغته المضغوطة وجدول دقته، وتقليم القنوات مع تناثر غير منتظم لكل طبقة مقابل التصغير المنتظم.
5 concepts5 مفاهيم, ، slides 19-25الشرائح 19-25
Why this part mattersلماذا يهمّ هذا الجزء
Your research targets embedded deployment, where the question is never "how many weights can I remove" but "which removal makes this board faster". This part is where the granularity spectrum of part 03 meets real hardware.
It explains why a 9x compressed AlexNet (or a 13x compressed VGG-16) can run no faster on a GPU, why NVIDIA built a 2:4 pattern into its Ampere Tensor Cores, and why the model-compression papers you will cite (AMC, channel pruning) search for per-layer ratios instead of one global number. These are also the three most examinable facts in the lecture: which granularity gives speedup on commodity GPUs and why, what sparsity 2:4 means, and why non-uniform per-layer sparsity beats uniform shrink.
بحثك يستهدف النشر على الأنظمة المدمجة (embedded deployment)، حيث لا يكون السؤال أبدًا «كم وزنًا أستطيع أن أحذف» بل «أي حذف يجعل هذه اللوحة أسرع». هذا الجزء هو المكان الذي يلتقي فيه طيف درجة التقليم (granularity) من الجزء 03 بالعتاد الحقيقي.
يشرح لماذا قد لا يعمل AlexNet المضغوط بمقدار 9x (أو VGG-16 المضغوط بمقدار 13x) أسرع على GPU، ولماذا بنت NVIDIA نمط 2:4 داخل Tensor Cores في معمارية Ampere، ولماذا تبحث أوراق ضغط النماذج التي ستستشهد بها (AMC وتقليم القنوات channel pruning) عن نسب خاصة بكل طبقة بدلًا من رقم عام واحد. وهذه أيضًا أكثر ثلاث حقائق يُتوقع السؤال عنها في الامتحان من هذه المحاضرة: أي درجة تقليم تعطي تسريعًا على وحدات GPU التجارية الشائعة ولماذا، وما معنى تناثر 2:4، ولماذا يتفوق التناثر غير الموحّد لكل طبقة على التصغير الموحّد (uniform shrink).
By the end you canفي نهاية هذا الجزء ستستطيع
- Explain why fine-grained pruning gives the largest compression ratio but little or no speedup on GPUs with standard kernels, and name the hardware that can exploit it.تشرح لماذا يعطي التقليم الدقيق (fine-grained pruning) أكبر نسبة ضغط لكنه لا يعطي تسريعًا يُذكر، أو لا يعطي أي تسريع، على وحدات GPU التي تستخدم نوى (kernels) قياسية، وتسمّي العتاد الذي يستطيع الاستفادة منه.
- Define N:M sparsity under the NVIDIA convention, compute its sparsity for any N and M, and explain why the slide's wording is ambiguous.تعرّف تناثر N:M (N:M sparsity) وفق اصطلاح NVIDIA، وتحسب نسبة تناثره لأي قيمتين N وM، وتشرح لماذا صياغة الشريحة غامضة.
- Derive the 2:4 compressed layout and compute its memory saving for FP16 and INT8 values.تستنتج التخطيط المضغوط لنمط 2:4 وتحسب ما يوفّره من الذاكرة لقيم FP16 ولقيم INT8.
- State the pro and con of channel pruning and show how pruning one layer's channels shrinks two layers.تذكر ميزة تقليم القنوات (channel pruning) وعيبه، وتبيّن كيف يؤدي تقليم قنوات طبقة واحدة إلى تصغير طبقتين.
- Argue with AMC's measured Pixel 1 numbers why per-layer sparsity ratios beat uniform shrink at equal latency.تستدل بأرقام AMC المقاسة على هاتف Pixel 1 على أن نسب التناثر الخاصة بكل طبقة تتفوق على التصغير الموحّد (uniform shrink) عند زمن استجابة (latency) متساوٍ.
Go back to the very first picture of this lecture: a network before and after pruning, with individual synapses cut out while every neuron stays. That picture is fine-grained pruning, the synapse pruning of slide 4 seen through the lens of granularity. Slides 19 and 20 bring it back only to attach numbers to it, so treat them as a short callback rather than new material.
عُد إلى أول صورة في هذه المحاضرة: شبكة قبل التقليم وبعده، حيث قُطعت مشابك (synapses) منفردة وبقيت كل الخلايا العصبية. تلك الصورة هي fine-grained pruning (التقليم الدقيق)، أي synapse pruning في الشريحة 4 منظورًا إليه من زاوية granularity (درجة التقليم). الشريحتان 19 و20 تعيدانه فقط لتربطا به أرقامًا، فتعامل معهما على أنهما تذكير قصير لا مادة جديدة.
The numbers are the ones from part 02. Han et al. pruned AlexNet from 61 M to 6.7 M parameters and VGG-16 from 138 M to 10.3 M without losing accuracy, a pruning ratio of roughly 89% and 93% (Han, Pool, Tran and Dally, NIPS 2015). Those results are only possible because the method may zero any single weight, wherever it sits in the tensor. The slide calls this "flexible pruning indices": the set of surviving positions is unconstrained, so the algorithm can find redundant weights anywhere and usually reaches the largest compression ratio of all granularities.
الأرقام هي نفسها من الجزء 02. قلّم Han et al. شبكة AlexNet من 61 M إلى 6.7 M معامل، وشبكة VGG-16 من 138 M إلى 10.3 M، دون خسارة في الدقة، أي pruning ratio (نسبة تقليم) تقارب 89% و93% (Han, Pool, Tran and Dally, NIPS 2015). هذه النتائج ممكنة فقط لأن الطريقة يجوز لها تصفير أي وزن منفرد أينما كان موقعه في الموتّر (tensor). تسمي الشريحة ذلك «flexible pruning indices» (فهارس تقليم مرنة): مجموعة المواقع الباقية غير مقيّدة، فتستطيع الخوارزمية أن تجد الأوزان الزائدة في أي مكان، وعادةً تصل إلى أكبر نسبة ضغط بين كل درجات التقليم.
| Networkالشبكة | Parameters beforeالمعاملات قبل | Parameters afterالمعاملات بعد | Reductionالتخفيض |
|---|---|---|---|
| AlexNetAlexNet | 61 M61 M | 6.7 M6.7 M | 9x9x |
| VGG-16VGG-16 | 138 M138 M | 10.3 M10.3 M | 12x (paper: 13x)12x (في الورقة: 13x) |
| GoogleNetGoogleNet | 7 M7 M | 2.0 M2.0 M | 3.5x3.5x |
| ResNet-50ResNet-50 | 26 M26 M | 7.47 M7.47 M | 3.4x3.4x |
Why flexibility is expensive at run timeلماذا تكون المرونة مكلفة وقت التشغيل
Now look at what the flexibility leaves behind. After fine-grained pruning the weight tensor still has its original shape; it is simply riddled with zeros at irregular positions. A dense matrix multiply on a GPU does not know the zeros are there and multiplies them anyway, so the work is unchanged. To skip them you must store the weights in a sparse format such as CSR, CSC or COO, where every surviving value carries an index saying where it belongs. Mishra et al. note that these formats make memory accesses data dependent and that the index metadata can cost up to 200% of the weight storage when the weights are 8-bit (Mishra et al., 2021). Zhou et al. summarize the situation in one line: fine-grained sparsity "can achieve a high compression ratio but is not hardware friendly and hence receives limited speed gains" (Zhou et al., ICLR 2021).
انظر الآن إلى ما تتركه المرونة خلفها. بعد التقليم الدقيق يبقى موتّر الأوزان بشكله الأصلي؛ هو فقط مليء بالأصفار في مواقع غير منتظمة. ضرب المصفوفات الكثيف (dense matrix multiply) على GPU لا يعرف أن الأصفار موجودة فيضربها على أي حال، فيبقى العمل كما هو. لكي تتخطاها يجب أن تخزّن الأوزان في sparse format (صيغة متناثرة) مثل CSR أو CSC أو COO، حيث تحمل كل قيمة باقية فهرسًا يحدد مكانها. يشير Mishra et al. إلى أن هذه الصيغ تجعل الوصول إلى الذاكرة معتمدًا على البيانات، وأن البيانات الوصفية للفهارس قد تكلّف حتى 200% من مساحة تخزين الأوزان عندما تكون الأوزان بدقة 8 بت (Mishra et al., 2021). ويلخص Zhou et al. الوضع في سطر واحد: التناثر الدقيق «يمكن أن يحقق نسبة ضغط عالية لكنه غير ملائم للعتاد، ولذلك لا يحصل إلا على مكاسب محدودة في السرعة» (Zhou et al., ICLR 2021).
That is why the red line on slide 20 matters more than the table. Speedup from fine-grained sparsity needs hardware built around indices. Han's own EIE accelerator is the example the MIT source deck names: by reading compressed weights and skipping zero activations, it ran fully-connected layers 189x faster than a CPU and 13x faster than a GPU running the uncompressed network (Han et al., ISCA 2016). With sparse kernels the picture depends on batch size: in EIE's own measurements cuSPARSE ran pruned FC layers 4x to 9x faster than dense at batch 1 on a Titan X, but slower at batch 64, which is why the slide says "not GPU (easily)". On an ordinary GPU with dense kernels, the same pruned network runs at roughly dense speed.
لهذا السبب يهم الخط الأحمر في الشريحة 20 أكثر من الجدول. التسريع من sparsity (التناثر) الدقيق يحتاج إلى عتاد مبني حول الفهارس. مسرّع EIE الذي صممه Han نفسه هو المثال الذي تذكره عروض MIT الأصلية: بقراءة الأوزان المضغوطة وتخطي التفعيلات (activations) الصفرية، شغّل الطبقات المتصلة بالكامل (fully-connected) أسرع بمقدار 189x من CPU وأسرع بمقدار 13x من GPU يشغّل الشبكة غير المضغوطة (Han et al., ISCA 2016). مع النوى المتناثرة (sparse kernels) تعتمد الصورة على حجم الدفعة (batch size): في قياسات EIE نفسها شغّلت مكتبة cuSPARSE طبقات FC المقلّمة أسرع من الكثيفة بمقدار 4x إلى 9x عند دفعة حجمها 1 على Titan X، لكنها كانت أبطأ عند دفعة حجمها 64، ولهذا تقول الشريحة «not GPU (easily)» (ليس على GPU بسهولة). على GPU عادي بنوى كثيفة، تعمل الشبكة المقلّمة نفسها بسرعة قريبة من سرعة الشبكة الكثيفة.
EIE on compressed fully-connected layers (Han et al., ISCA 2016)EIE على الطبقات المتصلة بالكامل المضغوطة (Han et al., ISCA 2016)
- Speedup over CPUالتسريع مقارنةً بـ CPU
- 189x189x
- Speedup over GPUالتسريع مقارنةً بـ GPU
- 13x13x
- Energy efficiency over GPUكفاءة الطاقة مقارنةً بـ GPU
- 3400x3400x
Recall
Why does fine-grained pruning usually reach a larger compression ratio than channel pruning, and why does that not translate into GPU speedup?لماذا يصل التقليم الدقيق عادةً إلى نسبة ضغط أكبر من تقليم القنوات، ولماذا لا يتحول ذلك إلى تسريع على GPU؟
Quick checkاختبار سريع
A layer is pruned to 90 percent unstructured sparsity and run on a plain GPU with dense kernels. What happens to latency?قُلّمت طبقة إلى تناثر غير منظّم بنسبة 90 بالمئة وشُغّلت على GPU عادي بنوى كثيفة. ماذا يحدث لزمن الاستجابة؟
Take one row of eight FP16 weights and split it into two groups of four. In each group keep the two largest magnitudes and zero the other two. Every group now has exactly two zeros and two nonzeros, so the row is 50% sparse, and so is every other row treated the same way. That is 2:4 sparsity, the classic case of N:M sparsity and the reason the lecture lists pattern-based pruning as its own step on the granularity spectrum.
خذ صفًا واحدًا من ثمانية أوزان بصيغة FP16 وقسّمه إلى مجموعتين من أربعة. في كل مجموعة احتفظ بأكبر قيمتين من حيث المقدار (magnitude) وصفّر القيمتين الأخريين. أصبحت كل مجموعة تحتوي بالضبط على صفرين وقيمتين غير صفريتين، فيكون الصف متناثرًا بنسبة 50%، وكذلك كل صف آخر يُعامل بالطريقة نفسها. هذا هو 2:4 sparsity، الحالة الكلاسيكية من N:M sparsity، وهو سبب أن المحاضرة تضع pattern-based pruning (التقليم القائم على نمط) خطوةً مستقلة على طيف درجات التقليم.
The general rule needs one careful sentence, because the slide's sentence is ambiguous. In NVIDIA's definition, which is the one hardware implements, an N:M pattern allows at most N nonzero values in every contiguous group of M. The Ampere whitepaper describes 2:4 as a matrix "that allows two non-zero values in every four-entry vector", and Mishra et al. write of "the 2 nonzero values in each group of 4" (NVIDIA, 2020; Mishra et al., 2021). Slide 21 instead says that "N of them is pruned". For 2:4 the two readings agree, since two kept and two pruned are the same thing. For any other pattern they do not.
القاعدة العامة تحتاج إلى جملة دقيقة، لأن جملة الشريحة غامضة. في تعريف NVIDIA، وهو التعريف الذي ينفّذه العتاد، يسمح نمط N:M بـ N قيم غير صفرية على الأكثر في كل مجموعة متجاورة من M. تصف الورقة البيضاء لمعمارية Ampere نمط 2:4 بأنه مصفوفة «تسمح بقيمتين غير صفريتين في كل متجه من أربعة عناصر»، ويكتب Mishra et al. عن «القيمتين غير الصفريتين في كل مجموعة من 4» (NVIDIA, 2020; Mishra et al., 2021). أما الشريحة 21 فتقول إن «N of them is pruned» (يُقلَّم N منها). في نمط 2:4 تتفق القراءتان، لأن الاحتفاظ باثنتين وتقليم اثنتين شيء واحد. أما في أي نمط آخر فلا تتفقان.
Why a pattern is the middle of the spectrumلماذا يقع النمط في منتصف الطيف
Inside each group of four the pattern is still fine-grained: any two of the four positions may survive, six possible masks, chosen by magnitude. Across the matrix it is rigidly structured: every group holds exactly two values, no more and no fewer. Mishra et al. point out what this buys: because the sparsity is constant across the matrix, "there is no indirection required; a nonzero value's position in memory can be determined from the compression rate directly" (Mishra et al., 2021). The hardware always knows that group g starts at value slot 2g. That is the difference between a lookup and an address calculation, and it is what makes fine-grained-in-the-small, structured-in-the-large worth a place of its own.
داخل كل مجموعة من أربعة يبقى النمط دقيقًا: أي اثنين من المواقع الأربعة يمكن أن يبقيا، أي ستة أقنعة (masks) ممكنة، يُختار منها حسب المقدار. وعلى مستوى المصفوفة كلها هو منظّم بصرامة: كل مجموعة تحمل قيمتين بالضبط، لا أكثر ولا أقل. يوضح Mishra et al. ما يكسبه ذلك: لأن التناثر ثابت عبر المصفوفة، «لا حاجة إلى أي إحالة غير مباشرة (indirection)؛ يمكن تحديد موقع القيمة غير الصفرية في الذاكرة من معدل الضغط مباشرةً» (Mishra et al., 2021). العتاد يعرف دائمًا أن المجموعة g تبدأ عند خانة القيمة 2g. هذا هو الفرق بين البحث في جدول (lookup) وحساب عنوان، وهو ما يجعل النمط «الدقيق على المستوى الصغير، المنظّم على المستوى الكبير» جديرًا بمكان مستقل.
The compressed formatالصيغة المضغوطة
The rule also fixes the storage layout, which is the right-hand panel of slide 21. An R by C dense matrix becomes an R by C/2 block of nonzero values plus an R by C/2 block of 2-bit indices, where each index records the position, 0 to 3, of a kept value inside its group of four. Two bits are enough because a group has only four positions. One corner case keeps the format regular: if a group happens to have three or four zeros after training, two values are stored anyway, padded with zeros as needed (Mishra et al., 2021).
القاعدة تحدد أيضًا تخطيط التخزين، وهو اللوحة اليمنى في الشريحة 21. المصفوفة الكثيفة بحجم R by C تصبح كتلة بحجم R by C/2 من القيم غير الصفرية، مع كتلة بحجم R by C/2 من 2-bit indices (فهارس من بتّين)، حيث يسجّل كل فهرس موقع القيمة المحتفظ بها داخل مجموعتها الرباعية، من 0 إلى 3. البتّان كافيان لأن المجموعة فيها أربعة مواقع فقط. وهناك حالة طرفية واحدة تحفظ انتظام الصيغة: إذا صادف أن مجموعة فيها ثلاثة أصفار أو أربعة بعد التدريب، تُخزَّن قيمتان على أي حال، مع حشوها بأصفار عند الحاجة (Mishra et al., 2021).
Worked exampleمثال محلول
Compressing an 8 by 8 FP16 matrixضغط مصفوفة 8 في 8 بصيغة FP16
Dense storageالتخزين الكثيف
64 values at 16 bits each: 64 x 16 = 1024 bits.64 قيمة، كل منها 16 bits: 64 x 16 = 1024 bits.Kept valuesالقيم المحتفظ بها
Half survive, 32 values: 32 x 16 = 512 bits.يبقى النصف، أي 32 قيمة: 32 x 16 = 512 bits.Indicesالفهارس
One 2-bit position per kept value: 32 x 2 = 64 bits.موقع من بتّين لكل قيمة محتفظ بها: 32 x 2 = 64 bits.Compressed totalالمجموع بعد الضغط
512 + 64 = 576 bits.512 + 64 = 576 bits.Resultالنتيجة
1024 / 576 = 1.78x smaller, 43.75% saved. Per group of four the arithmetic is 64 bits versus 36 bits, which is exact for a matrix of any size.أصغر بمقدار 1024 / 576 = 1.78x، أي توفير 43.75%. لكل مجموعة من أربعة يكون الحساب 64 bits مقابل 36 bits، وهذا دقيق لمصفوفة بأي حجم.
2:4 storage for FP16 weights, 8 by 8 matrixتخزين 2:4 لأوزان FP16، مصفوفة 8 في 8
- Dense FP16FP16 كثيف
- 1024 bits1024 بت
- Kept valuesالقيم المحتفظ بها
- 512 bits512 بت
- 2-bit indicesفهارس من بتّين
- 64 bits64 بت
- Compressed totalالإجمالي بعد الضغط
- 576 bits576 بت
- Ratioالنسبة
- 1.78x1.78x
- Index overhead on the kept valuesكلفة الفهارس نسبةً إلى القيم المحتفظ بها
- 12.5%12.5%
The same matrix with INT8 weightsالمصفوفة نفسها بأوزان INT8
- Dense INT8INT8 كثيف
- 512 bits512 بت
- Kept valuesالقيم المحتفظ بها
- 256 bits256 بت
- 2-bit indicesفهارس من بتّين
- 64 bits64 بت
- Compressed totalالإجمالي بعد الضغط
- 320 bits320 بت
- Ratioالنسبة
- 1.6x1.6x
- Index overhead on the kept valuesكلفة الفهارس نسبةً إلى القيم المحتفظ بها
- 25%25%
The two tables carry an insight that matters when you combine pruning with the quantization lectures: the index costs two bits whatever the value width, so the narrower the value type the more the index costs relatively. Mishra et al. give the same figures, about 44% saved for 16-bit and about 38% for 8-bit weights, which is why NVIDIA says the format cuts storage and bandwidth by "almost" 2x rather than exactly 2x (Mishra et al., 2021; NVIDIA, 2020).
يحمل الجدولان فكرة مهمة عندما تجمع التقليم مع محاضرات التكميم (quantization): الفهرس يكلّف بتّين مهما كان عرض القيمة، فكلما ضاق نوع القيمة زادت كلفة الفهرس نسبيًا. يعطي Mishra et al. الأرقام نفسها، توفير نحو 44% للأوزان بدقة 16 بت ونحو 38% للأوزان بدقة 8 بت، ولهذا تقول NVIDIA إن الصيغة تخفض التخزين وعرض النطاق (bandwidth) «تقريبًا» بمقدار 2x وليس 2x بالضبط (Mishra et al., 2021; NVIDIA, 2020).
Where the 2x speedup comes fromمن أين يأتي تسريع 2x
Storage is only half of the payoff. The Ampere A100 added Sparse Tensor Core instructions that take a 2:4 compressed operand and, in the whitepaper's words, "skip the compute on entries that have zero values, resulting in a doubling of the Tensor Core compute throughput": a 16 x 8 x 16 matrix multiply instruction completes in half the cycles of its dense counterpart (NVIDIA, 2020). Software reaches it through TensorRT 8 and cuSPARSELt; the slide's link covers the TensorRT 8.0 path. Zhou et al. restate the same about 2x for the A100, citing NVIDIA rather than measuring it themselves (Zhou et al., ICLR 2021).
التخزين نصف المكسب فقط. أضافت Ampere A100 تعليمات Sparse Tensor Core التي تأخذ مُعامَلًا (operand) مضغوطًا بنمط 2:4، وبتعبير الورقة البيضاء «تتخطى الحساب على المدخلات ذات القيم الصفرية، مما يؤدي إلى مضاعفة إنتاجية الحساب في Tensor Core»: تعليمة ضرب مصفوفات بحجم 16 x 8 x 16 تكتمل في نصف عدد الدورات التي تحتاجها نظيرتها الكثيفة (NVIDIA, 2020). تصل البرمجيات إليها عبر TensorRT 8 وcuSPARSELt؛ ورابط الشريحة يغطي مسار TensorRT 8.0. ويعيد Zhou et al. ذكر الرقم نفسه، نحو 2x على A100، نقلًا عن NVIDIA لا بقياس خاص بهم (Zhou et al., ICLR 2021).
Try the pattern yourself below. Switch the convention from "N nonzero" to "N pruned" at 2:4 and nothing changes; switch it at 1:4 and the sparsity flips from 75% to 25%, which is exactly the ambiguity flagged above. Then toggle FP16 to INT8 and watch the index overhead double.
جرّب النمط بنفسك في الأسفل. غيّر الاصطلاح من «N nonzero» إلى «N pruned» عند 2:4 ولن يتغير شيء؛ غيّره عند 1:4 وسينقلب التناثر من 75% إلى 25%، وهذا بالضبط الغموض المشار إليه أعلاه. ثم بدّل من FP16 إلى INT8 وراقب كلفة الفهرس الإضافية وهي تتضاعف.
Recall
Define 2:4 sparsity, give its sparsity percentage, and state the storage layout.عرّف تناثر 2:4، واذكر نسبة تناثره، وصِف تخطيط تخزينه.
Recall
Under the NVIDIA convention, what is the sparsity of 1:4 and of 4:8?وفق اصطلاح NVIDIA، ما نسبة تناثر 1:4، وما نسبة تناثر 4:8؟
Quick checkاختبار سريع
A weight matrix satisfies the 2:4 pattern. What fraction of its weights is zero?مصفوفة أوزان تحقق نمط 2:4. ما نسبة أوزانها التي تساوي صفرًا؟
Quick checkاختبار سريع
Using NVIDIA's convention, how many weights in every group of four are zero under a 1:4 pattern?وفق اصطلاح NVIDIA، كم وزنًا في كل مجموعة من أربعة يساوي صفرًا في نمط 1:4؟
A format that halves storage and doubles matmul throughput is worth nothing if the network gets worse. So look at one row first: ResNet-50 on ImageNet scores 76.1% top-1 dense in FP16 and 76.2% after 2:4 pruning. Half the weights are gone and the accuracy is unchanged; the extra 0.1 is run-to-run noise, not a gain.
صيغة تخفض التخزين إلى النصف وتضاعف إنتاجية ضرب المصفوفات لا قيمة لها إذا ساءت الشبكة. لذلك انظر إلى صف واحد أولًا: ResNet-50 على ImageNet يحقق 76.1% في top-1 وهو كثيف بصيغة FP16، و76.2% بعد تقليم 2:4. ذهب نصف الأوزان وبقيت الدقة كما هي؛ والزيادة 0.1 مجرد ضجيج بين تشغيل وآخر، لا مكسب حقيقي.
The rule that produced that row is NVIDIA's three-step recipe. Train the dense network as usual. Prune it to 2:4 by keeping the two largest magnitudes in every group of four, which fixes the mask. Then retrain with the mask held fixed, using the original schedule and hyperparameters, so the survivors absorb the job of the pruned weights. That last step is the fine-tuning loop of part 02 applied under a structural constraint, and the whitepaper reports "virtually no loss in inferencing accuracy" across dozens of networks with it (NVIDIA, 2020). The choice of mask by magnitude inside each group previews the magnitude criterion of part 05.
القاعدة التي أنتجت ذلك الصف هي وصفة NVIDIA ذات الخطوات الثلاث. درّب الشبكة الكثيفة كالمعتاد. ثم قلّمها إلى 2:4 بالاحتفاظ بأكبر قيمتين من حيث المقدار في كل مجموعة من أربعة، وهذا يثبّت mask (القناع). ثم أعد التدريب مع إبقاء القناع ثابتًا، باستخدام الجدول الزمني والمعاملات الفائقة (hyperparameters) الأصلية، لكي تتولى الأوزان الباقية مهمة الأوزان المقلّمة. هذه الخطوة الأخيرة هي حلقة fine-tuning (الضبط الدقيق) من الجزء 02 مطبّقةً تحت قيد بنيوي، وتذكر الورقة البيضاء «عدم وجود خسارة تُذكر تقريبًا في دقة الاستدلال» عبر عشرات الشبكات باستخدامها (NVIDIA, 2020). واختيار القناع حسب المقدار داخل كل مجموعة يمهّد لمعيار المقدار (magnitude criterion) في الجزء 05.
| Networkالشبكة | Data setمجموعة البيانات | Metricالمقياس | Dense FP16FP16 كثيف | Sparse FP16FP16 متناثر | Changeالتغيّر |
|---|---|---|---|---|---|
| ResNet-50ResNet-50 | ImageNetImageNet | Top-1Top-1 | 76.176.1 | 76.276.2 | +0.1+0.1 |
| ResNeXt-101_32x8dResNeXt-101_32x8d | ImageNetImageNet | Top-1Top-1 | 79.379.3 | 79.379.3 | 0.00.0 |
| XceptionXception | ImageNetImageNet | Top-1Top-1 | 79.279.2 | 79.279.2 | 0.00.0 |
| SSD-RN50SSD-RN50 | COCO 2017COCO 2017 | bbAPbbAP | 24.824.8 | 24.824.8 | 0.00.0 |
| MaskRCNN-RN50MaskRCNN-RN50 | COCO 2017COCO 2017 | bbAPbbAP | 37.937.9 | 37.937.9 | 0.00.0 |
| FairSeq TransformerFairSeq Transformer | EN-DE WMT'14EN-DE WMT'14 | BLEUBLEU | 28.228.2 | 28.528.5 | +0.3+0.3 |
| BERT-LargeBERT-Large | SQuAD v1.1SQuAD v1.1 | F1F1 | 91.991.9 | 91.991.9 | 0.00.0 |
Read the table across, never down. The seven rows use four different metrics (top-1 accuracy, box AP, BLEU and F1), so the only meaningful comparison is dense versus sparse within one row. Read that way the evidence is unusually broad: image classification, object detection, instance segmentation, translation and question answering, spanning convolutional networks and Transformers, and not one row lost measurable accuracy. The whitepaper's explanation is that after training "only a subset of weights have acquired a meaningful purpose", and the retraining step lets the network re-adapt around the fixed mask (NVIDIA, 2020).
اقرأ الجدول أفقيًا، ولا تقرأه عموديًا أبدًا. الصفوف السبعة تستخدم أربعة مقاييس مختلفة (دقة top-1، وbox AP، وBLEU، وF1)، فالمقارنة الوحيدة ذات المعنى هي الكثيف مقابل المتناثر داخل الصف الواحد. وبهذه القراءة تكون الأدلة واسعة على نحو غير معتاد: تصنيف الصور، واكتشاف الأجسام، وتجزئة المثيلات (instance segmentation)، والترجمة، والإجابة عن الأسئلة، وتشمل الشبكات الالتفافية وTransformers، ولم يخسر صف واحد دقة قابلة للقياس. وتفسير الورقة البيضاء هو أنه بعد التدريب «لا تكتسب إلا مجموعة جزئية من الأوزان غرضًا ذا معنى»، وخطوة إعادة التدريب تسمح للشبكة بأن تتكيف من جديد حول القناع الثابت (NVIDIA, 2020).
Recall
Name the three steps of NVIDIA's 2:4 recipe and give one row of evidence that it holds accuracy.سمِّ الخطوات الثلاث في وصفة 2:4 من NVIDIA، وأعطِ صفًا واحدًا من الأدلة على أنها تحافظ على الدقة.
Now the coarse end of the spectrum. A convolution layer with 64 output channels is pruned at sparsity 0.5: thirty-two whole filters are deleted and the layer becomes a 32-channel layer. Nothing about the result is sparse. Its weight tensor, in the [c_o, c_i, k_h, k_w] layout of part 03, is simply smaller in the c_o dimension, and the next layer, which consumed those channels, is smaller in its c_i dimension.
الآن الطرف الخشن من الطيف. طبقة التفاف (convolution) لها 64 قناة خرج تُقلَّم بنسبة تناثر 0.5: تُحذف اثنان وثلاثون مرشّحًا (filter) كاملًا وتصبح الطبقة بـ 32 قناة. لا شيء في النتيجة متناثر. موتّر أوزانها، بالتخطيط [c_o, c_i, k_h, k_w] من الجزء 03، صار ببساطة أصغر في البعد c_o، والطبقة التالية التي كانت تستهلك تلك القنوات صارت أصغر في بعدها c_i.
That is the whole argument for channel pruning, and both sides of the slide's trade-off follow from it. Pro: direct speedup on any hardware, because a network with fewer channels does less work in every dense library that exists. Li et al. put it precisely: removing whole filters "does not result in sparse connectivity patterns", so it "does not need the support of sparse convolution libraries and can work with existing efficient BLAS libraries" (Li et al., ICLR 2017). He, Zhang and Sun report a 5x speedup on VGG-16 for a 0.3% increase in error and 2x on ResNet for 1.4% (He, Zhang and Sun, ICCV 2017). Con: a smaller compression ratio, because a channel is a much coarser unit than a weight. Keeping a channel means keeping all of its weights, including the weak ones that fine-grained pruning would have dropped, so you cannot reach the 9x to 13x of slide 20.
هذه هي الحجة الكاملة لصالح channel pruning (تقليم القنوات)، ومنها ينتج طرفا المقايضة في الشريحة. الميزة: تسريع مباشر على أي عتاد، لأن الشبكة ذات القنوات الأقل تؤدي عملًا أقل في كل مكتبة كثيفة موجودة. يعبّر Li et al. عن ذلك بدقة: إزالة مرشّحات كاملة (removing whole filters) «لا تؤدي إلى أنماط اتصال متناثرة»، ولذلك «لا تحتاج إلى دعم مكتبات الالتفاف المتناثر ويمكنها العمل مع مكتبات BLAS الفعالة الموجودة» (Li et al., ICLR 2017). ويذكر He, Zhang and Sun تسريعًا بمقدار 5x على VGG-16 مقابل زيادة في الخطأ قدرها 0.3%، و2x على ResNet مقابل 1.4% (He, Zhang and Sun, ICCV 2017). العيب: نسبة ضغط أصغر، لأن القناة وحدة أخشن بكثير من الوزن. الاحتفاظ بقناة يعني الاحتفاظ بكل أوزانها، بما فيها الأوزان الضعيفة التي كان التقليم الدقيق سيُسقطها، لذلك لا تستطيع الوصول إلى 9x حتى 13x كما في الشريحة 20.
Pruning one layer shrinks twoتقليم طبقة واحدة يصغّر طبقتين
The example above hid a compounding effect that the slide's bar chart depends on. Pruning the output channels of layer l removes rows from its own weight tensor and columns from layer l+1, because the input channels of l+1 are the output channels of l. The per-layer sparsity values on slide 24 therefore do not add up the way they look; they multiply through the chain.
أخفى المثال السابق أثرًا تراكميًا يعتمد عليه المخطط الشريطي في الشريحة. تقليم قنوات الخرج في الطبقة l يزيل صفوفًا من موتّر أوزانها هي وأعمدةً من الطبقة l+1، لأن قنوات الدخل في l+1 هي قنوات الخرج من l. لذلك فإن قيم sparsity (التناثر) لكل طبقة في الشريحة 24 لا تُجمع كما تبدو؛ بل تتضاعف بعضها في بعض عبر السلسلة.
Worked exampleمثال محلول
Five conv layers, uniform 0.3 versus the slide's per-layer sparsitiesخمس طبقات التفاف: تناثر موحّد 0.3 مقابل نسب التناثر الخاصة بكل طبقة في الشريحة
Set the baselineحدّد خط الأساس
Five stacked 3 x 3 layers, each 64 in and 64 out: 64 x 64 x 9 = 36,864 weights each, 184,320 in total. Layer 0's inputs come from the stem, which is not pruned, so its input columns are never removed.خمس طبقات 3 x 3 متراصّة، لكل منها 64 قناة دخل و64 قناة خرج: 64 x 64 x 9 = 36,864 وزنًا لكل طبقة، و184,320 في المجموع. مدخلات الطبقة 0 تأتي من الجذع (stem) غير المقلّم، فلا تُزال أعمدة دخلها أبدًا.Write the kept fraction of one layerاكتب النسبة المحتفظ بها لطبقة واحدة
Layer l keeps (1 - s_(l-1)) x (1 - s_l) of its weights: its input columns follow the previous layer's output sparsity, its output rows follow its own.الطبقة l تحتفظ بـ (1 - s_(l-1)) x (1 - s_l) من أوزانها: أعمدة دخلها تتبع تناثر خرج الطبقة السابقة، وصفوف خرجها تتبع تناثرها هي.Uniform shrink, s = 0.3 everywhereتصغير موحّد، s = 0.3 في كل مكان
Layer 0 keeps 0.70, every later layer keeps 0.7 x 0.7 = 0.49.الطبقة 0 تحتفظ بـ 0.70، وكل طبقة بعدها تحتفظ بـ 0.7 x 0.7 = 0.49.Per-layer sparsities 0.5, 0.3, 0.7, 0.2, 0.3نسب تناثر لكل طبقة: 0.5، 0.3، 0.7، 0.2، 0.3
Layer 0 keeps 0.50, then 0.35, 0.21, 0.24, 0.56.الطبقة 0 تحتفظ بـ 0.50، ثم 0.35، و0.21، و0.24، و0.56.Resultالنتيجة
Uniform shrink at 0.3 keeps 53.2% of the weights, uniform shrink at the per-layer set's mean of 0.4 keeps 40.8%, and the slide's per-layer set keeps 37.2%. Conv MACs scale with c_i x c_o, so the same fractions apply to compute.Uniform shrink (التصغير الموحّد) عند 0.3 يحتفظ بـ 53.2% من الأوزان، والتصغير الموحّد عند متوسط المجموعة الخاصة بكل طبقة وهو 0.4 يحتفظ بـ 40.8%، والمجموعة الخاصة بكل طبقة في الشريحة تحتفظ بـ 37.2%. عدد MACs في الالتفاف يتناسب مع c_i x c_o، فتنطبق النسب نفسها على الحساب.
| Layerالطبقة | Uniform 0.3 keptالمحتفظ به عند 0.3 موحّدة | Uniform 0.4 keptالمحتفظ به عند 0.4 موحّدة | Per-layer keptالمحتفظ به بنسب لكل طبقة |
|---|---|---|---|
| Layer 0الطبقة 0 | 1.0 x 0.7 = 0.701.0 x 0.7 = 0.70 | 1.0 x 0.6 = 0.601.0 x 0.6 = 0.60 | 1.0 x 0.5 = 0.501.0 x 0.5 = 0.50 |
| Layer 1الطبقة 1 | 0.7 x 0.7 = 0.490.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.360.6 x 0.6 = 0.36 | 0.5 x 0.7 = 0.350.5 x 0.7 = 0.35 |
| Layer 2الطبقة 2 | 0.7 x 0.7 = 0.490.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.360.6 x 0.6 = 0.36 | 0.7 x 0.3 = 0.210.7 x 0.3 = 0.21 |
| Layer 3الطبقة 3 | 0.7 x 0.7 = 0.490.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.360.6 x 0.6 = 0.36 | 0.3 x 0.8 = 0.240.3 x 0.8 = 0.24 |
| Layer 4الطبقة 4 | 0.7 x 0.7 = 0.490.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.360.6 x 0.6 = 0.36 | 0.8 x 0.7 = 0.560.8 x 0.7 = 0.56 |
| Total keptإجمالي المحتفظ به | 2.66 / 5 = 53.2%2.66 / 5 = 53.2% | 2.04 / 5 = 40.8%2.04 / 5 = 40.8% | 1.86 / 5 = 37.2%1.86 / 5 = 37.2% |
Uniform shrink versus channel pruneالتصغير الموحّد مقابل تقليم القنوات
The inequality on slide 24, "Uniform Shrink < Channel Prune", compares accuracy at a comparable budget. Uniform shrink applies one ratio to every layer, which is what a MobileNet width multiplier does. It ignores the fact that layers differ in how much redundancy they carry: some tolerate 70% removal and others only 20%. Channel pruning proper starts from the trained wide network, chooses a ratio per layer, deletes the least useful channels in each, and fine-tunes. Under the same latency or MAC budget, spending the cuts where they hurt least keeps more accuracy. Slide 24 defers the obvious question, how to find those ratios; the sensitivity analysis of lecture 04-2 (Pruning ratios, fine-tuning and sparse hardware) and the AMC search of the next concept are the answers.
المتباينة في الشريحة 24، «Uniform Shrink < Channel Prune»، تقارن الدقة عند ميزانية متقاربة. التصغير الموحّد يطبّق نسبة واحدة على كل طبقة، وهذا ما يفعله مُضاعِف العرض (width multiplier) في MobileNet. وهو يتجاهل أن الطبقات تختلف في مقدار الزيادة التي تحملها: بعضها يتحمل إزالة 70% وبعضها 20% فقط. أما تقليم القنوات بمعناه الصحيح فيبدأ من الشبكة العريضة المدرّبة، ويختار نسبة لكل طبقة، ويحذف أقل القنوات فائدة في كل منها، ثم يضبطها ضبطًا دقيقًا. تحت ميزانية زمن استجابة أو MACs نفسها، يحافظ توزيع القطع حيث يضر أقل على دقة أكبر. تؤجل الشريحة 24 السؤال البديهي، وهو كيف نجد تلك النسب؛ والجواب هو تحليل الحساسية في المحاضرة 04-2 (Pruning ratios, fine-tuning and sparse hardware) وبحث AMC في المفهوم التالي.
Recall
State the pro and con of channel pruning in one sentence each.اذكر ميزة تقليم القنوات وعيبه، في جملة واحدة لكل منهما.
Quick checkاختبار سريع
Which granularity speeds up inference on any GPU that has only dense BLAS libraries?أي درجة تقليم تسرّع الاستدلال على أي GPU لا يملك إلا مكتبات BLAS كثيفة؟
On a Google Pixel 1, the full-width MobileNet takes 123.3 ms per image and scores 70.6% ImageNet top-1. Shrinking it uniformly with the 0.75 width multiplier brings the latency down to 72.3 ms but the accuracy down to 68.4%. The channel-pruned model found by AMC runs in 68.3 ms at 70.5%: as fast as the shrunken model, 2.1 points more accurate, and only 0.1 below the full model at 1.81x its speed (He et al., ECCV 2018).
على هاتف Google Pixel 1، يستغرق MobileNet بكامل عرضه 123.3 ms لكل صورة ويحقق 70.6% في ImageNet top-1. تصغيره تصغيرًا موحّدًا (uniform shrink) بمضاعف العرض 0.75 يخفض زمن الاستجابة إلى 72.3 ms لكنه يخفض الدقة إلى 68.4%. أما النموذج المقلّم القنوات (channel-pruned) الذي وجده AMC فيعمل في 68.3 ms بدقة 70.5%: بسرعة النموذج المصغّر نفسها، وأدق منه بـ 2.1 نقطة، وأقل من النموذج الكامل بـ 0.1 فقط مع سرعة تبلغ 1.81x من سرعته (He et al., ECCV 2018).
AMC (AutoML for Model Compression) is the method behind the red curve on slide 25. It treats the per-layer sparsity ratios as actions for a reinforcement-learning agent, which walks the network layer by layer, proposes a ratio for each, and is rewarded by the accuracy the pruned model reaches under a FLOPs or latency constraint. The pruned model is then fine-tuned. The baseline is the easiest thing one could do instead, which the paper states plainly: "the easiest way to reduce the channels of a model is to use uniform channel shrinkage, i.e. use a width multiplier", and the result is that AMC "consistently outperforms the uniform baselines" (He et al., ECCV 2018).
AMC (AutoML for Model Compression) هي الطريقة وراء المنحنى الأحمر في الشريحة 25. تعامل نسب التناثر لكل طبقة على أنها أفعال (actions) لوكيل تعلم معزّز (reinforcement learning) يمر على الشبكة طبقةً طبقة، ويقترح نسبة لكل منها، ويُكافأ بالدقة التي يبلغها النموذج المقلّم تحت قيد على FLOPs أو على زمن الاستجابة. ثم يُضبط النموذج المقلّم ضبطًا دقيقًا. خط الأساس هو أسهل ما يمكن فعله بدلًا من ذلك، والورقة تقوله صراحةً: «أسهل طريقة لتقليل قنوات نموذج هي استخدام تصغير قنوات موحّد، أي استخدام مضاعف عرض»، والنتيجة أن AMC «يتفوق باستمرار على خطوط الأساس الموحّدة» (He et al., ECCV 2018).
| Modelالنموذج | MMACsMMACs | Top-1Top-1 | Pixel 1 latencyزمن الاستجابة على Pixel 1 | Speedupالتسريع |
|---|---|---|---|---|
| MobileNet 1.0 (full width)MobileNet 1.0 (العرض الكامل) | 569569 | 70.6%70.6% | 123.3 ms123.3 ms | 1.00x1.00x |
| MobileNet 0.75 (uniform shrink)MobileNet 0.75 (تصغير موحّد) | 325325 | 68.4%68.4% | 72.3 ms72.3 ms | 1.7x1.7x |
| AMC, 50% FLOPs budgetAMC، ميزانية 50% من FLOPs | 285285 | 70.5%70.5% | 68.3 ms68.3 ms | 1.81x1.81x |
| AMC, 50% latency budgetAMC، ميزانية 50% من زمن الاستجابة | 272272 | 70.2%70.2% | 63.3 ms63.3 ms | 1.95x1.95x |
The chart on the slide is AMC's Figure 5b. The four table rows above are exact; the remaining points in the table below are read off the figure and are approximate. Either way the shape is the same. At equal latency the searched ratios are about 1.5 to 2 points better. At similar accuracy they are much faster: the 50% latency-budget model keeps 70.2% at 63.3 ms, 1.95x faster than the 123.3 ms full model at 70.6%, only 0.4 points higher.
المخطط في الشريحة هو الشكل 5b من ورقة AMC. صفوف الجدول الأربعة أعلاه دقيقة؛ أما النقاط الباقية في الجدول أدناه فمقروءة من الشكل وتقريبية. وفي الحالتين الشكل العام واحد. عند زمن استجابة متساوٍ تكون النسب المبحوث عنها أفضل بنحو 1.5 إلى 2 نقطة. وعند دقة متقاربة تكون أسرع بكثير: النموذج ذو ميزانية زمن الاستجابة 50% يحافظ على 70.2% عند 63.3 ms، أي أسرع بمقدار 1.95x من النموذج الكامل البالغ 123.3 ms بدقة 70.6%، الذي يزيد عليه بـ 0.4 نقطة فقط.
| Curveالمنحنى | Latencyزمن الاستجابة | Top-1Top-1 |
|---|---|---|
| Uniformموحّد | about 52 msنحو 52 ms | about 67.5%نحو 67.5% |
| Uniformموحّد | about 90 msنحو 90 ms | about 69.1%نحو 69.1% |
| AMCAMC | about 52 msنحو 52 ms | about 69.2%نحو 69.2% |
Choosing a granularity for a real boardاختيار درجة التقليم للوحة حقيقية
This is where the part comes together for your project. The granularity you pick is a hardware decision, not a compression decision:
هنا يجتمع هذا الجزء في خدمة مشروعك. درجة التقليم التي تختارها قرار يتعلق بالعتاد، لا قرار يتعلق بالضغط:
- Target is an Ampere-class or newer NVIDIA GPU (a Jetson Orin, an A100): prune to 2:4. Half the weights, about 2x on the matmuls, accuracy held by retraining.إذا كان الهدف GPU من NVIDIA من فئة Ampere أو أحدث (Jetson Orin، أو A100): قلّم إلى 2:4. نصف الأوزان، ونحو 2x في ضرب المصفوفات، والدقة محفوظة بإعادة التدريب.
- Target is a phone CPU, a microcontroller or an NPU with dense kernels only: channel pruning with searched per-layer ratios, AMC style. A smaller dense network is the safest choice, since it needs no special kernels. Some mobile runtimes (XNNPACK) do accelerate high unstructured sparsity in 1x1 convolutions, so check what your runtime supports.إذا كان الهدف CPU هاتف، أو متحكمًا دقيقًا (microcontroller)، أو NPU بنوى كثيفة فقط: تقليم القنوات بنسب لكل طبقة مبحوث عنها على طريقة AMC. الشبكة الكثيفة الأصغر هي الخيار الأكثر أمانًا، لأنها لا تحتاج إلى نوى خاصة. بعض بيئات التشغيل على الهواتف (XNNPACK) تسرّع فعلًا التناثر غير المنظّم العالي في الالتفافات 1x1، فتحقق مما تدعمه بيئة التشغيل لديك.
- Target has a sparse accelerator such as EIE, or the constraint is storage and not latency: fine-grained pruning, for the largest compression ratio.إذا كان الهدف فيه مسرّع متناثر مثل EIE، أو كان القيد هو التخزين لا زمن الاستجابة: التقليم الدقيق، للحصول على أكبر نسبة ضغط.
Quick checkاختبار سريع
Why does channel pruning with per-layer sparsities beat a uniform width multiplier at the same latency?لماذا يتفوق تقليم القنوات بنسب تناثر خاصة بكل طبقة على مضاعف العرض الموحّد عند زمن الاستجابة نفسه؟
Recall
Give the AMC versus uniform numbers that show per-layer ratios beat uniform shrink.أعطِ أرقام AMC مقابل التصغير الموحّد التي تبيّن أن النسب الخاصة بكل طبقة تتفوق على التصغير الموحّد.
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- Fine-grained pruning may zero any weight, so it compresses most (AlexNet 9x, VGG-16 13x) but needs a per-weight index; only custom hardware such as EIE turns that into speed.التقليم الدقيق يجوز له تصفير أي وزن، لذلك يحقق أكبر ضغط (AlexNet بمقدار 9x، وVGG-16 بمقدار 13x) لكنه يحتاج فهرسًا لكل وزن؛ ولا يحوّل ذلك إلى سرعة إلا عتاد مخصص مثل EIE.
- N:M sparsity keeps at most N nonzeros in every contiguous M weights; 2:4 is 50 percent sparse under either reading, but 1:4 is 75 percent (NVIDIA) versus 25 percent (slide wording).تناثر N:M يُبقي N قيمًا غير صفرية على الأكثر في كل M أوزان متجاورة؛ نمط 2:4 تناثره 50 بالمئة بأي القراءتين، أما 1:4 فتناثره 75 بالمئة (اصطلاح NVIDIA) مقابل 25 بالمئة (صياغة الشريحة).
- A 2:4 matrix stores half its values plus 2-bit indices: 36 bits per four FP16 weights instead of 64, about 1.78x, and Ampere Sparse Tensor Cores skip the zeros for about 2x math throughput.مصفوفة 2:4 تخزّن نصف قيمها مع فهارس من بتّين: 36 بت لكل أربعة أوزان FP16 بدلًا من 64، أي نحو 1.78x، وتتخطى Sparse Tensor Cores في معمارية Ampere الأصفار فتعطي نحو 2x في إنتاجية العمليات الحسابية.
- NVIDIA's train, prune to 2:4, retrain recipe held accuracy on all seven slide-22 tasks (ResNet-50 76.1 to 76.2, BERT-Large 91.9 to 91.9).وصفة NVIDIA (درّب، ثم قلّم إلى 2:4، ثم أعد التدريب) حافظت على الدقة في المهام السبع كلها في الشريحة 22 (ResNet-50 من 76.1 إلى 76.2، وBERT-Large من 91.9 إلى 91.9).
- Channel pruning removes whole channels, so the result is a smaller dense network with direct speedup on any hardware, at the cost of a smaller compression ratio.تقليم القنوات يزيل قنوات كاملة، فتكون النتيجة شبكة كثيفة (dense) أصغر تعطي تسريعًا مباشرًا على أي عتاد، على حساب نسبة ضغط أصغر.
- Pruning layer l's output channels also shrinks layer l+1's inputs, so per-layer channel sparsities compound in parameters and MACs.تقليم قنوات الخرج في الطبقة l يصغّر أيضًا مدخلات الطبقة l+1، لذلك تتضاعف نسب تناثر القنوات لكل طبقة بعضها في بعض في عدد المعاملات وفي عدد MACs.
- Uniform shrink applies one ratio everywhere; AMC's searched per-layer ratios give 70.5 percent at 68.3 ms versus 68.4 percent at 72.3 ms for the 0.75 width MobileNet on a Pixel 1.التصغير الموحّد يطبّق نسبة واحدة في كل مكان؛ أما نسب AMC المبحوث عنها لكل طبقة فتعطي 70.5 بالمئة عند 68.3 ms مقابل 68.4 بالمئة عند 72.3 ms لنموذج MobileNet بعرض 0.75 على هاتف Pixel 1.
- Higher sparsity is not faster inference unless the sparsity has a structure the target hardware can exploit.التناثر الأعلى لا يعني استدلالًا أسرع ما لم يكن لهذا التناثر بنية يستطيع العتاد المستهدف استغلالها.
Sourcesالمصادر
- Accelerating Inference with Sparsity Using the NVIDIA Ampere Architecture and NVIDIA TensorRTDocsNVIDIA Developer BlogThe slide's own link: 2:4 definition, the train, prune, retrain recipe, and the seven-row accuracy table.رابط الشريحة نفسها: تعريف 2:4، ووصفة درّب ثم قلّم ثم أعد التدريب، وجدول الدقة ذو الصفوف السبعة.(opens in a new tab)(يفتح في تبويب جديد)
- NVIDIA A100 Tensor Core GPU ArchitectureDocsNVIDIAPages 31 to 32: 2:4 definition, almost 2x storage saving, Sparse MMA doubling throughput.الصفحتان 31 و32: تعريف 2:4، وتوفير في التخزين يقارب 2x، وعمليات Sparse MMA التي تضاعف الإنتاجية.(opens in a new tab)(يفتح في تبويب جديد)
- NVIDIA Ampere Architecture In-DepthDocsNVIDIA Developer BlogFine-grained structured sparsity section.قسم التناثر المنظّم الدقيق (fine-grained structured sparsity).(opens in a new tab)(يفتح في تبويب جديد)
- Accelerating Sparse Deep Neural NetworksPaperMishra et al., arXiv 2021Section 3.1: 2-bit indices, 64 versus 36 bits per group, 44 and 38 percent savings, CSR metadata overhead.القسم 3.1: فهارس من بتّين، و64 مقابل 36 بت لكل مجموعة، وتوفير بنسبة 44 و38 بالمئة، وكلفة البيانات الوصفية في صيغة CSR.(opens in a new tab)(يفتح في تبويب جديد)
- Learning N:M Fine-grained Structured Sparse Neural Networks From ScratchPaperZhou et al., ICLR 2021Fine-grained sparsity is not hardware friendly; restates NVIDIA's about 2x on the A100 (not independently measured).التناثر الدقيق غير ملائم للعتاد؛ وتعيد الورقة ذكر رقم NVIDIA البالغ نحو 2x على A100 (دون قياس مستقل).(opens in a new tab)(يفتح في تبويب جديد)
- Learning both Weights and Connections for Efficient Neural NetworksPaperHan, Pool, Tran and Dally, NIPS 2015AlexNet 9x and VGG-16 13x parameter reduction without accuracy loss.تخفيض عدد المعاملات في AlexNet بمقدار 9x وفي VGG-16 بمقدار 13x دون خسارة في الدقة.(opens in a new tab)(يفتح في تبويب جديد)
- EIE: Efficient Inference Engine on Compressed Deep Neural NetworkPaperHan et al., ISCA 2016189x over CPU, 13x over GPU, 3400x more energy efficient than GPU, compared with CPU and GPU running the same DNN without compression.أسرع بمقدار 189x من CPU و13x من GPU، وأكفأ في استهلاك الطاقة بمقدار 3400x من GPU، مقارنةً بـ CPU وGPU يشغّلان الشبكة العصبية العميقة نفسها دون ضغط.(opens in a new tab)(يفتح في تبويب جديد)
- Efficient Methods and Hardware for Deep LearningBookSong Han, PhD thesis, Stanford 2017Table 3.1: GoogleNet 7 M to 2 M, ResNet-50 25.5 M to 7.47 M.الجدول 3.1: GoogleNet من 7 M إلى 2 M، وResNet-50 من 25.5 M إلى 7.47 M.(opens in a new tab)(يفتح في تبويب جديد)
- Pruning Filters for Efficient ConvNetsPaperLi et al., ICLR 2017Filter pruning needs no sparse libraries; 34 and 38 percent inference cost reduction.تقليم المرشّحات لا يحتاج إلى مكتبات متناثرة؛ وتخفيض كلفة الاستدلال بنسبة 34 و38 بالمئة.(opens in a new tab)(يفتح في تبويب جديد)
- Channel Pruning for Accelerating Very Deep Neural NetworksPaperHe, Zhang and Sun, ICCV 2017VGG-16 5x speedup at 0.3 percent error increase, ResNet 2x at 1.4 percent.تسريع VGG-16 بمقدار 5x مع زيادة في الخطأ قدرها 0.3 بالمئة، وتسريع ResNet بمقدار 2x مع زيادة قدرها 1.4 بالمئة.(opens in a new tab)(يفتح في تبويب جديد)
- AMC: AutoML for Model Compression and Acceleration on Mobile DevicesPaperHe, Lin, Liu, Wang, Li and Han, ECCV 2018Table 4 and Figure 5b: Pixel 1 latencies and the uniform width-multiplier baseline.الجدول 4 والشكل 5b: أزمنة الاستجابة على Pixel 1، وخط الأساس لمضاعف العرض الموحّد.(opens in a new tab)(يفتح في تبويب جديد)
- TinyML and Efficient Deep Learning Computing, Lecture 3: Pruning and Sparsity (Part I)DocsMIT 6.5940, Song Han, Fall 2024Source deck for slides 19 to 25, including the '(e.g., EIE)' example dropped from the COE 592 copy.العرض الأصلي للشرائح 19 إلى 25، بما فيه مثال «(e.g., EIE)» الذي حُذف من نسخة COE 592.(opens in a new tab)(يفتح في تبويب جديد)
Part 05: Pruning criteria: magnitude and scaling factorsمعايير التقليم: المقدار ومعاملات القياس
What makes a parameter less important, magnitude-based importance at element and row level with L1, L2 and general Lp norms, and scaling-based filter pruning that reuses batch normalization gamma factors.ما الذي يجعل المعامل أقل أهمية، والأهمية القائمة على المقدار (magnitude) على مستوى العنصر والصف باستخدام معايير L1 وL2 وLp العامة، وتقليم المرشحات القائم على معاملات القياس الذي يعيد استخدام معاملات gamma في تطبيع الدفعة.
4 concepts4 مفاهيم, ، slides 26-33الشرائح 26-33
Why this part mattersلماذا يهمّ هذا الجزء
Parts 03 and 04 settled the shape of what gets removed: a single weight, a pattern, a row, a whole channel. They never said which one. This part answers that question with the two criteria that run most real pruning: the magnitude of a weight or a group of weights, and a learned scaling factor per channel.
The same computations come back in three places. In a COE 592 exam you will be handed a small matrix and asked for its element-wise and row-wise importances and the pruned result. In code, every call to PyTorch's prune.l1_unstructured or prune.ln_structured does exactly what this part derives by hand. And in your research project, when a channel-pruned model has to justify its accuracy on an embedded board, the batch normalization gamma criterion at the end of this part is the one most practical channel-pruning pipelines actually use.
حسم الجزءان 03 و04 شكل ما يُحذف: وزن واحد، أو نمط، أو صف، أو قناة كاملة. لكنهما لم يحددا أيّها نحذف. هذا الجزء يجيب عن هذا السؤال بالمعيارين اللذين تقوم عليهما معظم عمليات التقليم الفعلية: مقدار الوزن أو مقدار مجموعة من الأوزان، ومعامل تحجيم (scaling factor) متعلَّم لكل قناة.
الحسابات نفسها تعود في ثلاثة مواضع. في امتحان COE 592 ستُعطى مصفوفة صغيرة ويُطلب منك حساب أهميتها على مستوى العنصر وعلى مستوى الصف ثم النتيجة بعد التقليم. وفي الكود، كل استدعاء لـ prune.l1_unstructured أو prune.ln_structured في PyTorch يفعل بالضبط ما يشتقه هذا الجزء يدويًا. وفي مشروعك البحثي، حين يحتاج نموذج مقلَّم القنوات إلى تبرير دقته على لوحة مدمجة، فإن معيار gamma في batch normalization الذي يأتي في نهاية هذا الجزء هو المعيار الذي تستخدمه فعلًا معظم خطوط تقليم القنوات العملية.
By the end you canفي نهاية هذا الجزء ستستطيع
- State the principle behind every pruning criterion and apply it to a single neuron.تذكر المبدأ الذي يقوم عليه كل معيار تقليم وتطبّقه على عصبون واحد.
- Compute element-wise importances |W| and produce the pruned matrix for a target sparsity.تحسب الأهمية على مستوى العنصر |W| وتُخرج المصفوفة المقلَّمة لنسبة تناثر مستهدفة.
- Score rows or channels with L1, L2 and general Lp norms and say which row is pruned.تقيّم الصفوف أو القنوات بالمعايير L1 وL2 والمعيار العام Lp وتحدد أي صف يُقلَّم.
- Show with numbers when L1 and L2 rank structural sets differently.تبيّن بالأرقام متى يرتّب L1 وL2 المجموعات الهيكلية ترتيبًا مختلفًا.
- Explain scaling-based pruning and why batch norm gamma is a free channel importance.تشرح التقليم القائم على التحجيم ولماذا تمثّل gamma في batch norm أهمية مجانية للقناة.
Start with one neuron and three inputs. Its output is y = ReLU(10 x_0 - 8 x_1 + 0.1 x_2), and the budget says one of the three connections has to go. Removing the 10 changes the pre-activation by up to 10 |x_0|. Removing the -8 changes it by up to 8 |x_1|. Removing the 0.1 changes it by at most 0.1 |x_2|. If the three inputs are of similar size, the third cut is a hundred times gentler than the first, and that is the one to make.
ابدأ بعصبون واحد له ثلاثة مدخلات. خرجه هو y = ReLU(10 x_0 - 8 x_1 + 0.1 x_2)، والميزانية تقول إن واحدًا من الاتصالات الثلاثة يجب أن يُحذف. حذف الوزن 10 يغيّر ما قبل التنشيط (pre-activation) بما يصل إلى 10 |x_0|. وحذف الوزن -8 يغيّره بما يصل إلى 8 |x_1|. أما حذف الوزن 0.1 فيغيّره بما لا يزيد على 0.1 |x_2|. إذا كانت المدخلات الثلاثة متقاربة في الحجم، فالحذف الثالث ألطف بمئة مرة من الأول، وهو الحذف الذي ينبغي أن نختاره.
That small decision contains the whole idea of a Pruning criterion. Pruning asks the network to give up parameters, and the principle the lecture states is simple: the less important the parameters being removed are, the better the performance of the pruned network is. Every criterion in this lecture is a different way of estimating importance, and importance always means the same thing underneath: how much the loss would change if this parameter, or this group, were set to zero. Magnitude, the subject of this part, is the cheapest such estimate. Second-order methods in the next part spend far more compute to estimate the same quantity more carefully (Second-order pruning).
هذا القرار الصغير يحمل الفكرة الكاملة لمعيار التقليم (pruning criterion). التقليم (pruning) يطلب من الشبكة أن تتخلى عن معاملات، والمبدأ الذي تنص عليه المحاضرة بسيط: كلما قلّت أهمية المعاملات المحذوفة كان أداء الشبكة المقلَّمة أفضل. كل معيار في هذه المحاضرة هو طريقة مختلفة لتقدير الأهمية، والأهمية تعني في جوهرها الشيء نفسه دائمًا: كم ستتغير الخسارة (loss) لو جُعل هذا المعامل، أو هذه المجموعة، صفرًا. المقدار (magnitude)، وهو موضوع هذا الجزء، أرخص تقدير من هذا النوع. أما الطرق من الدرجة الثانية في الجزء التالي فتنفق حسابًا أكبر بكثير لتقدير الكمية نفسها بعناية أكبر (second-order pruning).
Worked exampleمثال محلول
Three candidate deletionsثلاثة حذوفات مرشّحة
Cut the 10احذف الوزن 10
The pre-activation loses 10 x_0. For a typical input this is the largest term in the sum, so the output can flip from firing to silent.يخسر ما قبل التنشيط الحدّ 10 x_0. لمدخل نموذجي يكون هذا أكبر حدّ في المجموع، فقد ينقلب الخرج من عصبون نشِط إلى عصبون صامت.Cut the -8احذف الوزن -8
The pre-activation loses -8 x_1. The sign is negative, but the size of the change is 8 |x_1|, almost as large as the first case.يخسر ما قبل التنشيط الحدّ -8 x_1. الإشارة سالبة، لكن حجم التغيير هو 8 |x_1|، وهو يكاد يساوي الحالة الأولى.Cut the 0.1احذف الوزن 0.1
The pre-activation loses 0.1 x_2. With inputs of similar scale, this is a rounding error next to the other two terms.يخسر ما قبل التنشيط الحدّ 0.1 x_2. ومع مدخلات متقاربة في المقياس، يكون هذا مجرد خطأ تقريب مقارنة بالحدّين الآخرين.Remove the 0.1احذف الوزن 0.1
The connection with the smallest absolute weight is removed, and y = ReLU(10 x_0 - 8 x_1) is almost the same function as before.يُحذف الاتصال ذو أصغر وزن بالقيمة المطلقة، فتصبح y = ReLU(10 x_0 - 8 x_1) تقريبًا الدالة نفسها التي كانت من قبل.
Notice what the example needed to make the decision: nothing but the weights. No data, no gradients, no second run through the training set. That is the appeal of magnitude criteria and also their limit. They answer the Pruning formulation only approximately, because the formulation asks for the smallest increase in loss under a budget on nonzeros, and magnitude is a proxy for loss, not the loss itself. The next three sections make the proxy precise for single weights, for rows, and for whole channels.
لاحظ ما احتاجه المثال لاتخاذ القرار: الأوزان فقط. لا بيانات، ولا تدرجات (gradients)، ولا مرور ثانٍ على مجموعة التدريب. هذه هي جاذبية معايير المقدار وهي أيضًا حدّها. فهي تجيب عن صياغة التقليم (pruning formulation) تقريبيًا فقط، لأن الصياغة تطلب أصغر زيادة في الخسارة تحت ميزانية على عدد القيم غير الصفرية، والمقدار بديل تقريبي (proxy) للخسارة وليس الخسارة نفسها. الأقسام الثلاثة التالية تجعل هذا البديل دقيقًا للأوزان المفردة، وللصفوف، وللقنوات الكاملة.
Recall
W = [10, -8, 0.1] feeds a ReLU neuron. Which weight goes first, and what assumption makes that answer safe?المتجه W = [10, -8, 0.1] يغذّي عصبون ReLU. أي وزن يُحذف أولًا، وما الافتراض الذي يجعل هذه الإجابة آمنة؟
Quick checkاختبار سريع
With W = [10, -8, 0.1] and inputs of similar scale, which weight does magnitude pruning remove first?مع W = [10, -8, 0.1] ومدخلات متقاربة في المقياس، أي وزن يحذفه تقليم المقدار أولًا؟
Now scale the neuron up to a weight matrix. Take W = [[3, -2], [1, -5]] and a budget of 50 percent Sparsity, which on four weights means exactly two zeros. Write the absolute value of every entry, keep the two largest, zero the rest. The importances are [[3, 2], [1, 5]], the survivors are 3 and -5, and the pruned matrix is [[3, 0], [0, -5]].
الآن وسّع العصبون إلى مصفوفة أوزان. خذ W = [[3, -2], [1, -5]] وميزانية تناثر (sparsity) بنسبة 50 بالمئة، وهذا يعني على أربعة أوزان صفرين بالضبط. اكتب القيمة المطلقة لكل عنصر، واحتفظ بأكبر قيمتين، واجعل الباقي صفرًا. الأهميات هي [[3, 2], [1, 5]]، والناجيان هما 3 و-5، والمصفوفة المقلَّمة هي [[3, 0], [0, -5]].
This is Magnitude-based pruning at its finest granularity, the fine-grained case from part 03, and it is the criterion of the paper the slides cite. Han, Pool, Tran and Dally train a network, prune every connection whose weight falls below a threshold, and retrain the survivors. Done once, that took AlexNet to 5x fewer parameters; done iteratively, prune then retrain then prune again, it reached 9x on AlexNet (61M to 6.7M) and 13x on VGG-16 (138M to 10.3M) with no loss of accuracy. They also tried the obvious alternative, removing weights at random with probability tied to their magnitude, and report that it gave worse results. Hard thresholding on |w| won.
هذا هو التقليم القائم على المقدار (magnitude-based pruning) في أدق مستويات الحبيبية، أي الحالة الدقيقة (fine-grained) من الجزء 03، وهو معيار الورقة التي تستشهد بها الشرائح. يقوم Han وPool وTran وDally بتدريب شبكة، ثم يقلّمون كل اتصال يقع وزنه تحت عتبة (threshold)، ثم يعيدون تدريب الأوزان الناجية. حين طُبّق ذلك مرة واحدة خفّض AlexNet إلى معاملات أقل بـ 5x؛ وحين طُبّق تكراريًا، تقليم ثم إعادة تدريب ثم تقليم مرة أخرى، وصل إلى 9x على AlexNet (من 61M إلى 6.7M) وإلى 13x على VGG-16 (من 138M إلى 10.3M) دون أي خسارة في الدقة. وجرّبوا أيضًا البديل البديهي، أي حذف الأوزان عشوائيًا باحتمال مرتبط بمقدارها، وأفادوا بأنه أعطى نتائج أسوأ. فاز التحديد الصارم بعتبة على |w|.
Worked exampleمثال محلول
From W to the pruned matrix at 50 percent sparsityمن W إلى المصفوفة المقلَّمة عند تناثر 50 بالمئة
Take absolute valuesخذ القيم المطلقة
|W| = [[3, 2], [1, 5]]. The -2 becomes 2 and the -5 becomes 5.|W| = [[3, 2], [1, 5]]. تصبح -2 هي 2 وتصبح -5 هي 5.Count how many surviveاحسب عدد الناجين
Four weights at 50 percent sparsity means 4 × (1 - 0.5) = 2 survivors.أربعة أوزان عند تناثر 50 بالمئة تعني 4 × (1 - 0.5) = 2 من الأوزان الناجية.Rank and keepرتّب واحتفظ
Sorted importances are 5, 3, 2, 1. Keep the entries scoring 5 and 3, which are the original -5 and 3.الأهميات مرتبةً هي 5, 3, 2, 1. احتفظ بالعنصرين اللذين حصلا على 5 و3، وهما القيمتان الأصليتان -5 و3.Pruned weightالوزن المقلَّم
[[3, 0], [0, -5]]. The kept weights keep their signs; only the zeros are new.[[3, 0], [0, -5]]. الأوزان المحتفَظ بها تحتفظ بإشاراتها؛ الجديد فقط هو الأصفار.
In code, this is one call. PyTorch's prune.l1_unstructured(module, name, amount) prunes a tensor by removing the units with the lowest L1 norm, and amount can be a fraction such as 0.5 or an absolute count. The name is exact: on a single element the L1 norm is just its absolute value, so element-wise L1 and |W| are the same criterion, and the slide's label "L1-norm, element-wise" is the same statement as Importance = |W|. Any other p would give the same ranking on single elements, which is why the choice of norm only starts to matter in the next section.
في الكود، هذا استدعاء واحد. الدالة prune.l1_unstructured(module, name, amount) في PyTorch تقلّم موترًا (tensor) بحذف الوحدات ذات أدنى معيار L1، ويمكن أن يكون amount نسبة مثل 0.5 أو عددًا مطلقًا. الاسم دقيق: على عنصر مفرد يكون معيار L1 مجرد قيمته المطلقة، لذا فإن L1 على مستوى العنصر و|W| هما المعيار نفسه، وتسمية الشريحة "L1-norm, element-wise" هي العبارة نفسها Importance = |W|. وأي قيمة أخرى لـ p ستعطي الترتيب نفسه على العناصر المفردة، ولهذا لا يبدأ اختيار المعيار في أن يُحدث فرقًا إلا في القسم التالي.
Recall
Compute the element-wise importances of [[3, -2], [1, -5]] and the result at 50 percent sparsity.احسب الأهميات على مستوى العنصر للمصفوفة [[3, -2], [1, -5]] والنتيجة عند تناثر 50 بالمئة.
Keep the same matrix, [[3, -2], [1, -5]], but change the unit of removal. Instead of two individual entries, remove one whole row. A row of a linear layer's weight matrix is one output neuron's incoming connections, so deleting it is Neuron pruning, and the result is a smaller dense matrix that any library runs faster (Coarse-grained (structured) pruning). The question is how to score a row when it holds several weights of different sizes and signs.
احتفظ بالمصفوفة نفسها [[3, -2], [1, -5]]، لكن غيّر وحدة الحذف. بدلًا من عنصرين منفردين، احذف صفًا كاملًا. صف مصفوفة أوزان الطبقة الخطية هو الاتصالات الداخلة إلى عصبون خرج واحد، فحذفه هو تقليم العصبونات (neuron pruning)، والنتيجة مصفوفة كثيفة أصغر تشغّلها أي مكتبة بسرعة أكبر (coarse-grained pruning). السؤال هو كيف نقيّم صفًا يحتوي على عدة أوزان مختلفة في الحجم والإشارة.
The lecture's answer is to treat the row as a Structural set, written W^(S) for the set S of parameters it contains, and to collapse its absolute values into one number. Two collapses are standard. Add them: the L1-norm importance. Or square them, add, and take the root: the L2-norm importance. Row 0 scores |3| + |-2| = 5 under L1 and sqrt(9 + 4) = sqrt(13) = 3.61 under L2. Row 1 scores |1| + |-5| = 6 and sqrt(1 + 25) = sqrt(26) = 5.10. Both norms rank row 1 higher, so both prune row 0, and the pruned matrix is [[0, 0], [1, -5]].
جواب المحاضرة هو أن نعامل الصف بوصفه مجموعة هيكلية (structural set)، تُكتب W^(S) للمجموعة S من المعاملات التي يحتويها، وأن نختزل قيمها المطلقة في رقم واحد. هناك طريقتان معياريتان للاختزال. اجمعها: فتحصل على أهمية معيار L1 (L1-norm importance). أو ربّعها ثم اجمعها ثم خذ الجذر: فتحصل على أهمية معيار L2 (L2-norm importance). الصف 0 يحصل على |3| + |-2| = 5 بمعيار L1 وعلى sqrt(9 + 4) = sqrt(13) = 3.61 بمعيار L2. والصف 1 يحصل على |1| + |-5| = 6 وعلى sqrt(1 + 25) = sqrt(26) = 5.10. كلا المعيارين يضع الصف 1 في مرتبة أعلى، فكلاهما يقلّم الصف 0، والمصفوفة المقلَّمة هي [[0, 0], [1, -5]].
Worked exampleمثال محلول
Row-wise scores, both normsدرجات الصفوف بالمعيارين
Absolute values firstالقيم المطلقة أولًا
Row 0 is [3, 2] in magnitude, row 1 is [1, 5].الصف 0 مقداره [3, 2]، والصف 1 مقداره [1, 5].L1: addالمعيار L1: اجمع
Row 0: 3 + 2 = 5. Row 1: 1 + 5 = 6.الصف 0: 3 + 2 = 5. الصف 1: 1 + 5 = 6.L2: square, add, rootالمعيار L2: ربّع، اجمع، خذ الجذر
Row 0: sqrt(9 + 4) = sqrt(13) = 3.61. Row 1: sqrt(1 + 25) = sqrt(26) = 5.10.الصف 0: sqrt(9 + 4) = sqrt(13) = 3.61. الصف 1: sqrt(1 + 25) = sqrt(26) = 5.10.Compare and zero the loserقارن واجعل الخاسر صفرًا
Under both norms row 0 scores lower, so every entry of row 0 becomes zero.بكلا المعيارين يحصل الصف 0 على درجة أقل، فيصبح كل عنصر في الصف 0 صفرًا.Pruned weightالوزن المقلَّم
[[0, 0], [1, -5]]. Compare with the element-wise result [[3, 0], [0, -5]]: the same Sparsity, a different pattern, because the unit of removal changed.[[0, 0], [1, -5]]. قارنها بنتيجة مستوى العنصر [[3, 0], [0, -5]]: نسبة التناثر (sparsity) نفسها، لكن بنمط مختلف، لأن وحدة الحذف تغيّرت.
| Criterionالمعيار | Row 0 scoreدرجة الصف 0 | Row 1 scoreدرجة الصف 1 | Row prunedالصف المقلَّم | Pruned matrixالمصفوفة المقلَّمة |
|---|---|---|---|---|
| Element-wise |w||w| على مستوى العنصر | not a row scoreليست درجة صف | not a row scoreليست درجة صف | none (two smallest elements)لا شيء (أصغر عنصرين) | [[3, 0], [0, -5]][[3, 0], [0, -5]] |
| Row-wise L1L1 على مستوى الصف | 55 | 66 | row 0الصف 0 | [[0, 0], [1, -5]][[0, 0], [1, -5]] |
| Row-wise L2L2 على مستوى الصف | sqrt(13) = 3.61sqrt(13) = 3.61 | sqrt(26) = 5.10sqrt(26) = 5.10 | row 0الصف 0 | [[0, 0], [1, -5]][[0, 0], [1, -5]] |
One formula for every pصيغة واحدة لكل قيمة p
L1 and L2 are two settings of one dial. Goodfellow, Bengio and Courville define the Lp norm of a vector for any p ≥ 1 as the p-th root of the sum of p-th powers of the absolute values. Set p = 1 and the root and the power vanish, leaving slide 29. Set p = 2 and you get the Euclidean length of slide 30. Slide 31 is the same example under the general formula, not a new method.
المعياران L1 وL2 وضعيتان لقرص واحد. يعرّف Goodfellow وBengio وCourville معيار Lp (Lp norm) لمتجه لأي p ≥ 1 بأنه الجذر من الرتبة p لمجموع القوى من الرتبة p للقيم المطلقة. ضع p = 1 فيختفي الجذر والقوة، ويبقى ما في الشريحة 29. وضع p = 2 فتحصل على الطول الإقليدي في الشريحة 30. أما الشريحة 31 فهي المثال نفسه تحت الصيغة العامة، وليست طريقة جديدة.
When the norm changes the answerحين يغيّر المعيار الإجابة
On the slide's matrix L1 and L2 agree, and it is tempting to file the norm as a cosmetic choice. It is not. Compare a row [3, 3] with a row [0, 5] competing for the last surviving slot. L1 scores them 6 against 5 and keeps [3, 3]. L2 scores them sqrt(18) = 4.24 against 5 and keeps [0, 5]. Squaring amplifies the single largest entry, so L2 rewards a row with one dominant weight. Summing treats every unit of magnitude the same, so L1 rewards a row with many moderate weights. Goodfellow et al. describe the same contrast in general terms: the L1 norm grows at the same rate in all locations, while the squared L2 norm increases very slowly near the origin.
على مصفوفة الشريحة يتفق L1 وL2، ومن المغري أن تعتبر اختيار المعيار مسألة شكلية. لكنه ليس كذلك. قارن صفًا [3, 3] بصف [0, 5] يتنافسان على آخر مكان ناجٍ. يعطيهما L1 الدرجتين 6 مقابل 5 فيحتفظ بـ [3, 3]. ويعطيهما L2 sqrt(18) = 4.24 مقابل 5 فيحتفظ بـ [0, 5]. التربيع يضخّم أكبر عنصر منفرد، لذا يكافئ L2 الصف الذي فيه وزن واحد مهيمن. والجمع يعامل كل وحدة من المقدار بالتساوي، لذا يكافئ L1 الصف الذي فيه أوزان متوسطة كثيرة. ويصف Goodfellow et al. التباين نفسه بعبارات عامة: معيار L1 ينمو بالمعدل نفسه في كل المواضع، بينما يزداد مربع معيار L2 ببطء شديد قرب نقطة الأصل.
| Rowالصف | L1 scoreدرجة L1 | L2 scoreدرجة L2 |
|---|---|---|
| [3, 3][3, 3] | 3 + 3 = 63 + 3 = 6 | sqrt(9 + 9) = 4.24sqrt(9 + 9) = 4.24 |
| [0, 5][0, 5] | 0 + 5 = 50 + 5 = 5 | sqrt(0 + 25) = 5sqrt(0 + 25) = 5 |
| Row keptالصف المحتفَظ به | [3, 3][3, 3] | [0, 5][0, 5] |
Try it yourself. The explorer below scores an editable matrix element-wise or row-wise, always computes both row norms so a disagreement is visible without toggling, and ships with the slide's example and the [3, 3] against [0, 5] case as presets. Change a single entry and watch which row the two norms fight over.
جرّب بنفسك. المستكشف أدناه يقيّم مصفوفة قابلة للتعديل على مستوى العنصر أو على مستوى الصف، ويحسب دائمًا معياري الصف كليهما بحيث يظهر أي اختلاف دون الحاجة إلى التبديل، ويأتي بإعدادين جاهزين: مثال الشريحة وحالة [3, 3] مقابل [0, 5]. غيّر عنصرًا واحدًا وراقب على أي صف يتنازع المعياران.
Keeping the top 2 of 4 elements by |w|; the rest become zero. Signs never enter the score. Ties keep the lower index. Achieved sparsity: 50 percent of 4 weights.نحتفظ بأعلى 2 عناصر من أصل 4 حسب |w|؛ ويصبح الباقي أصفارًا. الإشارات لا تدخل في الدرجة أبدًا. عند التعادل يُحتفظ بالفهرس الأصغر. التناثرية المحققة: 50 بالمئة من 4 وزنًا.
Where the row-wise criteria come fromمن أين تأتي معايير الصفوف
The L1 row score is the criterion of Li et al. Their filter importance is the sum of the absolute kernel weights of a filter, which they describe as an expectation of the magnitude of the output feature map. They remove the m filters with the smallest sums, delete the matching input channels from the next layer, and show that pruning the smallest works better than pruning at random or pruning the largest. On CIFAR-10 this cut inference cost by up to 34 percent for VGG-16 and 38 percent for ResNet-110 with retraining recovering the accuracy. Because a filter is a structural set, this filter pruning is Channel pruning from part 04 with an explicit score attached.
درجة الصف بمعيار L1 هي معيار Li et al.. أهمية المرشح عندهم هي مجموع القيم المطلقة لأوزان نواة المرشح، ويصفونها بأنها توقّع لمقدار خريطة السمات الناتجة. يحذفون m من المرشحات ذات أصغر المجاميع، ويحذفون قنوات الدخل المقابلة لها من الطبقة التالية، ويبيّنون أن تقليم الأصغر أفضل من التقليم العشوائي ومن تقليم الأكبر. على CIFAR-10 خفّض هذا تكلفة الاستدلال بنسبة تصل إلى 34 بالمئة لـ VGG-16 و38 بالمئة لـ ResNet-110 مع استعادة الدقة بإعادة التدريب. ولأن المرشح مجموعة هيكلية، فإن تقليم المرشحات هذا (filter pruning) هو تقليم القنوات (channel pruning) من الجزء 04 مع درجة صريحة مرفقة به.
The L2 row score is what Wen et al. put inside training. Their structured sparsity learning adds a group Lasso regularizer to the loss, a sum over groups of sqrt(sum of squared weights in the group), which is exactly the L2 norm of each structural set. The optimizer is then rewarded for driving whole filters, channels, filter shapes or even layers to zero, and they report 5.1x CPU and 3.1x GPU speedups on AlexNet's convolutional layers, and a ResNet on CIFAR-10 shrunk from 20 to 18 layers with accuracy moving from 91.25 to 92.60 percent, still above the original 32-layer ResNet. The difference between the two papers is when the norm is used: Li et al. score a trained network after the fact, Wen et al. shape the network during training so the sets to remove are already near zero.
درجة الصف بمعيار L2 هي ما وضعه Wen et al. داخل التدريب. أسلوبهم لتعلّم التناثر الهيكلي (structured sparsity learning) يضيف إلى الخسارة منظِّم group Lasso، وهو مجموع على المجموعات لـ sqrt(sum of squared weights in the group)، أي بالضبط معيار L2 لكل مجموعة هيكلية. عندها يُكافأ المُحسِّن (optimizer) على دفع مرشحات كاملة، أو قنوات، أو أشكال مرشحات، أو حتى طبقات كاملة إلى الصفر، ويذكرون تسريعًا بمقدار 5.1x على CPU و3.1x على GPU في الطبقات الالتفافية لـ AlexNet، وشبكة ResNet على CIFAR-10 تقلّصت من 20 إلى 18 طبقة مع انتقال الدقة من 91.25 إلى 92.60 بالمئة، وهي ما تزال أعلى من شبكة ResNet الأصلية ذات 32 طبقة. الفرق بين الورقتين هو توقيت استخدام المعيار: يقيّم Li et al. شبكة مدرَّبة بعد انتهاء التدريب، بينما يشكّل Wen et al. الشبكة أثناء التدريب بحيث تكون المجموعات المراد حذفها قريبة من الصفر مسبقًا.
PyTorch exposes the post-hoc version directly. prune.ln_structured(module, name, amount, n, dim) removes the channels with the lowest Ln norm along the specified dimension; n = 1 or 2 picks the norm, and dim = 0 on a weight of shape [c_o, c_i, k_h, k_w] scores whole filters. Finer structural sets such as a row inside a kernel (Vector-level pruning) use the same formula on a smaller S.
تتيح PyTorch النسخة اللاحقة للتدريب (post-hoc) مباشرة. الدالة prune.ln_structured(module, name, amount, n, dim) تحذف القنوات ذات أدنى معيار Ln على امتداد البُعد المحدد؛ القيمة n = 1 أو 2 تختار المعيار، وdim = 0 على وزن شكله [c_o, c_i, k_h, k_w] يقيّم مرشحات كاملة. والمجموعات الهيكلية الأدق مثل صف داخل نواة (vector-level pruning) تستخدم الصيغة نفسها على مجموعة S أصغر.
Recall
Row-wise L1 and L2 scores of [[3, -2], [1, -5]], and the pruned result at 50 percent.ما درجات الصفوف بمعياري L1 وL2 للمصفوفة [[3, -2], [1, -5]]، وما النتيجة المقلَّمة عند 50 بالمئة؟
Recall
Give two rows where L1 and L2 disagree, with the numbers.أعطِ صفّين يختلف عليهما L1 وL2، مع الأرقام.
Quick checkاختبار سريع
Row-wise L1 pruning of [[3, -2], [1, -5]] at 50 percent sparsity removes which row, and why?تقليم L1 على مستوى الصف للمصفوفة [[3, -2], [1, -5]] عند تناثر 50 بالمئة يحذف أي صف، ولماذا؟
Quick checkاختبار سريع
Rows [3, 3] and [0, 5] compete for one surviving slot. Which row does each norm keep?الصفان [3, 3] و[0, 5] يتنافسان على مكان ناجٍ واحد. أي صف يحتفظ به كل معيار؟
A convolution layer has N filters, one per output channel (Convolution weight dimensions). Give each filter a single trainable number, its scaling factor, and multiply that channel's entire output by it. On the slide the factors come out as 1.17, 0.10, 0.29, 0.82, ..., 0.56. Suppose the threshold is 0.3 (the slide only marks the two smallest factors as pruned) and two channels fall below it: filter 1 at 0.10 and filter 2 at 0.29. Delete those filters, delete the input channels that consumed their outputs in the next layer, and what remains is filter 0, filter 3, on to filter N-1: a physically narrower layer.
الطبقة الالتفافية لها N من المرشحات، مرشح لكل قناة خرج (conv weight dimensions). أعطِ كل مرشح رقمًا واحدًا قابلًا للتدريب، هو معامل التحجيم الخاص به، واضرب فيه خرج تلك القناة كله. في الشريحة تظهر المعاملات 1.17, 0.10, 0.29, 0.82, ..., 0.56. افترض أن العتبة 0.3 (الشريحة تكتفي بتعليم أصغر معاملين على أنهما مقلَّمان) وأن قناتين تقعان تحتها: المرشح 1 عند 0.10 والمرشح 2 عند 0.29. احذف هذين المرشحين، واحذف قنوات الدخل التي كانت تستهلك خرجهما في الطبقة التالية، فيبقى المرشح 0 والمرشح 3 وصولًا إلى المرشح N-1: طبقة أضيق فعليًا.
This is Scaling-based pruning, and it differs from the norms in one important way. A norm scores a trained network after the fact, from the weights alone. A scaling factor is a parameter that training itself sets, so the network is asked, during training, how much it wants each channel. Liu et al. call the method network slimming and make the question sharp by adding an L1 penalty on the factors to the loss.
هذا هو التقليم القائم على التحجيم (scaling-based pruning)، وهو يختلف عن المعايير السابقة في أمر مهم واحد. المعيار يقيّم شبكة مدرَّبة بعد انتهاء التدريب، من الأوزان وحدها. أما معامل التحجيم فهو معامل يضبطه التدريب نفسه، فالشبكة تُسأل أثناء التدريب عن مدى حاجتها إلى كل قناة. يسمّي Liu et al. هذه الطريقة network slimming (تنحيف الشبكة) ويجعلون السؤال حادًا بإضافة عقوبة L1 على المعاملات إلى الخسارة.
The L1 penalty is the same L1 from the previous section, now used as a regularizer rather than a score: it charges every unit of |gamma| equally, so factors that the loss does not defend slide all the way to zero. Liu et al. use lambda = 1e-4 for VGGNet and 1e-5 for ResNet and DenseNet on CIFAR. After training they sort every factor in the whole network and set one global threshold at a percentile: pruning 70 percent of channels means the threshold is the 70th percentile of all factors, so layers with many weak channels lose more than layers with strong ones, which is the per-layer Pruning ratio falling out automatically. Then they fine-tune the slimmed network, and can repeat the whole loop.
عقوبة L1 هي نفسها معيار L1 من القسم السابق، لكنها تُستخدم الآن منظِّمًا (regularizer) لا درجةً: فهي تفرض الكلفة نفسها على كل وحدة من |gamma|، فتنزلق المعاملات التي لا تدافع عنها الخسارة حتى تصل إلى الصفر. يستخدم Liu et al. القيمة lambda = 1e-4 لـ VGGNet و1e-5 لـ ResNet وDenseNet على CIFAR. بعد التدريب يرتّبون كل المعاملات في الشبكة كلها ويضعون عتبة عامة واحدة عند نسبة مئوية: تقليم 70 بالمئة من القنوات يعني أن العتبة هي المئين 70 لجميع المعاملات، فالطبقات التي فيها قنوات ضعيفة كثيرة تخسر أكثر من الطبقات ذات القنوات القوية، وهذا هو معدل التقليم (pruning ratio) لكل طبقة يظهر تلقائيًا. ثم يُجرون ضبطًا دقيقًا (fine-tune) للشبكة المنحَّفة، ويمكنهم تكرار الحلقة كلها.
Network slimming on VGGNet, CIFAR-10, 70 percent of channels pruned (Liu et al., 2017)أسلوب network slimming على VGGNet مع CIFAR-10، بتقليم 70 بالمئة من القنوات (Liu et al., 2017)
- Test errorخطأ الاختبار
- 6.34 percent to 6.20 percentمن 6.34 بالمئة إلى 6.20 بالمئة
- Parametersالمعاملات
- 20.04M to 2.30M (88.5 percent fewer)من 20.04M إلى 2.30M (أقل بنسبة 88.5 بالمئة)
- FLOPs
- 7.97e8 to 3.91e8 (51.0 percent fewer)من 7.97e8 إلى 3.91e8 (أقل بنسبة 51.0 بالمئة)
- Multi-passعدة جولات
- up to 20x smaller and 5x less computeأصغر بما يصل إلى 20x وحساب أقل بـ 5x
Why the factor is already there: batch norm gammaلماذا المعامل موجود أصلًا: gamma في batch norm
Where does the scaling factor live? Liu et al. observe that almost every modern convolution is followed by batch normalization, and batch normalization already contains one. Ioffe and Szegedy normalize each channel of a mini-batch to zero mean and unit variance, then let the network undo that with two learned parameters per channel: a scale gamma and a shift beta. Goodfellow et al. explain why they exist: the normalized activation is replaced by gamma H' + beta so the new variable can have any mean and standard deviation the network wants. That gamma is the Batch normalization scaling factor, one per output channel, and it is the scaling factor the slide reuses.
أين يوجد معامل التحجيم؟ يلاحظ Liu et al. أن كل طبقة التفافية حديثة تقريبًا يتبعها batch normalization، وأن batch normalization يحتوي أصلًا على واحد. يطبّع Ioffe وSzegedy كل قناة في الدفعة الصغيرة (mini-batch) إلى متوسط صفري وتباين واحد، ثم يتركان الشبكة تتراجع عن ذلك بمعاملين متعلَّمين لكل قناة: معامل تحجيم gamma ومعامل إزاحة beta. ويشرح Goodfellow et al. سبب وجودهما: يُستبدل التنشيط المطبَّع بـ gamma H' + beta كي يمكن للمتغير الجديد أن يأخذ أي متوسط وانحراف معياري تريده الشبكة. هذه gamma هي batch norm gamma، واحدة لكل قناة خرج، وهي معامل التحجيم الذي تعيد الشريحة استخدامه.
Two things make gamma the right choice, and both are exam material. First, cost: reusing gamma adds no new parameters and no new layers. Liu et al. say it introduces no overhead, and in PyTorch the vector is already sitting in BatchNorm2d.weight, a learnable parameter of size C initialized to one, next to beta in BatchNorm2d.bias initialized to zero, with epsilon = 1e-5 by default.
أمران يجعلان gamma الخيار الصحيح، وكلاهما من مادة الامتحان. الأول هو الكلفة: إعادة استخدام gamma لا تضيف معاملات جديدة ولا طبقات جديدة. يقول Liu et al. إنها لا تُدخل أي عبء إضافي، وفي PyTorch يوجد المتجه أصلًا في BatchNorm2d.weight، وهو معامل قابل للتعلّم حجمه C ومهيّأ بالقيمة واحد، بجانب beta في BatchNorm2d.bias المهيّأ بالصفر، مع epsilon = 1e-5 افتراضيًا.
Second, and more subtle, meaning. Suppose you skipped batch normalization and simply inserted a scaling layer after the convolution. Convolution is linear and scaling is linear, so the network could halve every factor and double the corresponding filter weights without changing a single output. The factor would then say nothing about importance, because the network can move magnitude freely between the factor and the weights, and an L1 penalty on the factor would be defeated the same way. Liu et al. call such a factor meaningless. Batch normalization breaks the symmetry: the normalized activation has a fixed unit scale regardless of what the filter weights do, so gamma alone sets the size of the channel's output and its magnitude is a genuine measure of how much the channel contributes.
الأمر الثاني، وهو أدق، هو المعنى. افترض أنك تخطّيت batch normalization وأدخلت ببساطة طبقة تحجيم بعد الالتفاف. الالتفاف خطي والتحجيم خطي، فتستطيع الشبكة أن تقسم كل معامل على اثنين وتضاعف أوزان المرشح المقابل دون أن يتغير أي خرج. عندها لن يقول المعامل شيئًا عن الأهمية، لأن الشبكة تستطيع نقل المقدار بحرية بين المعامل والأوزان، وستُهزم عقوبة L1 على المعامل بالطريقة نفسها. يصف Liu et al. مثل هذا المعامل بأنه بلا معنى. أما batch normalization فيكسر هذا التماثل: التنشيط المطبَّع له مقياس ثابت يساوي واحدًا مهما فعلت أوزان المرشح، فتحدد gamma وحدها حجم خرج القناة، ويكون مقدارها مقياسًا حقيقيًا لمدى مساهمة القناة.
Recall
Why does network slimming reuse batch norm gamma instead of adding a new scaling layer?لماذا يعيد network slimming استخدام gamma في batch norm بدلًا من إضافة طبقة تحجيم جديدة؟
Recall
Factors 1.17, 0.10, 0.29, 0.82 and 0.56 with a threshold of 0.3: which filters go?المعاملات 1.17 و0.10 و0.29 و0.82 و0.56 مع عتبة 0.3: أي المرشحات تُحذف؟
Quick checkاختبار سريع
Why does network slimming reuse batch normalization's gamma as the channel scaling factor?لماذا يعيد network slimming استخدام gamma في batch normalization بوصفها معامل تحجيم القناة؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- A criterion estimates importance. The less important the removed parameters, the better the pruned network performs.المعيار يقدّر الأهمية. كلما قلّت أهمية المعاملات المحذوفة كان أداء الشبكة المقلَّمة أفضل.
- Magnitude pruning uses absolute value, never the signed weight: -5 is more important than 3.تقليم المقدار يستخدم القيمة المطلقة وليس الوزن بإشارته أبدًا: الوزن -5 أهم من الوزن 3.
- Element-wise: Importance = |W|. [[3, -2], [1, -5]] at 50 percent sparsity becomes [[3, 0], [0, -5]].على مستوى العنصر: Importance = |W|. المصفوفة [[3, -2], [1, -5]] عند تناثر 50 بالمئة تصبح [[3, 0], [0, -5]].
- Row-wise L1 gives 5 and 6, row-wise L2 gives 3.61 and 5.10. Both prune row 0, giving [[0, 0], [1, -5]].على مستوى الصف يعطي L1 القيمتين 5 و6، ويعطي L2 القيمتين 3.61 و5.10. كلاهما يقلّم الصف 0، فتصبح المصفوفة [[0, 0], [1, -5]].
- General form: ||W^(S)||_p = (sum over i in S of |w_i|^p)^(1/p). L1 favors many moderate weights, L2 favors one dominant weight, as [3, 3] against [0, 5] shows.الصيغة العامة: ||W^(S)||_p = (مجموع |w_i|^p على كل i في S)^(1/p). المعيار L1 يفضّل أوزانًا متوسطة كثيرة، والمعيار L2 يفضّل وزنًا واحدًا مهيمنًا، كما تُظهر المقارنة بين [3, 3] و[0, 5].
- Scaling-based pruning trains one factor per output channel and prunes small |gamma|. Network slimming adds an L1 penalty on gamma and prunes below a global percentile.التقليم القائم على التحجيم يدرّب معاملًا واحدًا لكل قناة خرج ويقلّم القنوات ذات |gamma| الصغيرة. أسلوب network slimming يضيف عقوبة L1 على gamma ويقلّم ما يقع تحت نسبة مئوية (percentile) عامة واحدة.
- Batch norm gamma is that factor for free: z_o = gamma (z_i - mu_B)/sqrt(sigma_B^2 + epsilon) + beta, one gamma per channel, no extra parameters.قيمة gamma في batch norm هي هذا المعامل مجانًا: z_o = gamma (z_i - mu_B)/sqrt(sigma_B^2 + epsilon) + beta، قيمة gamma واحدة لكل قناة، ومن دون أي معاملات إضافية.
Sourcesالمصادر
- Learning both Weights and Connections for Efficient Neural NetworksPaperHan, Pool, Tran and Dally, NeurIPS 2015Threshold on absolute value, threshold as quality parameter times layer std, 9x AlexNet and 13x VGG-16 with iterative pruningعتبة على القيمة المطلقة، والعتبة بوصفها معامل جودة مضروبًا في الانحراف المعياري للطبقة، و9x على AlexNet و13x على VGG-16 مع التقليم التكراري(opens in a new tab)(يفتح في تبويب جديد)
- Pruning Filters for Efficient ConvNetsPaperLi, Kadav, Durdanovic, Samet and Graf, ICLR 2017Filter importance as the sum of absolute kernel weights; smallest beats random and largest; 34 percent VGG-16 and 38 percent ResNet-110 FLOP cuts on CIFAR-10أهمية المرشح بوصفها مجموع القيم المطلقة لأوزان النواة؛ حذف الأصغر يتفوق على الحذف العشوائي وحذف الأكبر؛ وخفض FLOPs بنسبة 34 بالمئة على VGG-16 و38 بالمئة على ResNet-110 مع CIFAR-10(opens in a new tab)(يفتح في تبويب جديد)
- Learning Structured Sparsity in Deep Neural NetworksPaperWen, Wu, Wang, Chen and Li, NeurIPS 2016Group Lasso with the L2 norm of each group; filter, channel, shape and depth structures; 5.1x CPU and 3.1x GPU AlexNet conv speedupsأسلوب group Lasso بمعيار L2 لكل مجموعة؛ وبنى على مستوى المرشح والقناة والشكل والعمق؛ وتسريع طبقات الالتفاف في AlexNet بمقدار 5.1x على CPU و3.1x على GPU(opens in a new tab)(يفتح في تبويب جديد)
- Learning Efficient Convolutional Networks through Network SlimmingPaperLiu, Li, Shen, Huang, Yan and Zhang, ICCV 2017L1 penalty on BN gamma, global percentile threshold, why a bare scaling layer is meaningless, VGGNet CIFAR-10 numbersعقوبة L1 على gamma في BN، وعتبة نسبة مئوية (percentile) عامة، ولماذا تكون طبقة التحجيم المجردة بلا معنى، وأرقام VGGNet على CIFAR-10(opens in a new tab)(يفتح في تبويب جديد)
- Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate ShiftPaperIoffe and Szegedy, ICML 2015Algorithm 1: mini-batch mean and variance, normalization with epsilon, learned gamma and beta per feature mapالخوارزمية 1: متوسط وتباين الدفعة الصغيرة (mini-batch)، والتطبيع مع epsilon، وقيمتا gamma وbeta المتعلَّمتان لكل خريطة سمات(opens in a new tab)(يفتح في تبويب جديد)
- Deep Learning, chapter 2.5: NormsBookGoodfellow, Bengio and Courville, MIT PressLp norm definition (eq. 2.30), L1 versus squared L2 growth, L0 as incorrect terminologyتعريف معيار Lp (المعادلة 2.30)، ونمو L1 مقابل مربع L2، وتسمية L0 بوصفها مصطلحًا غير صحيح(opens in a new tab)(يفتح في تبويب جديد)
- Deep Learning, section 8.7.1: Batch NormalizationBookGoodfellow, Bengio and Courville, MIT PressWhy gamma and beta are reintroduced after normalizationلماذا تُعاد gamma وbeta بعد التطبيع(opens in a new tab)(يفتح في تبويب جديد)
- torch.nn.utils.prune.l1_unstructuredDocsPyTorch documentationRemoves the units with the lowest L1 norm; amount as a fraction or a countتحذف الوحدات ذات أدنى معيار L1؛ ويكون amount نسبة أو عددًا(opens in a new tab)(يفتح في تبويب جديد)
- torch.nn.utils.prune.ln_structuredDocsPyTorch documentationRemoves channels with the lowest Ln norm along a chosen dimensionتحذف القنوات ذات أدنى معيار Ln على امتداد بُعد مختار(opens in a new tab)(يفتح في تبويب جديد)
- torch.nn.BatchNorm2dDocsPyTorch documentationgamma and beta as learnable vectors of size C, gamma initialized to 1, eps default 1e-5gamma وbeta متجهان قابلان للتعلم بحجم C، وتبدأ gamma بالقيمة 1، والقيمة الافتراضية لـ eps هي 1e-5(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, fall 2024DocsMIT HAN LabLectures 3 and 4, Pruning and Sparsity, the source lineage of these slidesالمحاضرتان 3 و4، التقليم والتناثر (Pruning and Sparsity)، وهما الأصل الذي انحدرت منه هذه الشرائح(opens in a new tab)(يفتح في تبويب جديد)
Part 06: Second-order, activation and regression criteriaمعايير الرتبة الثانية والتنشيط والانحدار
Optimal Brain Damage's Taylor-expansion importance 1/2 h_ii w_i^2, neuron pruning as coarse-grained weight pruning, APoZ activation-sparsity scoring, and regression-based channel pruning that minimizes layer output reconstruction error.أهمية Optimal Brain Damage المبنية على مفكوك تايلور 1/2 h_ii w_i^2، وتقليم العصبونات بوصفه تقليمًا خشنًا للأوزان، وتقييم تناثر التنشيط APoZ، وتقليم القنوات القائم على الانحدار الذي يقلل خطأ إعادة بناء مخرج الطبقة.
6 concepts6 مفاهيم, ، slides 34-43الشرائح 34-43
Why this part mattersلماذا يهمّ هذا الجزء
Part 05 ranked weights by their absolute value and nothing else. That rule cannot tell a small weight sitting in a steep valley of the loss from a small weight resting on a flat plain, and only one of those two is safe to delete. This part gives you three criteria that look past the weight value to what actually happens when the weight is gone.
The first reads the curvature of the loss: Optimal Brain Damage from 1989, the root of the SparseGPT-style methods that prune large language models today. The second reads the activations: APoZ, the cheapest data-driven structured criterion you can run before deploying on an embedded board. The third reads the layer output itself: regression-based channel pruning, the basis of the pipelines used to shrink networks for edge accelerators. All three are standard exam derivations, and the reasoning behind them is what you will reuse when your research project has to justify a pruning choice.
رتّب الجزء 05 الأوزان بحسب قيمتها المطلقة ولا شيء غير ذلك. هذه القاعدة لا تستطيع التمييز بين وزن صغير يقع في وادٍ شديد الانحدار من سطح الخسارة ووزن صغير يستقر على سهل منبسط، وواحد فقط من هذين الوزنين يمكن حذفه بأمان. يقدّم لك هذا الجزء ثلاثة معايير تنظر إلى ما وراء قيمة الوزن، أي إلى ما يحدث فعلًا حين يختفي الوزن.
المعيار الأول يقرأ انحناء دالة الخسارة: Optimal Brain Damage من عام 1989، وهو أصل الطرق على نمط SparseGPT التي تقلّم النماذج اللغوية الكبيرة اليوم. المعيار الثاني يقرأ التنشيطات (activations): APoZ، وهو أرخص معيار هيكلي (structured) قائم على البيانات يمكنك تشغيله قبل النشر على لوحة مدمجة. المعيار الثالث يقرأ مخرجات الطبقة نفسها: التقليم القائم على الانحدار لاختيار القنوات (regression-based channel pruning)، وهو أساس خطوط المعالجة المستخدمة لتصغير الشبكات من أجل مسرّعات الحافة (edge accelerators). الثلاثة كلها اشتقاقات امتحانية معتادة، والمنطق الذي يقف خلفها هو ما ستعيد استخدامه حين يحتاج مشروعك البحثي إلى تبرير اختيار طريقة تقليم.
By the end you canفي نهاية هذا الجزء ستستطيع
- Derive the OBD importance 1/2 h_ii w_i^2 from the Taylor expansion and name the assumption that removes each term.تشتق أهمية OBD وهي 1/2 h_ii w_i^2 من مفكوك تايلور، وتسمّي الافتراض الذي يحذف كل حد.
- Explain why magnitude pruning is OBD with a constant Hessian diagonal, and show a case where the two rankings disagree.تشرح لماذا يُعدّ التقليم بالمقدار (magnitude pruning) حالة من OBD يكون فيها قطر الـ Hessian ثابتًا، وتعرض حالة يختلف فيها الترتيبان.
- Compute APoZ for a channel from its activation maps and decide which channel to prune.تحسب APoZ لقناة من خرائط تنشيطها، وتقرر أي قناة تُقلَّم.
- State the regression-based channel pruning objective, its L0 constraint and the two alternating LASSO and least-squares steps.تكتب هدف التقليم القائم على الانحدار لاختيار القنوات، وقيد L0 فيه، والخطوتين المتناوبتين: LASSO ثم المربعات الصغرى (least squares).
- Place each criterion in the reference list and say what data it needs.تضع كل معيار في مكانه من قائمة المراجع، وتذكر ما يحتاجه من بيانات.
Start with a trained network and its loss L(x; W). Setting one weight to zero moves the parameter vector from W to W_P = W + δW, where δW is zero everywhere except at the pruned position, where δw_i = -w_i. The question every criterion in this part is trying to answer is simple: how much does the loss move? You could answer it exactly by re-evaluating the loss after each candidate deletion, but LeCun, Denker and Solla call that approach prohibitively laborious, and for a network with thousands of weights it is. Second-order pruning builds a local model of the loss instead.
ابدأ بشبكة مدرَّبة ودالة خسارتها L(x; W). جعل وزن واحد صفرًا ينقل متجه المعاملات من W إلى W_P = W + δW، حيث δW صفر في كل مكان عدا الموضع المقلَّم، وفيه δw_i = -w_i. السؤال الذي يحاول كل معيار في هذا الجزء أن يجيب عنه بسيط: بكم تتحرك الخسارة؟ يمكنك الإجابة بدقة بإعادة حساب الخسارة بعد كل عملية حذف مرشَّحة، لكن LeCun وDenker وSolla يصفون هذا الأسلوب بأنه مُرهِق إلى حد يمنع استخدامه، وهو كذلك فعلًا لشبكة فيها آلاف الأوزان. لذلك يبني second-order pruning نموذجًا محليًا للخسارة بدلًا من ذلك.
One weight before the general case. A weight sits at w = 0.5 in a valley of the loss surface given by L(w) = 1 + 2(w - 0.5)². Setting it to zero walks back to w = 0 and raises the loss from 1 to 1.5, and that rise is exactly ½ h w² with curvature h = 4: the gradient at the bottom of the valley is zero, so the first-order term contributes nothing and the curvature term contributes everything. Now scale the picture up to a whole parameter vector. The local model is a Taylor expansion of the loss around the trained point. Perturbing the weights by δW changes the loss by a first-order slope term, a second-order curvature term, and a remainder that shrinks as the cube of the perturbation.
لنبدأ بوزن واحد قبل الحالة العامة. يقع وزن عند w = 0.5 في وادٍ من سطح الخسارة معطى بالعلاقة L(w) = 1 + 2(w - 0.5)². جعله صفرًا يعيده إلى w = 0 ويرفع الخسارة من 1 إلى 1.5، وهذه الزيادة تساوي تمامًا ½ h w² مع انحناء h = 4: الميل عند قاع الوادي صفر، فحد الدرجة الأولى لا يساهم بشيء وحد الانحناء يساهم بكل شيء. الآن كبّر الصورة إلى متجه معاملات كامل. النموذج المحلي هو Taylor expansion للخسارة حول النقطة المدرَّبة. تحريك الأوزان بمقدار δW يغيّر الخسارة بحد ميل من الدرجة الأولى، وحد انحناء من الدرجة الثانية، وباقٍ يصغر بمكعّب مقدار الاضطراب.
Read the four pieces one at a time. The first sum is the slope: how fast the loss rises if you nudge each weight on its own. The second sum is the self-curvature: how quickly that slope itself changes along each weight's own axis, weighted by the square of the nudge. The third sum is the cross-curvature: whether moving weight i also tilts the loss along weight j. The last piece is everything the quadratic picture misses. The Hessian is the matrix that holds the second and third pieces together: its diagonal h_ii feeds the self-curvature sum and its off-diagonal h_ij feeds the cross terms.
اقرأ الأجزاء الأربعة واحدًا تلو الآخر. المجموع الأول هو الميل: مدى سرعة ارتفاع الخسارة إذا حرّكت كل وزن وحده. المجموع الثاني هو الانحناء الذاتي: مدى سرعة تغيّر هذا الميل نفسه على امتداد محور كل وزن، مضروبًا في مربع مقدار التحريك. المجموع الثالث هو الانحناء التقاطعي: هل تحريك الوزن i يُميل الخسارة أيضًا على امتداد الوزن j؟ والجزء الأخير هو كل ما تفوته الصورة التربيعية. الـ Hessian هو المصفوفة التي تجمع الجزأين الثاني والثالث: قطرها h_ii يغذّي مجموع الانحناء الذاتي، وعناصرها خارج القطر h_ij تغذّي الحدود التقاطعية.
Goodfellow, Bengio and Courville define the Hessian exactly this way, as the matrix with entries ∂²f/(∂x_i ∂x_j), and note that it is symmetric wherever the second partials are continuous. The cross sum runs over ordered pairs i ≠ j, so each unordered pair appears twice, once as (i, j) and once as (j, i); the one half in front is the second-order Taylor coefficient from ½ δWᵀ H δW, not a symmetry correction. Because H is symmetric the same term can be written without the one half as Σ_{i < j} h_ij δw_i δw_j. They also use this same second-order expansion to derive Newton's method, so the expression on the slide is not a pruning trick: it is the standard local model of any smooth function.
يعرّف Goodfellow وBengio وCourville الـ Hessian بهذه الطريقة بالضبط، أي المصفوفة التي عناصرها ∂²f/(∂x_i ∂x_j)، ويلاحظون أنها متماثلة (symmetric) حيثما كانت المشتقات الجزئية الثانية متصلة. المجموع التقاطعي يمر على الأزواج المرتبة i ≠ j، فيظهر كل زوج غير مرتب مرتين، مرة بصورة (i, j) ومرة بصورة (j, i)؛ والنصف الموجود في المقدمة هو معامل تايلور من الدرجة الثانية القادم من ½ δWᵀ H δW، وليس تصحيحًا بسبب التماثل. ولأن H متماثلة، يمكن كتابة الحد نفسه دون النصف بصورة Σ_{i < j} h_ij δw_i δw_j. ويستخدم المؤلفون أيضًا المفكوك نفسه من الدرجة الثانية لاشتقاق طريقة نيوتن (Newton's method)، فالتعبير الموجود في الشريحة ليس حيلة خاصة بالتقليم: إنه النموذج المحلي القياسي لأي دالة ملساء.
How big the Hessian is for the OBD zip-code network (LeCun et al., 1989, p. 600)حجم الـ Hessian لشبكة الرموز البريدية في OBD (LeCun وزملاؤه، 1989، ص 600)
- Parametersالمعاملات
- about 2600 (2578 free parameters)نحو 2600 (2578 معاملًا حرًا)
- Full Hessian entriesعناصر الـ Hessian الكامل
- about 6.5 × 10⁶, the figure the paper quotesنحو 6.5 × 10⁶، وهو الرقم الذي تذكره الورقة
- Diagonal entriesعناصر القطر
- about 2600, one per parameterنحو 2600، عنصر واحد لكل معامل
The table is the reason the rest of this part exists. Even a 1989 network with about 2600parameters has millions of Hessian entries, and a modern network with 10⁸ weights would have 10¹⁶. Nobody computes that matrix. The whole art of second-order pruning is deciding which of its entries you can afford to ignore.
هذا الجدول هو سبب وجود بقية هذا الجزء. حتى شبكة من عام 1989 فيها نحو 2600 معامل تملك ملايين العناصر في الـ Hessian، وشبكة حديثة فيها 10⁸ وزن سيكون لديها 10¹⁶ عنصر. لا أحد يحسب هذه المصفوفة. فن التقليم من الدرجة الثانية كله هو أن تقرر أي عناصرها يمكنك تحمّل تجاهله.
Recall
Write the second-order Taylor expansion of the loss change and name what each of its four pieces measures.اكتب مفكوك تايلور من الدرجة الثانية لتغيّر الخسارة، وسمِّ ما يقيسه كل جزء من أجزائه الأربعة.
Four terms is three too many. Optimal Brain Damage keeps the expansion usable by making three assumptions, and each one erases exactly one piece of the sum. The paper gives them names, the slide gives them plain-language bullets, and you should be able to match the two lists and say which term each one kills.
أربعة حدود تزيد ثلاثة عن الحاجة. يُبقي Optimal Brain Damage المفكوك قابلًا للاستخدام عبر ثلاثة افتراضات، وكل افتراض يمحو جزءًا واحدًا بالضبط من المجموع. الورقة تعطي هذه الافتراضات أسماء، والشريحة تعرضها بنقاط بلغة بسيطة، وعليك أن تستطيع المطابقة بين القائمتين وتقول أي حد يقضي عليه كل افتراض.
| OBD nameالاسم في OBD | Slide wordingصياغة الشريحة | Term removedالحد المحذوف | Why it is allowedلماذا يُسمح به |
|---|---|---|---|
| Quadraticالتربيعي (Quadratic) | L is nearly quadraticالخسارة L تربيعية تقريبًا | O(||δW||³)O(||δW||³) | Near the minimum the loss surface is well described by its curvature alone, so the cubic remainder is negligible.قرب القيمة الصغرى يصف الانحناء وحده سطح الخسارة وصفًا جيدًا، فيصبح الباقي التكعيبي مهملًا. |
| Extremalالطرفي (Extremal) | Training has convergedالتدريب قد تقارب | Σ gᵢ δwᵢΣ gᵢ δwᵢ | At a local minimum every partial derivative is zero, so the whole first-order sum vanishes and every hᵢᵢ is non-negative.عند قيمة صغرى محلية تكون كل مشتقة جزئية صفرًا، فيتلاشى مجموع الدرجة الأولى كله، وتكون كل قيم hᵢᵢ غير سالبة. |
| Diagonalالقطري (Diagonal) | Deletion errors are independentأخطاء الحذف مستقلة | ½ Σᵢ≠ⱼ hᵢⱼ δwᵢ δwⱼ½ Σᵢ≠ⱼ hᵢⱼ δwᵢ δwⱼ | The cost of deleting several weights is taken as the sum of their individual costs, which is exactly what dropping the off-diagonal terms means.تُعدّ كلفة حذف عدة أوزان مساوية لمجموع كلفها المنفردة، وهذا بالضبط معنى إسقاط الحدود خارج القطر. |
The extremal assumption does double duty. Because training stopped at a local minimum, the gradient is zero and the first sum disappears, but LeCun, Denker and Solla also point out that at a local minimum all the h_ii are non-negative, so any perturbation of the parameters will cause the loss to increase or stay the same. That single sentence is the source of the footnote on slide 36 that h_ii is non-negative, and it is what lets the surviving term serve as a cost rather than a signed change.
الافتراض الطرفي (extremal) يؤدي مهمتين. لأن التدريب توقف عند قيمة صغرى محلية، يكون الميل صفرًا فيختفي المجموع الأول، لكن LeCun وDenker وSolla يشيرون أيضًا إلى أن كل قيم h_ii عند القيمة الصغرى المحلية غير سالبة، فأي اضطراب في المعاملات سيجعل الخسارة تزيد أو تبقى كما هي. هذه الجملة الواحدة هي مصدر الحاشية في الشريحة 36 التي تقول إن h_ii غير سالبة، وهي ما يسمح للحد الباقي بأن يعمل ككلفة لا كتغيّر له إشارة.
What survives is the diagonal curvature term alone. Deleting weight i means setting it to zero and, in the paper's words, freezing it there, so the step along that axis has the size of the weight itself, |δw_i| = |w_i|. The squared terms of the expansion do not care about the sign of δw_i, so substitute and you have the OBD estimate of the loss increase.
ما يبقى هو حد الانحناء القطري وحده. حذف الوزن i يعني جعله صفرًا، وبتعبير الورقة تجميده هناك، فتكون الخطوة على ذلك المحور بحجم الوزن نفسه، |δw_i| = |w_i|. الحدود المربعة في المفكوك لا تهتم بإشارة δw_i، فعوّض وستحصل على تقدير OBD لزيادة الخسارة.
The paper calls this quantity the saliency of a parameter, s_k = h_kk w_k² / 2 (the paper writes its parameter as u_k, the same variable as the w_k used on the slide and here), and the recipe is to delete the parameters with the lowest saliency. Notice what the formula says about a weight's importance: it is the product of two things, how large the weight is and how sharply the loss curves along that weight's axis. Magnitude pruning from part 05 kept only the first factor.
تسمي الورقة هذه الكمية saliency (البروز) للمعامل، s_k = h_kk w_k² / 2 (تكتب الورقة معاملها بالرمز u_k، وهو المتغير نفسه الذي يُكتب w_k في الشريحة وهنا)، والوصفة هي حذف المعاملات ذات البروز الأقل. لاحظ ما تقوله الصيغة عن أهمية الوزن: إنها حاصل ضرب شيئين، حجم الوزن ومدى حدة انحناء الخسارة على امتداد محور ذلك الوزن. أما التقليم بالمقدار في الجزء 05 فأبقى العامل الأول فقط.
Magnitude pruning is OBD with the curvature assumed constantالتقليم بالمقدار هو OBD مع افتراض أن الانحناء ثابت
Suppose every h_ii were the same number h. Then importance would be (h/2) w_i², and ranking weights by that value is exactly ranking them by |w_i|, since squaring and scaling by a positive constant preserve the order. So Magnitude-based pruning is OBD under a fourth, hidden assumption: that the loss curves equally steeply along every weight. The 1989 paper states its goal as moving beyond the approximation that magnitude equals saliency, and the point of a second-order criterion is to drop that assumption. The table below is a small case where doing so changes the answer.
افترض أن كل h_ii تساوي العدد نفسه h. عندها تصبح الأهمية (h/2) w_i²، وترتيب الأوزان بهذه القيمة هو بالضبط ترتيبها بحسب |w_i|، لأن التربيع والضرب في ثابت موجب يحافظان على الترتيب. إذن magnitude-based pruning هو OBD تحت افتراض رابع خفي: أن الخسارة تنحني بالحدة نفسها على امتداد كل وزن. تذكر ورقة 1989 أن هدفها هو تجاوز التقريب الذي يجعل المقدار مساويًا للبروز، والغاية من معيار من الدرجة الثانية هي التخلص من هذا الافتراض. الجدول التالي حالة صغيرة يغيّر فيها ذلك الإجابة.
| Weightالوزن | wᵢwᵢ | hᵢᵢhᵢᵢ | |wᵢ||wᵢ| | ½ hᵢᵢ wᵢ²½ hᵢᵢ wᵢ² | Magnitudeالمقدار | OBDOBD |
|---|---|---|---|---|---|---|
| AA | 1.51.5 | 0.20.2 | 1.51.5 | 0.2250.225 | keepيُبقى | pruneيُقلَّم |
| BB | 1.01.0 | 1.01.0 | 1.01.0 | 0.50.5 | keepيُبقى | keepيُبقى |
| CC | -0.6-0.6 | 4.04.0 | 0.60.6 | 0.720.72 | keepيُبقى | keepيُبقى |
| DD | 0.50.5 | 8.08.0 | 0.50.5 | 1.01.0 | pruneيُقلَّم | keepيُبقى |
| EE | 0.20.2 | 2.02.0 | 0.20.2 | 0.040.04 | pruneيُقلَّم | pruneيُقلَّم |
Worked exampleمثال محلول
Five weights, two rankings, prune twoخمسة أوزان، ترتيبان، نقلّم اثنين
Square each weightربّع كل وزن
1.5² = 2.25, 1.0² = 1.0, (-0.6)² = 0.36, 0.5² = 0.25, 0.2² = 0.04. The sign of C disappears, as it does in |w|.1.5² = 2.25، 1.0² = 1.0، (-0.6)² = 0.36، 0.5² = 0.25، 0.2² = 0.04. تختفي إشارة C، كما تختفي في |w|.Multiply by the curvature and halveاضرب في الانحناء ثم خذ النصف
A: ½ × 0.2 × 2.25 = 0.225, B: ½ × 1.0 × 1.0 = 0.5, C: ½ × 4.0 × 0.36 = 0.72, D: ½ × 8.0 × 0.25 = 1.0, E: ½ × 2.0 × 0.04 = 0.04.A: ½ × 0.2 × 2.25 = 0.225، B: ½ × 1.0 × 1.0 = 0.5، C: ½ × 4.0 × 0.36 = 0.72، D: ½ × 8.0 × 0.25 = 1.0، E: ½ × 2.0 × 0.04 = 0.04.Rank by each criterion, lowest firstرتّب بحسب كل معيار، من الأقل إلى الأعلى
Magnitude: E, D, C, B, A. Saliency: E, A, B, C, D.المقدار (Magnitude): E, D, C, B, A. البروز (Saliency): E, A, B, C, D.Pruning two weightsتقليم وزنين
Both criteria delete E. Magnitude then deletes D, the weight OBD rates as the most important of all five. OBD deletes A instead, the largest weight in the set, because it sits on almost flat ground.كلا المعيارين يحذف E. ثم يحذف معيار المقدار D، وهو الوزن الذي يعدّه OBD الأهم بين الخمسة كلها. أما OBD فيحذف A بدلًا منه، وهو أكبر وزن في المجموعة، لأنه يقع على أرض شبه منبسطة.
| Weight | w_i | h_ii | |w_i| | ½ h_ii w_i² | mag rank | magnitude | obd rank | obd |
|---|---|---|---|---|---|---|---|---|
| A | 1.5 | 0.225 | 5 | keep | 2 | prune | ||
| B | 1 | 0.5 | 4 | keep | 3 | keep | ||
| C | 0.6 | 0.72 | 3 | keep | 4 | keep | ||
| D | 0.5 | 1 | 2 | prune | 5 | keep | ||
| E | 0.2 | 0.04 | 1 | prune | 1 | prune |
Set every h_ii in the table to the same value and watch the two decision columns fall into line. Then give a small weight a large curvature and watch them split again. That is the entire relationship between the two criteria in one gesture.
اجعل كل h_ii في الجدول بالقيمة نفسها وراقب عمودي القرار وهما يتطابقان. ثم أعطِ وزنًا صغيرًا انحناءً كبيرًا وراقبهما يفترقان من جديد. هذه هي العلاقة كاملة بين المعيارين في حركة واحدة.
Why the slide says the Hessian is difficultلماذا تقول الشريحة إن الـ Hessian صعب
The full Hessian has n² entries, and the previous concept showed that this is out of reach even for a small network. OBD never computes it. The diagonal approximation means only the n entries h_ii are needed, and the paper derives a second back-propagation pass that computes them with, in its words, the same order of complexity as computing the gradient. Along the way it drops the terms involving the second derivative of the activation function, a Levenberg-Marquardt style approximation that gives guaranteed positive estimates of the second derivative. So the difficulty the slide flags is real for the full matrix and for networks with 10⁸ parameters, where even a diagonal pass over the whole training set is expensive, but it is not a reason OBD itself was impractical. Optimal Brain Surgeon (Hassibi and Stork, 1993) kept the cross terms by using the inverse of the full Hessian. SparseGPT (2023) makes second-order pruning practical at scale by solving layer-wise reconstruction problems with block-wise Hessian updates, which the final concept points to.
الـ Hessian الكامل فيه n² عنصر، وقد بيّن المفهوم السابق أن هذا بعيد المنال حتى لشبكة صغيرة. OBD لا يحسبه أبدًا. التقريب القطري يعني أن المطلوب فقط هو العناصر n وهي h_ii، وتشتق الورقة تمريرًا ثانيًا للانتشار العكسي يحسبها، بتعبيرها، بنفس رتبة تعقيد حساب الميل. وفي الطريق تُسقط الحدود التي تتضمن المشتقة الثانية لدالة التنشيط، وهو تقريب على نمط Levenberg-Marquardt يعطي تقديرات موجبة مضمونة للمشتقة الثانية. إذن الصعوبة التي تشير إليها الشريحة حقيقية بالنسبة للمصفوفة الكاملة وللشبكات ذات 10⁸ معامل، حيث يكون حتى التمرير القطري على كامل مجموعة التدريب مكلفًا، لكنها ليست سببًا في أن OBD نفسه كان غير عملي. أبقى Optimal Brain Surgeon (Hassibi وStork، 1993) على الحدود التقاطعية باستخدام معكوس الـ Hessian الكامل. ويجعل SparseGPT (2023) التقليم من الدرجة الثانية عمليًا على نطاق واسع بحل مسائل إعادة بناء على مستوى كل طبقة مع تحديثات للـ Hessian على شكل كتل (block-wise)، وهو ما يشير إليه المفهوم الأخير.
The recipe and what it achievedالوصفة وما حققته
The abstract on the slide states the motivation the formula serves. Deleting unimportant weights is a trade-off between network complexity and training-set error, and the paper expects better generalization, fewer training examples required and faster learning and classification from it. That is why the recipe below is framed as model selection, not only compression.
الملخص الموجود في الشريحة يذكر الدافع الذي تخدمه الصيغة. حذف الأوزان غير المهمة موازنة بين تعقيد الشبكة وخطأ مجموعة التدريب، وتتوقع الورقة من ذلك تعميمًا أفضل، وحاجة إلى أمثلة تدريب أقل، وتعلّمًا وتصنيفًا أسرع. لهذا تُصاغ الوصفة التالية على أنها اختيار للنموذج (model selection)، لا مجرد ضغط.
- Choose a reasonable network architecture.اختر معمارية شبكة معقولة.
- Train the network until reasonable convergence.درّب الشبكة حتى تتقارب تقاربًا معقولًا.
- Compute the second derivatives h_kk for each parameter.احسب المشتقات الثانية h_kk لكل معامل.
- Compute the saliencies s_k = h_kk w_k² / 2.احسب قيم البروز s_k = h_kk w_k² / 2.
- Sort the parameters by saliency and delete some low-saliency parameters.رتّب المعاملات بحسب البروز واحذف بعض المعاملات ذات البروز المنخفض.
- Return to step 2.عُد إلى الخطوة 2.
The loop back to training is the Iterative pruning and Fine-tuning pattern from part 02, thirty years earlier. The 1989 experiment applied it to a handwritten zip-code recognizer.
العودة إلى التدريب هي نمط iterative pruning وfine-tuning من الجزء 02، قبله بثلاثين عامًا. طبّقت تجربة 1989 هذا النمط على نظام للتعرف على الرموز البريدية المكتوبة بخط اليد.
Optimal Brain Damage results (LeCun, Denker and Solla, 1989)نتائج Optimal Brain Damage (LeCun وDenker وSolla، 1989)
- Setupالإعداد
- about 10⁵ connections controlled by 2578 free parameters, trained on roughly 9300 digits and tested on 3350نحو 10⁵ وصلة يتحكم فيها 2578 معاملًا حرًا، دُرّبت على نحو 9300 رقم واختُبرت على 3350
- Prediction qualityجودة التنبؤ
- The quadratic, extremal, diagonal estimate tracks the measured loss up to about 800 deleted parameters, roughly 30%; beyond that the cross terms and higher-order terms the approximation dropped start to matterالتقدير التربيعي الطرفي القطري يتبع الخسارة المقيسة حتى نحو 800 معامل محذوف، أي قرابة 30%؛ وبعد ذلك تبدأ الحدود التقاطعية والحدود الأعلى رتبة التي أسقطها التقريب في التأثير
- After retrainingبعد إعادة التدريب
- Up to 1500 parameters, about 60%, deleted with almost unchanged training and test errorحُذف حتى 1500 معامل، أي نحو 60%، مع بقاء خطأ التدريب والاختبار شبه ثابتين
- Versus magnitudeمقارنة بالمقدار
- Deleting in order of saliency causes a significantly smaller increase of the objective than deleting by magnitude (figure 1a)الحذف بترتيب البروز يسبب زيادة في دالة الهدف أصغر بكثير من الحذف بحسب المقدار (الشكل 1a)
- Versus randomمقارنة بالحذف العشوائي
- Random deletion was so much worse it could not be plotted on the same scaleكان الحذف العشوائي أسوأ بكثير إلى حد أنه لم يمكن رسمه على المقياس نفسه
- Venueمكان النشر
- Advances in Neural Information Processing Systems 2 (NIPS 1989), AT&T Bell Laboratories, Holmdel NJAdvances in Neural Information Processing Systems 2 (NIPS 1989)، مختبرات AT&T Bell Laboratories، Holmdel NJ
Quick checkاختبار سريع
Under OBD, which assumption removes the first-order gradient term from the Taylor expansion?في OBD، أي افتراض يحذف حد الميل من الدرجة الأولى من مفكوك تايلور؟
Quick checkاختبار سريع
Weight A has w = 1.0 and h = 1; weight B has w = 0.5 and h = 8. Which does OBD keep first?الوزن A فيه w = 1.0 وh = 1، والوزن B فيه w = 0.5 وh = 8. أيهما يُبقيه OBD أولًا؟
Recall
Why is magnitude pruning a special case of OBD?لماذا يُعد التقليم بالمقدار حالة خاصة من OBD؟
Everything so far scored individual synapses. Take a linear layer with 5 inputs and 4 outputs, so its weight matrix has shape [4, 5]. Deleting the second output neuron does not zero one entry; it removes the entire row W[1, :], all 5 incoming weights at once, along with the edges drawn into that neuron on the slide, which is why the lower layer shows three circles with a gap where the fourth stood. The matrix becomes [3, 5], a smaller dense matrix, which is the reason Coarse-grained (structured) pruning gives real speedup without any sparse format.
كل ما سبق كان يقيّم وصلات (synapses) منفردة. خذ طبقة خطية لها 5 مدخلات و4 مخرجات، فتكون مصفوفة أوزانها بالشكل [4, 5]. حذف العصبون الثاني في المخرجات لا يجعل عنصرًا واحدًا صفرًا؛ بل يحذف الصف كاملًا W[1, :]، أي الأوزان الداخلة الـ 5 كلها دفعة واحدة، مع الحواف المرسومة الداخلة إلى ذلك العصبون في الشريحة، ولهذا تُظهر الطبقة السفلى ثلاث دوائر وفجوة في مكان الرابعة. تصبح المصفوفة [3, 5]، أي مصفوفة كثيفة أصغر، وهذا سبب أن coarse-grained pruning يعطي تسريعًا حقيقيًا دون أي صيغة تخزين متفرقة (sparse format).
That is the whole content of the sentence on the slide: Neuron pruning is coarse-grained weight pruning. In a convolution layer with weights of shape [c_o, c_i, k_h, k_w] (recall Convolution weight dimensions), deleting output channel o deletes W[o, :, :, :], one full row of c_i kernels in the slide's grid, where rows 3 and 5 of six filters are blanked out. It also deletes the corresponding map from the layer's output, and therefore the input channel o of every filter in the next layer, a point He et al. make explicitly in their figure. Channel pruning cuts twice.
هذا هو كل مضمون الجملة الموجودة في الشريحة: neuron pruning هو تقليم أوزان خشن الحبيبات. في طبقة التفاف أوزانها بالشكل [c_o, c_i, k_h, k_w] (تذكّر conv weight dimensions)، فإن حذف قناة المخرجات o يحذف W[o, :, :, :]، أي صفًا كاملًا من c_i نواة (kernel) في شبكة الشريحة، حيث يُفرَّغ الصفان 3 و5 من ستة مرشحات. ويحذف أيضًا الخريطة المقابلة من مخرجات الطبقة، وبالتالي قناة المدخلات o في كل مرشح من الطبقة التالية، وهي نقطة يذكرها He وزملاؤه صراحة في الشكل الخاص بهم. إذن channel pruning يقطع مرتين.
| Unit removedالوحدة المحذوفة | Slice deletedالشريحة المحذوفة من الموتر | Weights deletedالأوزان المحذوفة | Shape afterالشكل بعد الحذف |
|---|---|---|---|
| Output neuron of a linear layerعصبون مخرجات في طبقة خطية | W[o, :]W[o, :] | One row: all incoming weights of that neuronصف واحد: كل الأوزان الداخلة إلى ذلك العصبون | [c_o - 1, c_i][c_o - 1, c_i] |
| Output channel (filter) of a conv layerقناة مخرجات (مرشح) في طبقة التفاف | W[o, :, :, :]W[o, :, :, :] | c_i kernels of k_h × k_w eachc_i نواة، كل منها بحجم k_h × k_w | [c_o - 1, c_i, k_h, k_w][c_o - 1, c_i, k_h, k_w] |
| Input channel of the next conv layerقناة مدخلات في طبقة الالتفاف التالية | W[:, o, :, :]W[:, o, :, :] | c_o kernels, one per filter, that read the removed mapc_o نواة، واحدة لكل مرشح، كانت تقرأ الخريطة المحذوفة | [c_o, c_i - 1, k_h, k_w][c_o, c_i - 1, k_h, k_w] |
The rule on the slide is then almost a tautology: the less useful the removed neurons are, the better the pruned network performs. The work is in defining useful. The Pruning criterion question has simply moved up one level of granularity, and part 05 already gave one answer, the L1 or L2 norm of the row or filter. The next two concepts give two answers that need no Hessian and no norm: look at the activations the neuron produces, or look at how well the layer output can be rebuilt without it.
القاعدة الموجودة في الشريحة تكاد تكون بديهية إذن: كلما قلّت فائدة العصبونات المحذوفة، كان أداء الشبكة المقلَّمة أفضل. العمل الحقيقي هو في تعريف معنى الفائدة. سؤال pruning criterion انتقل ببساطة مستوى واحدًا إلى أعلى في درجة الحبيبية (granularity)، وقد أعطى الجزء 05 إجابة واحدة بالفعل، وهي معيار L1 أو L2 للصف أو المرشح. والمفهومان التاليان يعطيان إجابتين لا تحتاجان إلى Hessian ولا إلى معيار (norm): انظر إلى التنشيطات التي ينتجها العصبون، أو انظر إلى مدى إمكانية إعادة بناء مخرجات الطبقة دونه.
Recall
A linear layer has weight shape [8, 16]. You prune three output neurons. How many weights disappear and what is the new shape?طبقة خطية شكل أوزانها [8, 16]. قلّمت ثلاثة عصبونات من المخرجات. كم وزنًا يختفي، وما الشكل الجديد؟
ReLU outputs zero for every negative pre-activation. A channel whose output map is mostly zero, image after image, contributes almost nothing to the layer that follows, whatever its weights look like. Hu, Peng, Tai and Tang turned that observation into a criterion. On VGG-16 they found 631 neurons whose activations were zero more than 90% of the time on ImageNet validation images, and they found that the mean fraction of zeros is far higher in the deeper convolutional layers and the fully connected layers than in the early layers, so most of the redundancy sits at the top of the network.
يُخرج ReLU صفرًا لكل قيمة سالبة قبل التنشيط. القناة التي تكون خريطة مخرجاتها صفرًا في معظمها، صورة بعد صورة، لا تساهم بشيء تقريبًا في الطبقة التي تليها، مهما كان شكل أوزانها. حوّل Hu وPeng وTai وTang هذه الملاحظة إلى معيار. على VGG-16 وجدوا 631 عصبونًا كانت تنشيطاتها صفرًا في أكثر من 90% من الوقت على صور التحقق في ImageNet، ووجدوا أن متوسط نسبة الأصفار أعلى بكثير في طبقات الالتفاف العميقة والطبقات المتصلة بالكامل (fully connected) منه في الطبقات الأولى، فمعظم التكرار الزائد يقع في أعلى الشبكة.
| Layerالطبقة | Mean APoZمتوسط APoZ |
|---|---|
| CONV1-1CONV1-1 | 47.07%47.07% |
| CONV3-3CONV3-3 | 69.93%69.93% |
| CONV4-3CONV4-3 | 87.30%87.30% |
| CONV5-3CONV5-3 | 93.19%93.19% |
| FC6FC6 | 75.26%75.26% |
| FC7FC7 | 74.14%74.14% |
The score is the APoZ. For channel c of a layer, run N validation images through the network, look at every position of the H × W output map for every image, and count how often the value is exactly zero. Divide by the number of positions you looked at.
الدرجة هي APoZ. للقناة c من طبقة ما، مرّر N صورة تحقق عبر الشبكة، وانظر إلى كل موضع في خريطة المخرجات ذات الأبعاد H × W لكل صورة، وعُدّ كم مرة تكون القيمة صفرًا تمامًا. ثم اقسم على عدد المواضع التي نظرت إليها.
The slide writes the same thing as zeros divided by batch times height times width. Its example uses a batch of 2, three channels and 4 × 4 maps, so every channel is judged over 2 × 4 × 4 = 32 positions. Count the bold zeros in each grid and the numbers on the slide come out exactly.
تكتب الشريحة الشيء نفسه على أنه عدد الأصفار مقسومًا على حجم الدفعة (batch) مضروبًا في الارتفاع مضروبًا في العرض. مثالها يستخدم دفعة من 2، وثلاث قنوات، وخرائط 4 × 4، فتُقيَّم كل قناة على 2 × 4 × 4 = 32 موضعًا. عُدّ الأصفار الغامقة في كل شبكة وستخرج أرقام الشريحة بالضبط.
Worked exampleمثال محلول
APoZ for the three channels on the slideAPoZ للقنوات الثلاث في الشريحة
Count zeros per channel in batch 1عُدّ الأصفار في كل قناة في الدفعة 1
Channel 0: 5. Channel 1: 5. Channel 2: 6.القناة 0: 5. القناة 1: 5. القناة 2: 6.Count zeros per channel in batch 2عُدّ الأصفار في كل قناة في الدفعة 2
Channel 0: 6. Channel 1: 7. Channel 2: 8.القناة 0: 6. القناة 1: 7. القناة 2: 8.Divide the totals by 2 x 4 x 4 = 32اقسم المجاميع على 2 x 4 x 4 = 32
Channel 0: 11/32 = 0.344. Channel 1: 12/32 = 0.375. Channel 2: 14/32 = 0.438.القناة 0: 11/32 = 0.344. القناة 1: 12/32 = 0.375. القناة 2: 14/32 = 0.438.Channel 2 is prunedتُقلَّم القناة 2
Smaller APoZ means a more important channel. Channel 2 is silent most often, so it is the one crossed out on the slide; channels 0 and 1 are kept.كلما صغرت APoZ كانت القناة أهم. القناة 2 هي الأكثر صمتًا، لذلك هي المشطوبة في الشريحة؛ وتُبقى القناتان 0 و1.
Zero counts verified against the slide gridsأعداد الأصفار بعد التحقق منها مقابل شبكات الشريحة
- Channel 0القناة 0
- 5 + 6 = 11 zeros, APoZ 11/32 = 34.4%5 + 6 = 11 صفرًا، وAPoZ = 11/32 = 34.4%
- Channel 1القناة 1
- 5 + 7 = 12 zeros, APoZ 12/32 = 37.5%5 + 7 = 12 صفرًا، وAPoZ = 12/32 = 37.5%
- Channel 2القناة 2
- 6 + 8 = 14 zeros, APoZ 14/32 = 43.8%6 + 8 = 14 صفرًا، وAPoZ = 14/32 = 43.8%
- Denominatorالمقام
- batch 2 × height 4 × width 4 = 32الدفعة 2 × الارتفاع 4 × العرض 4 = 32
Each grid is one 4 × 4 output map after ReLU. A zero cell is a position where the pre-activation was negative. Switch batches to edit the other 16 positions of the same channel.كل شبكة هي خريطة مخرجات واحدة بحجم 4 × 4 بعد ReLU. الخلية الصفرية موضع كانت قيمته قبل التفعيل سالبة. بدّل الدفعة لتعديل المواضع الـ 16 الأخرى من القناة نفسها.
| Channel | zeros b1 | zeros b2 | total | APoZ | bar | decision |
|---|---|---|---|---|---|---|
| Channel 0 | 5 | 6 | 11/32 | 34.4% | keep | |
| Channel 1 | 5 | 7 | 12/32 | 37.5% | keep | |
| Channel 2 | 6 | 8 | 14/32 | 43.8% | prune |
APoZ_c = (z_c,1 + z_c,2) / (2 × 4 × 4)
Direction is the only thing people get wrong here, so state it in words: importance falls as APoZ rises. The paper's operating rule, the procedure it names Network Trimming, is to trim the neurons whose APoZ is more than one standard deviation above the layer's mean, which under a Gaussian assumption on APoZ values rejects about 16% of the neurons in a trimmed layer on average. Trimming is iterative: prune a few high-APoZ layers, retrain with the surviving weights initialized from the pre-trim network rather than from scratch, and repeat. The authors show that training the trimmed architecture from scratch leaves more zero-activation neurons than initializing from the trimmed weights does, so the initialization matters.
الاتجاه هو الشيء الوحيد الذي يخطئ فيه الناس هنا، فلنقله بالكلمات: الأهمية تنخفض كلما ارتفعت APoZ. قاعدة العمل في الورقة، أي الإجراء الذي تسميه Network Trimming، هي تشذيب العصبونات التي تزيد APoZ لديها بأكثر من انحراف معياري واحد فوق متوسط الطبقة، وهذا تحت افتراض توزيع غاوسي لقيم APoZ يستبعد في المتوسط نحو 16% من العصبونات في الطبقة المشذَّبة. التشذيب تكراري: قلّم بضع طبقات ذات APoZ مرتفعة، ثم أعِد التدريب مع تهيئة الأوزان الباقية من الشبكة قبل التشذيب بدلًا من البدء من الصفر، وكرّر. ويبيّن المؤلفون أن تدريب المعمارية المشذَّبة من الصفر يترك عصبونات ذات تنشيط صفري أكثر مما تتركه التهيئة من الأوزان المشذَّبة، فالتهيئة مهمة.
Network Trimming results (Hu et al., 2016)نتائج Network Trimming (Hu وزملاؤه، 2016)
- LeNet on MNISTLeNet على MNIST
- 20-50-500-10 trimmed to 20-24-252-10, 3.85× fewer parameters, accuracy 99.31% to 99.26%شُذّبت من 20-50-500-10 إلى 20-24-252-10، بمعاملات أقل بمقدار 3.85×، وتغيّرت الدقة من 99.31% إلى 99.26%
- VGG-16, trim CONV5-3 and FC6VGG-16، تشذيب CONV5-3 وFC6
- Top-5 85.900% before retraining, 90.278% after, above the original 88.444%دقة Top-5 هي 85.900% قبل إعادة التدريب و90.278% بعدها، أعلى من القيمة الأصلية 88.444%
- VGG-16, trim CONV4, CONV5, FC6, FC7 at onceVGG-16، تشذيب CONV4 وCONV5 وFC6 وFC7 دفعة واحدة
- Top-5 falls to 46.650% before retraining, the reason trimming is done a few layers at a timeتنخفض دقة Top-5 إلى 46.650% قبل إعادة التدريب، ولهذا يُجرى التشذيب على بضع طبقات في كل مرة
- Validation setمجموعة التحقق
- ImageNet, N = 50,000 images per APoZ measurementImageNet، بعدد N = 50,000 صورة لكل قياس APoZ
| Criterionالمعيار | Readsما يقرؤه | Costالكلفة | Granularityدرجة الحبيبية | Scoreالدرجة |
|---|---|---|---|---|
| Magnitude (part 05)المقدار (Magnitude، الجزء 05) | Weight values onlyقيم الأوزان فقط | None, read the tensorلا شيء، تُقرأ قيم الموتر مباشرة | Anyأي مستوى | |w|, Lp norm of a structural set|w|، أو معيار Lp لمجموعة هيكلية |
| OBDOBD | Weights and hᵢᵢ from a second backward passالأوزان وقيم hᵢᵢ من تمرير عكسي ثانٍ | About one gradient computationنحو كلفة حساب ميل واحد | Weightالوزن | ½ hᵢᵢ wᵢ²½ hᵢᵢ wᵢ² |
| APoZAPoZ | ReLU outputs on a validation setمخرجات ReLU على مجموعة تحقق | One forward pass over N imagesتمرير أمامي واحد على N صورة | Neuron or channelعصبون أو قناة | Fraction of zero activationsنسبة التنشيطات الصفرية |
| Regressionالانحدار (Regression) | Sampled layer inputs and outputsعيّنات من مدخلات الطبقة ومخرجاتها | LASSO plus least squares per layerLASSO ثم مربعات صغرى لكل طبقة | Input channelقناة مدخلات | Reconstruction error of Zخطأ إعادة بناء Z |
The comparison shows a split that matters for your project. Magnitude and OBD are read off the weights and their derivatives. APoZ and the regression criterion of the next concept are data-driven: they need a forward pass over real inputs, so they capture what the network does on your data rather than what its parameters look like, at the price of needing that data available at pruning time.
تُظهر المقارنة انقسامًا مهمًا لمشروعك. المقدار وOBD يُقرآن من الأوزان ومشتقاتها. أما APoZ ومعيار الانحدار في المفهوم التالي فقائمان على البيانات: يحتاجان إلى تمرير أمامي على مدخلات حقيقية، فيلتقطان ما تفعله الشبكة على بياناتك لا شكل معاملاتها، مقابل ثمن هو ضرورة توفر تلك البيانات وقت التقليم.
Quick checkاختبار سريع
Over a batch of 2 with 4 x 4 maps, channel 2 has 14 zeros and channel 0 has 11. Which is pruned under APoZ?على دفعة من 2 بخرائط 4 x 4، في القناة 2 أربعة عشر صفرًا وفي القناة 0 أحد عشر صفرًا. أيهما يُقلَّم بحسب APoZ؟
Recall
What is the Network Trimming operating threshold, what fraction of a layer's neurons does it remove on average, and why does retraining start from the pre-trim weights?ما عتبة العمل في Network Trimming، وما نسبة عصبونات الطبقة التي تحذفها في المتوسط، ولماذا تبدأ إعادة التدريب من الأوزان السابقة للتشذيب؟
OBD asked what pruning does to the loss. APoZ looked at what a channel emits. He, Zhang and Sun ask a third question that is easier to answer than the first and more precise than the second: after you remove some input channels of a layer, how well can the survivors reproduce the layer's original output? Take one conv layer and sample b positions from real images (the paper used 5000 images with 10 samples each). Unroll each receptive field into a row of a matrix X of shape b × c_i in the slide's simplified picture. The layer's output at those positions is a matrix multiply.
سأل OBD عمّا يفعله التقليم بالخسارة. ونظر APoZ إلى ما تُصدره القناة. أما He وZhang وSun فيطرحون سؤالًا ثالثًا أسهل في الإجابة من الأول وأدق من الثاني: بعد أن تحذف بعض قنوات المدخلات في طبقة ما، إلى أي حد تستطيع القنوات الباقية إعادة إنتاج المخرجات الأصلية للطبقة؟ خذ طبقة التفاف واحدة واسحب عيّنة من b موضعًا من صور حقيقية (استخدمت الورقة 5000 صورة مع 10 عيّنات من كل منها). افرد كل حقل استقبال (receptive field) في صف من مصفوفة X شكلها b × c_i في الصورة المبسطة التي تعرضها الشريحة. مخرجات الطبقة عند تلك المواضع هي عملية ضرب مصفوفات.
The second equality is the whole idea. A matrix product can be split by the shared dimension: column c of X times row c of W^T is one b × c_o outer product, and Z is the sum of c_i of them, one per input channel. Removing input channel c means removing exactly one term of that sum. Regression-based pruning attaches a switch β_c to each term and asks which switches can be turned off while keeping the sum close to the original.
المساواة الثانية هي الفكرة كلها. يمكن تقسيم حاصل ضرب المصفوفات على البعد المشترك: العمود c من X مضروبًا في الصف c من W^T هو ضرب خارجي (outer product) واحد بالشكل b × c_o، وZ هي مجموع c_i من هذه الحواصل، واحد لكل قناة مدخلات. حذف قناة المدخلات c يعني حذف حد واحد بالضبط من هذا المجموع. يربط regression-based pruning مفتاحًا β_c بكل حد، ويسأل أي المفاتيح يمكن إطفاؤها مع إبقاء المجموع قريبًا من الأصل.
Name every symbol. β is the Channel selection coefficient, a vector of length c_i; β_c = 0 prunes input channel c. N_c is the number of channels allowed to survive, so the L0 norm constraint counts nonzero switches, the same kind of constraint as the pruning formulation of part 01. The objective is the Reconstruction error: the Frobenius norm is the square root of the sum of all squared entries, so its square is just the elementwise squared error summed over the whole b × c_o output. Nothing about the network loss, the labels or the layers downstream appears anywhere.
سمِّ كل رمز. β هو channel selection coefficient، وهو متجه طوله c_i؛ وβ_c = 0 تقلّم قناة المدخلات c. وN_c هو عدد القنوات المسموح لها بالبقاء، فقيد L0 norm يعدّ المفاتيح غير الصفرية، وهو من نوع القيد نفسه في صياغة التقليم في الجزء 01. والهدف هو reconstruction error: معيار Frobenius norm هو الجذر التربيعي لمجموع مربعات كل العناصر، فمربعه ببساطة هو مجموع مربعات الأخطاء عنصرًا بعنصر على كامل المخرجات b × c_o. لا يظهر في أي مكان شيء عن خسارة الشبكة، ولا عن التسميات (labels)، ولا عن الطبقات اللاحقة.
The figure on the slide shows why the input side is the one that shrinks. X_P loses a column and W_P^T loses the row that multiplied it; the two disappear as a pair, because they were only ever used together. The output Ẑ still has b rows and c_o columns. The next layer sees an input of the same shape as before, only slightly perturbed, which is what lets the paper prune a very deep network layer by layer and account for the accumulated error by always regressing toward the un-pruned model's output.
يوضح الشكل في الشريحة لماذا يكون جانب المدخلات هو الذي يصغر. تفقد X_P عمودًا وتفقد W_P^T الصف الذي كان يُضرب فيه؛ يختفيان معًا كزوج، لأنهما لم يُستخدما إلا معًا. أما المخرجات Ẑ فما زال فيها b صفًا وc_o عمودًا. الطبقة التالية ترى مدخلات بالشكل نفسه كما كانت، مع اضطراب طفيف فقط، وهذا ما يسمح للورقة بتقليم شبكة عميقة جدًا طبقة بعد طبقة ومراعاة الخطأ المتراكم بأن تجعل الانحدار دائمًا نحو مخرجات النموذج غير المقلَّم.
Solving it: alternate between selecting and rebuildingالحل: التناوب بين الاختيار وإعادة البناء
The L0 constraint makes the problem NP-hard, so the paper relaxes it to an L1 penalty, adding λ ||β||₁ to the objective. That turns channel selection into LASSO regression, whose solutions are naturally sparse: as λ grows, more β_c are driven exactly to zero. With two unknowns, β and W, the paper alternates.
قيد L0 يجعل المسألة NP-hard، لذلك تُرخيها الورقة إلى عقوبة L1، بإضافة λ ||β||₁ إلى الهدف. هذا يحوّل اختيار القنوات إلى انحدار LASSO، وحلوله متفرقة (sparse) بطبيعتها: كلما كبرت λ دُفعت قيم β_c أكثر إلى الصفر تمامًا. ومع وجود مجهولين، β وW، تتناوب الورقة بينهما.
| Stepالخطوة | Fixedالمثبَّت | Solvedالمجهول المحلول | Solverطريقة الحل | Outputالناتج |
|---|---|---|---|---|
| 11 | WW | ββ | LASSO (L1-relaxed selection)LASSO (اختيار مُرخى بعقوبة L1) | Which input channels surviveأي قنوات المدخلات تبقى |
| 22 | ββ | WW | Least squares (closed form)المربعات الصغرى (صيغة مغلقة) | Weights that best rebuild Z from the survivorsالأوزان التي تعيد بناء Z بأفضل شكل من القنوات الباقية |
With W fixed, Ẑ is linear in β, so the objective is an ordinary least-squares fit in β and the added L1 penalty makes it a LASSO problem that picks the channels. With β fixed, the survivors' weights are re-fitted by ordinary least squares so that they rebuild Z as well as possible, in closed form. A constraint ||W_c||_F = 1 on each channel's weights stops the trivial solution of shrinking β while inflating W. In practice the authors run the selection step repeatedly, raising λ until ||β||₀ drops to the target, and then run the reconstruction step once.
عند تثبيت W تكون Ẑ خطية في β، فيصبح الهدف ملاءمة عادية بالمربعات الصغرى في β، وعقوبة L1 المضافة تجعلها مسألة LASSO تختار القنوات. وعند تثبيت β يُعاد ملاءمة أوزان القنوات الباقية بالمربعات الصغرى العادية لتعيد بناء Z بأفضل ما يمكن، بصيغة مغلقة (closed form). ويمنع القيد ||W_c||_F = 1 على أوزان كل قناة الحل التافه الذي يصغّر β بينما يضخّم W. وفي التطبيق يشغّل المؤلفون خطوة الاختيار مرارًا، رافعين λ حتى تنخفض ||β||₀ إلى القيمة المستهدفة، ثم يشغّلون خطوة إعادة البناء مرة واحدة.
Channel pruning results (He, Zhang and Sun, ICCV 2017)نتائج تقليم القنوات (He وZhang وSun، ICCV 2017)
- VGG-16
- 4× speedup with 1.0% increase in top-5 error; 5× with tensor factorization at 0.3%تسريع 4× مع زيادة 1.0% في خطأ top-5؛ و5× مع تحليل الموترات (tensor factorization) بزيادة 0.3%
- ResNet-50 and Xception-50ResNet-50 وXception-50
- 2× speedup at 1.4% and 1.0% extra top-5 errorتسريع 2× مقابل زيادة 1.4% و1.0% في خطأ top-5
- Fine-tuningالضبط الدقيق (Fine-tuning)
- 10 epochs, batch 128, learning rate 10⁻⁵10 حقب (epochs)، ودفعة بحجم 128، ومعدل تعلّم 10⁻⁵
- Samples for regressionعيّنات الانحدار
- 5000 images × 10 positions each5000 صورة × 10 مواضع من كل صورة
Quick checkاختبار سريع
In regression-based channel pruning, what does setting beta_c = 0 do?في التقليم القائم على الانحدار لاختيار القنوات، ماذا يفعل جعل beta_c = 0؟
Recall
State the regression-based pruning objective and its two alternating steps.اكتب هدف التقليم القائم على الانحدار وخطوتيه المتناوبتين.
The reference list at the end of the deck is a map of where every Pruning criterion in parts 05 and 06 came from, and of what comes next. Reading it as a family tree makes the lecture easier to hold in memory than reading it as nineteen unrelated titles.
قائمة المراجع في نهاية العرض خريطة لمصدر كل pruning criterion في الجزأين 05 و06، ولما يأتي بعدها. قراءتها كشجرة عائلة تجعل المحاضرة أسهل في التذكر من قراءتها كتسعة عشر عنوانًا لا رابط بينها.
| Criterionالمعيار | What it readsما يقرؤه | Refالمرجع | Paperالورقة | Where taughtأين يُدرَّس |
|---|---|---|---|---|
| Magnitudeالمقدار (Magnitude) | Weight valuesقيم الأوزان | 44 | Han et al., NeurIPS 2015Han et al., NeurIPS 2015 | Part 05الجزء 05 |
| Scaling factorمعامل التحجيم (Scaling factor) | Trainable γ per channelمعامل γ قابل للتدريب لكل قناة | 1111 | Liu et al., Network Slimming, ICCV 2017Liu et al., Network Slimming, ICCV 2017 | Part 05الجزء 05 |
| Second orderالدرجة الثانية (Second order) | Loss curvature hᵢᵢانحناء الخسارة hᵢᵢ | 33 | LeCun, Denker, Solla, NeurIPS 1989LeCun, Denker, Solla, NeurIPS 1989 | This partهذا الجزء |
| Second order, modernالدرجة الثانية، الحديث | Hessian of a layer-wise reconstructionHessian لمسألة إعادة بناء على مستوى الطبقة | 1818 | Frantar and Alistarh, SparseGPT, 2023Frantar and Alistarh, SparseGPT, 2023 | Pointerإشارة فقط |
| Activationالتنشيط (Activation) | Zero fraction after ReLUنسبة الأصفار بعد ReLU | 1414 | Hu et al., Network Trimming, 2016Hu et al., Network Trimming, 2016 | This partهذا الجزء |
| Regressionالانحدار (Regression) | Layer output reconstructionإعادة بناء مخرجات الطبقة | 1616 | He, Zhang, Sun, ICCV 2017He, Zhang, Sun, ICCV 2017 | This partهذا الجزء |
| Next-layer statisticsإحصاءات الطبقة التالية | Next layer's reconstructionإعادة بناء الطبقة التالية | 1717 | Luo, Wu, Lin, ThiNet, ICCV 2017Luo, Wu, Lin, ThiNet, ICCV 2017 | Pointerإشارة فقط |
| First-order Taylorتايلور من الدرجة الأولى | Gradient times value on mini-batchesالميل مضروبًا في القيمة على دفعات صغيرة | 15, 1315, 13 | Molchanov et al., ICLR 2017 and CVPR 2019Molchanov et al., ICLR 2017 and CVPR 2019 | Pointerإشارة فقط |
Three of the pointers deserve a sentence each. SparseGPT is the modern descendant of Second-order pruning: it prunes GPT-scale models with 175 billion parameters in one shot to 50 to 60% unstructured sparsity with little loss in perplexity, using Hessian information of a layer-wise reconstruction problem very much like the one in the previous concept. ThiNet selects filters using statistics from the next layer rather than the current one, a cousin of Regression-based pruning. Molchanov's first-order Taylor criterion scores units by gradient times value on mini-batches. It is the same expansion as OBD with the gradient term kept and the Hessian dropped.
ثلاث من هذه الإشارات تستحق جملة لكل منها. SparseGPT هو السليل الحديث لـ second-order pruning: يقلّم نماذج بحجم GPT فيها 175 مليار معامل دفعة واحدة إلى تفرّق غير هيكلي (unstructured sparsity) بنسبة 50 إلى 60% مع خسارة قليلة في الـ perplexity، مستخدمًا معلومات الـ Hessian لمسألة إعادة بناء على مستوى الطبقة تشبه كثيرًا تلك التي في المفهوم السابق. ThiNet يختار المرشحات باستخدام إحصاءات من الطبقة التالية بدلًا من الطبقة الحالية، وهو قريب من regression-based pruning. ومعيار تايلور من الدرجة الأولى عند Molchanov يقيّم الوحدات بحاصل ضرب الميل في القيمة على دفعات صغيرة. إنه المفكوك نفسه في OBD مع الإبقاء على حد الميل وإسقاط الـ Hessian.
Recall
Given the criterion, name the paper and what it reads: magnitude, OBD, APoZ, regression.لكل معيار، سمِّ الورقة وما يقرؤه: magnitude وOBD وAPoZ وregression.
Recall
Which of the criteria in this part need data pushed through the network, and which read only the parameters?أي معايير هذا الجزء يحتاج إلى تمرير بيانات عبر الشبكة، وأيها يقرأ المعاملات فقط؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- Pruning is a perturbation delta W. Its loss cost is approximated by a second-order Taylor expansion with a gradient term, a diagonal Hessian term, cross terms and a cubic remainder.التقليم اضطراب delta W في الأوزان. تُقرَّب كلفته على الخسارة بمفكوك تايلور من الدرجة الثانية يضم حد الميل (gradient)، وحد قطر الـ Hessian، والحدود التقاطعية، وباقيًا من الدرجة الثالثة.
- OBD keeps only 1/2 h_ii w_i^2: the quadratic assumption removes the remainder, convergence removes the gradient term, independent deletions remove the cross terms; h_ii is non-negative at a minimum.يُبقي OBD الحد 1/2 h_ii w_i^2 وحده: افتراض الشكل التربيعي يحذف الباقي، والتقارب يحذف حد الميل، واستقلال عمليات الحذف يحذف الحدود التقاطعية؛ وتكون h_ii غير سالبة عند القيمة الصغرى.
- Magnitude pruning is OBD with every h_ii equal. The full Hessian has n^2 entries; OBD computes only the diagonal by a second back-propagation pass.التقليم بالمقدار هو OBD حين تتساوى كل قيم h_ii. يضم الـ Hessian الكامل n^2 عنصرًا، أما OBD فيحسب القطر فقط بتمرير ثانٍ للانتشار العكسي (back-propagation).
- Removing a neuron deletes a row of a linear weight matrix; removing a conv channel deletes a whole filter. Neuron pruning is coarse-grained weight pruning.حذف عصبون يحذف صفًا من مصفوفة أوزان الطبقة الخطية، وحذف قناة في طبقة الالتفاف يحذف مرشحًا (filter) كاملًا. تقليم العصبونات هو تقليم أوزان خشن الحبيبات (coarse-grained).
- APoZ = zeros / (batch x H x W). The slide's channels score 11/32, 12/32 and 14/32 and the largest, channel 2, is pruned. Smaller APoZ means more important.APoZ = عدد الأصفار / (batch x H x W). قنوات الشريحة تحصل على 11/32 و12/32 و14/32، وتُقلَّم القناة 2 صاحبة القيمة الأكبر. كلما صغرت APoZ زادت أهمية القناة.
- Regression-based pruning minimizes ||Z - sum_c beta_c X_c W_c^T||_F^2 subject to ||beta||_0 <= N_c, alternating LASSO channel selection and least-squares reconstruction. VGG-16 reached 4x speedup at 1.0 percent extra top-5 error.التقليم القائم على الانحدار يقلّل ||Z - sum_c beta_c X_c W_c^T||_F^2 بشرط ||beta||_0 <= N_c، بالتناوب بين اختيار القنوات بـ LASSO وإعادة البناء بالمربعات الصغرى. وصل VGG-16 إلى تسريع 4x مقابل زيادة 1.0 بالمئة في خطأ top-5.
- Slide errata: the h_ii denominator on slide 36, the sign convention on slide 34, Network Trimming is 2016 not 2017, and the 'more importance' typo on slide 40.أخطاء الشرائح: مقام h_ii في الشريحة 36، واصطلاح الإشارة في الشريحة 34، وأن Network Trimming صدرت عام 2016 لا 2017، والخطأ اللغوي 'more importance' في الشريحة 40.
Sourcesالمصادر
- Optimal Brain DamagePaperAdvances in Neural Information Processing Systems 2 (NIPS 1989), LeCun, Denker and SollaTaylor expansion (eq. 1 to 3), non-negative h_ii at a minimum, 6.5 million Hessian entries, Levenberg-Marquardt estimate, recipe and saliency, zip-code experiments.مفكوك تايلور (المعادلات 1 إلى 3)، وعدم سالبية h_ii عند القيمة الصغرى، و6.5 مليون عنصر في الـ Hessian، وتقدير Levenberg-Marquardt، والوصفة والبروز (saliency)، وتجارب الرموز البريدية.(opens in a new tab)(يفتح في تبويب جديد)
- Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep ArchitecturesPaperarXiv 1607.03250, Hu, Peng, Tai and Tang, 2016APoZ definition (eq. 1), mean APoZ per layer (Table 1), 631 neurons above 90 percent, mean plus one standard deviation threshold, LeNet and VGG-16 results.تعريف APoZ (المعادلة 1)، ومتوسط APoZ لكل طبقة (الجدول 1)، و631 عصبونًا فوق 90 بالمئة، وعتبة المتوسط زائد انحراف معياري واحد، ونتائج LeNet وVGG-16.(opens in a new tab)(يفتح في تبويب جديد)
- Channel Pruning for Accelerating Very Deep Neural NetworksPaperICCV 2017, He, Zhang and Sun (arXiv 1707.06168)Objective (eq. 1 to 4), NP-hardness and L1 relaxation, unit Frobenius norm constraint, alternating LASSO and least squares, 5000 images times 10 samples, VGG-16 and ResNet-50 results.دالة الهدف (المعادلات 1 إلى 4)، وكون المسألة NP-hard وإرخاء L1، وقيد معيار Frobenius الواحدي، والتناوب بين LASSO والمربعات الصغرى، و5000 صورة في 10 عيّنات، ونتائج VGG-16 وResNet-50.(opens in a new tab)(يفتح في تبويب جديد)
- Deep Learning, chapter 4: Numerical ComputationBookMIT Press, Goodfellow, Bengio and Courville, 2016Hessian definition (eq. 4.6), symmetry (eq. 4.7), second-order Taylor expansion used for Newton's method (eq. 4.11).تعريف الـ Hessian (المعادلة 4.6)، وتماثله (المعادلة 4.7)، ومفكوك تايلور من الدرجة الثانية المستخدم في طريقة نيوتن (المعادلة 4.11).(opens in a new tab)(يفتح في تبويب جديد)
- Learning both Weights and Connections for Efficient Neural NetworksPaperNIPS 2015, Han, Pool, Tran and DallyMagnitude criterion baseline referenced as item 4 on slide 43.معيار المقدار الأساسي (baseline)، وهو المرجع رقم 4 في الشريحة 43.(opens in a new tab)(يفتح في تبويب جديد)
- Pruning Convolutional Neural Networks for Resource Efficient InferencePaperICLR 2017, Molchanov, Tyree, Karras, Aila and KautzFirst-order Taylor criterion, pointer only.معيار تايلور من الدرجة الأولى، إشارة فقط.(opens in a new tab)(يفتح في تبويب جديد)
- ThiNet: A Filter Level Pruning Method for Deep Neural Network CompressionPaperICCV 2017, Luo, Wu and LinFilter selection using statistics of the next layer, pointer only.اختيار المرشحات باستخدام إحصاءات الطبقة التالية، إشارة فقط.(opens in a new tab)(يفتح في تبويب جديد)
- SparseGPT: Massive Language Models Can Be Accurately Pruned in One-ShotPaperarXiv 2301.00774, Frantar and Alistarh, 2023One-shot pruning of 175B-parameter models to 50 to 60 percent sparsity, the modern descendant of second-order pruning.تقليم نماذج فيها 175 مليار معامل دفعة واحدة إلى تفرّق بنسبة 50 إلى 60 بالمئة، وهو السليل الحديث للتقليم من الدرجة الثانية.(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Fall 2024, Lecture 3: Pruning and Sparsity (Part I)DocsMIT HAN Lab, Song HanThe course deck these slides follow, listed as reference 19.عرض المقرر الذي تتبعه هذه الشرائح، وهو المرجع رقم 19.(opens in a new tab)(يفتح في تبويب جديد)