Lecture 04-2 · Pruning and Sparsity II
المحاضرة 04-2 · التقليم والتناثر (Pruning and Sparsity II)
Per-layer ratios and sensitivity sweep
نِسَب التقليم لكل طبقة ومسح الحساسية (sensitivity sweep)
P2 SHOULDOne pruning ratio for every layer wastes accuracy, because layers differ in how much they can lose. Sensitivity analysis measures that difference: prune one layer alone at ten ratios, record the accuracy, restore, repeat.
نسبة تقليم واحدة لكل الطبقات تهدر الدقة، لأن الطبقات تختلف في مقدار ما تتحمل خسارته. وsensitivity analysis يقيس هذا الاختلاف: قلّم طبقة واحدة وحدها عند عشر نسب، وسجّل الدقة، ثم أعدها كما كانت، وكرر.
Describe the four steps of sensitivity analysis, say which layers are pruned while Li is measured, count the evaluations (layers x ratios), and explain why the first layer is usually the most sensitive. A MobileNet comparison can appear as a one-line fact.
صِف الخطوات الأربع لـ sensitivity analysis، وقل أي الطبقات تُقلَّم أثناء قياس Li، واحسب عدد التقييمات (layers x ratios)، واشرح لماذا تكون الطبقة الأولى عادةً الأكثر حساسية. وقد تأتي مقارنة MobileNet كمعلومة في سطر واحد.
Recap: where 04-1 left off, slides 1 to 7
مراجعة: أين توقفت المحاضرة 04-1، الشرائح 1 إلى 7
Pruning is the constrained problem min L(x; WP) subject to ‖WP‖0 ≤ N: keep at most N nonzero weights while keeping the loss as low as possible. Lecture 04-1 answered three of the five questions: the formulation, the granularity (fine-grained, pattern, vector, kernel, channel, from most flexible to most hardware-friendly) and the criterion (magnitude |W| and the others). Example: weights 3, −2, 1, −5 at 50 percent sparsity keep 3 and −5.
التقليم مسألة مقيّدة: min L(x; WP) بشرط ‖WP‖0 ≤ N، أي أبقِ على الأكثر N وزناً غير صفري مع أقل زيادة ممكنة في الخسارة. المحاضرة 04-1 أجابت عن ثلاثة من الأسئلة الخمسة: الصياغة، والـ granularity (من fine-grained إلى pattern وvector وkernel وchannel، من الأكثر مرونة إلى الأنسب للعتاد)، والمعيار (|W| وغيره). مثال: الأوزان 3, −2, 1, −5 عند 50% sparsity يبقى منها 3 و−5.
Lecture 04-2 answers the remaining two: what ratio should each layer get, and how to fine-tune afterwards. This page and the next cover the first.
المحاضرة 04-2 تجيب عن السؤالين الباقيين: ما النسبة التي تأخذها كل طبقة، وكيف نعيد الضبط (fine-tune) بعد ذلك. هذه الصفحة والتي تليها تغطيان السؤال الأول.
Uniform shrink loses to per-layer pruning, slides 8 and 9
التصغير المنتظم يخسر أمام التقليم لكل طبقة، الشريحتان 8 و9
Uniform shrinking scales every layer by the same factor (MobileNet's width multiplier). Channel pruning lets each layer keep a different fraction. On ImageNet with a Pixel 1 phone (AMC, He et al., ECCV 2018) the per-layer version wins at the same latency.
uniform shrinking يصغّر كل طبقة بالعامل نفسه (width multiplier في MobileNet). أما channel pruning فيسمح لكل طبقة بأن تحتفظ بنسبة مختلفة. على ImageNet وهاتف Pixel 1 (AMC، He et al.، ECCV 2018) تفوز النسخة متعددة النسب عند الزمن نفسه.
| Modelالنموذج | Top-1Top-1 | Latencyزمن الاستجابة (Latency) |
|---|---|---|
| 1.0 MobileNet (dense)1.0 MobileNet (كثيف) | 70.6% | 123.3 ms |
| 0.75 MobileNet (uniform shrink)0.75 MobileNet (تصغير منتظم) | 68.4% | 72.3 ms |
| AMC per-layer pruningتقليم AMC لكل طبقة | 70.5% | 68.3 ms |
في الجدول: عند زمن متقارب (72.3 ms مقابل 68.3 ms) تحتفظ النسخة متعددة النسب بـ 2.1 نقطة دقة إضافية، وتقلّ عن الشبكة الكاملة بـ 0.1 نقطة فقط وهي أسرع بنحو 1.8x.
Slide 9 ends with the question this page answers: how should we find ratios for each layer?
تنتهي الشريحة 9 بالسؤال الذي تجيب عنه هذه الصفحة: كيف نجد النسبة المناسبة لكل طبقة؟
Layers differ in sensitivity, slides 10 and 11
الطبقات تختلف في حساسيتها، الشريحتان 10 و11
Some layers are more sensitive (the first layer is the slide's example), some are more redundant. Three reasons the first layer is fragile: it has the fewest weights (VGG-11 L0 is 3 x 3 x 3 x 64 = 1,728 weights, against 73,728 in L1), it sees only 3 input channels (RGB) so there is little redundancy, and every later feature is computed from its output.
بعض الطبقات أكثر حساسية (والطبقة الأولى هي مثال الشريحة)، وبعضها أكثر تكراراً (redundant). ثلاثة أسباب تجعل الطبقة الأولى هشّة: لديها أقل عدد من الأوزان (L0 في VGG-11 هي 3 x 3 x 3 x 64 = 1,728 وزناً، مقابل 73,728 في L1)، وترى 3 قنوات دخل فقط (RGB) فالتكرار فيها قليل، وكل ميزة لاحقة تُحسب من خرجها.
Sensitivity is the whole curve of ΔAcc against r for that layer, not a single number. A steep curve means a sensitive layer; a flat curve means a redundant one.
الحساسية هي المنحنى كاملاً لـ ΔAcc مقابل r لتلك الطبقة، لا رقماً واحداً. المنحنى الحاد يعني طبقة حساسة؛ والمنحنى المسطّح يعني طبقة فيها تكرار.
The sweep, slides 12 to 17
المسح، الشرائح 12 إلى 17
- Pick a layer Li in the model. Every other layer stays dense, exactly as trained.
اختر طبقة Li من النموذج. كل الطبقات الأخرى تبقى dense كما دُرّبت تماماً.
- Prune only Li at r ∈ {0, 0.1, 0.2, ..., 0.9} (or other strides), using magnitude pruning on that one tensor.
قلّم Li وحدها عند r ∈ {0, 0.1, 0.2, ..., 0.9} (أو بخطوات أخرى)، باستخدام magnitude pruning على هذا الـ tensor وحده.
- Observe the accuracy degradation ΔAccri for each ratio by evaluating on the test set. No fine-tuning, no gradient step.
سجّل تدهور الدقة ΔAccri لكل نسبة بالتقييم على مجموعة الاختبار. لا fine-tuning ولا أي خطوة gradient.
- Restore Li and repeat for all layers. Plot every layer's curve on the same axes.
أعد Li إلى حالتها وكرر لكل الطبقات. ارسم منحنى كل طبقة على المحاور نفسها.
| Layerالطبقة | r = 0.5 | r = 0.7 | r = 0.8 | r = 0.9 | Verdictالحكم |
|---|---|---|---|---|---|
| L0 (first conv)L0 (أول طبقة التفاف) | 92 | 83.5 | 71 | 32 | most sensitiveالأكثر حساسية |
| L1 | 93 | 93 | 92 | 85 | most redundantالأكثر زيادة عن الحاجة (redundant) |
| L2 | 93 | 91.5 | 89.5 | 79 | redundantزائدة عن الحاجة (redundant) |
| L3 | 93 | 91.5 | 85.5 | 51 | breaks lateتنهار متأخرة |
| L4 | 93 | 90.5 | 77 | 39 | sensitive past 70%حساسة بعد 70% |
| L5 | 93 | 92 | 90 | 82 | redundantزائدة عن الحاجة (redundant) |
قيم الدقة (%) مقروءة من الرسم. الطبقة L0 تنهار إلى نحو 32 عند 90%، وL1 تبقى عند نحو 85: النسبة نفسها، وفرق يقارب 53 نقطة. الطبقتان L2 وL4 لهما اللون الأحمر نفسه في وسيلة الإيضاح؛ ترتيب بناء الشرائح يجعل L2 المسطّحة وL4 الحادة.
What the sweep costs
كم يكلف المسح
Each point on each curve is one full evaluation over the test set. The number of evaluations is layers x ratios. CIFAR-10 VGG-11 has 9 weight layers (8 conv plus the classifier), so ten ratios give 90 evaluations, each over 10,000 test images.
كل نقطة على كل منحنى هي تقييم كامل على مجموعة الاختبار. عدد التقييمات هو layers x ratios. نسخة VGG-11 لـ CIFAR-10 فيها 9 طبقات أوزان (8 conv إضافةً إلى المصنّف)، فعشر نسب تعطي 90 تقييماً، كل واحد على 10,000 صورة اختبار.
VGG-11, CIFAR-10 layers = 9 ratios = 10 (0, 0.1, ..., 0.9) evaluations = 9 x 10 = 90 forward passes = 90 x 10,000 = 900,000 (r = 0 is the same dense model for every layer: evaluate it once and the count is 9 x 9 + 1 = 82) 50-layer net, ImageNet val (50,000 images) evaluations = 50 x 10 = 500 forward passes = 500 x 50,000 = 25,000,000 weights left in L0 at r = 0.9: 1,728 x 0.1 = 173 weights left in L5 at r = 0.9: 2,359,296 x 0.1 = 235,930
The cost is linear in depth and involves no training, but on deep networks it is already large. That, plus the missing layer interactions, is why AMC and NetAdapt search ratios instead of sweeping.
الكلفة خطية في العمق ولا تتضمن أي تدريب، لكنها كبيرة بالفعل في الشبكات العميقة. وهذا، إضافةً إلى غياب التفاعل بين الطبقات، هو سبب أن AMC وNetAdapt يبحثان عن النسب بدل المسح.
The sweep ignores interactions between layers. Each curve is measured with every other layer dense. Pruning L0 and L4 together usually costs more than either curve shows, and the sweep never measures that.
المسح يتجاهل التفاعل بين الطبقات. كل منحنى يُقاس وكل الطبقات الأخرى dense. تقليم L0 وL4 معاً يكلّف عادةً أكثر مما يُظهره أي منحنى منهما، والمسح لا يقيس ذلك أبداً.
No fine-tuning inside the sweep. It is prune, evaluate, restore. That is why the drops at 90 percent look so violent.
لا fine-tuning داخل المسح. الخطوات هي: قلّم، قيّم، أعد. ولهذا تبدو الانهيارات عند 90% عنيفة جداً.
Most parameters does not mean most sensitive. The first layer is the smallest and the most sensitive; the big late layers have the most slack.
أكثر عدد من المعاملات لا يعني الأكثر حساسية. الطبقة الأولى هي الأصغر والأكثر حساسية؛ والطبقات الكبيرة المتأخرة فيها أكبر هامش.
Pull one fuse at a time. Prune one layer, read the accuracy, put it back. The sweep gives curves, not ratios; a threshold turns curves into ratios on the next page.
انزع فيوزاً واحداً في كل مرة. قلّم طبقة واحدة، واقرأ الدقة، ثم أعدها. المسح يعطيك منحنيات لا نسباً؛ والعتبة (threshold) هي التي تحوّل المنحنيات إلى نسب في الصفحة التالية.
Check yourself
اختبر نفسك
While the sensitivity curve of layer Li is being measured, which layers are pruned?
أثناء قياس منحنى الحساسية للطبقة Li، أي الطبقات تكون مقلّمة؟
Isolation is the point of the sweep: if two layers were pruned together, a drop in accuracy could not be attributed to either one. After measuring, Li is restored before the next layer is swept.
العزل هو جوهر المسح: لو قُلّمت طبقتان معاً لما أمكن نسبة انخفاض الدقة إلى أيّ منهما. وبعد القياس تُعاد Li إلى حالتها قبل مسح الطبقة التالية.
A network has 16 prunable layers. You sweep r ∈ {0, 0.1, ..., 0.9} for each layer, counting every (layer, ratio) pair. How many evaluations, and how many training epochs?
شبكة فيها 16 طبقة قابلة للتقليم. تمسح r ∈ {0, 0.1, ..., 0.9} لكل طبقة، وتعدّ كل زوج (طبقة، نسبة). كم تقييماً، وكم epoch تدريب؟
Cost = layers x ratios = 16 x 10 = 160 evaluations (or 16 x 9 + 1 = 145 if the shared dense point is evaluated once). The sweep is evaluation only: no fine-tuning, so zero training epochs.
الكلفة = layers x ratios = 16 x 10 = 160 تقييماً (أو 16 x 9 + 1 = 145 إذا قُيّمت النقطة dense المشتركة مرة واحدة). المسح تقييم فقط: لا fine-tuning، إذن صفر epochs تدريب.
Which is NOT a reason the first conv layer is usually the most sensitive to pruning?
أي مما يلي ليس سبباً لكون أول طبقة conv عادةً الأكثر حساسية للتقليم؟
The first layer has the fewest parameters, not the most: 1,728 in VGG-11 against millions in later layers. A, B and C are the three standard reasons.
الطبقة الأولى لديها أقل عدد من المعاملات، لا أكثرها: 1,728 في VGG-11 مقابل الملايين في الطبقات اللاحقة. الخيارات A وB وC هي الأسباب الثلاثة المعروفة.
On slide 9, 0.75 MobileNet reaches 68.4 percent at 72.3 ms and AMC reaches 70.5 percent at 68.3 ms. What does this show?
في الشريحة 9، يصل 0.75 MobileNet إلى 68.4% عند 72.3 ms، ويصل AMC إلى 70.5% عند 68.3 ms. ماذا يُظهر ذلك؟
At similar latency AMC keeps 2.1 more points of top-1. Layers have different slack, so giving each its own ratio spends the pruning budget where it hurts least.
عند زمن متقارب يحتفظ AMC بـ 2.1 نقطة إضافية من top-1. للطبقات هوامش مختلفة، فإعطاء كل طبقة نسبتها الخاصة يصرف ميزانية التقليم حيث يكون الضرر أقل.