Majid Al-RaimiM:N sparsity on NVIDIA tensor coresتناثر M:N على أنوية NVIDIA tensor cores

COE 592Lecture 4.2المحاضرة 4.2Part 10الجزء 10

M:N sparsity on NVIDIA tensor coresتناثر M:N على أنوية NVIDIA tensor cores

Fine-grained structured sparsity keeps exactly N nonzeros in every block of M weights, compresses the matrix to half plus two-bit indices, and lets Ampere sparse tensor cores double GEMM throughput with no accuracy loss.التناثر المهيكل الدقيق يُبقي N عناصر غير صفرية بالضبط في كل كتلة من M وزنًا، ويضغط المصفوفة إلى النصف مع فهارس من بتين، ويسمح لأنوية tensor cores المتناثرة في Ampere بمضاعفة إنتاجية GEMM دون فقدان في الدقة.

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

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

EIE proved that a sparse network can run faster and cooler than a dense one, but only on a chip nobody could buy. This part is the version you can run today. The same GPUs that train the models in your research project will accept a weight matrix in a fixed 2:4 pattern and double their matrix math, and NVIDIA ships the pruning recipe, the storage format and the library that does it.

Three things are worth taking from it. The exam will ask you to compute the storage of a 2:4 matrix, to explain how the tensor core uses two-bit indices to skip half its multiplies, and to justify why the accuracy tables show no loss. Beyond the exam, 2:4 is the reference point for every future claim you will read about a sparse accelerator: it is what a fixed, mild, hardware-friendly pattern buys, and where it stops.

أثبت EIE أن الشبكة المتناثرة يمكن أن تعمل أسرع وبحرارة أقل من الشبكة الكثيفة، لكن على شريحة لم يكن بوسع أحد شراؤها. هذا الجزء هو النسخة التي يمكنك تشغيلها اليوم. وحدات GPU نفسها التي تدرّب النماذج في مشروعك البحثي تقبل مصفوفة أوزان بنمط ثابت 2:4 وتضاعف سرعة عمليات المصفوفات، وNVIDIA توفّر وصفة التقليم (pruning) وصيغة التخزين والمكتبة التي تنفّذ ذلك.

هناك ثلاثة أشياء تستحق أن تأخذها من هذا الجزء. سيطلب منك الامتحان أن تحسب حجم تخزين مصفوفة 2:4، وأن تشرح كيف تستخدم نواة الـ tensor فهارس من بتين لتتخطى نصف عمليات الضرب، وأن تبرر لماذا لا تُظهر جداول الدقة أي خسارة. وأبعد من الامتحان، يمثّل 2:4 النقطة المرجعية لكل ادعاء ستقرؤه مستقبلًا عن مسرّع متناثر: فهو يُريك ما يشتريه نمط ثابت ومعتدل وملائم للعتاد، وأين تقف حدوده.

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

  1. Define an a:b fine-grained structured pattern, state that 2:4 is 50 percent sparsity, and explain why a fixed count per block is what makes it hardware friendly.تعرّف نمطًا بنيويًا دقيق الحبيبات من الشكل a:b، وتذكر أن 2:4 يعني تناثرًا بنسبة 50 بالمئة، وتشرح لماذا يجعله العدد الثابت في كل كتلة ملائمًا للعتاد.
  2. Compute the storage of a 2:4 compressed matrix (values plus 2-bit metadata) and the resulting saving for FP16 and INT8 weights.تحسب حجم تخزين مصفوفة مضغوطة بنمط 2:4 (القيم مع بيانات وصفية من بتين) والتوفير الناتج لأوزان FP16 وINT8.
  3. Trace how a sparse tensor core uses the 2-bit indices to select K/2 activations from a dense operand and halve the multiplies.تتتبّع كيف تستخدم نواة الـ tensor المتناثرة الفهارس ذات البتين لاختيار K/2 من التنشيطات من المعامل الكثيف وتقليص عمليات الضرب إلى النصف.
  4. Reproduce NVIDIA's train, prune, retrain recipe and explain why it recovers accuracy without a hyper-parameter search.تعيد بناء وصفة NVIDIA (درّب، قلّم، أعد التدريب) وتشرح لماذا تستعيد الدقة دون أي بحث عن المعاملات الفائقة (hyper-parameters).
  5. Explain why GEMM speedup grows with K toward a 2x ceiling and why end-to-end inference gains are smaller.تشرح لماذا يزداد تسريع GEMM مع K مقتربًا من سقف 2x، ولماذا تكون مكاسب الاستدلال الكامل (end-to-end) أصغر.

Look at the first row of the structured-sparse matrix on the slide. Read it four cells at a time. The first four hold a value, a zero, a zero, a value. The next four hold a zero, a value, a value, a zero. Every group of four consecutive weights along the row has exactly two survivors, and the survivors can sit anywhere inside the group. Mishra et al. write the metadata for that row as [[0, 3], [1, 2]]: the positions of the survivors, group by group.

انظر إلى الصف الأول من المصفوفة المتناثرة البنيوية في الشريحة، واقرأه أربع خلايا في كل مرة. الخلايا الأربع الأولى تحتوي: قيمة، صفر، صفر، قيمة. والأربع التالية تحتوي: صفر، قيمة، قيمة، صفر. كل مجموعة من أربعة أوزان متتالية على طول الصف يبقى فيها وزنان بالضبط، ويمكن أن يقع الناجيان في أي موضع داخل المجموعة. يكتب Mishraوزملاؤه البيانات الوصفية (metadata) لهذا الصف هكذا [[0, 3], [1, 2]]: مواضع الأوزان الباقية، مجموعةً بعد مجموعة.

That is the whole definition of 2:4 sparsity: for each group of four values along a row, at least two must be zero. The general form keeps the same shape. Write a pattern as a:b, where the first number is how many weights survive and the second is the block size. Sparsity is then fixed by the pattern, not by the data.

هذا هو التعريف الكامل لـ 2:4 sparsity: في كل مجموعة من أربع قيم على طول الصف، يجب أن تكون قيمتان على الأقل صفرًا. والصيغة العامة تحافظ على الشكل نفسه. اكتب النمط على هيئة a:b، حيث الرقم الأول هو عدد الأوزان الباقية والثاني هو حجم الكتلة. وبذلك تتحدد نسبة التناثر بالنمط نفسه، لا بالبيانات.

sparsity=1−ab,2:4  ⇒  1−24=50%\text{sparsity} = 1 - \frac{a}{b}, \qquad 2{:}4 \;\Rightarrow\; 1 - \tfrac{2}{4} = 50\%
Sparsity of an a:b patternالتناثر لنمط a:b

2:4 is the instance that ships. Ampere sparse tensor cores accept it for FP16, BF16 and INT8 weights, and for TF32 the block halves to 1:2, still 50 percent (Mishra et al., section 3.2). NVIDIA describes the pattern as "two non-zero values in every four-entry vector" and calls it fine-grained structured sparsity (NVIDIA Ampere in-depth blog). The A100 whitepaper is explicit that the pattern is enforced along rows.

2:4 هو النمط المطبّق فعليًا في المنتجات. تقبله أنوية الـ tensor المتناثرة في معمارية Ampere لأوزان FP16 وBF16 وINT8، أما في TF32 فتنقسم الكتلة إلى النصف لتصبح 1:2، وتبقى النسبة 50 بالمئة (Mishra et al., section 3.2). تصف NVIDIA النمط بأنه "قيمتان غير صفريتين في كل متجه من أربعة عناصر" وتسمّيه التناثر البنيوي دقيق الحبيبات (fine-grained structured sparsity) (مدونة NVIDIA Ampere in-depth). وتنص الورقة البيضاء لـ A100 صراحةً على أن النمط يُفرض على طول الصفوف.

Fine-grained in what it removes, structured in how manyدقيق الحبيبات في ما يحذفه، بنيوي في عدد ما يحذفه

Lecture 04-1 laid out pruning granularities on a line from irregular fine-grained pruning, which may zero any single weight, to channel pruning, which removes whole filters. 2:4 sits between them and borrows the best of each. It is fine-grained because the unit removed is a single weight, so the pruning criterion still gets to pick within every block, which is why accuracy survives. It is structured because the count per block is constant, so the hardware knows in advance that every four weights hide exactly two multiplies.

عرضت المحاضرة 04-1 مستويات دقة التقليم (pruning granularities) على خط يمتد من التقليم غير المنتظم دقيق الحبيبات، الذي يمكنه تصفير أي وزن منفرد، إلى تقليم القنوات (channel pruning) الذي يحذف مرشحات (filters) كاملة. يقع 2:4 بينهما ويأخذ أفضل ما في كل منهما. فهو دقيق الحبيبات لأن الوحدة المحذوفة وزن واحد، فيبقى معيار التقليم قادرًا على الاختيار داخل كل كتلة، ولهذا تصمد الدقة. وهو بنيوي لأن العدد في كل كتلة ثابت، فيعرف العتاد مسبقًا أن كل أربعة أوزان تخفي عمليتي ضرب بالضبط.

That constancy is the entire engineering payoff. Unstructured sparsity, the kind EIE handles, needs a data-dependent index for every nonzero and a pointer to the start of every column, and the paper notes it leads to poor utilization of cache lines because the survivors land anywhere. With 2:4, the paper points out, the sparsity is constant across the matrix, so no indirection is required: a nonzero's position in memory can be computed directly from the compression rate. Two bits per survivor say which of the four slots it came from, and nothing else needs to be stored.

هذا الثبات هو كل المكسب الهندسي. التناثر غير البنيوي، وهو النوع الذي يتعامل معه EIE، يحتاج إلى فهرس يعتمد على البيانات لكل قيمة غير صفرية، وإلى مؤشر (pointer) لبداية كل عمود، وتذكر الورقة أنه يؤدي إلى استغلال ضعيف لأسطر الذاكرة المخبئية (cache lines) لأن الأوزان الباقية تقع في أي مكان. أما مع 2:4، كما تشير الورقة، فالتناثر ثابت عبر المصفوفة كلها، فلا حاجة إلى أي عنونة غير مباشرة (indirection): يمكن حساب موضع القيمة غير الصفرية في الذاكرة مباشرة من معدل الضغط. بتّان لكل وزن باقٍ تحددان أي خانة من الخانات الأربع جاء منها، ولا حاجة إلى تخزين أي شيء آخر.

PatternالنمطWhat can be removedما يمكن حذفهMetadataالبيانات الوصفيةHardware that benefitsالعتاد المستفيدFlexibility for accuracyمرونة الحفاظ على الدقة
Unstructured (EIE)غير بنيوي (EIE)Any weight, anywhereأي وزن في أي موضعIndex per nonzero, pointers, paddingفهرس لكل قيمة غير صفرية، ومؤشرات، وحشو (padding)Custom accelerator or slow CPU kernelsمسرّع مخصص أو نوى CPU بطيئةHighest, chosen per weightالأعلى، تُختار لكل وزن
2:4 fine-grained structuredبنيوي دقيق الحبيبات بنمط 2:4Any two of every four in a rowأي اثنين من كل أربعة في الصف2 bits per stored value, no pointers2 بت لكل قيمة مخزنة، بلا مؤشراتEvery Ampere and later GPUكل GPU من جيل Ampere وما بعدهHigh, chosen per blockعالية، تُختار لكل كتلة
Channel pruningتقليم القنوات (channel pruning)Whole output channelsقنوات خرج كاملةNone, matrix just shrinksلا شيء، فالمصفوفة تصغر فحسبAny dense hardwareأي عتاد كثيفLowest, chosen per channelالأدنى، تُختار لكل قناة
Three granularities, what they cost to describe and where they runثلاث درجات من الحبيبية: كلفة وصف كل منها وأين تعمل

One more fact will matter in the next two concepts: the groups of four run along the row of the weight matrix W. In the GEMM that a layer becomes, that row is the reduction dimension, the axis along which products are summed. The pattern has to live there, because that is the only axis on which skipping a weight also skips a multiply.

هناك حقيقة أخرى ستهمّ في المفهومين التاليين: مجموعات الأربعة تمتد على طول صف مصفوفة الأوزان W. وفي عملية GEMM التي تتحول إليها الطبقة، يكون هذا الصف هو بُعد الاختزال (reduction dimension)، أي المحور الذي تُجمع على طوله حواصل الضرب. يجب أن يقع النمط هناك، لأنه المحور الوحيد الذي يعني فيه تخطي وزن تخطي عملية ضرب أيضًا.

Where this sits among the three case studiesأين يقع هذا بين دراسات الحالة الثلاث

The divider slide that opens this section lists three sparse-hardware case studies. EIE (Efficient Inference Engine) came first: a custom accelerator exploiting Weight sparsity and Activation sparsity at once. This part is the middle one, and it takes the opposite bet. It exploits weight sparsity only, at a fixed and modest 50 percent, in exchange for running on a GPU that already sits in every data center. TorchSparse and PointAcc, which follow, go back to activation sparsity in point clouds. Keeping the three apart by which sparsity they exploit and what hardware they need is the fastest way to remember them.

تسرد الشريحة الفاصلة التي تفتتح هذا القسم ثلاث دراسات حالة لعتاد متناثر. جاء EIE (Efficient Inference Engine) أولًا: مسرّع مخصص يستغل Weight sparsity وActivation sparsity في آن واحد. هذا الجزء هو الأوسط، ويراهن رهانًا معاكسًا. فهو يستغل تناثر الأوزان فقط، بنسبة ثابتة ومتواضعة قدرها 50 بالمئة، مقابل أن يعمل على GPU موجود أصلًا في كل مركز بيانات. ثم يعود TorchSparse وPointAcc، اللذان يليانه، إلى تناثر التنشيطات في السحب النقطية (point clouds). التمييز بين الثلاثة بحسب نوع التناثر الذي يستغله كل منها والعتاد الذي يحتاجه هو أسرع طريقة لتذكّرها.

Recall

Why is 2:4 called fine-grained structured sparsity?لماذا يُسمّى نمط 2:4 تناثرًا بنيويًا دقيق الحبيبات؟

Fine-grained because individual weights are removed, so the criterion still chooses within each block. Structured because every block of four keeps exactly the same count, so positions need only 2-bit tags and no indirection.
دقيق الحبيبات لأن الأوزان تُحذف منفردة، فيبقى المعيار هو من يختار داخل كل كتلة. وبنيوي لأن كل كتلة من أربعة تحتفظ بالعدد نفسه بالضبط، فلا تحتاج المواضع إلا إلى وسوم من بتين دون أي عنونة غير مباشرة.

Take one group of four FP16 weights. Dense, it costs 4 x 16 = 64 bits. Under 2:4, only two values are stored, 2 x 16 = 32 bits, plus a 2-bit index for each, 2 x 2 = 4 bits. The group now costs 36 bits, a saving of about 44 percent (Mishra et al., section 3.1). Not 50 percent: the indices are small but they are not free.

خذ مجموعة واحدة من أربعة أوزان FP16. في الصيغة الكثيفة تكلّف 4 x 16 = 64 bits. وتحت نمط 2:4 لا تُخزَّن إلا قيمتان، أي 2 x 16 = 32 bits، مع فهرس من بتين لكل منهما، أي 2 x 2 = 4 bits. فتصبح كلفة المجموعة 36 bits، أي توفير بنحو 44 بالمئة (Mishra et al., section 3.1). ليس 50 بالمئة: الفهارس صغيرة لكنها ليست مجانية.

Scale that to a whole matrix and you get the format on the slide. A structured-sparse W of size R x C is stored as an R x C/2 block of nonzero values and an R x C/2 block of two-bit indices. The slide's instruction is to push all the nonzero elements to the left in memory. The survivors of each row are packed contiguously at half the original width, and the index block, drawn beside them, records where each came from.

عمّم ذلك على مصفوفة كاملة تحصل على الصيغة التي في الشريحة. المصفوفة W المتناثرة بنيويًا بحجم R x C تُخزَّن على هيئة كتلة بحجم R x C/2 من القيم غير الصفرية، وكتلة بحجم R x C/2 من الفهارس ذات البتين. تعليمات الشريحة هي دفع كل العناصر غير الصفرية إلى اليسار في الذاكرة. تُرصّ الأوزان الباقية في كل صف متجاورةً بنصف العرض الأصلي، وكتلة الفهارس المرسومة بجانبها تسجّل من أين جاءت كل قيمة.

Each row loses its zeros, its survivors slide left into a half-width value block, and a strip of 2-bit tags records which of the four slots each value came fromكل صف يفقد أصفاره، وتنزلق قيمه الباقية إلى اليسار في كتلة قيم بنصف العرض، وشريط من الوسوم ذات البتين يسجّل من أي خانة من الخانات الأربع جاءت كل قيمة
bits2:4=R⋅C2⋅b⏟values+R⋅C2⋅2⏟indices,bitsdense=R⋅C⋅b\text{bits}_{2:4} = \underbrace{R \cdot \tfrac{C}{2} \cdot b}_{\text{values}} + \underbrace{R \cdot \tfrac{C}{2} \cdot 2}_{\text{indices}}, \qquad \text{bits}_{\text{dense}} = R \cdot C \cdot b
Storage of a 2:4 compressed matrix with b-bit valuesتخزين مصفوفة مضغوطة بنمط 2:4 بقيم من b بت

Worked exampleمثال محلول

An FP16 layer of 1024 x 1024 weightsطبقة FP16 من 1024 x 1024 وزنًا

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

    1024 x 1024 x 16 = 16,777,216 bits, which is 2 MiB.
    1024 x 1024 x 16 = 16,777,216 bits، أي 2 MiB.
  2. Stored valuesالقيم المخزّنة

    Half the columns survive: 1024 x 512 = 524,288 values at 16 bits each, 8,388,608 bits = 1 MiB.
    يبقى نصف الأعمدة: 1024 x 512 = 524,288 قيمة، كل منها 16 bits، أي 8,388,608 bits = 1 MiB.
  3. Metadataالبيانات الوصفية

    One 2-bit index per stored value: 524,288 x 2 = 1,048,576 bits = 128 KiB.
    فهرس واحد من بتين لكل قيمة مخزّنة: 524,288 x 2 = 1,048,576 bits = 128 KiB.
  4. Total and savingالمجموع والتوفير

    8,388,608 + 1,048,576 = 9,437,184 bits = 1.125 MiB. The ratio to dense is 9,437,184 / 16,777,216 = 0.5625.
    8,388,608 + 1,048,576 = 9,437,184 bits = 1.125 MiB. والنسبة إلى الكثيف هي 9,437,184 / 16,777,216 = 0.5625.
  5. Resultالنتيجة

    43.75% saved. The value array halves; the indices add back an eighth of what remains.
    توفير بنسبة 43.75%. مصفوفة القيم تنقص إلى النصف، والفهارس تضيف ثُمن ما تبقّى.
CaseالحالةDenseكثيفValuesالقيمMetadataالبيانات الوصفيةTotalالمجموعSavingالتوفير
FP16, R = C = 1024FP16, R = C = 102416,777,216 (2 MiB)16,777,216 (2 MiB)8,388,608 (1 MiB)8,388,608 (1 MiB)1,048,576 (128 KiB)1,048,576 (128 KiB)9,437,184 (1.125 MiB)9,437,184 (1.125 MiB)43.75%43.75%
INT8, R = C = 4096INT8, R = C = 4096134,217,728 (16 MiB)134,217,728 (16 MiB)67,108,864 (8 MiB)67,108,864 (8 MiB)16,777,216 (2 MiB)16,777,216 (2 MiB)83,886,080 (10 MiB)83,886,080 (10 MiB)37.5%37.5%
The same arithmetic for the two shipping weight widths, in bitsالحساب نفسه لعرضَي الأوزان المستخدمين فعليًا، بالبت

The index cost is a fixed 2 bits per stored value, so its weight relative to the values depends on the value width: 2 / 16 = 12.5% overhead for FP16 and 2 / 8 = 25% for INT8, which is why the INT8 saving is the smaller 37.5 percent (Mishra et al., section 3.1). Compare that with the format EIE relied on. CSC stores a 4-bit relative index and a 4-bit weight-sharing code per nonzero, a 16-bit pointer per column, and a padding entry whenever a run of zeros exceeds fifteen (Han et al., EIE, section III). Mishra et al. note that a plain CSR with 8-bit weights and 16-bit column indices can spend up to 200 percent of the value bits on metadata. 2:4 spends 12.5 or 25 percent, with no pointers and no padding, because the pattern itself carries most of the position information.

كلفة الفهرس ثابتة عند بتين لكل قيمة مخزّنة، لذا يعتمد وزنها النسبي مقارنةً بالقيم على عرض القيمة: 2 / 16 = 12.5% كلفة إضافية في FP16 و2 / 8 = 25% في INT8، ولهذا يكون توفير INT8 هو الأصغر بنسبة 37.5 بالمئة (Mishra et al., section 3.1). قارن ذلك بالصيغة التي اعتمد عليها EIE. تخزّن صيغة CSC فهرسًا نسبيًا من 4 بتات ورمزًا من 4 بتات لمشاركة الأوزان (weight-sharing) لكل قيمة غير صفرية، ومؤشرًا من 16 بتًا لكل عمود، ومدخل حشو (padding) كلما تجاوزت سلسلة من الأصفار خمسة عشر (Han et al., EIE, section III). ويشير Mishra وزملاؤه إلى أن صيغة CSR عادية بأوزان من 8 بتات وفهارس أعمدة من 16 بتًا قد تنفق ما يصل إلى 200 بالمئة من بتات القيم على البيانات الوصفية. أما 2:4 فينفق 12.5 أو 25 بالمئة، بلا مؤشرات وبلا حشو، لأن النمط نفسه يحمل معظم معلومات المواضع.

One group of four weights under 2:4مجموعة واحدة من أربعة أوزان بنمط 2:4

FP16 denseFP16 الكثيف
4 x 16 = 64 bits4 x 16 = 64 بت
FP16 compressedFP16 المضغوط
2 x 16 + 2 x 2 = 36 bits, about 44% saved2 x 16 + 2 x 2 = 36 بت، أي توفير نحو 44%
INT8 denseINT8 الكثيف
4 x 8 = 32 bits4 x 8 = 32 بت
INT8 compressedINT8 المضغوط
2 x 8 + 2 x 2 = 20 bits, about 38% saved2 x 8 + 2 x 2 = 20 بت، أي توفير نحو 38%

Why insist on pushing everything to the left rather than leaving zeros in place and skipping them? Because memory is read in wide lines. With the survivors contiguous at half width, every byte a memory read brings in is a value the tensor core will use, which the paper describes as letting hardware fully utilize large memory reads. The A100 whitepaper puts the same point as a reduction of memory storage and bandwidth by almost 2x. Zeros left in place would fill half of every line with nothing.

لماذا الإصرار على دفع كل شيء إلى اليسار بدلًا من ترك الأصفار في مكانها وتخطيها؟ لأن الذاكرة تُقرأ في أسطر عريضة. حين تكون الأوزان الباقية متجاورة بنصف العرض، فكل بايت تجلبه عملية قراءة من الذاكرة هو قيمة ستستخدمها نواة الـ tensor، وهو ما تصفه الورقة بأنه يتيح للعتاد استغلال قراءات الذاكرة الكبيرة استغلالًا كاملًا. وتعبّر الورقة البيضاء لـ A100 عن الفكرة نفسها بأنها تقليل لمساحة التخزين وعرض النطاق (bandwidth) بما يقارب 2x. أما الأصفار المتروكة في مكانها فستملأ نصف كل سطر بلا شيء.

Simulatorمحاكي2:4 storage and speedup calculatorحاسبة التخزين والتسريع لنمط 2:4
R = 1024
C = 1024
f = 0.70
1.80x
stored values = R × C × 2/4 = 524.3 kvalue bits = 524.3 k × 16 b, metadata bits = 524.3 k × 2 bsaving = 1 − (value + metadata) / dense = 43.75%
Dense weights2.00MiBR × C × 16 b
Stored values1.00MiB2 of every 42 من كل 4
Metadata128KiB2 b per stored value2 b لكل قيمة مخزنة
Compressed total1.13MiBvalues plus indicesالقيم مع الفهارس
Storage saving43.75%below 50 because of the indicesأقل من 50 بسبب الفهارس
Metadata overhead12.50%index bits over value bitsبتات الفهارس إلى بتات القيم
MACs per GEMMMACs لكل GEMM536.87 MMACdense 1.07 G with M = N = K = Cالكثيف 1.07 G مع M = N = K = C
End-to-end speedup1.45xAmdahl: 1 / ((1 − f) + f / s)

Check against Mishra et al.: 43.75 percent, the paper's about 44 percent for FP16.مقارنة بـ Mishra et al.: 43.75 بالمئة، والورقة تذكر نحو 44 بالمئة لـ FP16.

The value array always halves under 2:4, but every stored value drags a 2-bit index with it, so the saving lands at 43.75 percent for 16-bit weights and 37.5 percent for 8-bit weights, never at 50. The MAC count halves exactly, which is the 2x the sparse tensor core can deliver on the matrix math alone. The last readout applies Amdahl to the whole network: with 70 percent of inference time inside GEMMs and a measured 1.8x on those GEMMs, the model runs about 1.45x faster. Drag the GEMM share down to see why memory-bound layers and small batches hide most of the gain.تنكمش مصفوفة القيم دائمًا إلى النصف تحت 2:4، لكن كل قيمة مخزنة تجر معها فهرسًا بطول 2-bit، لذا يستقر التوفير عند 43.75 بالمئة للأوزان ذات 16-bit و37.5 بالمئة للأوزان ذات 8-bit، ولا يبلغ 50 أبدًا. أما عدد عمليات MAC فينخفض إلى النصف تمامًا، وهذا هو التسريع 2x الذي تستطيع sparse tensor core تقديمه في حساب المصفوفات وحده. يطبق المؤشر الأخير قانون Amdahl على الشبكة كلها: إذا كان 70 بالمئة من زمن الاستدلال داخل عمليات GEMM وكان التسريع المقيس عليها 1.8x، يعمل النموذج أسرع بنحو 1.45x. اسحب حصة GEMM إلى الأسفل لترى لماذا تخفي الطبقات المقيدة بالذاكرة والدفعات الصغيرة معظم المكسب.

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

A 2:4 sparse FP16 weight matrix has R = 512 rows and C = 1024 columns. How many metadata bits does the compressed format hold?مصفوفة أوزان FP16 متناثرة بنمط 2:4 فيها R = 512 صفًا وC = 1024 عمودًا. كم بتًا من البيانات الوصفية تحتويها الصيغة المضغوطة؟

Recall

For an R x C weight matrix in 2:4 format, how many values and how many metadata bits are stored?في مصفوفة أوزان بحجم R x C بصيغة 2:4، كم قيمة وكم بتًا من البيانات الوصفية تُخزَّن؟

R x C/2 values and R x C/2 x 2 = R x C metadata bits, so the metadata is 2 bits per stored value, or one bit per original weight position.
R x C/2 قيمة وR x C/2 x 2 = R x C بتًا من البيانات الوصفية، أي أن البيانات الوصفية بتّان لكل قيمة مخزّنة، أو بت واحد لكل موضع وزن أصلي.

Follow one output element through a small GEMM with K = 8. Dense, the tensor core takes a row of A with eight values, a column of B with eight values, multiplies them pairwise and accumulates eight products. Now store that row of A in 2:4 form: four values and four 2-bit indices. The core reads the indices, pulls exactly the four elements of the B column that sit at those positions, multiplies four pairs, and accumulates. The slide's caption says it in one line: the indices are used to mask out the inputs, and only two multiplications will be done out of four.

تتبّع عنصر إخراج واحدًا خلال GEMM صغيرة بـ K = 8. في الحالة الكثيفة، تأخذ نواة الـ tensor صفًا من A فيه ثماني قيم، وعمودًا من B فيه ثماني قيم، فتضربهما زوجًا زوجًا وتراكم ثمانية حواصل ضرب. الآن خزّن ذلك الصف من A بصيغة 2:4: أربع قيم وأربعة فهارس من بتين. تقرأ النواة الفهارس، وتسحب بالضبط العناصر الأربعة من عمود B الواقعة في تلك المواضع، وتضرب أربعة أزواج، ثم تراكم. ويلخص تعليق الشريحة ذلك في سطر واحد: تُستخدم الفهارس لحجب المدخلات (mask out)، ولا تُنفَّذ إلا عمليتا ضرب من كل أربع.

Two compressed A values carry tags 00 and 11. The tags open two of the four gates on the dense B column, the two chosen pairs meet at the multiplier, and one result lands in the accumulator. The two greyed inputs are never fetched.قيمتان مضغوطتان من A تحملان الوسمين 00 و11. يفتح الوسمان بوابتين من البوابات الأربع على عمود B الكثيف، فيلتقي الزوجان المختاران عند المضاعِف، وتصل نتيجة واحدة إلى المراكم. المدخلان الرماديان لا يُجلبان أبدًا.

The rule behind the example is worth stating precisely, because exam questions turn on it. A Sparse tensor core performs sparse matrix times dense matrix equals dense matrix. Only the first operand, A of size M x K, is compressed, to M x K/2 values plus indices. The second operand B (K x N) and the output C (M x N) stay dense (Mishra et al., section 3.2). NVIDIA's TensorRT blog describes the mechanism as using the metadata to pull only the necessary values from the other, uncompressed operand. The metadata belongs to the weights, but it is applied to the activations.

القاعدة وراء المثال تستحق أن تُذكر بدقة، لأن أسئلة الامتحان تدور حولها. تنفّذ Sparse tensor core عملية: مصفوفة متناثرة ضرب مصفوفة كثيفة يساوي مصفوفة كثيفة. المعامل الأول وحده، A بحجم M x K، يُضغط إلى M x K/2 من القيم مع الفهارس. أما المعامل الثاني B (K x N) والإخراج C (M x N) فيبقيان كثيفين (Mishra et al., section 3.2). وتصف مدونة TensorRT من NVIDIA الآلية بأنها تستخدم البيانات الوصفية لسحب القيم الضرورية فقط من المعامل الآخر غير المضغوط. البيانات الوصفية تخص الأوزان، لكنها تُطبَّق على التنشيطات.

A, compressedA مضغوطة
K/2 values plus 2-bit indicesK/2 قيمة مع فهارس بطول 2-bit

The weight row, already packed left.

صف الأوزان، مرصوص إلى اليسار مسبقًا.

indicesالفهارس
Selectorالمنتقي
choose matching K/2 of Kاختيار K/2 المطابقة من K

A multiplexer over the dense B column.

مُجمِّع انتقائي (multiplexer) على عمود B الكثيف.

K/2 pairsK/2 زوجًا
Multiply and accumulateالضرب والتجميع
half the productsنصف حواصل الضرب

Writes a dense element of C.

يكتب عنصرًا كثيفًا من C.

One sparse tensor core step: the 2-bit indices route the dense operand through a selector so that only K/2 products are formedخطوة واحدة في نواة tensor متناثرة: توجّه الفهارس ذات البتين المعامل الكثيف عبر مُنتقٍ بحيث لا يُحسب إلا K/2 من حواصل الضرب

Halving the pairs halves the work, and the hardware is built so that the saving shows up as time. The A100 whitepaper states that a standard MMA on a 16 x 8 x 16 tile takes some number of cycles N, and the sparse MMA on the same tile takes N/2, a 2x speedup. The paper's Table 1 reports the resulting peak rates.

تقليص الأزواج إلى النصف يقلّص العمل إلى النصف، والعتاد مصمَّم بحيث يظهر هذا التوفير في الزمن. تنص الورقة البيضاء لـ A100 على أن عملية MMA عادية على قطعة بحجم 16 x 8 x 16 تستغرق عددًا من الدورات قدره N، وأن عملية MMA المتناثرة على القطعة نفسها تستغرق N/2، أي تسريع 2x. ويعرض الجدول 1 في الورقة المعدلات القصوى الناتجة.

A100 peak dense versus sparse tensor throughput, in TOPS (Mishra et al., Table 1)الإنتاجية القصوى لنوى tensor في A100 كثيفةً مقابل متناثرة، بوحدة TOPS (Mishra وزملاؤه، الجدول 1)

TF32 (1:2 pattern)TF32 (نمط 1:2)
156 dense, 312 sparse156 كثيف، 312 متناثر
FP16 / BF16
312 dense, 624 sparse312 كثيف، 624 متناثر
INT8
624 dense, 1248 sparse624 كثيف، 1248 متناثر

Why must the pattern run along K? Because K is the axis the selector walks. Each output element is a dot product over K, and a zero weight at position k means the product with B[k, n] can be dropped for every n. Zeros arranged along M or N would zero entire rows or columns of the output, which is a smaller network, not a faster GEMM. This is also why the library has shape rules: the reduction dimension must be a multiple of 16 for 16-bit formats and 32 for INT8, and layers that fail the rule, such as the first convolution of an image network with K = 3 x 7 x 7 = 147, are simply left dense (Mishra et al., sections 3.2 and 5.1). cuSPARSELt exposes the compression and the sparse GEMM to programmers, and TensorRT 8 applies them automatically to a network whose weights already follow the pattern.

لماذا يجب أن يمتد النمط على طول K؟ لأن K هو المحور الذي يسير عليه المُنتقي. كل عنصر إخراج هو جداء نقطي (dot product) على K، والوزن الصفري في الموضع k يعني أن حاصل ضربه في B[k, n] يمكن إسقاطه لكل n. أما الأصفار المرتبة على طول M أو N فستصفّر صفوفًا أو أعمدة كاملة من الإخراج، وهذا يعطي شبكة أصغر لا GEMM أسرع. ولهذا أيضًا للمكتبة قواعد للأبعاد: يجب أن يكون بُعد الاختزال مضاعفًا لـ 16 في الصيغ ذات 16 بتًا ولـ 32 في INT8، والطبقات التي لا تحقق القاعدة، مثل الالتفاف (convolution) الأول في شبكة صور حيث K = 3 x 7 x 7 = 147، تُترك ببساطة كثيفة (Mishra et al., sections 3.2 and 5.1). توفّر مكتبة cuSPARSELt الضغط وGEMM المتناثرة للمبرمجين، ويطبّقهما TensorRT 8 تلقائيًا على الشبكة التي تتبع أوزانها النمط مسبقًا.

What changed since EIEما الذي تغيّر منذ EIE

Set the two designs beside each other and the trade becomes visible. EIE (Efficient Inference Engine) reaches for every zero it can find: about 90 percent in the weights and about 70 percent in the activations, both exploited at once. To do that it needs Leading non-zero detection to find the next live activation, a FIFO in front of each Processing element (PE) to keep Load balance across uneven columns, and a custom chip to hold all of it. The sparse tensor core asks for far less sparsity, exactly 50 percent in the weights alone, which is static and known before the run. That is what lets the whole mechanism collapse into a multiplexer driven by 2-bit tags, small enough to add to a tensor core that every GPU already has.

ضع التصميمين جنبًا إلى جنب وستتضح المقايضة. يسعى EIE (Efficient Inference Engine) إلى كل صفر يمكنه إيجاده: نحو 90 بالمئة في الأوزان ونحو 70 بالمئة في التنشيطات، ويستغلهما معًا. ولفعل ذلك يحتاج إلى Leading non-zero detection لإيجاد التنشيط الحي التالي، وإلى طابور FIFO أمام كل Processing element (PE) للحفاظ على Load balance عبر أعمدة غير متساوية، وإلى شريحة مخصصة تحمل كل ذلك. أما نواة الـ tensor المتناثرة فتطلب تناثرًا أقل بكثير، 50 بالمئة بالضبط في الأوزان وحدها، وهو تناثر static (ساكن) معروف قبل التشغيل. وهذا ما يسمح للآلية كلها بأن تنكمش إلى مُنتقٍ تقوده وسوم من بتين، صغير بما يكفي لإضافته إلى نواة tensor موجودة أصلًا في كل GPU.

AspectالجانبEIE (ISCA 2016)EIE (ISCA 2016)2:4 sparse tensor core (2020)نواة tensor متناثرة بنمط 2:4 (2020)
Sparsity exploitedالتناثر المستغَلWeights (about 90 percent) and activations (about 70 percent)الأوزان (نحو 90 بالمئة) والتنشيطات (نحو 70 بالمئة)Weights only, exactly 50 percentالأوزان فقط، 50 بالمئة بالضبط
Weight formatصيغة الأوزانCSC: 4-bit relative index plus 4-bit code per nonzero, column pointers, paddingCSC: فهرس نسبي من 4 بت مع رمز من 4 بت لكل قيمة غير صفرية، ومؤشرات أعمدة، وحشوContiguous values plus one 2-bit index per stored valueقيم متجاورة مع فهرس واحد من بتين لكل قيمة مخزنة
Finding workإيجاد العملLeading nonzero detection, activation FIFO for load balanceكشف أول قيمة غير صفرية (leading nonzero detection)، وطابور FIFO للتنشيطات لموازنة الحملMultiplexer driven by the 2-bit indices, no searchمُنتقٍ (multiplexer) تقوده الفهارس ذات البتين، بلا بحث
HardwareالعتادCustom 45 nm ASIC, never soldشريحة ASIC مخصصة بتقنية 45 nm، لم تُطرح للبيع قطEvery Ampere or later GPU, cuSPARSELt and TensorRTكل GPU من جيل Ampere أو أحدث، مع cuSPARSELt وTensorRT
Ceiling on mathسقف تسريع الحسابProportional to combined sparsityيتناسب مع التناثر المجمّع2x, fixed by the pattern2x، يحدده النمط
EIE versus 2:4 on a sparse tensor coreEIE مقابل 2:4 على نواة tensor متناثرة

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

Which statement about 2:4 sparse GEMMs on Ampere sparse tensor cores is correct?أي العبارات التالية صحيحة عن عمليات GEMM المتناثرة بنمط 2:4 على نوى tensor المتناثرة في Ampere؟

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

Compared with EIE, what makes 2:4 sparsity easy to deploy on commodity hardware?مقارنةً بـ EIE، ما الذي يجعل تناثر 2:4 سهل النشر على عتاد تجاري؟

Recall

Which GEMM operand is stored sparse, which is dense, and along which dimension must the 2:4 pattern run?أي معامل في GEMM يُخزَّن متناثرًا، وأيها كثيف، وعلى طول أي بُعد يجب أن يمتد نمط 2:4؟

The weight operand A (M x K) is sparse and compressed to M x K/2. B (K x N) and C (M x N) are dense. The pattern runs along K, the reduction dimension.
معامل الأوزان A (M x K) متناثر ويُضغط إلى M x K/2. أما B (K x N) وC (M x N) فكثيفان. ويمتد النمط على طول K، وهو بُعد الاختزال.

ResNet-50 on ImageNet scores 76.1 top-1 dense in FP16. After 2:4 pruning and retraining it scores 76.2 in FP16 and 76.2 in INT8 (Mishra et al., Table 2). Half the weights are gone from almost every layer, the GEMMs can run on the sparse path, and the accuracy did not move. The slide's takeaway is the plain version of this: pruning CNNs with 2:4 sparsity brings a large speedup for GEMM workloads and does not incur a performance drop for the models. The rest of this concept explains how that is achieved, how large the speedup really is, and where both claims stop.

تحقق ResNet-50 على ImageNet دقة top-1 قدرها 76.1 وهي كثيفة بصيغة FP16. وبعد التقليم بنمط 2:4 وإعادة التدريب تحقق 76.2 في FP16 و76.2 في INT8 (Mishra et al., Table 2). اختفى نصف الأوزان من كل الطبقات تقريبًا، وصار بإمكان عمليات GEMM أن تعمل على المسار المتناثر، ولم تتحرك الدقة. والخلاصة في الشريحة هي الصيغة المبسطة لهذا: تقليم شبكات CNN بنمط 2:4 يجلب تسريعًا كبيرًا لأحمال GEMM ولا يسبب تراجعًا في أداء النماذج. بقية هذا المفهوم تشرح كيف يتحقق ذلك، وما حجم التسريع الحقيقي، وأين يتوقف كل من الادعاءين.

The recipe: one prune, one retrain, no searchالوصفة: تقليم واحد، وإعادة تدريب واحدة، ولا بحث

The deck does not show the procedure itself, so take it from the paper (Mishra et al., section 4) and from the A100 whitepaper, which calls it a simple and universal recipe. It has three steps.

لا تعرض الشرائح الإجراء نفسه، لذا خذه من الورقة (Mishra et al., section 4) ومن الورقة البيضاء لـ A100 التي تسمّيه وصفة بسيطة وعامة. وله ثلاث خطوات.

  1. Train the model without sparsity, exactly as you normally would.درّب النموذج دون تناثر، تمامًا كما تفعل عادةً.
  2. Prune it to 2:4 by magnitude: in every group of four weights along the row, zero the two with the smallest absolute value.قلّمه إلى 2:4 بحسب المقدار (magnitude): في كل مجموعة من أربعة أوزان على طول الصف، صفّر الوزنين صاحبي أصغر قيمة مطلقة.
  3. Retrain from those weights using the same optimizer, learning-rate schedule and number of epochs as step 1, with the zeros held fixed so the pattern survives. Optimizer state such as momentum is reset.أعد التدريب انطلاقًا من تلك الأوزان باستخدام المُحسِّن (optimizer) نفسه وجدول معدل التعلم نفسه وعدد الحقب (epochs) نفسه كما في الخطوة 1، مع تثبيت الأصفار كي يبقى النمط. وتُعاد حالة المُحسِّن، مثل الزخم (momentum)، إلى البداية.

Two things distinguish this from the Fine-tuning and Iterative pruning you met earlier in this lecture. It is one-shot: a single prune straight to the target, then a full second training run rather than a short low-learning-rate touch-up. And it needs no hyper-parameter search, because step 3 reuses step 1 wholesale. The paper is candid about the cost, a second full training, and argues it is worth paying once for a workflow with nothing to tune, since deployment amortizes it. NVIDIA packages the procedure as the ASP library for PyTorch.

أمران يميّزان هذا عن Fine-tuning وIterative pruning اللذين قابلتهما سابقًا في هذه المحاضرة. فهو أحادي الخطوة (one-shot): تقليم واحد مباشرة إلى الهدف، ثم جولة تدريب ثانية كاملة بدلًا من تحسين قصير بمعدل تعلم منخفض. ولا يحتاج إلى أي بحث عن المعاملات الفائقة، لأن الخطوة 3 تعيد استخدام الخطوة 1 بالكامل. والورقة صريحة بشأن الكلفة، وهي تدريب كامل ثانٍ، وترى أنها تستحق أن تُدفع مرة واحدة مقابل سير عمل لا شيء فيه يحتاج إلى ضبط، لأن النشر يوزّع هذه الكلفة على المدى. وتحزم NVIDIA هذا الإجراء في مكتبة ASP لـ PyTorch.

How much faster: a staircase toward 2xكم أسرع: درج يصعد نحو 2x

The chart on the slide compares INT8 GEMMs from cuSPARSELt, with one operand in 2:4 form, against dense cuBLAS GEMMs on an A100, at M = N = 10240 and K sweeping from 1280 to 20480. The bars start near 1.2x and climb toward 2x without reaching it. Mishra et al. read it the same way: larger GEMMs achieve nearly a 2x speedup with sparse tensor cores.

يقارن المخطط في الشريحة عمليات GEMM بـ INT8 من cuSPARSELt، حيث أحد المعاملين بصيغة 2:4، مع عمليات GEMM كثيفة من cuBLAS على A100، عند M = N = 10240 وK يتدرج من 1280 إلى 20480. تبدأ الأعمدة قرب 1.2x وتصعد نحو 2x دون أن تبلغه. ويقرأ Mishra وزملاؤه المخطط بالطريقة نفسها: عمليات GEMM الأكبر تحقق تسريعًا يقارب 2x باستخدام sparse tensor cores.

Speedup bars from the A100 chart rise with GEMM-K and flatten just below the dashed 2x line, which is the most the halved math can ever giveأعمدة التسريع من مخطط A100 ترتفع مع GEMM-K وتستوي تحت خط 2x المتقطع بقليل، وهو أقصى ما يمكن أن يعطيه تقليص الحساب إلى النصف
GEMM-KGEMM-KSpeedupالتسريع
12801280about 1.2xنحو 1.2x
25602560about 1.5xنحو 1.5x
38403840about 1.7xنحو 1.7x
76807680about 1.8xنحو 1.8x
1280012800about 1.9xنحو 1.9x
2048020480about 1.95xنحو 1.95x
INT8 sparse versus dense GEMM speedup on A100, read from the slide's chart (approximate)تسريع GEMM بـ INT8 متناثرًا مقابل كثيف على A100، مقروءًا من مخطط الشريحة (تقريبي)

Why does the speedup depend on K at all, when the pattern halves the multiplies at every size? Because the sparse tensor core halves only the arithmetic. A GEMM also has to move its operands in and its result out, and it pays fixed launch and scheduling costs. A small GEMM has low arithmetic intensity: few operations per byte moved, so its time is dominated by memory traffic and overheads that 2:4 does not touch. As K grows, the operations per output element grow while the output traffic does not, the GEMM becomes math bound, and halving the math approaches halving the time. The paper says exactly this: larger GEMMs tend to have higher arithmetic intensity, so they get closer to the 2x speedup.

لماذا يعتمد التسريع على K أصلًا، في حين أن النمط يقلّص عمليات الضرب إلى النصف عند كل حجم؟ لأن نواة الـ tensor المتناثرة لا تقلّص إلا العمليات الحسابية. فعملية GEMM يجب أيضًا أن تنقل معاملاتها إلى الداخل ونتيجتها إلى الخارج، وتدفع كلفة ثابتة للإطلاق والجدولة. لعملية GEMM الصغيرة arithmetic intensity (شدة حسابية) منخفضة: عمليات قليلة لكل بايت منقول، فيهيمن على زمنها نقل البيانات من الذاكرة والكلفة الإضافية التي لا يمسّها 2:4. ومع نمو K تزداد العمليات لكل عنصر إخراج بينما لا يزداد نقل الإخراج، فتصبح GEMM محكومة بالحساب (math bound)، ويقترب تقليص الحساب إلى النصف من تقليص الزمن إلى النصف. والورقة تقول هذا بالضبط: عمليات GEMM الأكبر تميل إلى شدة حسابية أعلى، لذا تقترب أكثر من تسريع 2x.

Worked exampleمثال محلول

From GEMM speedup to model speedup with Amdahlمن تسريع GEMM إلى تسريع النموذج باستخدام قانون Amdahl

  1. Name the fraction that improvesحدّد الجزء الذي يتحسن

    Suppose GEMMs take 70% of inference time (f = 0.7) and the sparse path makes them 1.8x faster (k = 1.8), a typical large-K reading from the chart.
    افترض أن عمليات GEMM تستغرق 70% من زمن الاستدلال (f = 0.7) وأن المسار المتناثر يجعلها أسرع بمقدار 1.8x (k = 1.8)، وهي قراءة نموذجية من المخطط عند K كبير.
  2. Apply Amdahl's lawطبّق قانون Amdahl

    S = 1 / ((1 - 0.7) + 0.7 / 1.8) = 1 / (0.3 + 0.389) = 1 / 0.689.
    S = 1 / ((1 - 0.7) + 0.7 / 1.8) = 1 / (0.3 + 0.389) = 1 / 0.689.
  3. Repeat for a small-K layerكرّر الحساب لطبقة ذات K صغير

    With k = 1.2 the GEMM term is 0.7 / 1.2 = 0.583, so S = 1 / 0.883 = 1.13x.
    مع k = 1.2 يصبح حدّ GEMM هو 0.7 / 1.2 = 0.583، إذن S = 1 / 0.883 = 1.13x.
  4. Resultالنتيجة

    About 1.45x end to end at 1.8x on the GEMMs, and only 1.13x when the GEMMs are small. The pattern is doing its job on the math either way; the rest of the network decides what the user sees.
    نحو 1.45x على مستوى النموذج كاملًا عند 1.8x في عمليات GEMM، و1.13x فقط حين تكون عمليات GEMM صغيرة. النمط يؤدي عمله في الحساب في الحالتين؛ أما بقية الشبكة فهي التي تحدد ما يراه المستخدم.

Accuracy: the table that justifies the claimالدقة: الجدول الذي يبرر الادعاء

The right half of the slide is the paper's Table 2: twenty ImageNet classifiers, each in dense FP16, sparse FP16 and sparse INT8. Read down any row and the three numbers agree to within a few tenths of a point; the widest spread is SUNet-128 at 75.6, 76.0 and 75.4. The paper states that the differences are within run-to-run variation, which is the honest way to say zero loss.

النصف الأيمن من الشريحة هو الجدول 2 في الورقة: عشرون مصنِّفًا على ImageNet، كل منها بصيغة FP16 كثيفة وFP16 متناثرة وINT8 متناثرة. اقرأ أي صف وستجد الأرقام الثلاثة متفقة في حدود بضعة أعشار النقطة؛ وأوسع فارق هو SUNet-128 عند 75.6 و76.0 و75.4. وتنص الورقة على أن الفروق تقع ضمن التفاوت بين التشغيلات (run-to-run variation)، وهذه هي الطريقة الأمينة لقول: لا خسارة.

NetworkالشبكةDense FP16FP16 كثيفSparse FP16FP16 متناثرSparse INT8INT8 متناثر
ResNet-34ResNet-3473.773.773.973.973.773.7
ResNet-50ResNet-5076.176.176.276.276.276.2
ResNet-101ResNet-10177.777.778.078.077.977.9
ResNeXt-101-32x16 (WSL)ResNeXt-101-32x16 (WSL)84.284.284.084.084.284.2
DenseNet-121DenseNet-12175.575.575.375.375.375.3
Inception v3Inception v377.177.177.177.177.177.1
VGG-16VGG-1674.074.074.174.174.174.1
DRN-105DRN-10579.479.479.579.579.479.4
ImageNet top-1 accuracy, dense versus 2:4 sparse (Mishra et al., Table 2, selected rows)دقة top-1 على ImageNet، كثيف مقابل متناثر بنمط 2:4 (Mishra وزملاؤه، الجدول 2، صفوف مختارة)

Two details in that table repay attention. Sparse INT8 matches sparse FP16, so the pruning and INT8 quantization, which this course turns to after pruning, compose without compounding their losses, at least on these networks. And the largest model, ResNeXt-101-32x16 trained with weak supervision, loses 0.2 in FP16 and nothing in INT8, so the pattern is not exploiting a weakness of small or old architectures. VGG, DenseNet, Inception, Xception and the dilated residual networks all behave the same way.

تفصيلان في ذلك الجدول يستحقان الانتباه. أولًا، INT8 المتناثر يطابق FP16 المتناثر، أي أن التقليم والتكميم (quantization) إلى INT8، الذي ينتقل إليه هذا المقرر بعد التقليم، يجتمعان دون أن تتراكم خسائرهما، على الأقل في هذه الشبكات. وثانيًا، أكبر نموذج، ResNeXt-101-32x16 المدرَّب بإشراف ضعيف (weak supervision)، يخسر 0.2 في FP16 ولا شيء في INT8، فالنمط لا يستغل نقطة ضعف في المعماريات الصغيرة أو القديمة. وتتصرف VGG وDenseNet وInception وXception والشبكات المتبقية الموسَّعة (dilated residual networks) كلها بالطريقة نفسها.

NetworkالشبكةDenseكثيف2:4, plain recipe2:4، الوصفة العادية2:4 with permutation2:4 مع تبديل الترتيب
MobileNet v2MobileNet v271.5571.5569.5669.5671.5671.56
EfficientNet B0EfficientNet B077.2577.2575.9875.9877.2977.29
Parameter-efficient networks under the plain recipe and with channel permutation (Mishra et al., Table 3)الشبكات الموفّرة للمعاملات بالوصفة العادية ومع تبديل ترتيب القنوات (Mishra وزملاؤه، الجدول 3)

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

On the A100 chart, why does the sparse versus dense INT8 GEMM speedup climb toward 2x only as GEMM-K grows?في مخطط A100، لماذا لا يقترب تسريع GEMM بـ INT8 المتناثر مقابل الكثيف من 2x إلا مع ازدياد GEMM-K؟

Recall

State the three steps of NVIDIA's 2:4 recipe and the one hyper-parameter search it needs.اذكر الخطوات الثلاث لوصفة 2:4 من NVIDIA، وبحث المعاملات الفائقة الوحيد الذي تحتاجه.

Train dense; prune the two smallest of every four weights along each row; retrain from those weights with the same optimizer, schedule and epochs while keeping the zeros fixed. It needs no hyper-parameter search at all.
درّب النموذج كثيفًا؛ ثم احذف أصغر وزنين من كل أربعة أوزان على طول كل صف؛ ثم أعد التدريب من تلك الأوزان بالمُحسِّن والجدول وعدد الحقب نفسها مع تثبيت الأصفار. ولا تحتاج إلى أي بحث عن المعاملات الفائقة على الإطلاق.

Recall

Why is the INT8 speedup only about 1.2x at K = 1280 but about 1.95x at K = 20480?لماذا يكون تسريع INT8 نحو 1.2x فقط عند K = 1280 لكنه نحو 1.95x عند K = 20480؟

Sparse tensor cores halve only the math. Small GEMMs have low arithmetic intensity and are bound by memory traffic and fixed costs, so halving the math barely moves the wall clock. Large GEMMs are math bound and approach the 2x ceiling.
أنوية الـ tensor المتناثرة لا تقلّص إلا الحساب إلى النصف. عمليات GEMM الصغيرة ذات شدة حسابية منخفضة ومحكومة بنقل البيانات من الذاكرة والكلفة الثابتة، فلا يكاد تقليص الحساب إلى النصف يغيّر الزمن الفعلي. أما عمليات GEMM الكبيرة فمحكومة بالحساب وتقترب من سقف 2x.

Recapالخلاصة

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

  • 2:4 keeps at most two nonzeros in every four consecutive weights along a row: 50 percent sparsity, fine-grained in what it removes, structured in how many it removes.يُبقي نمط 2:4 على قيمتين غير صفريتين على الأكثر في كل أربعة أوزان متتالية على طول الصف: تناثر بنسبة 50 بالمئة، دقيق الحبيبات في ما يحذفه، وبنيوي في عدد ما يحذفه.
  • Compressed W = R x C/2 values plus R x C/2 two-bit indices. Per group of four, 64 bits become 36 (FP16, about 44 percent saving) and 32 become 20 (INT8, about 38 percent).المصفوفة W المضغوطة = R x C/2 من القيم مع R x C/2 من الفهارس ذات البتين. في كل مجموعة من أربعة، تصبح 64 بت 36 بت (FP16، توفير نحو 44 بالمئة) وتصبح 32 بت 20 بت (INT8، توفير نحو 38 بالمئة).
  • The pattern runs along GEMM-K. The sparse tensor core uses the indices to pick K/2 matching elements of the dense B operand, so only half the multiplies run.يمتد النمط على طول البعد K في GEMM. تستخدم نواة الـ tensor المتناثرة الفهارس لاختيار K/2 من العناصر المقابلة في المعامل الكثيف B، فلا يُنفَّذ إلا نصف عمليات الضرب.
  • Peak A100 throughput doubles: FP16 312 to 624 TOPS, INT8 624 to 1248 TOPS.تتضاعف الإنتاجية القصوى لـ A100: في FP16 من 312 إلى 624 TOPS، وفي INT8 من 624 إلى 1248 TOPS.
  • Recipe: train dense, prune the two smallest of every four, retrain with the identical schedule keeping the zeros fixed. No hyper-parameter search.الوصفة: درّب النموذج كثيفًا، ثم احذف أصغر وزنين في كل أربعة، ثم أعد التدريب بالجدول نفسه تمامًا مع تثبيت الأصفار. لا حاجة إلى بحث عن المعاملات الفائقة.
  • Sparse FP16 and INT8 match dense FP16 within run-to-run noise on 20 ImageNet CNNs (ResNet-50 76.1 versus 76.2). Small nets like MobileNet v2 need channel permutation to recover.يطابق FP16 وINT8 المتناثران نموذج FP16 الكثيف ضمن حدود التفاوت بين التشغيلات على 20 شبكة CNN على ImageNet (ResNet-50: 76.1 مقابل 76.2). الشبكات الصغيرة مثل MobileNet v2 تحتاج إلى تبديل ترتيب القنوات (channel permutation) لاستعادة دقتها.
  • INT8 GEMM speedup rises from about 1.2x at K = 1280 to about 1.95x at K = 20480. The 2x caps the math only; end-to-end gains are smaller (about 1.2x for ResNeXt-101 in NVIDIA's blog).يرتفع تسريع GEMM بـ INT8 من نحو 1.2x عند K = 1280 إلى نحو 1.95x عند K = 20480. سقف 2x يخص الحساب الرياضي فقط؛ أما المكاسب الكاملة فأصغر (نحو 1.2x لـ ResNeXt-101 في مدونة NVIDIA).
  • Versus EIE: a fixed pattern and 2-bit tags on a commodity GPU instead of per-value indices, load balancing and a custom ASIC.مقارنةً بـ EIE: نمط ثابت ووسوم من بتين على GPU تجاري، بدلًا من فهرس لكل قيمة وموازنة حمل وشريحة ASIC مخصصة.

Sourcesالمصادر