Majid Al-RaimiFine-grained, N:M and channel pruning in practiceالتقليم الدقيق وN:M وتقليم القنوات عمليًا

COE 592Lecture 4.1المحاضرة 4.1Part 04الجزء 04

Fine-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 مع صيغته المضغوطة وجدول دقته، وتقليم القنوات مع تناثر غير منتظم لكل طبقة مقابل التصغير المنتظم.

Conceptsالمفاهيم
5
Slidesالشرائح
19-25
Readingمدة القراءة
30 min30 دقيقة
Understoodما فهمته
0/5 conceptsمفاهيم

Why this part mattersلماذا يهمّ هذا الجزء

Your research targets embedded deployment, where the question is never "how many weights can I remove" but "which removal makes this board faster". This part is where the granularity spectrum of part 03 meets real hardware.

It explains why a 9x compressed AlexNet (or a 13x compressed VGG-16) can run no faster on a GPU, why NVIDIA built a 2:4 pattern into its Ampere Tensor Cores, and why the model-compression papers you will cite (AMC, channel pruning) search for per-layer ratios instead of one global number. These are also the three most examinable facts in the lecture: which granularity gives speedup on commodity GPUs and why, what sparsity 2:4 means, and why non-uniform per-layer sparsity beats uniform shrink.

بحثك يستهدف النشر على الأنظمة المدمجة (embedded deployment)، حيث لا يكون السؤال أبدًا «كم وزنًا أستطيع أن أحذف» بل «أي حذف يجعل هذه اللوحة أسرع». هذا الجزء هو المكان الذي يلتقي فيه طيف درجة التقليم (granularity) من الجزء 03 بالعتاد الحقيقي.

يشرح لماذا قد لا يعمل AlexNet المضغوط بمقدار 9x (أو VGG-16 المضغوط بمقدار 13x) أسرع على GPU، ولماذا بنت NVIDIA نمط 2:4 داخل Tensor Cores في معمارية Ampere، ولماذا تبحث أوراق ضغط النماذج التي ستستشهد بها (AMC وتقليم القنوات channel pruning) عن نسب خاصة بكل طبقة بدلًا من رقم عام واحد. وهذه أيضًا أكثر ثلاث حقائق يُتوقع السؤال عنها في الامتحان من هذه المحاضرة: أي درجة تقليم تعطي تسريعًا على وحدات GPU التجارية الشائعة ولماذا، وما معنى تناثر 2:4، ولماذا يتفوق التناثر غير الموحّد لكل طبقة على التصغير الموحّد (uniform shrink).

By the end you canفي نهاية هذا الجزء ستستطيع

  1. Explain why fine-grained pruning gives the largest compression ratio but little or no speedup on GPUs with standard kernels, and name the hardware that can exploit it.تشرح لماذا يعطي التقليم الدقيق (fine-grained pruning) أكبر نسبة ضغط لكنه لا يعطي تسريعًا يُذكر، أو لا يعطي أي تسريع، على وحدات GPU التي تستخدم نوى (kernels) قياسية، وتسمّي العتاد الذي يستطيع الاستفادة منه.
  2. Define N:M sparsity under the NVIDIA convention, compute its sparsity for any N and M, and explain why the slide's wording is ambiguous.تعرّف تناثر N:M (N:M sparsity) وفق اصطلاح NVIDIA، وتحسب نسبة تناثره لأي قيمتين N وM، وتشرح لماذا صياغة الشريحة غامضة.
  3. Derive the 2:4 compressed layout and compute its memory saving for FP16 and INT8 values.تستنتج التخطيط المضغوط لنمط 2:4 وتحسب ما يوفّره من الذاكرة لقيم FP16 ولقيم INT8.
  4. State the pro and con of channel pruning and show how pruning one layer's channels shrinks two layers.تذكر ميزة تقليم القنوات (channel pruning) وعيبه، وتبيّن كيف يؤدي تقليم قنوات طبقة واحدة إلى تصغير طبقتين.
  5. Argue with AMC's measured Pixel 1 numbers why per-layer sparsity ratios beat uniform shrink at equal latency.تستدل بأرقام AMC المقاسة على هاتف Pixel 1 على أن نسب التناثر الخاصة بكل طبقة تتفوق على التصغير الموحّد (uniform shrink) عند زمن استجابة (latency) متساوٍ.

Go back to the very first picture of this lecture: a network before and after pruning, with individual synapses cut out while every neuron stays. That picture is fine-grained pruning, the synapse pruning of slide 4 seen through the lens of granularity. Slides 19 and 20 bring it back only to attach numbers to it, so treat them as a short callback rather than new material.

عُد إلى أول صورة في هذه المحاضرة: شبكة قبل التقليم وبعده، حيث قُطعت مشابك (synapses) منفردة وبقيت كل الخلايا العصبية. تلك الصورة هي fine-grained pruning (التقليم الدقيق)، أي synapse pruning في الشريحة 4 منظورًا إليه من زاوية granularity (درجة التقليم). الشريحتان 19 و20 تعيدانه فقط لتربطا به أرقامًا، فتعامل معهما على أنهما تذكير قصير لا مادة جديدة.

The numbers are the ones from part 02. Han et al. pruned AlexNet from 61 M to 6.7 M parameters and VGG-16 from 138 M to 10.3 M without losing accuracy, a pruning ratio of roughly 89% and 93% (Han, Pool, Tran and Dally, NIPS 2015). Those results are only possible because the method may zero any single weight, wherever it sits in the tensor. The slide calls this "flexible pruning indices": the set of surviving positions is unconstrained, so the algorithm can find redundant weights anywhere and usually reaches the largest compression ratio of all granularities.

الأرقام هي نفسها من الجزء 02. قلّم Han et al. شبكة AlexNet من 61 M إلى 6.7 M معامل، وشبكة VGG-16 من 138 M إلى 10.3 M، دون خسارة في الدقة، أي pruning ratio (نسبة تقليم) تقارب 89% و93% (Han, Pool, Tran and Dally, NIPS 2015). هذه النتائج ممكنة فقط لأن الطريقة يجوز لها تصفير أي وزن منفرد أينما كان موقعه في الموتّر (tensor). تسمي الشريحة ذلك «flexible pruning indices» (فهارس تقليم مرنة): مجموعة المواقع الباقية غير مقيّدة، فتستطيع الخوارزمية أن تجد الأوزان الزائدة في أي مكان، وعادةً تصل إلى أكبر نسبة ضغط بين كل درجات التقليم.

NetworkالشبكةParameters beforeالمعاملات قبلParameters afterالمعاملات بعدReductionالتخفيض
AlexNetAlexNet61 M61 M6.7 M6.7 M9x9x
VGG-16VGG-16138 M138 M10.3 M10.3 M12x (paper: 13x)12x (في الورقة: 13x)
GoogleNetGoogleNet7 M7 M2.0 M2.0 M3.5x3.5x
ResNet-50ResNet-5026 M26 M7.47 M7.47 M3.4x3.4x
Fine-grained pruning results as printed on slide 20, reused from slide 11 (source: Han, PhD thesis, Table 3.1)نتائج التقليم الدقيق كما طُبعت في الشريحة 20، منقولة من الشريحة 11 (المصدر: أطروحة Han للدكتوراه، الجدول 3.1)

Why flexibility is expensive at run timeلماذا تكون المرونة مكلفة وقت التشغيل

Now look at what the flexibility leaves behind. After fine-grained pruning the weight tensor still has its original shape; it is simply riddled with zeros at irregular positions. A dense matrix multiply on a GPU does not know the zeros are there and multiplies them anyway, so the work is unchanged. To skip them you must store the weights in a sparse format such as CSR, CSC or COO, where every surviving value carries an index saying where it belongs. Mishra et al. note that these formats make memory accesses data dependent and that the index metadata can cost up to 200% of the weight storage when the weights are 8-bit (Mishra et al., 2021). Zhou et al. summarize the situation in one line: fine-grained sparsity "can achieve a high compression ratio but is not hardware friendly and hence receives limited speed gains" (Zhou et al., ICLR 2021).

انظر الآن إلى ما تتركه المرونة خلفها. بعد التقليم الدقيق يبقى موتّر الأوزان بشكله الأصلي؛ هو فقط مليء بالأصفار في مواقع غير منتظمة. ضرب المصفوفات الكثيف (dense matrix multiply) على GPU لا يعرف أن الأصفار موجودة فيضربها على أي حال، فيبقى العمل كما هو. لكي تتخطاها يجب أن تخزّن الأوزان في sparse format (صيغة متناثرة) مثل CSR أو CSC أو COO، حيث تحمل كل قيمة باقية فهرسًا يحدد مكانها. يشير Mishra et al. إلى أن هذه الصيغ تجعل الوصول إلى الذاكرة معتمدًا على البيانات، وأن البيانات الوصفية للفهارس قد تكلّف حتى 200% من مساحة تخزين الأوزان عندما تكون الأوزان بدقة 8 بت (Mishra et al., 2021). ويلخص Zhou et al. الوضع في سطر واحد: التناثر الدقيق «يمكن أن يحقق نسبة ضغط عالية لكنه غير ملائم للعتاد، ولذلك لا يحصل إلا على مكاسب محدودة في السرعة» (Zhou et al., ICLR 2021).

Zeros land anywhere in the tile, and every survivor needs an address written next to it. Flexibility buys compression and charges an index per weight.تقع الأصفار في أي مكان داخل البلاطة، وكل وزن باقٍ يحتاج إلى عنوان مكتوب بجانبه. المرونة تشتري الضغط وتفرض في المقابل فهرسًا لكل وزن.

That is why the red line on slide 20 matters more than the table. Speedup from fine-grained sparsity needs hardware built around indices. Han's own EIE accelerator is the example the MIT source deck names: by reading compressed weights and skipping zero activations, it ran fully-connected layers 189x faster than a CPU and 13x faster than a GPU running the uncompressed network (Han et al., ISCA 2016). With sparse kernels the picture depends on batch size: in EIE's own measurements cuSPARSE ran pruned FC layers 4x to 9x faster than dense at batch 1 on a Titan X, but slower at batch 64, which is why the slide says "not GPU (easily)". On an ordinary GPU with dense kernels, the same pruned network runs at roughly dense speed.

لهذا السبب يهم الخط الأحمر في الشريحة 20 أكثر من الجدول. التسريع من sparsity (التناثر) الدقيق يحتاج إلى عتاد مبني حول الفهارس. مسرّع EIE الذي صممه Han نفسه هو المثال الذي تذكره عروض MIT الأصلية: بقراءة الأوزان المضغوطة وتخطي التفعيلات (activations) الصفرية، شغّل الطبقات المتصلة بالكامل (fully-connected) أسرع بمقدار 189x من CPU وأسرع بمقدار 13x من GPU يشغّل الشبكة غير المضغوطة (Han et al., ISCA 2016). مع النوى المتناثرة (sparse kernels) تعتمد الصورة على حجم الدفعة (batch size): في قياسات EIE نفسها شغّلت مكتبة cuSPARSE طبقات FC المقلّمة أسرع من الكثيفة بمقدار 4x إلى 9x عند دفعة حجمها 1 على Titan X، لكنها كانت أبطأ عند دفعة حجمها 64، ولهذا تقول الشريحة «not GPU (easily)» (ليس على GPU بسهولة). على GPU عادي بنوى كثيفة، تعمل الشبكة المقلّمة نفسها بسرعة قريبة من سرعة الشبكة الكثيفة.

EIE on compressed fully-connected layers (Han et al., ISCA 2016)EIE على الطبقات المتصلة بالكامل المضغوطة (Han et al., ISCA 2016)

Speedup over CPUالتسريع مقارنةً بـ CPU
189x189x
Speedup over GPUالتسريع مقارنةً بـ GPU
13x13x
Energy efficiency over GPUكفاءة الطاقة مقارنةً بـ GPU
3400x3400x

Recall

Why does fine-grained pruning usually reach a larger compression ratio than channel pruning, and why does that not translate into GPU speedup?لماذا يصل التقليم الدقيق عادةً إلى نسبة ضغط أكبر من تقليم القنوات، ولماذا لا يتحول ذلك إلى تسريع على GPU؟

It may zero any weight, so it finds redundancy anywhere. But survivors sit at irregular positions, need per-weight indices and data-dependent memory access, and dense GPU kernels cannot skip them. Custom hardware such as EIE can (13x over a GPU running the dense model).
لأنه يجوز له تصفير أي وزن، فيجد الزيادة (redundancy) في أي مكان. لكن الأوزان الباقية تقع في مواقع غير منتظمة، وتحتاج إلى فهرس لكل وزن وإلى وصول للذاكرة معتمد على البيانات، ونوى GPU الكثيفة لا تستطيع تخطيها. العتاد المخصص مثل EIE يستطيع ذلك (13x مقارنةً بـ GPU يشغّل النموذج الكثيف).

Quick checkاختبار سريع

A layer is pruned to 90 percent unstructured sparsity and run on a plain GPU with dense kernels. What happens to latency?قُلّمت طبقة إلى تناثر غير منظّم بنسبة 90 بالمئة وشُغّلت على GPU عادي بنوى كثيفة. ماذا يحدث لزمن الاستجابة؟

Take one row of eight FP16 weights and split it into two groups of four. In each group keep the two largest magnitudes and zero the other two. Every group now has exactly two zeros and two nonzeros, so the row is 50% sparse, and so is every other row treated the same way. That is 2:4 sparsity, the classic case of N:M sparsity and the reason the lecture lists pattern-based pruning as its own step on the granularity spectrum.

خذ صفًا واحدًا من ثمانية أوزان بصيغة FP16 وقسّمه إلى مجموعتين من أربعة. في كل مجموعة احتفظ بأكبر قيمتين من حيث المقدار (magnitude) وصفّر القيمتين الأخريين. أصبحت كل مجموعة تحتوي بالضبط على صفرين وقيمتين غير صفريتين، فيكون الصف متناثرًا بنسبة 50%، وكذلك كل صف آخر يُعامل بالطريقة نفسها. هذا هو 2:4 sparsity، الحالة الكلاسيكية من N:M sparsity، وهو سبب أن المحاضرة تضع pattern-based pruning (التقليم القائم على نمط) خطوةً مستقلة على طيف درجات التقليم.

The general rule needs one careful sentence, because the slide's sentence is ambiguous. In NVIDIA's definition, which is the one hardware implements, an N:M pattern allows at most N nonzero values in every contiguous group of M. The Ampere whitepaper describes 2:4 as a matrix "that allows two non-zero values in every four-entry vector", and Mishra et al. write of "the 2 nonzero values in each group of 4" (NVIDIA, 2020; Mishra et al., 2021). Slide 21 instead says that "N of them is pruned". For 2:4 the two readings agree, since two kept and two pruned are the same thing. For any other pattern they do not.

القاعدة العامة تحتاج إلى جملة دقيقة، لأن جملة الشريحة غامضة. في تعريف NVIDIA، وهو التعريف الذي ينفّذه العتاد، يسمح نمط N:M بـ N قيم غير صفرية على الأكثر في كل مجموعة متجاورة من M. تصف الورقة البيضاء لمعمارية Ampere نمط 2:4 بأنه مصفوفة «تسمح بقيمتين غير صفريتين في كل متجه من أربعة عناصر»، ويكتب Mishra et al. عن «القيمتين غير الصفريتين في كل مجموعة من 4» (NVIDIA, 2020; Mishra et al., 2021). أما الشريحة 21 فتقول إن «N of them is pruned» (يُقلَّم N منها). في نمط 2:4 تتفق القراءتان، لأن الاحتفاظ باثنتين وتقليم اثنتين شيء واحد. أما في أي نمط آخر فلا تتفقان.

s=1−NMs = 1 - \frac{N}{M}
Sparsity of an N:M pattern under the N-nonzero conventionالتناثر (sparsity) لنمط N:M وفق اصطلاح N قيمة غير صفرية

Why a pattern is the middle of the spectrumلماذا يقع النمط في منتصف الطيف

Inside each group of four the pattern is still fine-grained: any two of the four positions may survive, six possible masks, chosen by magnitude. Across the matrix it is rigidly structured: every group holds exactly two values, no more and no fewer. Mishra et al. point out what this buys: because the sparsity is constant across the matrix, "there is no indirection required; a nonzero value's position in memory can be determined from the compression rate directly" (Mishra et al., 2021). The hardware always knows that group g starts at value slot 2g. That is the difference between a lookup and an address calculation, and it is what makes fine-grained-in-the-small, structured-in-the-large worth a place of its own.

داخل كل مجموعة من أربعة يبقى النمط دقيقًا: أي اثنين من المواقع الأربعة يمكن أن يبقيا، أي ستة أقنعة (masks) ممكنة، يُختار منها حسب المقدار. وعلى مستوى المصفوفة كلها هو منظّم بصرامة: كل مجموعة تحمل قيمتين بالضبط، لا أكثر ولا أقل. يوضح Mishra et al. ما يكسبه ذلك: لأن التناثر ثابت عبر المصفوفة، «لا حاجة إلى أي إحالة غير مباشرة (indirection)؛ يمكن تحديد موقع القيمة غير الصفرية في الذاكرة من معدل الضغط مباشرةً» (Mishra et al., 2021). العتاد يعرف دائمًا أن المجموعة g تبدأ عند خانة القيمة 2g. هذا هو الفرق بين البحث في جدول (lookup) وحساب عنوان، وهو ما يجعل النمط «الدقيق على المستوى الصغير، المنظّم على المستوى الكبير» جديرًا بمكان مستقل.

The compressed formatالصيغة المضغوطة

The rule also fixes the storage layout, which is the right-hand panel of slide 21. An R by C dense matrix becomes an R by C/2 block of nonzero values plus an R by C/2 block of 2-bit indices, where each index records the position, 0 to 3, of a kept value inside its group of four. Two bits are enough because a group has only four positions. One corner case keeps the format regular: if a group happens to have three or four zeros after training, two values are stored anyway, padded with zeros as needed (Mishra et al., 2021).

القاعدة تحدد أيضًا تخطيط التخزين، وهو اللوحة اليمنى في الشريحة 21. المصفوفة الكثيفة بحجم R by C تصبح كتلة بحجم R by C/2 من القيم غير الصفرية، مع كتلة بحجم R by C/2 من 2-bit indices (فهارس من بتّين)، حيث يسجّل كل فهرس موقع القيمة المحتفظ بها داخل مجموعتها الرباعية، من 0 إلى 3. البتّان كافيان لأن المجموعة فيها أربعة مواقع فقط. وهناك حالة طرفية واحدة تحفظ انتظام الصيغة: إذا صادف أن مجموعة فيها ثلاثة أصفار أو أربعة بعد التدريب، تُخزَّن قيمتان على أي حال، مع حشوها بأصفار عند الحاجة (Mishra et al., 2021).

Each run of four snaps to two survivors, the survivors slide left into a half-width block, and a 2-bit sidecar records where each came from.كل مجموعة من أربعة تنكمش إلى قيمتين باقيتين، وتنزلق القيمتان إلى اليسار في كتلة بنصف العرض، وسجلٌّ جانبي من بتّين يحفظ من أين جاءت كل قيمة.

Worked exampleمثال محلول

Compressing an 8 by 8 FP16 matrixضغط مصفوفة 8 في 8 بصيغة FP16

  1. Dense storageالتخزين الكثيف

    64 values at 16 bits each: 64 x 16 = 1024 bits.
    64 قيمة، كل منها 16 bits: 64 x 16 = 1024 bits.
  2. Kept valuesالقيم المحتفظ بها

    Half survive, 32 values: 32 x 16 = 512 bits.
    يبقى النصف، أي 32 قيمة: 32 x 16 = 512 bits.
  3. Indicesالفهارس

    One 2-bit position per kept value: 32 x 2 = 64 bits.
    موقع من بتّين لكل قيمة محتفظ بها: 32 x 2 = 64 bits.
  4. Compressed totalالمجموع بعد الضغط

    512 + 64 = 576 bits.
    512 + 64 = 576 bits.
  5. Resultالنتيجة

    1024 / 576 = 1.78x smaller, 43.75% saved. Per group of four the arithmetic is 64 bits versus 36 bits, which is exact for a matrix of any size.
    أصغر بمقدار 1024 / 576 = 1.78x، أي توفير 43.75%. لكل مجموعة من أربعة يكون الحساب 64 bits مقابل 36 bits، وهذا دقيق لمصفوفة بأي حجم.

2:4 storage for FP16 weights, 8 by 8 matrixتخزين 2:4 لأوزان FP16، مصفوفة 8 في 8

Dense FP16FP16 كثيف
1024 bits1024 بت
Kept valuesالقيم المحتفظ بها
512 bits512 بت
2-bit indicesفهارس من بتّين
64 bits64 بت
Compressed totalالإجمالي بعد الضغط
576 bits576 بت
Ratioالنسبة
1.78x1.78x
Index overhead on the kept valuesكلفة الفهارس نسبةً إلى القيم المحتفظ بها
12.5%12.5%

The same matrix with INT8 weightsالمصفوفة نفسها بأوزان INT8

Dense INT8INT8 كثيف
512 bits512 بت
Kept valuesالقيم المحتفظ بها
256 bits256 بت
2-bit indicesفهارس من بتّين
64 bits64 بت
Compressed totalالإجمالي بعد الضغط
320 bits320 بت
Ratioالنسبة
1.6x1.6x
Index overhead on the kept valuesكلفة الفهارس نسبةً إلى القيم المحتفظ بها
25%25%

The two tables carry an insight that matters when you combine pruning with the quantization lectures: the index costs two bits whatever the value width, so the narrower the value type the more the index costs relatively. Mishra et al. give the same figures, about 44% saved for 16-bit and about 38% for 8-bit weights, which is why NVIDIA says the format cuts storage and bandwidth by "almost" 2x rather than exactly 2x (Mishra et al., 2021; NVIDIA, 2020).

يحمل الجدولان فكرة مهمة عندما تجمع التقليم مع محاضرات التكميم (quantization): الفهرس يكلّف بتّين مهما كان عرض القيمة، فكلما ضاق نوع القيمة زادت كلفة الفهرس نسبيًا. يعطي Mishra et al. الأرقام نفسها، توفير نحو 44% للأوزان بدقة 16 بت ونحو 38% للأوزان بدقة 8 بت، ولهذا تقول NVIDIA إن الصيغة تخفض التخزين وعرض النطاق (bandwidth) «تقريبًا» بمقدار 2x وليس 2x بالضبط (Mishra et al., 2021; NVIDIA, 2020).

Where the 2x speedup comes fromمن أين يأتي تسريع 2x

Storage is only half of the payoff. The Ampere A100 added Sparse Tensor Core instructions that take a 2:4 compressed operand and, in the whitepaper's words, "skip the compute on entries that have zero values, resulting in a doubling of the Tensor Core compute throughput": a 16 x 8 x 16 matrix multiply instruction completes in half the cycles of its dense counterpart (NVIDIA, 2020). Software reaches it through TensorRT 8 and cuSPARSELt; the slide's link covers the TensorRT 8.0 path. Zhou et al. restate the same about 2x for the A100, citing NVIDIA rather than measuring it themselves (Zhou et al., ICLR 2021).

التخزين نصف المكسب فقط. أضافت Ampere A100 تعليمات Sparse Tensor Core التي تأخذ مُعامَلًا (operand) مضغوطًا بنمط 2:4، وبتعبير الورقة البيضاء «تتخطى الحساب على المدخلات ذات القيم الصفرية، مما يؤدي إلى مضاعفة إنتاجية الحساب في Tensor Core»: تعليمة ضرب مصفوفات بحجم 16 x 8 x 16 تكتمل في نصف عدد الدورات التي تحتاجها نظيرتها الكثيفة (NVIDIA, 2020). تصل البرمجيات إليها عبر TensorRT 8 وcuSPARSELt؛ ورابط الشريحة يغطي مسار TensorRT 8.0. ويعيد Zhou et al. ذكر الرقم نفسه، نحو 2x على A100، نقلًا عن NVIDIA لا بقياس خاص بهم (Zhou et al., ICLR 2021).

Try the pattern yourself below. Switch the convention from "N nonzero" to "N pruned" at 2:4 and nothing changes; switch it at 1:4 and the sparsity flips from 75% to 25%, which is exactly the ambiguity flagged above. Then toggle FP16 to INT8 and watch the index overhead double.

جرّب النمط بنفسك في الأسفل. غيّر الاصطلاح من «N nonzero» إلى «N pruned» عند 2:4 ولن يتغير شيء؛ غيّره عند 1:4 وسينقلب التناثر من 75% إلى 25%، وهذا بالضبط الغموض المشار إليه أعلاه. ثم بدّل من FP16 إلى INT8 وراقب كلفة الفهرس الإضافية وهي تتضاعف.

SimulatorمحاكيN:M pruner: keep the largest magnitudes in every groupمقلّم N:M: احتفظ بأكبر المقادير في كل مجموعة
-0.380.180.130.72
0.08-0.37-0.790.78
-0.13-0.220.30-0.58
0.590.260.610.06
kept values (2 per group)
-0.380.72
-0.790.78
0.30-0.58
0.590.61
position indices
0011
1011
1011
0010
Sparsityالتناثر (sparsity)50.0%8 of 16 zero1 - 2/4
Index widthعرض الفهرس2bitslog2(4) per kept valuelog2(4) لكل قيمة محتفظ بها
Per groupلكل مجموعة36of 64 bits32 value + 4 index
Compressionنسبة الضغط1.78x43.8% savedindex overhead 12.5%
Scaled to an 8 × 8 matrix (16 groups): dense 1024 bits, compressed 576 bits, ratio 1.78x. The ratio never depends on matrix size, only on M, N and the value width.عند التوسيع إلى مصفوفة 8 × 8 (16 مجموعة): الكثيفة 1024 bits، والمضغوطة 576 bits، والنسبة 1.78x. لا تعتمد النسبة أبدًا على حجم المصفوفة، بل على M وN وعرض القيمة فقط.

Recall

Define 2:4 sparsity, give its sparsity percentage, and state the storage layout.عرّف تناثر 2:4، واذكر نسبة تناثره، وصِف تخطيط تخزينه.

Two nonzeros in every contiguous four (two zeros), so 50%. Stored as half the values plus a 2-bit index per kept value: 36 bits per group of four FP16 weights instead of 64, about 1.78x.
قيمتان غير صفريتين في كل أربع متجاورة (وصفران)، أي 50%. يُخزَّن على شكل نصف القيم مع فهرس من بتّين لكل قيمة محتفظ بها: 36 bits لكل مجموعة من أربعة أوزان FP16 بدلًا من 64، أي نحو 1.78x.

Recall

Under the NVIDIA convention, what is the sparsity of 1:4 and of 4:8?وفق اصطلاح NVIDIA، ما نسبة تناثر 1:4، وما نسبة تناثر 4:8؟

1:4 keeps one of four, so 75% sparsity. 4:8 keeps four of eight, so 50%.
1:4 يُبقي واحدة من أربع، أي تناثر 75%. و4:8 يُبقي أربعًا من ثمانٍ، أي 50%.

Quick checkاختبار سريع

A weight matrix satisfies the 2:4 pattern. What fraction of its weights is zero?مصفوفة أوزان تحقق نمط 2:4. ما نسبة أوزانها التي تساوي صفرًا؟

Quick checkاختبار سريع

Using NVIDIA's convention, how many weights in every group of four are zero under a 1:4 pattern?وفق اصطلاح NVIDIA، كم وزنًا في كل مجموعة من أربعة يساوي صفرًا في نمط 1:4؟

A format that halves storage and doubles matmul throughput is worth nothing if the network gets worse. So look at one row first: ResNet-50 on ImageNet scores 76.1% top-1 dense in FP16 and 76.2% after 2:4 pruning. Half the weights are gone and the accuracy is unchanged; the extra 0.1 is run-to-run noise, not a gain.

صيغة تخفض التخزين إلى النصف وتضاعف إنتاجية ضرب المصفوفات لا قيمة لها إذا ساءت الشبكة. لذلك انظر إلى صف واحد أولًا: ResNet-50 على ImageNet يحقق 76.1% في top-1 وهو كثيف بصيغة FP16، و76.2% بعد تقليم 2:4. ذهب نصف الأوزان وبقيت الدقة كما هي؛ والزيادة 0.1 مجرد ضجيج بين تشغيل وآخر، لا مكسب حقيقي.

The rule that produced that row is NVIDIA's three-step recipe. Train the dense network as usual. Prune it to 2:4 by keeping the two largest magnitudes in every group of four, which fixes the mask. Then retrain with the mask held fixed, using the original schedule and hyperparameters, so the survivors absorb the job of the pruned weights. That last step is the fine-tuning loop of part 02 applied under a structural constraint, and the whitepaper reports "virtually no loss in inferencing accuracy" across dozens of networks with it (NVIDIA, 2020). The choice of mask by magnitude inside each group previews the magnitude criterion of part 05.

القاعدة التي أنتجت ذلك الصف هي وصفة NVIDIA ذات الخطوات الثلاث. درّب الشبكة الكثيفة كالمعتاد. ثم قلّمها إلى 2:4 بالاحتفاظ بأكبر قيمتين من حيث المقدار في كل مجموعة من أربعة، وهذا يثبّت mask (القناع). ثم أعد التدريب مع إبقاء القناع ثابتًا، باستخدام الجدول الزمني والمعاملات الفائقة (hyperparameters) الأصلية، لكي تتولى الأوزان الباقية مهمة الأوزان المقلّمة. هذه الخطوة الأخيرة هي حلقة fine-tuning (الضبط الدقيق) من الجزء 02 مطبّقةً تحت قيد بنيوي، وتذكر الورقة البيضاء «عدم وجود خسارة تُذكر تقريبًا في دقة الاستدلال» عبر عشرات الشبكات باستخدامها (NVIDIA, 2020). واختيار القناع حسب المقدار داخل كل مجموعة يمهّد لمعيار المقدار (magnitude criterion) في الجزء 05.

NetworkالشبكةData setمجموعة البياناتMetricالمقياسDense FP16FP16 كثيفSparse FP16FP16 متناثرChangeالتغيّر
ResNet-50ResNet-50ImageNetImageNetTop-1Top-176.176.176.276.2+0.1+0.1
ResNeXt-101_32x8dResNeXt-101_32x8dImageNetImageNetTop-1Top-179.379.379.379.30.00.0
XceptionXceptionImageNetImageNetTop-1Top-179.279.279.279.20.00.0
SSD-RN50SSD-RN50COCO 2017COCO 2017bbAPbbAP24.824.824.824.80.00.0
MaskRCNN-RN50MaskRCNN-RN50COCO 2017COCO 2017bbAPbbAP37.937.937.937.90.00.0
FairSeq TransformerFairSeq TransformerEN-DE WMT'14EN-DE WMT'14BLEUBLEU28.228.228.528.5+0.3+0.3
BERT-LargeBERT-LargeSQuAD v1.1SQuAD v1.1F1F191.991.991.991.90.00.0
Dense versus 2:4 sparse FP16 accuracy after NVIDIA's train, prune, retrain recipe (NVIDIA Developer Blog)دقة FP16 الكثيفة مقابل FP16 المتناثرة بنمط 2:4 بعد وصفة NVIDIA (درّب، ثم قلّم، ثم أعد التدريب) (مدونة NVIDIA للمطورين)

Read the table across, never down. The seven rows use four different metrics (top-1 accuracy, box AP, BLEU and F1), so the only meaningful comparison is dense versus sparse within one row. Read that way the evidence is unusually broad: image classification, object detection, instance segmentation, translation and question answering, spanning convolutional networks and Transformers, and not one row lost measurable accuracy. The whitepaper's explanation is that after training "only a subset of weights have acquired a meaningful purpose", and the retraining step lets the network re-adapt around the fixed mask (NVIDIA, 2020).

اقرأ الجدول أفقيًا، ولا تقرأه عموديًا أبدًا. الصفوف السبعة تستخدم أربعة مقاييس مختلفة (دقة top-1، وbox AP، وBLEU، وF1)، فالمقارنة الوحيدة ذات المعنى هي الكثيف مقابل المتناثر داخل الصف الواحد. وبهذه القراءة تكون الأدلة واسعة على نحو غير معتاد: تصنيف الصور، واكتشاف الأجسام، وتجزئة المثيلات (instance segmentation)، والترجمة، والإجابة عن الأسئلة، وتشمل الشبكات الالتفافية وTransformers، ولم يخسر صف واحد دقة قابلة للقياس. وتفسير الورقة البيضاء هو أنه بعد التدريب «لا تكتسب إلا مجموعة جزئية من الأوزان غرضًا ذا معنى»، وخطوة إعادة التدريب تسمح للشبكة بأن تتكيف من جديد حول القناع الثابت (NVIDIA, 2020).

Recall

Name the three steps of NVIDIA's 2:4 recipe and give one row of evidence that it holds accuracy.سمِّ الخطوات الثلاث في وصفة 2:4 من NVIDIA، وأعطِ صفًا واحدًا من الأدلة على أنها تحافظ على الدقة.

Train dense, prune each group of four to its two largest magnitudes, retrain with the original schedule and the mask fixed. Evidence: BERT-Large on SQuAD v1.1 scores 91.9 F1 both dense and sparse; ResNet-50 goes from 76.1% to 76.2% top-1.
درّب الشبكة كثيفةً، ثم قلّم كل مجموعة من أربعة إلى أكبر قيمتين فيها من حيث المقدار، ثم أعد التدريب بالجدول الزمني الأصلي مع تثبيت القناع. الدليل: BERT-Large على SQuAD v1.1 يحقق 91.9 في F1 كثيفًا ومتناثرًا معًا؛ وResNet-50 ينتقل من 76.1% إلى 76.2% في top-1.

Now the coarse end of the spectrum. A convolution layer with 64 output channels is pruned at sparsity 0.5: thirty-two whole filters are deleted and the layer becomes a 32-channel layer. Nothing about the result is sparse. Its weight tensor, in the [c_o, c_i, k_h, k_w] layout of part 03, is simply smaller in the c_o dimension, and the next layer, which consumed those channels, is smaller in its c_i dimension.

الآن الطرف الخشن من الطيف. طبقة التفاف (convolution) لها 64 قناة خرج تُقلَّم بنسبة تناثر 0.5: تُحذف اثنان وثلاثون مرشّحًا (filter) كاملًا وتصبح الطبقة بـ 32 قناة. لا شيء في النتيجة متناثر. موتّر أوزانها، بالتخطيط [c_o, c_i, k_h, k_w] من الجزء 03، صار ببساطة أصغر في البعد c_o، والطبقة التالية التي كانت تستهلك تلك القنوات صارت أصغر في بعدها c_i.

That is the whole argument for channel pruning, and both sides of the slide's trade-off follow from it. Pro: direct speedup on any hardware, because a network with fewer channels does less work in every dense library that exists. Li et al. put it precisely: removing whole filters "does not result in sparse connectivity patterns", so it "does not need the support of sparse convolution libraries and can work with existing efficient BLAS libraries" (Li et al., ICLR 2017). He, Zhang and Sun report a 5x speedup on VGG-16 for a 0.3% increase in error and 2x on ResNet for 1.4% (He, Zhang and Sun, ICCV 2017). Con: a smaller compression ratio, because a channel is a much coarser unit than a weight. Keeping a channel means keeping all of its weights, including the weak ones that fine-grained pruning would have dropped, so you cannot reach the 9x to 13x of slide 20.

هذه هي الحجة الكاملة لصالح channel pruning (تقليم القنوات)، ومنها ينتج طرفا المقايضة في الشريحة. الميزة: تسريع مباشر على أي عتاد، لأن الشبكة ذات القنوات الأقل تؤدي عملًا أقل في كل مكتبة كثيفة موجودة. يعبّر Li et al. عن ذلك بدقة: إزالة مرشّحات كاملة (removing whole filters) «لا تؤدي إلى أنماط اتصال متناثرة»، ولذلك «لا تحتاج إلى دعم مكتبات الالتفاف المتناثر ويمكنها العمل مع مكتبات BLAS الفعالة الموجودة» (Li et al., ICLR 2017). ويذكر He, Zhang and Sun تسريعًا بمقدار 5x على VGG-16 مقابل زيادة في الخطأ قدرها 0.3%، و2x على ResNet مقابل 1.4% (He, Zhang and Sun, ICCV 2017). العيب: نسبة ضغط أصغر، لأن القناة وحدة أخشن بكثير من الوزن. الاحتفاظ بقناة يعني الاحتفاظ بكل أوزانها، بما فيها الأوزان الضعيفة التي كان التقليم الدقيق سيُسقطها، لذلك لا تستطيع الوصول إلى 9x حتى 13x كما في الشريحة 20.

Pruning one layer shrinks twoتقليم طبقة واحدة يصغّر طبقتين

The example above hid a compounding effect that the slide's bar chart depends on. Pruning the output channels of layer l removes rows from its own weight tensor and columns from layer l+1, because the input channels of l+1 are the output channels of l. The per-layer sparsity values on slide 24 therefore do not add up the way they look; they multiply through the chain.

أخفى المثال السابق أثرًا تراكميًا يعتمد عليه المخطط الشريطي في الشريحة. تقليم قنوات الخرج في الطبقة l يزيل صفوفًا من موتّر أوزانها هي وأعمدةً من الطبقة l+1، لأن قنوات الدخل في l+1 هي قنوات الخرج من l. لذلك فإن قيم sparsity (التناثر) لكل طبقة في الشريحة 24 لا تُجمع كما تبدو؛ بل تتضاعف بعضها في بعض عبر السلسلة.

Worked exampleمثال محلول

Five conv layers, uniform 0.3 versus the slide's per-layer sparsitiesخمس طبقات التفاف: تناثر موحّد 0.3 مقابل نسب التناثر الخاصة بكل طبقة في الشريحة

  1. Set the baselineحدّد خط الأساس

    Five stacked 3 x 3 layers, each 64 in and 64 out: 64 x 64 x 9 = 36,864 weights each, 184,320 in total. Layer 0's inputs come from the stem, which is not pruned, so its input columns are never removed.
    خمس طبقات 3 x 3 متراصّة، لكل منها 64 قناة دخل و64 قناة خرج: 64 x 64 x 9 = 36,864 وزنًا لكل طبقة، و184,320 في المجموع. مدخلات الطبقة 0 تأتي من الجذع (stem) غير المقلّم، فلا تُزال أعمدة دخلها أبدًا.
  2. Write the kept fraction of one layerاكتب النسبة المحتفظ بها لطبقة واحدة

    Layer l keeps (1 - s_(l-1)) x (1 - s_l) of its weights: its input columns follow the previous layer's output sparsity, its output rows follow its own.
    الطبقة l تحتفظ بـ (1 - s_(l-1)) x (1 - s_l) من أوزانها: أعمدة دخلها تتبع تناثر خرج الطبقة السابقة، وصفوف خرجها تتبع تناثرها هي.
  3. Uniform shrink, s = 0.3 everywhereتصغير موحّد، s = 0.3 في كل مكان

    Layer 0 keeps 0.70, every later layer keeps 0.7 x 0.7 = 0.49.
    الطبقة 0 تحتفظ بـ 0.70، وكل طبقة بعدها تحتفظ بـ 0.7 x 0.7 = 0.49.
  4. Per-layer sparsities 0.5, 0.3, 0.7, 0.2, 0.3نسب تناثر لكل طبقة: 0.5، 0.3، 0.7، 0.2، 0.3

    Layer 0 keeps 0.50, then 0.35, 0.21, 0.24, 0.56.
    الطبقة 0 تحتفظ بـ 0.50، ثم 0.35، و0.21، و0.24، و0.56.
  5. Resultالنتيجة

    Uniform shrink at 0.3 keeps 53.2% of the weights, uniform shrink at the per-layer set's mean of 0.4 keeps 40.8%, and the slide's per-layer set keeps 37.2%. Conv MACs scale with c_i x c_o, so the same fractions apply to compute.
    Uniform shrink (التصغير الموحّد) عند 0.3 يحتفظ بـ 53.2% من الأوزان، والتصغير الموحّد عند متوسط المجموعة الخاصة بكل طبقة وهو 0.4 يحتفظ بـ 40.8%، والمجموعة الخاصة بكل طبقة في الشريحة تحتفظ بـ 37.2%. عدد MACs في الالتفاف يتناسب مع c_i x c_o، فتنطبق النسب نفسها على الحساب.
LayerالطبقةUniform 0.3 keptالمحتفظ به عند 0.3 موحّدةUniform 0.4 keptالمحتفظ به عند 0.4 موحّدةPer-layer keptالمحتفظ به بنسب لكل طبقة
Layer 0الطبقة 01.0 x 0.7 = 0.701.0 x 0.7 = 0.701.0 x 0.6 = 0.601.0 x 0.6 = 0.601.0 x 0.5 = 0.501.0 x 0.5 = 0.50
Layer 1الطبقة 10.7 x 0.7 = 0.490.7 x 0.7 = 0.490.6 x 0.6 = 0.360.6 x 0.6 = 0.360.5 x 0.7 = 0.350.5 x 0.7 = 0.35
Layer 2الطبقة 20.7 x 0.7 = 0.490.7 x 0.7 = 0.490.6 x 0.6 = 0.360.6 x 0.6 = 0.360.7 x 0.3 = 0.210.7 x 0.3 = 0.21
Layer 3الطبقة 30.7 x 0.7 = 0.490.7 x 0.7 = 0.490.6 x 0.6 = 0.360.6 x 0.6 = 0.360.3 x 0.8 = 0.240.3 x 0.8 = 0.24
Layer 4الطبقة 40.7 x 0.7 = 0.490.7 x 0.7 = 0.490.6 x 0.6 = 0.360.6 x 0.6 = 0.360.8 x 0.7 = 0.560.8 x 0.7 = 0.56
Total keptإجمالي المحتفظ به2.66 / 5 = 53.2%2.66 / 5 = 53.2%2.04 / 5 = 40.8%2.04 / 5 = 40.8%1.86 / 5 = 37.2%1.86 / 5 = 37.2%
Kept fraction per layer, (1 - input sparsity) x (1 - output sparsity)النسبة المحتفظ بها في كل طبقة، (1 - تناثر المدخلات) x (1 - تناثر المخرجات)
Five layers shrink by their own ratio while the dashed line marks the uniform 0.3 cut. Layers 0 and 2 go far past it, layer 3 stops well short.خمس طبقات تنكمش كل منها بنسبتها الخاصة، بينما يحدد الخط المتقطع القطع الموحّد عند 0.3. الطبقتان 0 و2 تتجاوزانه بكثير، والطبقة 3 تتوقف قبله بمسافة واضحة.

Uniform shrink versus channel pruneالتصغير الموحّد مقابل تقليم القنوات

The inequality on slide 24, "Uniform Shrink < Channel Prune", compares accuracy at a comparable budget. Uniform shrink applies one ratio to every layer, which is what a MobileNet width multiplier does. It ignores the fact that layers differ in how much redundancy they carry: some tolerate 70% removal and others only 20%. Channel pruning proper starts from the trained wide network, chooses a ratio per layer, deletes the least useful channels in each, and fine-tunes. Under the same latency or MAC budget, spending the cuts where they hurt least keeps more accuracy. Slide 24 defers the obvious question, how to find those ratios; the sensitivity analysis of lecture 04-2 (Pruning ratios, fine-tuning and sparse hardware) and the AMC search of the next concept are the answers.

المتباينة في الشريحة 24، «Uniform Shrink < Channel Prune»، تقارن الدقة عند ميزانية متقاربة. التصغير الموحّد يطبّق نسبة واحدة على كل طبقة، وهذا ما يفعله مُضاعِف العرض (width multiplier) في MobileNet. وهو يتجاهل أن الطبقات تختلف في مقدار الزيادة التي تحملها: بعضها يتحمل إزالة 70% وبعضها 20% فقط. أما تقليم القنوات بمعناه الصحيح فيبدأ من الشبكة العريضة المدرّبة، ويختار نسبة لكل طبقة، ويحذف أقل القنوات فائدة في كل منها، ثم يضبطها ضبطًا دقيقًا. تحت ميزانية زمن استجابة أو MACs نفسها، يحافظ توزيع القطع حيث يضر أقل على دقة أكبر. تؤجل الشريحة 24 السؤال البديهي، وهو كيف نجد تلك النسب؛ والجواب هو تحليل الحساسية في المحاضرة 04-2 (Pruning ratios, fine-tuning and sparse hardware) وبحث AMC في المفهوم التالي.

Recall

State the pro and con of channel pruning in one sentence each.اذكر ميزة تقليم القنوات وعيبه، في جملة واحدة لكل منهما.

Pro: direct speedup on any hardware, because the pruned network simply has fewer channels and runs with dense kernels. Con: smaller compression ratio, because a whole channel is a coarse unit and its weak weights survive with it.
الميزة: تسريع مباشر على أي عتاد، لأن الشبكة المقلّمة ببساطة فيها قنوات أقل وتعمل بنوى كثيفة. العيب: نسبة ضغط أصغر، لأن القناة الكاملة وحدة خشنة وأوزانها الضعيفة تبقى معها.

Quick checkاختبار سريع

Which granularity speeds up inference on any GPU that has only dense BLAS libraries?أي درجة تقليم تسرّع الاستدلال على أي GPU لا يملك إلا مكتبات BLAS كثيفة؟

On a Google Pixel 1, the full-width MobileNet takes 123.3 ms per image and scores 70.6% ImageNet top-1. Shrinking it uniformly with the 0.75 width multiplier brings the latency down to 72.3 ms but the accuracy down to 68.4%. The channel-pruned model found by AMC runs in 68.3 ms at 70.5%: as fast as the shrunken model, 2.1 points more accurate, and only 0.1 below the full model at 1.81x its speed (He et al., ECCV 2018).

على هاتف Google Pixel 1، يستغرق MobileNet بكامل عرضه 123.3 ms لكل صورة ويحقق 70.6% في ImageNet top-1. تصغيره تصغيرًا موحّدًا (uniform shrink) بمضاعف العرض 0.75 يخفض زمن الاستجابة إلى 72.3 ms لكنه يخفض الدقة إلى 68.4%. أما النموذج المقلّم القنوات (channel-pruned) الذي وجده AMC فيعمل في 68.3 ms بدقة 70.5%: بسرعة النموذج المصغّر نفسها، وأدق منه بـ 2.1 نقطة، وأقل من النموذج الكامل بـ 0.1 فقط مع سرعة تبلغ 1.81x من سرعته (He et al., ECCV 2018).

AMC (AutoML for Model Compression) is the method behind the red curve on slide 25. It treats the per-layer sparsity ratios as actions for a reinforcement-learning agent, which walks the network layer by layer, proposes a ratio for each, and is rewarded by the accuracy the pruned model reaches under a FLOPs or latency constraint. The pruned model is then fine-tuned. The baseline is the easiest thing one could do instead, which the paper states plainly: "the easiest way to reduce the channels of a model is to use uniform channel shrinkage, i.e. use a width multiplier", and the result is that AMC "consistently outperforms the uniform baselines" (He et al., ECCV 2018).

AMC (AutoML for Model Compression) هي الطريقة وراء المنحنى الأحمر في الشريحة 25. تعامل نسب التناثر لكل طبقة على أنها أفعال (actions) لوكيل تعلم معزّز (reinforcement learning) يمر على الشبكة طبقةً طبقة، ويقترح نسبة لكل منها، ويُكافأ بالدقة التي يبلغها النموذج المقلّم تحت قيد على FLOPs أو على زمن الاستجابة. ثم يُضبط النموذج المقلّم ضبطًا دقيقًا. خط الأساس هو أسهل ما يمكن فعله بدلًا من ذلك، والورقة تقوله صراحةً: «أسهل طريقة لتقليل قنوات نموذج هي استخدام تصغير قنوات موحّد، أي استخدام مضاعف عرض»، والنتيجة أن AMC «يتفوق باستمرار على خطوط الأساس الموحّدة» (He et al., ECCV 2018).

ModelالنموذجMMACsMMACsTop-1Top-1Pixel 1 latencyزمن الاستجابة على Pixel 1Speedupالتسريع
MobileNet 1.0 (full width)MobileNet 1.0 (العرض الكامل)56956970.6%70.6%123.3 ms123.3 ms1.00x1.00x
MobileNet 0.75 (uniform shrink)MobileNet 0.75 (تصغير موحّد)32532568.4%68.4%72.3 ms72.3 ms1.7x1.7x
AMC, 50% FLOPs budgetAMC، ميزانية 50% من FLOPs28528570.5%70.5%68.3 ms68.3 ms1.81x1.81x
AMC, 50% latency budgetAMC، ميزانية 50% من زمن الاستجابة27227270.2%70.2%63.3 ms63.3 ms1.95x1.95x
MobileNet on ImageNet, latency measured on a Google Pixel 1 with TensorFlow Lite (AMC, Table 4; the 0.75 row's 1.7x is computed here as 123.3 / 72.3)MobileNet على ImageNet، مع زمن استجابة مقاس على هاتف Google Pixel 1 باستخدام TensorFlow Lite (AMC، الجدول 4؛ قيمة 1.7x في صف 0.75 محسوبة هنا على أنها 123.3 / 72.3)
AMC's curve sits above and left of the uniform width-multiplier line. At about 68 ms the vertical gap is roughly two points of ImageNet accuracy.منحنى AMC يقع فوق خط مضاعف العرض الموحّد وإلى يساره. عند نحو 68 ms تبلغ الفجوة الرأسية قرابة نقطتين من دقة ImageNet.

The chart on the slide is AMC's Figure 5b. The four table rows above are exact; the remaining points in the table below are read off the figure and are approximate. Either way the shape is the same. At equal latency the searched ratios are about 1.5 to 2 points better. At similar accuracy they are much faster: the 50% latency-budget model keeps 70.2% at 63.3 ms, 1.95x faster than the 123.3 ms full model at 70.6%, only 0.4 points higher.

المخطط في الشريحة هو الشكل 5b من ورقة AMC. صفوف الجدول الأربعة أعلاه دقيقة؛ أما النقاط الباقية في الجدول أدناه فمقروءة من الشكل وتقريبية. وفي الحالتين الشكل العام واحد. عند زمن استجابة متساوٍ تكون النسب المبحوث عنها أفضل بنحو 1.5 إلى 2 نقطة. وعند دقة متقاربة تكون أسرع بكثير: النموذج ذو ميزانية زمن الاستجابة 50% يحافظ على 70.2% عند 63.3 ms، أي أسرع بمقدار 1.95x من النموذج الكامل البالغ 123.3 ms بدقة 70.6%، الذي يزيد عليه بـ 0.4 نقطة فقط.

CurveالمنحنىLatencyزمن الاستجابةTop-1Top-1
Uniformموحّدabout 52 msنحو 52 msabout 67.5%نحو 67.5%
Uniformموحّدabout 90 msنحو 90 msabout 69.1%نحو 69.1%
AMCAMCabout 52 msنحو 52 msabout 69.2%نحو 69.2%
Approximate points read off AMC Figure 5b (slide 25)نقاط تقريبية مقروءة من الشكل 5b في ورقة AMC (الشريحة 25)

Choosing a granularity for a real boardاختيار درجة التقليم للوحة حقيقية

This is where the part comes together for your project. The granularity you pick is a hardware decision, not a compression decision:

هنا يجتمع هذا الجزء في خدمة مشروعك. درجة التقليم التي تختارها قرار يتعلق بالعتاد، لا قرار يتعلق بالضغط:

  • Target is an Ampere-class or newer NVIDIA GPU (a Jetson Orin, an A100): prune to 2:4. Half the weights, about 2x on the matmuls, accuracy held by retraining.إذا كان الهدف GPU من NVIDIA من فئة Ampere أو أحدث (Jetson Orin، أو A100): قلّم إلى 2:4. نصف الأوزان، ونحو 2x في ضرب المصفوفات، والدقة محفوظة بإعادة التدريب.
  • Target is a phone CPU, a microcontroller or an NPU with dense kernels only: channel pruning with searched per-layer ratios, AMC style. A smaller dense network is the safest choice, since it needs no special kernels. Some mobile runtimes (XNNPACK) do accelerate high unstructured sparsity in 1x1 convolutions, so check what your runtime supports.إذا كان الهدف CPU هاتف، أو متحكمًا دقيقًا (microcontroller)، أو NPU بنوى كثيفة فقط: تقليم القنوات بنسب لكل طبقة مبحوث عنها على طريقة AMC. الشبكة الكثيفة الأصغر هي الخيار الأكثر أمانًا، لأنها لا تحتاج إلى نوى خاصة. بعض بيئات التشغيل على الهواتف (XNNPACK) تسرّع فعلًا التناثر غير المنظّم العالي في الالتفافات 1x1، فتحقق مما تدعمه بيئة التشغيل لديك.
  • Target has a sparse accelerator such as EIE, or the constraint is storage and not latency: fine-grained pruning, for the largest compression ratio.إذا كان الهدف فيه مسرّع متناثر مثل EIE، أو كان القيد هو التخزين لا زمن الاستجابة: التقليم الدقيق، للحصول على أكبر نسبة ضغط.

Quick checkاختبار سريع

Why does channel pruning with per-layer sparsities beat a uniform width multiplier at the same latency?لماذا يتفوق تقليم القنوات بنسب تناثر خاصة بكل طبقة على مضاعف العرض الموحّد عند زمن الاستجابة نفسه؟

Recall

Give the AMC versus uniform numbers that show per-layer ratios beat uniform shrink.أعطِ أرقام AMC مقابل التصغير الموحّد التي تبيّن أن النسب الخاصة بكل طبقة تتفوق على التصغير الموحّد.

On a Pixel 1, the 0.75 MobileNet gives 68.4% at 72.3 ms. AMC gives 70.5% at 68.3 ms and 70.2% at 63.3 ms, the latter 1.95x faster than the 123.3 ms full model at 70.6%.
على Pixel 1، يعطي MobileNet بعرض 0.75 دقة 68.4% عند 72.3 ms. ويعطي AMC دقة 70.5% عند 68.3 ms، و70.2% عند 63.3 ms، والأخير أسرع بمقدار 1.95x من النموذج الكامل البالغ 123.3 ms بدقة 70.6%.

Recapالخلاصة

If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا

  • Fine-grained pruning may zero any weight, so it compresses most (AlexNet 9x, VGG-16 13x) but needs a per-weight index; only custom hardware such as EIE turns that into speed.التقليم الدقيق يجوز له تصفير أي وزن، لذلك يحقق أكبر ضغط (AlexNet بمقدار 9x، وVGG-16 بمقدار 13x) لكنه يحتاج فهرسًا لكل وزن؛ ولا يحوّل ذلك إلى سرعة إلا عتاد مخصص مثل EIE.
  • N:M sparsity keeps at most N nonzeros in every contiguous M weights; 2:4 is 50 percent sparse under either reading, but 1:4 is 75 percent (NVIDIA) versus 25 percent (slide wording).تناثر N:M يُبقي N قيمًا غير صفرية على الأكثر في كل M أوزان متجاورة؛ نمط 2:4 تناثره 50 بالمئة بأي القراءتين، أما 1:4 فتناثره 75 بالمئة (اصطلاح NVIDIA) مقابل 25 بالمئة (صياغة الشريحة).
  • A 2:4 matrix stores half its values plus 2-bit indices: 36 bits per four FP16 weights instead of 64, about 1.78x, and Ampere Sparse Tensor Cores skip the zeros for about 2x math throughput.مصفوفة 2:4 تخزّن نصف قيمها مع فهارس من بتّين: 36 بت لكل أربعة أوزان FP16 بدلًا من 64، أي نحو 1.78x، وتتخطى Sparse Tensor Cores في معمارية Ampere الأصفار فتعطي نحو 2x في إنتاجية العمليات الحسابية.
  • NVIDIA's train, prune to 2:4, retrain recipe held accuracy on all seven slide-22 tasks (ResNet-50 76.1 to 76.2, BERT-Large 91.9 to 91.9).وصفة NVIDIA (درّب، ثم قلّم إلى 2:4، ثم أعد التدريب) حافظت على الدقة في المهام السبع كلها في الشريحة 22 (ResNet-50 من 76.1 إلى 76.2، وBERT-Large من 91.9 إلى 91.9).
  • Channel pruning removes whole channels, so the result is a smaller dense network with direct speedup on any hardware, at the cost of a smaller compression ratio.تقليم القنوات يزيل قنوات كاملة، فتكون النتيجة شبكة كثيفة (dense) أصغر تعطي تسريعًا مباشرًا على أي عتاد، على حساب نسبة ضغط أصغر.
  • Pruning layer l's output channels also shrinks layer l+1's inputs, so per-layer channel sparsities compound in parameters and MACs.تقليم قنوات الخرج في الطبقة l يصغّر أيضًا مدخلات الطبقة l+1، لذلك تتضاعف نسب تناثر القنوات لكل طبقة بعضها في بعض في عدد المعاملات وفي عدد MACs.
  • Uniform shrink applies one ratio everywhere; AMC's searched per-layer ratios give 70.5 percent at 68.3 ms versus 68.4 percent at 72.3 ms for the 0.75 width MobileNet on a Pixel 1.التصغير الموحّد يطبّق نسبة واحدة في كل مكان؛ أما نسب AMC المبحوث عنها لكل طبقة فتعطي 70.5 بالمئة عند 68.3 ms مقابل 68.4 بالمئة عند 72.3 ms لنموذج MobileNet بعرض 0.75 على هاتف Pixel 1.
  • Higher sparsity is not faster inference unless the sparsity has a structure the target hardware can exploit.التناثر الأعلى لا يعني استدلالًا أسرع ما لم يكن لهذا التناثر بنية يستطيع العتاد المستهدف استغلالها.

Sourcesالمصادر