Majid Al-RaimiPruning criteria: magnitude and scaling factorsمعايير التقليم: المقدار ومعاملات القياس

COE 592Lecture 4.1المحاضرة 4.1Part 05الجزء 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 في تطبيع الدفعة.

Conceptsالمفاهيم
4
Slidesالشرائح
26-33
Readingمدة القراءة
24 min24 دقيقة
Understoodما فهمته
0/4 conceptsمفاهيم

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في نهاية هذا الجزء ستستطيع

  1. State the principle behind every pruning criterion and apply it to a single neuron.تذكر المبدأ الذي يقوم عليه كل معيار تقليم وتطبّقه على عصبون واحد.
  2. Compute element-wise importances |W| and produce the pruned matrix for a target sparsity.تحسب الأهمية على مستوى العنصر |W| وتُخرج المصفوفة المقلَّمة لنسبة تناثر مستهدفة.
  3. Score rows or channels with L1, L2 and general Lp norms and say which row is pruned.تقيّم الصفوف أو القنوات بالمعايير L1 وL2 والمعيار العام Lp وتحدد أي صف يُقلَّم.
  4. Show with numbers when L1 and L2 rank structural sets differently.تبيّن بالأرقام متى يرتّب L1 وL2 المجموعات الهيكلية ترتيبًا مختلفًا.
  5. 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|. إذا كانت المدخلات الثلاثة متقاربة في الحجم، فالحذف الثالث ألطف بمئة مرة من الأول، وهو الحذف الذي ينبغي أن نختاره.

y=f(∑iwixi+b)y = f\Big(\sum_i w_i x_i + b\Big)
One neuron: a weighted sum of inputs, a bias, then a nonlinearity f such as ReLUعصبون واحد: مجموع موزون للمدخلات، وانحياز، ثم لاخطية f مثل ReLU

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).

The two strong connections light up and the output survives; the 0.1 connection is cut because it moves the sum leastيضيء الاتصالان القويان ويبقى الخرج؛ ويُقطع الاتصال ذو الوزن 0.1 لأنه أقل ما يحرّك المجموع

Worked exampleمثال محلول

Three candidate deletionsثلاثة حذوفات مرشّحة

  1. 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. لمدخل نموذجي يكون هذا أكبر حدّ في المجموع، فقد ينقلب الخرج من عصبون نشِط إلى عصبون صامت.
  2. 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|، وهو يكاد يساوي الحالة الأولى.
  3. 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. ومع مدخلات متقاربة في المقياس، يكون هذا مجرد خطأ تقريب مقارنة بالحدّين الآخرين.
  4. 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. أي وزن يُحذف أولًا، وما الافتراض الذي يجعل هذه الإجابة آمنة؟

The 0.1, because it has the smallest absolute value. The answer assumes x_0, x_1 and x_2 have similar scale, since the removed term is really |w_i| |x_i|.
الوزن 0.1، لأن قيمته المطلقة هي الأصغر. تفترض الإجابة أن x_0 وx_1 وx_2 متقاربة في المقياس، لأن الحدّ المحذوف في الحقيقة هو |w_i| |x_i|.

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]].

Importance=∣W∣\text{Importance} = |W|
Element-wise magnitude: each weight is scored by its own absolute valueالمقدار لكل عنصر: يُقيَّم كل وزن بقيمته المطلقة
The minus signs drop away, the two largest magnitudes fill in, and the pruned matrix keeps 3 and -5تسقط إشارات السالب، وتُملأ أكبر قيمتين بالمقدار، وتحتفظ المصفوفة المقلَّمة بالقيمتين 3 و-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 بالمئة

  1. 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.
  2. Count how many surviveاحسب عدد الناجين

    Four weights at 50 percent sparsity means 4 × (1 - 0.5) = 2 survivors.
    أربعة أوزان عند تناثر 50 بالمئة تعني 4 × (1 - 0.5) = 2 من الأوزان الناجية.
  3. 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.
  4. 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 بالمئة.

Importances [[3, 2], [1, 5]]. Two survivors: 3 and -5. Pruned matrix [[3, 0], [0, -5]].
الأهميات [[3, 2], [1, 5]]. ناجيان: 3 و-5. المصفوفة المقلَّمة [[3, 0], [0, -5]].

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]].

ImportanceL1=∑i∈S∣wi∣\text{Importance}_{L1} = \sum_{i \in S} |w_i|
Row-wise L1: the sum of absolute values over the structural set SL1 لكل صف: مجموع القيم المطلقة على المجموعة البنيوية S
ImportanceL2=∑i∈S∣wi∣2\text{Importance}_{L2} = \sqrt{\sum_{i \in S} |w_i|^2}
Row-wise L2: the Euclidean length of the rowL2 لكل صف: الطول الإقليدي للصف
The two rows collapse to their L1 scores 5 and 6; the lower score loses and its whole row becomes zerosيُختزل الصفان إلى درجتيهما بمعيار L1، أي 5 و6؛ الدرجة الأدنى تخسر ويصبح صفها كله أصفارًا

Worked exampleمثال محلول

Row-wise scores, both normsدرجات الصفوف بالمعيارين

  1. Absolute values firstالقيم المطلقة أولًا

    Row 0 is [3, 2] in magnitude, row 1 is [1, 5].
    الصف 0 مقداره [3, 2]، والصف 1 مقداره [1, 5].
  2. L1: addالمعيار L1: اجمع

    Row 0: 3 + 2 = 5. Row 1: 1 + 5 = 6.
    الصف 0: 3 + 2 = 5. الصف 1: 1 + 5 = 6.
  3. 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.
  4. Compare and zero the loserقارن واجعل الخاسر صفرًا

    Under both norms row 0 scores lower, so every entry of row 0 becomes zero.
    بكلا المعيارين يحصل الصف 0 على درجة أقل، فيصبح كل عنصر في الصف 0 صفرًا.
  5. 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درجة الصف 0Row 1 scoreدرجة الصف 1Row 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 على مستوى الصف5566row 0الصف 0[[0, 0], [1, -5]][[0, 0], [1, -5]]
Row-wise L2L2 على مستوى الصفsqrt(13) = 3.61sqrt(13) = 3.61sqrt(26) = 5.10sqrt(26) = 5.10row 0الصف 0[[0, 0], [1, -5]][[0, 0], [1, -5]]
Three criteria on [[3, -2], [1, -5]] at 50 percent sparsityثلاثة معايير على المصفوفة [[3, -2], [1, -5]] عند تناثر 50 بالمئة

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 فهي المثال نفسه تحت الصيغة العامة، وليست طريقة جديدة.

∥W(S)∥p=(∑i∈S∣wi∣p)1/p\big\lVert W^{(S)} \big\rVert_p = \Big(\sum_{i \in S} |w_i|^p\Big)^{1/p}
The Lp norm of a structural set; p = 1 and p = 2 recover the two criteria aboveمعيار Lp لمجموعة بنيوية؛ وp = 1 وp = 2 تعيدان المعيارين السابقين

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درجة L1L2 scoreدرجة L2
[3, 3][3, 3]3 + 3 = 63 + 3 = 6sqrt(9 + 9) = 4.24sqrt(9 + 9) = 4.24
[0, 5][0, 5]0 + 5 = 50 + 5 = 5sqrt(0 + 25) = 5sqrt(0 + 25) = 5
Row keptالصف المحتفَظ به[3, 3][3, 3][0, 5][0, 5]
Two rows, two norms, two different survivorsصفّان، ومعياران، وناجيان مختلفان
The L1 diamond of radius 6 passes through a = [3, 3] with b inside it; the L2 circle of radius 5 passes through b = [0, 5] with a inside itمعيّن L1 ذو نصف القطر 6 يمر بالنقطة a = [3, 3] والنقطة b داخله؛ ودائرة L2 ذات نصف القطر 5 تمر بالنقطة b = [0, 5] والنقطة a داخلها

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]. غيّر عنصرًا واحدًا وراقب على أي صف يتنازع المعياران.

SimulatorمحاكيMagnitude criterion explorer: element-wise or row-wise, L1 or L2مستكشف معيار المقدار: لكل عنصر أو لكل صف، L1 أو L2
any p gives |w| on one elementأي قيمة لـ p تعطي |w| على عنصر واحد
Weight W
Editable weight matrix
Importance |W|
3215
Pruned W
300-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 بالمئة؟

L1: 5 and 6. L2: sqrt(13) = 3.61 and sqrt(26) = 5.10. Row 0 is pruned under both, giving [[0, 0], [1, -5]].
L1: 5 و6. L2: sqrt(13) = 3.61 وsqrt(26) = 5.10. الصف 0 يُقلَّم بكليهما، فتكون النتيجة [[0, 0], [1, -5]].

Recall

Give two rows where L1 and L2 disagree, with the numbers.أعطِ صفّين يختلف عليهما L1 وL2، مع الأرقام.

[3, 3] against [0, 5]. L1: 6 against 5, keeps [3, 3]. L2: 4.24 against 5, keeps [0, 5].
[3, 3] مقابل [0, 5]. L1: 6 مقابل 5، فيحتفظ بـ [3, 3]. L2: 4.24 مقابل 5، فيحتفظ بـ [0, 5].

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: طبقة أضيق فعليًا.

Hovering raises the threshold to 0.30; the channels with gamma 0.10 and 0.29 fade out and the survivors close the gapتمرير المؤشر يرفع العتبة إلى 0.30؛ فتتلاشى القناتان ذواتا gamma بقيمتي 0.10 و0.29 وتسدّ القنوات الناجية الفراغ

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 على المعاملات إلى الخسارة.

L=∑(x,y)ℓ(f(x,W),y)+λ∑γ∈Γ∣γ∣L = \sum_{(x, y)} \ell\big(f(x, W), y\big) + \lambda \sum_{\gamma \in \Gamma} |\gamma|
Network slimming: the usual loss plus an L1 penalty that pushes every channel scaling factor toward zeroNetwork 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، واحدة لكل قناة خرج، وهي معامل التحجيم الذي تعيد الشريحة استخدامه.

zo=γ zi−μBσB2+ϵ+βz_o = \gamma \, \frac{z_i - \mu_{\mathcal{B}}}{\sqrt{\sigma^2_{\mathcal{B}} + \epsilon}} + \beta
Batch normalization for one channel: mini-batch statistics normalize z_i, then gamma rescales and beta shiftsbatch normalization لقناة واحدة: إحصاءات الدفعة الصغيرة تطبّع z_i، ثم يعيد gamma التحجيم ويزيح beta

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 بدلًا من إضافة طبقة تحجيم جديدة؟

Gamma is already a per-channel trainable scale, so no new parameters or layers are needed. A standalone scaling layer after a linear convolution is meaningless because the scale could be moved into the weights, but batch normalization fixes the normalized activation's scale, so gamma alone measures the channel.
لأن gamma معامل تحجيم قابل للتدريب لكل قناة أصلًا، فلا حاجة إلى معاملات أو طبقات جديدة. وطبقة التحجيم المستقلة بعد التفاف خطي بلا معنى لأن التحجيم يمكن نقله إلى الأوزان، لكن batch normalization يثبّت مقياس التنشيط المطبَّع، فتقيس gamma وحدها القناة.

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: أي المرشحات تُحذف؟

Filters 1 and 2, with factors 0.10 and 0.29. Their input channels in the next layer are removed as well.
المرشحان 1 و2، بمعاملين 0.10 و0.29. وتُحذف أيضًا قنوات الدخل الخاصة بهما في الطبقة التالية.

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المصادر