Lecture 04-2 · Pruning and Sparsity II
المحاضرة 04-2 · التقليم والتناثر (Pruning and Sparsity II)
Fine-tuning, iterative pruning and regularization
Fine-tuning، والتقليم التكراري، وregularization
P1 MUSTEvery quoted pruning ratio in this course exists only because a fine-tune follows the cut. Cut, retrain the survivors gently, cut again: that loop took AlexNet from 5x to 9x with no accuracy loss.
كل نسبة تقليم مذكورة في هذا المقرر موجودة فقط لأن fine-tuning يتبع القطع. اقطع، ثم أعد تدريب الأوزان الباقية بلطف، ثم اقطع مرة أخرى: هذه الحلقة رفعت AlexNet من 5x إلى 9x بلا خسارة في الدقة.
Single numbers and single formulas: the fine-tuning learning rate (1/10 to 1/100 of the original), the definition of one iteration, 5x to 9x on AlexNet (61M to 6.7M), the L1 and L2 regularized losses, which one gives exact zeros, and which one Han found best for magnitude pruning. Expect a sparsity to compression-ratio conversion.
أرقام وصيغ مفردة: learning rate الخاص بـ fine-tuning (من 1/10 إلى 1/100 من الأصلي)، وتعريف التكرار الواحد، و5x إلى 9x على AlexNet (من 61M إلى 6.7M)، ودالتا الخسارة مع L1 وL2، وأيهما يعطي أصفاراً تامة، وأيهما وجده Han الأفضل لـ magnitude pruning. وتوقّع تحويلاً من sparsity إلى نسبة ضغط.
Why fine-tune, slides 41 to 43
لماذا fine-tuning، الشرائح 41 إلى 43
Slide 41 frames pruning as constrained optimization: minimize the loss over the pruned weights WP subject to at most N nonzeros. The mask decides which entries may be nonzero; fine-tuning is the argmin over the survivors with the mask fixed.
تصوغ الشريحة 41 pruning كمسألة تحسين مقيّدة: قلّل الخسارة على الأوزان المقلّمة WP بشرط ألا يزيد عدد غير الأصفار عن N. القناع (mask) يقرر أي المدخلات يُسمح أن تكون غير صفرية، وfine-tuning هو إيجاد argmin على الأوزان الباقية مع تثبيت القناع.
الصيغة: أوجد WP التي تقلّل L(x; WP) بشرط ‖WP‖0 ≤ N، حيث ‖·‖0 هو عدد العناصر غير الصفرية.
After pruning, accuracy may drop, more steeply at larger ratios. The survivors were tuned together to complete a function that has just lost some of its terms. Fine-tuning continues gradient descent on only those survivors, removed weights held at zero, so they absorb the missing work. The slide's rule: the fine-tuning learning rate is usually 1/100 or 1/10 of the original (Han et al. used 1/10 for LeNet and 1/100 for AlexNet). The survivors are already near a good minimum; a full-size step would throw them out of the basin in which the magnitude ranking was measured.
بعد التقليم قد تنخفض الدقة، وبشدة أكبر عند النسب الأعلى. فالأوزان الباقية ضُبطت معاً لتكمل دالة فقدت للتو بعض حدودها. وfine-tuning يتابع gradient descent على هذه الأوزان الباقية فقط، مع إبقاء المحذوفة عند الصفر، فتمتص العمل الناقص. قاعدة الشريحة: learning rate للـ fine-tuning يكون عادة 1/100 أو 1/10 من الأصلي (استخدم Han et al. 1/10 لـ LeNet و1/100 لـ AlexNet). الأوزان الباقية قريبة أصلاً من قاع جيد، وخطوة بالحجم الكامل سترميها خارج الحوض الذي قيس فيه ترتيب magnitude.
It is not cheap. AlexNet took 75 hours to train on a Titan X and 173 hours to retrain after pruning. The paper calls retraining critical: without it, accuracy is significantly impacted.
وهذا ليس رخيصاً: تدريب AlexNet استغرق 75 ساعة على Titan X، وإعادة التدريب بعد التقليم 173 ساعة. وتصف الورقة إعادة التدريب بأنها حاسمة: بدونها تتأثر الدقة بشكل كبير.
Train Connectivity, Prune Connections, Train Weights
درّب الاتصالية، قلّم الاتصالات، درّب الأوزان (Train Connectivity, Prune Connections, Train Weights)
The three boxes are Figure 2 of Han et al. (NeurIPS 2015). Train Connectivity is ordinary training whose purpose is to learn which connections matter. Prune Connections zeroes weights below a threshold and fixes the mask. Train Weights retrains the sparse survivors. Pruned weights never come back.
الصناديق الثلاثة هي الشكل 2 من Han et al. (NeurIPS 2015). Train Connectivity تدريب عادي هدفه تعلّم أي الوصلات مهمة. Prune Connections يصفّر الأوزان تحت عتبة ويثبّت القناع. Train Weights يعيد تدريب الأوزان الباقية المتناثرة. والأوزان المحذوفة لا تعود أبداً.
يسار الشكل: السهم الراجع من Train Weights إلى Prune Connections هو فكرة iterative pruning كلها. يمين الشكل: منحنيات الشريحة 51 (تقريبية). التقليم وحده ينهار مبكراً، وتقليم مع fine-tune واحد يحافظ على خسارة صفرية حتى نحو 80% (5x)، والتكراري يحافظ عليها حتى نحو 89% (9x).
Reading the curves
قراءة المنحنيات
| Curveالمنحنى | Where loss appearsأين تظهر الخسارة | Key points (approximate)نقاط أساسية (تقريبية) |
|---|---|---|
| Pruning only (no retrain)التقليم فقط (بلا إعادة تدريب) | Beyond about 67% pruned (one third remaining)بعد تقليم نحو 67% (يبقى الثلث) | 50% about -0.1, 67% about -0.9, 75% about -2.1, 80% about -4.050% نحو -0.1، و67% نحو -0.9، و75% نحو -2.1، و80% نحو -4.0 |
| Prune + fine-tune (one shot)تقليم + fine-tuning (مرة واحدة) | Zero loss to about 80% (5x)خسارة صفرية حتى نحو 80% (5x) | 85.5% about -0.5, 90% about -1.7, 93% about -3.885.5% نحو -0.5، و90% نحو -1.7، و93% نحو -3.8 |
| Iterative prune + fine-tuneتقليم تكراري + fine-tuning | Zero loss to 9x, within 0.5% to about 92%خسارة صفرية حتى 9x، وضمن 0.5% حتى نحو 92% | -4% only near 95.5%-4% فقط قرب 95.5% |
يلخّص الجدول المنحنيات الثلاثة: التقليم وحده يبدأ بالخسارة بعد نحو 67% مقلّمة (ثلث الوصلات باقٍ). والتقليم مع fine-tune واحد بلا خسارة حتى نحو 80% (5x)، ثم -1.7% عند 90%. والتكراري بلا خسارة حتى 9x، وضمن 0.5% حتى نحو 92%، ولا يصل إلى -4% إلا قرب 95.5%.
Two green points (around 67 and 75 percent) sit slightly above zero: pruning found the right capacity and reduced overfitting. The y-axis on these slides is top-5 accuracy loss.
نقطتان خضراوان (نحو 67% و75%) فوق الصفر قليلاً: التقليم وجد السعة المناسبة وقلّل overfitting. والمحور الرأسي في هذه الشرائح هو خسارة دقة top-5.
Iterative pruning, slides 44 to 51
التقليم التكراري، الشرائح 44 إلى 51
Definition, worth quoting verbatim: pruning followed by a fine-tuning is one iteration, and iterative pruning gradually increases the target sparsity in each iteration (30 percent, retrain, 50 percent, retrain, 70 percent, retrain, ...). Each new ranking is measured on a network that has already adapted to the previous cut, so the weights it marks as small really are the least needed. A one-shot 90 percent cut ranks everything on a network that never adapted, and throws away weights that would have become important.
التعريف، ويستحق الحفظ حرفياً: التقليم متبوعاً بـ fine-tuning هو تكرار واحد، وiterative pruning يرفع target sparsity تدريجياً في كل تكرار (30% ثم إعادة تدريب، ثم 50% ثم إعادة تدريب، ثم 70%...). كل ترتيب جديد يُقاس على شبكة تكيّفت مع القطع السابق، فالأوزان التي يعلّمها صغيرة هي فعلاً الأقل حاجة. أما القطع الواحد إلى 90% فيرتّب كل شيء على شبكة لم تتكيف قط، فيرمي أوزاناً كانت ستصبح مهمة.
Slide 51's result: iterative pruning boosts the pruning ratio from 5x to 9x on AlexNet compared to single-step aggressive pruning. Parameters 61M to 6.7M; top-1 error 42.78 to 42.77 percent; top-5 error 19.73 to 19.67 percent. The same paper reaches 13x on VGG-16.
نتيجة الشريحة 51: iterative pruning يرفع نسبة التقليم من 5x إلى 9x على AlexNet مقارنة بالتقليم العنيف بخطوة واحدة. المعاملات من 61M إلى 6.7M، وخطأ top-1 من 42.78% إلى 42.77%، وخطأ top-5 من 19.73% إلى 19.67%. والورقة نفسها تصل إلى 13x على VGG-16.
Convert sparsity s (fraction pruned away) to a reduction factor with ratio = 1 / (1 - s), and back with s = 1 - 1/ratio. Then walk the slide's schedule.
حوّل sparsity s (الجزء المحذوف) إلى معامل تخفيض بالعلاقة ratio = 1 / (1 - s)، وبالعكس s = 1 - 1/ratio. ثم امشِ على جدول الشريحة.
target s kept ratio = 1/(1-s) fraction of SURVIVORS cut this round
30 % 70 % 1.43x 30 / 100 = 30.0 %
50 % 50 % 2.00x 20 / 70 = 28.6 %
70 % 30 % 3.33x 20 / 50 = 40.0 %
80 % 20 % 5.00x 10 / 30 = 33.3 %
90 % 10 % 10.00x 10 / 20 = 50.0 %
AlexNet 5x -> s = 1 - 1/5 = 80 % 61 M / 5 = 12.2 M kept
9x -> s = 1 - 1/9 = 88.9 % 61 M / 9 = 6.8 M (paper: 6.7 M, 61/6.7 = 9.1x)
extra removed by iterating: 12.2 - 6.8 = 5.4 M weights, no accuracy cost
The ratio column is not linear in s: the last 10 points of sparsity (80 to 90 percent) double the ratio from 5x to 10x. The right column shows what the schedule really does each round: it cuts a fraction of what survived the last round, not a fresh slice of the original.
عمود النسبة ليس خطياً في s: آخر 10 نقاط من sparsity (من 80% إلى 90%) تضاعف النسبة من 5x إلى 10x. والعمود الأيمن يبيّن ما يفعله الجدول فعلاً في كل جولة: يقطع جزءاً مما نجا في الجولة السابقة، لا شريحة جديدة من الأصل.
Regularization, slide 52
Regularization، الشريحة 52
When training, or fine-tuning a pruned network, a penalty is added to the loss to penalize non-zero parameters and encourage smaller parameters, so that more weights fall under the pruning threshold and the magnitude ranking becomes a cleaner signal. The two common choices:
أثناء التدريب، أو أثناء fine-tuning لشبكة مقلّمة، يُضاف حد جزاء إلى الخسارة لمعاقبة المعاملات غير الصفرية وتشجيع المعاملات الأصغر، فتقع أوزان أكثر تحت عتبة التقليم ويصبح ترتيب magnitude إشارة أنظف. الخياران الشائعان:
مع L1: L′ = L(x; W) + λ|W|. ومع L2: L′ = L(x; W) + λ‖W‖2. وλ يحدد قوة منافسة الجزاء لخسارة البيانات.
مشتقة L1 هي λ · sign(w) وحجمها ثابت، ومشتقة L2 هي 2λw وتتناقص مع w. وهذا وحده يفسّر الفرق في السلوك.
Near zero the L1 pull keeps its full size, so a weight is pushed onto exactly zero and pinned there (sparse solutions, as in LASSO). The L2 pull fades as the weight shrinks, so it multiplies every weight by a factor below one and never reaches zero (weight decay).
قرب الصفر يحتفظ سحب L1 بحجمه الكامل، فيُدفع الوزن إلى الصفر تماماً ويثبت هناك (حلول متناثرة كما في LASSO). أما سحب L2 فيضعف كلما صغر الوزن، فهو يضرب كل وزن في معامل أقل من واحد ولا يصل إلى الصفر أبداً (weight decay).
One weight w = 0.05, λ = 0.01, learning rate η = 0.1, penalty only (data loss ignored).
وزن واحد w = 0.05، وλ = 0.01، وη = 0.1، مع الجزاء فقط (نتجاهل خسارة البيانات).
L1 step: w <- w - η λ sign(w) = w - 0.001
0.05 / 0.001 = 50 steps -> exactly 0, and stays there
L2 step: w <- w - η 2λ w = w (1 - 0.002) = 0.998 w
after 50 steps: 0.05 x 0.998^50 = 0.0452
after 1000 steps: 0.05 x 0.998^1000 = 0.0068 never zero
L1 subtracts a constant and lands on zero. L2 multiplies by a constant and only approaches it.
L1 يطرح مقداراً ثابتاً فيصل إلى الصفر. وL2 يضرب في معامل ثابت فلا يقترب من الصفر إلا تدريجياً دون أن يبلغه.
Magnitude-based fine-grained pruning: L2 on weights
التقليم الدقيق المبني على magnitude: L2 على الأوزان
Han et al. found L1 gives better accuracy right after pruning (before retraining), since more weights sit near zero, but L2 gives better accuracy after retraining and is best overall. Switching L1 to L2 between phases did not help.
وجد Han et al. أن L1 يعطي دقة أفضل بعد التقليم مباشرة (قبل إعادة التدريب) لأن أوزاناً أكثر تكون قرب الصفر، لكن L2 يعطي دقة أفضل بعد إعادة التدريب وهو الأفضل إجمالاً. والتحويل من L1 إلى L2 بين المرحلتين لم يُفِد.
Network Slimming: L1 on BN γ
Network Slimming: L1 على BN γ
Liu et al. (ICCV 2017) put a sparsity penalty on the batch norm scaling factors γ, one per channel (the slide says smooth-L1; the paper's main form is plain L1, g(s) = |s|). Channels whose γ is pushed toward zero are removed by a global threshold, then fine-tuned. This is channel pruning, linked to the scaling-factor criterion of 04-1.
وضع Liu et al. (ICCV 2017) جزاء تناثر على معاملات القياس γ في batch norm، واحد لكل قناة (الشريحة تقول smooth-L1، والصيغة الأساسية في الورقة هي L1 العادي g(s) = |s|). القنوات التي يُدفع γ الخاص بها نحو الصفر تُحذف بعتبة عامة، ثم يُجرى fine-tuning. هذا channel pruning مرتبط بمعيار scaling factor في المحاضرة 04-1.
The fine-tuning learning rate is smaller, not larger: 1/10 to 1/100 of the original. "Use a larger rate to recover faster" is the distractor. And fine-tuning keeps the survivors' trained values with the mask fixed; it does not re-initialize them.
learning rate للـ fine-tuning أصغر لا أكبر: من 1/10 إلى 1/100 من الأصلي. وعبارة "استخدم معدلاً أكبر لتتعافى أسرع" هي المُضلِّل. وfine-tuning يحتفظ بقيم الأوزان الباقية المدرّبة مع تثبيت القناع، ولا يعيد تهيئتها.
L1 versus L2 gradient: L1 is λ·sign(w), constant in size, giving exact zeros; L2 is 2λw, proportional to w, giving shrinkage without zeros. Swapping these is the classic mistake. Second trap: "L1 gives exact zeros, so L1 is best for pruning" is false for magnitude pruning; Han found L2 best after retraining.
مشتقة L1 مقابل L2: مشتقة L1 هي λ·sign(w) بحجم ثابت فتعطي أصفاراً تامة، ومشتقة L2 هي 2λw متناسبة مع w فتعطي تقليصاً بلا أصفار. والخلط بينهما هو الخطأ الكلاسيكي. والفخ الثاني: "L1 يعطي أصفاراً تامة إذن هو الأفضل للتقليم" خاطئ في magnitude pruning، فقد وجد Han أن L2 هو الأفضل بعد إعادة التدريب.
Ratios are not linear in sparsity. 9x is 88.9 percent pruned, not 90; 5x is 80 percent. Always go through 1 / (1 - s).
النسب ليست خطية في sparsity. 9x تعني 88.9% مقلّمة لا 90%، و5x تعني 80%. مرّ دائماً عبر 1 / (1 - s).
"Cut, heal gently, cut again." Gently means a tenth to a hundredth of the learning rate. "L1 subtracts, L2 multiplies": subtracting a constant hits zero, multiplying by 0.998 never does. 5x one shot, 9x iterative.
"اقطع، عالِج بلطف، اقطع مرة أخرى." بلطف تعني عُشر إلى جزء من مئة من learning rate. "L1 يطرح، L2 يضرب": طرح مقدار ثابت يصل إلى الصفر، والضرب في 0.998 لا يصل أبداً. 5x بخطوة واحدة، و9x بالتكرار.
Check yourself
اختبر نفسك
Relative to the original training, what learning rate is usually used to fine-tune a pruned network?
نسبةً إلى التدريب الأصلي، ما learning rate المستخدم عادة لـ fine-tuning شبكة مقلّمة؟
B. The survivors are already near a good minimum; small steps recover accuracy without leaving it (LeNet 1/10, AlexNet 1/100). C would throw the weights out of the basin where the magnitude ranking was made. D is not fine-tuning at all.
الجواب B. الأوزان الباقية قريبة من قاع جيد، والخطوات الصغيرة تستعيد الدقة دون مغادرته (LeNet 1/10، وAlexNet 1/100). الخيار C سيرمي الأوزان خارج الحوض الذي جرى فيه ترتيب magnitude. والخيار D ليس fine-tuning أصلاً.
In iterative pruning, what is one iteration?
في iterative pruning، ما هو التكرار الواحد؟
C. The slide's definition. Connectivity is trained once at the start, and pruned connections never regrow, so D is wrong. B is the pruning-only curve that fails early.
الجواب C، وهو تعريف الشريحة. connectivity يُدرَّب مرة واحدة في البداية، والوصلات المحذوفة لا تنمو من جديد، فالخيار D خاطئ. والخيار B هو منحنى التقليم وحده الذي ينهار مبكراً.
On AlexNet, iterative pruning raised the achievable pruning ratio from what to what, and what does 9x mean in sparsity?
على AlexNet، رفع iterative pruning نسبة التقليم الممكنة من كم إلى كم، وماذا تعني 9x بلغة sparsity؟
D. s = 1 - 1/9 = 0.889. 61M to 6.7M parameters, top-5 error 19.73 to 19.67 percent. C has the right ratios but treats 9x as 90 percent (90 percent is 10x). 13x is the VGG-16 result.
الجواب D. s = 1 - 1/9 = 0.889. من 61M إلى 6.7M معامل، وخطأ top-5 من 19.73% إلى 19.67%. الخيار C نسبه صحيحة لكنه يعامل 9x كأنها 90% (و90% تعني 10x). و13x هي نتيجة VGG-16.
Why does an L1 penalty drive weights to exactly zero while L2 only shrinks them?
لماذا يدفع جزاء L1 الأوزان إلى الصفر تماماً بينما يقلّصها L2 فقط؟
A. A constant subtraction reaches zero in finite steps (0.05 in 50 steps of 0.001); a multiplicative 0.998 shrink never does. B is the exact swap the examiner hopes for. λ is a free choice in both.
الجواب A. الطرح الثابت يصل إلى الصفر في عدد محدود من الخطوات (0.05 في 50 خطوة بمقدار 0.001)، أما التقليص بالضرب في 0.998 فلا يصل أبداً. الخيار B هو القلب الذي يأمله الممتحن بالضبط. وλ اختيار حر في كليهما.
Which pairing matches slide 52's examples?
أي مطابقة تتفق مع أمثلة الشريحة 52؟
C. Han et al. found L2 gave the best results after retraining for fine-grained magnitude pruning. Network Slimming penalizes the per-channel batch norm γ with a sparsity penalty and removes channels whose γ is near zero. A is the tempting "L1 makes zeros, so L1 for pruning" error.
الجواب C. وجد Han et al. أن L2 يعطي أفضل النتائج بعد إعادة التدريب في fine-grained magnitude pruning. وNetwork Slimming يعاقب γ الخاص بكل قناة في batch norm بجزاء تناثر ويحذف القنوات التي يقترب γ الخاص بها من الصفر. والخيار A هو الخطأ المُغري "L1 يصنع أصفاراً إذن L1 للتقليم".