Lecture 04-2 · Pruning and Sparsity II

المحاضرة 04-2 · التقليم والتناثر (Pruning and Sparsity II)

Reading sensitivity curves with a threshold

قراءة منحنيات الحساسية باستخدام عتبة

Slides 18–23 الشرائح 18–23 P1 MUST

Draw one horizontal line T across the sensitivity chart. Each layer's pruning ratio is where its curve crosses T. The overall pruning rate is the parameter-weighted average of those ratios, and T is the single knob you turn until it hits the target.

ارسم خطاً أفقياً واحداً T عبر رسم الحساسية. نسبة تقليم كل طبقة هي النقطة التي يقطع فيها منحناها الخط T. ونسبة التقليم الكلية هي المتوسط الموزون بعدد المعاملات لتلك النسب، وT هو المقبض الوحيد الذي تديره حتى تصل إلى الهدف.

High exam risk احتمال عالٍ في الامتحان

The paper version of this is a small table: accuracy after pruning each layer alone at several ratios, a threshold T and a weight count per layer. You must give each ri, the overall rate as a weighted average, the compression factor, and one sentence on why the result is not optimal.

نسخة الامتحان الورقية من هذا جدول صغير: الدقة بعد تقليم كل طبقة وحدها عند عدة نسب، وعتبة T، وعدد الأوزان لكل طبقة. يجب أن تعطي كل ri، والنسبة الكلية كمتوسط موزون، ومعامل الضغط، وجملة واحدة عن سبب أن النتيجة ليست مثالية.

Sensitive versus redundant, slides 18 to 20

الحساسة مقابل الزائدة عن الحاجة، الشرائح 18 إلى 20

Every curve starts at the dense accuracy (about 93 percent), so the starting point says nothing. Sensitivity is the slope: how early and how steeply the curve bends as r grows. L0, the first conv layer, bends first and falls to about 32 percent at r = 0.9, so it is the most sensitive. L1 stays near 85 percent at r = 0.9, so it is the most redundant.

كل منحنى يبدأ من دقة الشبكة الكاملة (نحو 93%)، فنقطة البداية لا تخبرك بشيء. الحساسية هي الميل: متى وكم بحدّة ينحني المنحنى كلما زادت r. L0، أول طبقة conv، تنحني أولاً وتهبط إلى نحو 32% عند r = 0.9، فهي الأكثر حساسية. وL1 تبقى قرب 85% عند r = 0.9، فهي الأكثر تكراراً.

The rule that follows: prune redundant layers hard and sensitive layers gently. A threshold makes that rule mechanical.

القاعدة الناتجة: قلّم الطبقات ذات التكرار بقوة، والطبقات الحساسة بلطف. والعتبة تجعل هذه القاعدة آلية.

The threshold rule, slides 21 and 22

قاعدة العتبة، الشريحتان 21 و22

Slide 21 adds the last bullet: "pick a degradation threshold T such that the overall pruning rate is desired". The dashed line sits at about 79 to 80 percent accuracy (equivalently, an allowed drop of about 14 points from 93). For each layer, the pruning rate ri is where its curve crosses T.

الشريحة 21 تضيف البند الأخير: "اختر عتبة تدهور T بحيث تكون نسبة التقليم الكلية هي المطلوبة". الخط المتقطع يقع عند دقة نحو 79 إلى 80% (أي ما يعادل انخفاضاً مسموحاً بنحو 14 نقطة من 93). لكل طبقة، نسبة التقليم ri هي النقطة التي يقطع فيها منحناها الخط T.

ri = max { r ∈ {0, 0.1, ..., 0.9} : Accri ≥ T }

In table form: the largest swept ratio whose accuracy is still at or above T. On a chart you may interpolate between grid points, which is what the slide's dashed guides do. A layer whose curve never drops below T inside the sweep gets the maximum swept ratio, 90 percent.

في صورة جدول: أكبر نسبة ممسوحة ما زالت دقتها أكبر من T أو تساويها. وعلى الرسم يمكنك الاستيفاء بين نقاط الشبكة، وهذا ما تفعله الخطوط الإرشادية المتقطعة في الشريحة. والطبقة التي لا ينزل منحناها تحت T داخل المسح تأخذ أكبر نسبة ممسوحة، أي 90%.

30 44 58 72 86 100 10% 20% 30% 40% 50% 60% 70% 80% 90% pruning rate of the one layer being pruned accuracy (%) threshold T = 79% READ-OFF RATES (SLIDE GUIDES) L0 73% L4 80% L3 82% L1 L2 L5 90% L0 L1 L2 L3 L4 L5
T at about 79 percent. L0 crosses between its 70 and 80 percent points (about 73 percent), L3 just past 80 (about 82 percent), L4 near 80 (strict interpolation gives about 78.5; the slide draws 80). L1, L2 and L5 never cross inside the sweep and get 90 percent.
T عند نحو 79%. L0 تعبر العتبة بين نقطتي 70% و80% (نحو 73%)، وL3 بعد 80 بقليل (نحو 82%)، وL4 قرب 80 (الاستيفاء الدقيق يعطي نحو 78.5، والشريحة ترسم 80). أما L1 وL2 وL5 فلا تعبر داخل المسح أبداً وتأخذ 90%.
LayerالطبقةWeights (VGG-11)الأوزان (VGG-11)Rate at T ≈ 79%النسبة عند T ≈ 79%Weights prunedالأوزان المقلَّمة
L01,7280.731,261
L173,7280.9066,355
L2294,9120.90265,421
L3589,8240.82483,656
L41,179,6480.80943,718
L52,359,2960.902,123,366
Totalالمجموع4,499,136mean 0.842المتوسط 0.8423,883,778

أعداد الأوزان توضيحية: أول ست طبقات 3 x 3 conv في VGG-11 (بدون bias). الشريحة لا تذكرها، لكن النسبة الكلية تعتمد عليها. مجموع الأوزان المقلّمة 3,883,778 من أصل 4,499,136.

The overall rate is parameter-weighted

النسبة الكلية موزونة بعدد المعاملات

"Overall pruning rate" means the fraction of all weights removed. A 90 percent rate on a 2.36-million-weight layer removes far more than a 73 percent rate on a 1,728-weight layer, so each rate is weighted by its layer size.

"نسبة التقليم الكلية" تعني نسبة كل الأوزان المحذوفة. نسبة 90% في طبقة فيها 2.36 مليون وزن تحذف أكثر بكثير من نسبة 73% في طبقة فيها 1,728 وزناً، ولذلك تُوزن كل نسبة بحجم طبقتها.

R = Σi ri NiΣi Ni     compression = Σ NiΣ (1 − ri) Ni = 11 − R
Worked: the slide's T on VGG-11 مثال محلول: عتبة T من الشريحة على VGG-11
R = 3,883,778 / 4,499,136 = 0.863   (86.3 percent)
remaining = 4,499,136 - 3,883,778 = 615,358 weights
compression = 1 / (1 - 0.863) = 4,499,136 / 615,358 = 7.3x

unweighted mean = (73 + 90 + 90 + 82 + 80 + 90) / 6
                = 505 / 6 = 84.2 percent      WRONG for "overall"

The weighted rate is higher than the plain mean because the three largest layers (92 percent of all weights) get 80 to 90 percent, while the low 73 percent applies to the tiny L0.

النسبة الموزونة أعلى من المتوسط البسيط لأن الطبقات الثلاث الأكبر (92% من كل الأوزان) تأخذ 80 إلى 90%، بينما تنطبق النسبة المنخفضة 73% على الطبقة الصغيرة L0.

Worked: exam-style table مثال محلول: جدول بأسلوب الامتحان

Accuracy (%) after pruning each layer alone. Dense accuracy is 93 percent.

الدقة (%) بعد تقليم كل طبقة وحدها. دقة الشبكة الكاملة 93%.

Layer (weights)الطبقة (الأوزان)r = 0.50.60.70.80.9
A (20,000)9290867550
B (300,000)9393929084
C (600,000)9393939289
D (80,000)9188837045
T = 88 percent  (largest ratio with Acc >= 88)
  r_A = 0.6   (90 at 0.6, 86 at 0.7)
  r_B = 0.8   (90 at 0.8, 84 at 0.9)
  r_C = 0.9   (89 at 0.9, never below T)
  r_D = 0.6   (88 at 0.6 counts: >= T)

  pruned = 20,000 x 0.6 + 300,000 x 0.8 + 600,000 x 0.9 + 80,000 x 0.6
         = 12,000 + 240,000 + 540,000 + 48,000 = 840,000
  R = 840,000 / 1,000,000 = 84.0 percent
  remaining = 160,000      compression = 1 / 0.16 = 6.25x
  (unweighted mean = (60 + 80 + 90 + 60) / 4 = 72.5 percent, wrong)

T = 90 percent  (stricter floor)
  r_A = 0.6,  r_B = 0.8,  r_C = 0.8,  r_D = 0.5
  pruned = 12,000 + 240,000 + 480,000 + 40,000 = 772,000
  R = 77.2 percent      compression = 1 / 0.228 = 4.39x

Raising T from 88 to 90 lowered C and D and dropped R from 84.0 to 77.2 percent. If the target were 80 percent, T = 88 meets it and T = 90 does not, so you would keep T = 88 (or search between them).

رفع T من 88 إلى 90 خفّض نسبتي C وD، وأنزل R من 84.0% إلى 77.2%. لو كان الهدف 80% فإن T = 88 يحققه وT = 90 لا يحققه، فتُبقي T = 88 (أو تبحث بينهما).

Tuning T, and why the answer is not optimal, slide 23

ضبط T، ولماذا الجواب ليس الأمثل، الشريحة 23

T is the only knob. Higher T is a stricter accuracy floor: every curve crosses it earlier, so every ri shrinks or stays, and fewer weights are pruned. Lower T prunes more. The loop: pick T, read off the rates, compute the weighted R, compare with the target, move T, repeat. R is monotone in T, so this converges quickly.

T هو المقبض الوحيد. T الأعلى حدّ أدنى أكثر صرامة للدقة: كل منحنى يقطعه أبكر، فتصغر كل ri أو تبقى كما هي، ويُقلَّم عدد أقل من الأوزان. T الأدنى يقلّم أكثر. الحلقة: اختر T، واقرأ النسب، واحسب R الموزونة، وقارنها بالهدف، وحرّك T، وكرر. وR رتيبة (monotone) في T، فتتقارب الحلقة بسرعة.

Slide 23 asks "Is this optimal?" and answers "Maybe not. We do not consider the interaction between layers." Every curve is a single-layer experiment. When all layers are pruned at once, the losses compound in ways the chart never measured, so the combined accuracy is usually below T. The rule is a heuristic; AMC and NetAdapt go beyond it.

الشريحة 23 تسأل "هل هذا مثالي؟" وتجيب "ربما لا. نحن لا نأخذ التفاعل بين الطبقات في الحسبان." كل منحنى تجربة على طبقة واحدة. وعندما تُقلَّم كل الطبقات معاً تتراكم الخسائر بطرق لم يقسها الرسم أبداً، فتكون الدقة المجمّعة عادةً أقل من T. القاعدة heuristic؛ وAMC وNetAdapt يتجاوزانها.

Trap فخ

Weighted, not unweighted. The overall rate is Σ ri Ni / Σ Ni. Averaging the six percentages (84.2 percent on VGG-11, 72.5 percent in the table example) is the most common lost mark.

موزون، لا بسيط. النسبة الكلية هي Σ ri Ni / Σ Ni. أخذ متوسط النسب الست (84.2% في VGG-11، و72.5% في مثال الجدول) هو أكثر خطأ تضيع فيه الدرجات.

Direction of T. To prune more, lower T. Raising T keeps more weights. "Higher threshold, more pruning" is backwards.

اتجاه T. لتقلّم أكثر، اخفض T. رفع T يُبقي أوزاناً أكثر. عبارة "عتبة أعلى، تقليم أكثر" معكوسة.

At or above T counts. An accuracy exactly equal to T is still allowed (layer D at 88 with T = 88). And a layer that never crosses gets the maximum swept ratio, not 100 percent.

القيمة المساوية لـ T مقبولة. الدقة التي تساوي T تماماً ما زالت مسموحة (الطبقة D عند 88 مع T = 88). والطبقة التي لا تقطع الخط تأخذ أكبر نسبة ممسوحة، لا 100%.

Compression is 1/(1 − R), not 1/R. R = 0.875 means 8x, not 1.14x.

معامل الضغط هو 1/(1 − R) وليس 1/R. R = 0.875 يعني 8x لا 1.14x.

Memory hook خطّاف للذاكرة

One line, six crossings, one weighted sum, one caveat. Lower the water line and every valley floods further; the chart never saw the valleys flooding together.

خط واحد، ست نقاط تقاطع، مجموع موزون واحد، وتحفّظ واحد. اخفض خط الماء فيغمر كل وادٍ أكثر؛ والرسم لم يرَ الوديان تغمرها المياه معاً أبداً.

Check yourself

اختبر نفسك

Two layers: 200,000 weights pruned at 50 percent and 800,000 weights pruned at 90 percent. What is the overall pruning rate?

طبقتان: 200,000 وزن مقلّمة بنسبة 50%، و800,000 وزن مقلّمة بنسبة 90%. ما نسبة التقليم الكلية؟

(200,000 x 0.5 + 800,000 x 0.9) / 1,000,000 = (100,000 + 720,000) / 1,000,000 = 82 percent. A is the unweighted mean. D is the fraction of weights remaining.

(200,000 x 0.5 + 800,000 x 0.9) / 1,000,000 = (100,000 + 720,000) / 1,000,000 = 82%. الخيار A هو المتوسط غير الموزون. والخيار D هو نسبة الأوزان الباقية.

A layer's accuracies at r = 0.6, 0.7, 0.8, 0.9 are 94, 92, 89 and 81 percent. With T = 90 percent, what pruning ratio does the table rule give?

دقة طبقة عند r = 0.6, 0.7, 0.8, 0.9 هي 94 و92 و89 و81%. مع T = 90%، ما نسبة التقليم وفق قاعدة الجدول؟

Take the largest swept ratio whose accuracy is still at or above T. 92 at 0.7 passes; 89 at 0.8 is below 90. So r = 0.7.

خذ أكبر نسبة ممسوحة ما زالت دقتها أكبر من T أو تساويها. 92 عند 0.7 مقبولة؛ و89 عند 0.8 أقل من 90. إذن r = 0.7.

Your overall pruning rate comes out at 70 percent but the target is 80 percent. What do you do with T?

خرجت نسبة التقليم الكلية 70% لكن الهدف 80%. ماذا تفعل بـ T؟

A lower accuracy floor is crossed later by every curve, so each ri grows or stays at the maximum, and the weighted R rises. Raising T does the opposite. Fine-tuning recovers accuracy but does not change the ratios.

الحد الأدنى الأخفض للدقة يقطعه كل منحنى في وقت متأخر، فتكبر كل ri أو تبقى عند الحد الأقصى، وترتفع R الموزونة. رفع T يفعل العكس. وfine-tuning يستعيد الدقة لكنه لا يغيّر النسب.

The weighted overall pruning rate is R = 87.5 percent. What is the compression (reduction) factor in weights?

نسبة التقليم الكلية الموزونة R = 87.5%. ما معامل الضغط (التخفيض) في عدد الأوزان؟

Compression = 1 / (1 − R) = 1 / 0.125 = 8x: one weight in eight survives. A is 1/R, a common slip.

معامل الضغط = 1 / (1 − R) = 1 / 0.125 = 8x: يبقى وزن واحد من كل ثمانية. الخيار A هو 1/R، وهو خطأ شائع.

Slide 23 asks whether the threshold assignment is optimal. What is the reason it may not be?

الشريحة 23 تسأل هل توزيع النسب بالعتبة مثالي. ما سبب أنه قد لا يكون كذلك؟

The curves are single-layer experiments. Pruning all layers together compounds losses the chart never measured, so the joint accuracy usually falls below T. That gap is why automated methods (AMC, NetAdapt) exist.

المنحنيات تجارب على طبقة واحدة. تقليم كل الطبقات معاً يراكم خسائر لم يقسها الرسم أبداً، فتهبط الدقة المجمّعة عادةً تحت T. وهذه الفجوة هي سبب وجود الطرق الآلية (AMC وNetAdapt).