Majid Al-RaimiPruning and sparsity Iالتقليم (Pruning) والتناثر (Sparsity) الجزء الأول

COE 592Lecture 4.1المحاضرة 4.1

Pruning and sparsity Iالتقليم (Pruning) والتناثر (Sparsity) الجزء الأول

Why moving data costs more energy than computing on it, how pruning is posed as loss minimization under a nonzero budget, the granularity spectrum from fine-grained to channel-level sparsity (including NVIDIA 2:4), and the first pruning criteria: magnitude, scaling factors, second-order Optimal Brain Damage, APoZ and regression-based channel selection.لماذا يستهلك نقل البيانات طاقة أكثر من الحساب عليها، وكيف يُصاغ التقليم بوصفه تقليلًا للخسارة تحت ميزانية للعناصر غير الصفرية، وطيف الدقة (granularity) من التناثر الدقيق إلى التناثر على مستوى القنوات (بما فيه NVIDIA 2:4)، ومعايير التقليم الأولى: المقدار (magnitude)، ومعاملات القياس (scaling factors)، وOptimal Brain Damage من الرتبة الثانية، وAPoZ، واختيار القنوات القائم على الانحدار (regression).

Partsالأجزاء
6
Conceptsالمفاهيم
29
Slidesالشرائح
43
Readingمدة القراءة
174 min174 دقيقة
Understoodما فهمته
0/29 conceptsمفاهيم
Read the full guideاقرأ الشرح الكاملEvery part on one long page: 6 parts, 29 concepts, about 174 min.كل الأجزاء في صفحة واحدة طويلة: 6 أجزاء، و29 مفهومًا، في نحو 174 دقيقة.

AOverviewنظرة عامة

A trained network carries far more weights than it needs, and every one of those weights has to be fetched from memory before it can be multiplied. This lecture is about deleting the ones that do not matter. It opens with a single number, 640 pJ for a DRAM access against 3.1 pJ for a multiply, and by the end it has turned that number into a discipline: a formulation, a spectrum of shapes to cut, and a family of criteria that say which weight, row or channel goes first.

تحمل الشبكة المدرَّبة أوزانًا أكثر بكثير مما تحتاج، وكل وزن منها يجب جلبه من الذاكرة قبل أن يُضرب. تدور هذه المحاضرة حول حذف الأوزان التي لا تهم. تبدأ برقم واحد، 640 pJ لقراءة من DRAM مقابل 3.1 pJ لعملية ضرب، وبنهايتها تكون قد حوّلت هذا الرقم إلى منهج متكامل: صياغة رياضية، وطيف من الأشكال التي يمكن قطعها، وعائلة من المعايير تحدد أي وزن أو صف أو قناة يُحذف أولًا.

As a PhD student you need it in three places. Exams hand you a small weight matrix and ask for element-wise and row-wise importances, the pruned result and the sparsity, or ask you to derive the Optimal Brain Damage saliency and name the assumption that removes each Taylor term. Your research project puts a detector on an embedded board, and the first compression step in that pipeline is almost always pruning, so its evaluation section has to say what granularity you chose, which criterion ranked the channels and why the board got faster. And any efficient system you build or review is judged by the lesson this lecture hammers home: a matrix that is 90% zeros is only faster when the zeros sit in a shape the hardware can skip.

كطالب دكتوراه ستحتاج هذه المحاضرة في ثلاثة مواضع. في الامتحانات تُعطى مصفوفة أوزان صغيرة ويُطلب منك حساب الأهمية على مستوى العنصر (element-wise) وعلى مستوى الصف (row-wise)، والنتيجة بعد التقليم ونسبة التناثر (sparsity)، أو يُطلب منك اشتقاق مقياس الأهمية في Optimal Brain Damage وتسمية الافتراض الذي يحذف كل حد من حدود متسلسلة تايلور (Taylor). ومشروعك البحثي يضع كاشفًا (detector) على لوحة مدمجة، وأول خطوة ضغط في هذا المسار تكون غالبًا التقليم (pruning)، لذلك يجب أن يذكر قسم التقييم فيه الدرجة الحبيبية (granularity) التي اخترتها، وأي معيار رتّب القنوات، ولماذا أصبحت اللوحة أسرع. وأي نظام كفء تبنيه أو تراجعه يُحكم عليه بالدرس الذي تكرره هذه المحاضرة بإلحاح: المصفوفة التي 90% منها أصفار لا تصبح أسرع إلا إذا كانت الأصفار في شكل يستطيع العتاد تخطيه.

From the energy ladder to the curvature of the lossمن سُلّم الطاقة إلى انحناء دالة الخسارة

The path has five stops. You start with the energy argument and the formulation of pruning as minimizing the loss under an L0 budget, with the brain's own overprovision-then-prune curve as motivation. You watch Han et al. prove that train, prune and retrain removes 9x of AlexNet with no accuracy loss, and learn why the retraining step is the one that matters. You open a convolution weight along its four dimensions and order the five granularities from irregular to regular, then meet the three that ship: fine-grained pruning with EIE-style hardware, the NVIDIA 2:4 pattern, and channel pruning with per-layer ratios found by AMC. Finally you learn to rank what gets removed, first by magnitude and batch norm scaling factors, then by curvature, activations and layer reconstruction.

للمسار خمس محطات. تبدأ بحجة الطاقة وبصياغة التقليم كتقليل للخسارة تحت ميزانية L0، مع منحنى الدماغ نفسه (فائض في الوصلات ثم تقليم) كدافع. ثم تشاهد Han et al. يثبتون أن التدريب ثم التقليم ثم إعادة التدريب يزيل 9x من AlexNet دون أي خسارة في الدقة، وتتعلم لماذا خطوة إعادة التدريب هي الخطوة الحاسمة. بعدها تفتح وزن الالتفاف (convolution) على أبعاده الأربعة وترتب الدرجات الحبيبية الخمس من غير المنتظم إلى المنتظم، ثم تتعرف على الثلاث التي تُستخدم فعلًا: التقليم الدقيق (fine-grained) مع عتاد على طراز EIE، ونمط 2:4 من NVIDIA، وتقليم القنوات مع نسب لكل طبقة يجدها AMC. وأخيرًا تتعلم ترتيب ما يُحذف، أولًا بالمقدار (magnitude) وبمعاملات القياس في batch norm، ثم بالانحناء والتنشيطات (activations) وإعادة بناء مخرجات الطبقة.

Numbers you will own by the endأرقام ستتقنها بنهاية المحاضرة

These are the anchors the parts derive and the exam and reference sheet return to. By the last part you will have computed or justified every one of them rather than quoted it.

هذه هي الأرقام المرجعية التي تشتقها الأجزاء ويعود إليها الامتحان وورقة المرجع. بحلول الجزء الأخير ستكون قد حسبت كل واحد منها أو برّرته بدل أن تحفظه وتقتبسه.

Anchor numbers and formulas from the six parts of this lectureالأرقام والصيغ المرجعية من الأجزاء الستة لهذه المحاضرة

DRAM access versus integer multiplyقراءة DRAM مقابل ضرب الأعداد الصحيحة
640 pJ against 3.1 pJ, about 200x, in 45 nm640 pJ مقابل 3.1 pJ، أي نحو 200x، بتقنية 45 nm
Pruning formulationصياغة التقليم
argmin L(x; W_P) subject to ||W_P||_0 ≤ Nargmin L(x; W_P) subject to ||W_P||_0 ≤ N
Iterative prune and retrainالتقليم التكراري مع إعادة التدريب
AlexNet 9x, VGG-16 13x, no accuracy lossAlexNet 9x، وVGG-16 13x، دون خسارة في الدقة
Reduction factorمعامل التخفيض
1 / (1 - r): 80% is 5x, 90% is 10x1 / (1 - r): نسبة 80% تعطي 5x، ونسبة 90% تعطي 10x
NVIDIA 2:4 patternنمط 2:4 من NVIDIA
50% sparsity, about 2x math throughput on Ampereتناثر 50%، ونحو 2x في إنتاجية العمليات الحسابية على Ampere
AMC versus uniform shrinkAMC مقابل التصغير الموحد
70.5% at 68.3 ms against 68.4% at 72.3 ms on a Pixel 170.5% عند 68.3 ms مقابل 68.4% عند 72.3 ms على هاتف Pixel 1
Optimal Brain Damage saliencyمقياس الأهمية في Optimal Brain Damage
1/2 h_ii w_i^21/2 h_ii w_i^2

Success looks likeعلامات النجاح

  • Argue from the 45 nm energy table why fewer weights means less energy, and write the pruning formulation with every symbol named and the reason the L0 constraint forces heuristic criteria.أن تستدل من جدول الطاقة عند 45 nm على أن عدد أوزان أقل يعني طاقة أقل، وأن تكتب صياغة التقليم مع تسمية كل رمز وذكر السبب الذي يجعل قيد L0 يفرض معايير تقريبية (heuristic).
  • Read accuracy loss and reduction factor off the pruning-ratio chart for one-shot, retrained and iterative pruning, and explain from layer tables why parameters shrink 9x while MACs shrink only 3x.أن تقرأ خسارة الدقة ومعامل التخفيض (reduction factor) من مخطط نسبة التقليم للتقليم دفعة واحدة (one-shot) والتقليم مع إعادة التدريب والتقليم التكراري، وأن تشرح من جداول الطبقات لماذا تنكمش المعاملات 9x بينما تنكمش عمليات MAC بمقدار 3x فقط.
  • Read a convolution weight as [c_o, c_i, k_h, k_w], order the five granularities from fine-grained to channel-level, and count the weights and the surviving shape after removing a kernel, an input channel or a filter.أن تقرأ وزن الالتفاف على شكل [c_o, c_i, k_h, k_w]، وترتب الدرجات الحبيبية الخمس من الدقيق (fine-grained) إلى مستوى القناة (channel-level)، وتعد الأوزان والشكل المتبقي بعد حذف نواة (kernel) أو قناة إدخال أو مرشح (filter).
  • Define N:M sparsity, derive the 2:4 compressed layout and its memory saving, and say which granularity gives real speedup on commodity GPUs and why.أن تعرّف تناثر N:M، وتشتق التخطيط المضغوط لنمط 2:4 وما يوفره من ذاكرة، وتذكر أي درجة حبيبية تعطي تسريعًا حقيقيًا على وحدات GPU التجارية ولماذا.
  • Compute element-wise and row-wise importances with L1, L2 and general Lp norms, produce the pruned matrix for a target sparsity, and explain why batch norm gamma is a free channel score.أن تحسب الأهمية على مستوى العنصر وعلى مستوى الصف باستخدام L1 وL2 والـ norm العام Lp، وتنتج المصفوفة المقلَّمة لنسبة تناثر مستهدفة، وتشرح لماذا يمثل gamma في batch norm درجة أهمية مجانية للقناة.
  • Derive 1/2 h_ii w_i^2 from the Taylor expansion, name the assumption that removes each term, and show a case where magnitude and Optimal Brain Damage rank two weights differently.أن تشتق 1/2 h_ii w_i^2 من متسلسلة تايلور، وتسمي الافتراض الذي يحذف كل حد، وتعرض حالة يرتّب فيها معيار المقدار ومعيار Optimal Brain Damage وزنين ترتيبًا مختلفًا.
  • Compute APoZ for a channel from its activation maps, state the regression-based channel pruning objective with its L0 constraint, and say what data each criterion needs before you can run it.أن تحسب APoZ لقناة من خرائط تنشيطها، وتكتب هدف تقليم القنوات القائم على الانحدار (regression) مع قيد L0 الخاص به، وتذكر البيانات التي يحتاجها كل معيار قبل أن تتمكن من تشغيله.

How to study this lectureكيف تذاكر هذه المحاضرة

  1. Read the parts in order. The energy argument of part one justifies part two, the granularity ladder of part three is what part four tests against hardware, and parts five and six answer the question parts three and four leave open: which unit to remove.اقرأ الأجزاء بالترتيب. حجة الطاقة في الجزء الأول تبرر الجزء الثاني، وسُلّم الدرجات الحبيبية في الجزء الثالث هو ما يختبره الجزء الرابع أمام العتاد، والجزآن الخامس والسادس يجيبان عن السؤال الذي يتركه الجزآن الثالث والرابع مفتوحًا: أي وحدة نحذف.
  2. Keep a pencil next to every small matrix. Each worked example hides one computation behind a question, so compute the norms, the sparsity and the pruned result yourself before you reveal them.احتفظ بقلم بجانب كل مصفوفة صغيرة. كل مثال محلول يخفي حسابًا واحدًا خلف سؤال، فاحسب الـ norms ونسبة التناثر والنتيجة المقلَّمة بنفسك قبل كشفها.
  3. Answer every recall prompt in your head before opening it. The numbers and derivations that stick are the ones you retrieved, not the ones you read.أجب عن كل سؤال استرجاع في ذهنك قبل فتحه. الأرقام والاشتقاقات التي تبقى في الذاكرة هي التي استرجعتها، لا التي قرأتها.
  4. Take each quiz and read the explanation even when you are right. The wrong options are the exam traps.حل كل اختبار قصير واقرأ الشرح حتى عندما تكون إجابتك صحيحة. الخيارات الخاطئة هي فخاخ الامتحان.
  5. Mark a concept understood only when you could redo its formula and its headline number from a blank page. Unmarked concepts show you where to return.لا تعلّم على مفهوم أنه مفهوم إلا إذا كنت تستطيع إعادة كتابة صيغته ورقمه الرئيسي من صفحة فارغة. المفاهيم غير المعلَّمة تدلك على ما يجب أن تعود إليه.
  6. Keep the glossary open for terms and the reference sheet for the energy table, the granularity ladder, the norm formulas and the criteria comparison when you solve problems.أبقِ المسرد مفتوحًا للمصطلحات، وورقة المرجع مفتوحة لجدول الطاقة وسُلّم الدرجات الحبيبية وصيغ الـ norms ومقارنة المعايير عندما تحل المسائل.
  7. Come back after a few days and prune a layer of your own project detector cold, choosing a granularity and a criterion and justifying both. Spaced practice on a new network is what turns a formula into a skill.عد بعد بضعة أيام وقلّم طبقة من الكاشف في مشروعك دون الرجوع إلى المادة، مختارًا درجة حبيبية ومعيارًا ومبررًا كلًّا منهما. التدرب المتباعد على شبكة جديدة هو ما يحوّل الصيغة إلى مهارة.

Sourcesالمصادر

BThe 6 partsالأجزاء الـ6

  1. 01Why 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-630 min30 دقيقة
    1. 1.1Pruning is a pipeline of four decisionsالـ pruning سلسلة من أربعة قرارات
    2. 1.2Memory traffic, not arithmetic, sets the energy billحركة البيانات من الذاكرة، لا العمليات الحسابية، هي ما يحدد فاتورة الطاقة
    3. 1.3What pruning removes: synapses, neurons, or bothماذا يزيل الـ pruning: الوصلات، أم العصبونات، أم كليهما
    4. 1.4Pruning as an optimization problem with an L0 budgetالـ pruning كمسألة تحسين بميزانية L0
    5. 1.5The brain overprovisions and then prunesالدماغ يبني فائضًا من الوصلات ثم يقلّمها
  2. 02Train, 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-1336 min36 دقيقة
    1. 2.1Train first, then cut the small weights: what one-shot pruning costsدرّب أولاً ثم اقطع الأوزان الصغيرة: ما الذي يكلّفه التقليم دفعة واحدة
    2. 2.2Fine-tuning gives the loss back and reshapes the weightsالضبط الدقيق يستعيد الخسارة ويعيد تشكيل الأوزان
    3. 2.3Iterate: prune a little, retrain, repeatكرّر: قلّم قليلاً، أعد التدريب، ثم أعد الكرّة
    4. 2.4Reading the reduction table: parameters shrink 9x, compute only 3xقراءة جدول التخفيض: المعاملات تصغر 9x والحساب 3x فقط
    5. 2.5Pruning is not only for CNNs: the NeuralTalk LSTM at 10 percent densityالتقليم ليس للشبكات الالتفافية وحدها: LSTM الخاص بـ NeuralTalk عند كثافة 10 بالمئة
    6. 2.6A pruned matrix is only faster when hardware skips the zerosالمصفوفة المقلّمة لا تصبح أسرع إلا إذا كان العتاد يتخطى الأصفار
  3. 03Pruning 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-1818 min18 دقيقة
    1. 3.1Granularity: the shape of what you remove sets flexibility against speedالدقة (granularity): شكل ما تحذفه يوازن المرونة مقابل السرعة
    2. 3.2Four dimensions of a convolution weight, and how to count themالأبعاد الأربعة لوزن الالتفاف وكيف تعدّها
    3. 3.3Five granularities on one tensor, from irregular to regularخمسة مستويات دقة على موتّر واحد، من غير المنتظم إلى المنتظم
  4. 04Fine-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-2530 min30 دقيقة
    1. 4.1Fine-grained pruning: maximum flexibility, minimum hardware friendlinessالتقليم الدقيق: أقصى مرونة، وأدنى ملاءمة للعتاد
    2. 4.2N:M sparsity: a pattern that hardware can count onتناثر N:M: نمط يستطيع العتاد الاعتماد عليه
    3. 4.3Does 2:4 cost accuracy? The evidence across seven tasksهل يكلّف 2:4 شيئًا من الدقة؟ الأدلة عبر سبع مهام
    4. 4.4Channel pruning: direct speedup, smaller compressionتقليم القنوات: تسريع مباشر، وضغط أصغر
    5. 4.5AMC: the proof that per-layer ratios beat one global ratioAMC: الدليل على أن النسب الخاصة بكل طبقة تتفوق على نسبة عامة واحدة
  5. 05Pruning 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-3324 min24 دقيقة
    1. 5.1Which parameter to remove: the less important, the betterأيّ معامل نحذف: كلما قلّت أهميته كان ذلك أفضل
    2. 5.2Element-wise magnitude: importance is the absolute valueالمقدار على مستوى العنصر: الأهمية هي القيمة المطلقة
    3. 5.3Scoring a whole row: L1, L2 and the general Lp norm of a structural setتقييم صف كامل: المعيار L1 وL2 والمعيار العام Lp لمجموعة هيكلية
    4. 5.4Scaling factors: let training say which channel to drop, using batch norm gammaمعاملات التحجيم: دع التدريب يحدد أي قناة تُحذف باستخدام gamma في batch norm
  6. 06Second-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-4336 min36 دقيقة
    1. 6.1Pruning is a perturbation, and Taylor tells you what it costsالتقليم اضطراب في الأوزان، ومفكوك تايلور يخبرك بكلفته
    2. 6.2Optimal Brain Damage: three assumptions leave one half h w squaredOptimal Brain Damage: ثلاثة افتراضات تُبقي نصف h مضروبًا في مربع w
    3. 6.3Removing a neuron is removing a whole row of weightsحذف عصبون يعني حذف صف كامل من الأوزان
    4. 6.4Average Percentage of Zeros: let the data vote on each channelمتوسط نسبة الأصفار (APoZ): دع البيانات تصوّت على كل قناة
    5. 6.5Regression-based pruning: reproduce the layer's output, not the lossالتقليم القائم على الانحدار: أعِد إنتاج مخرجات الطبقة، لا دالة الخسارة
    6. 6.6Where the criteria come from, and what to read nextمن أين جاءت هذه المعايير، وماذا تقرأ بعدها

CGlossary and referenceالمصطلحات والمرجع