Lecture 05-3 · Quantization III
المحاضرة 05-3 · التكميم الثالث
Group quantization: VS-Quant and MX formats
التكميم بالمجموعات: VS-Quant وصيغ MX
P1 MUSTP1 ضروريGive a small group of values its own cheap scale, and keep one expensive scale for the whole tensor. The exam question is almost always the same one: what is the effective bit width? It is the element bits plus every scale's bits divided by the number of elements that share it.
أعطِ كل مجموعة صغيرة من القيم scale رخيصاً خاصاً بها، واحتفظ بـ scale واحد مكلف للـ tensor كله. وسؤال الاختبار هنا غالباً هو نفسه: ما هو effective bit width؟ والجواب هو عدد بتات العنصر زائد بتات كل scale مقسومة على عدد العناصر التي تشترك فيه.
Three granularities
ثلاثة مستويات لدقة التقسيم
Slide 14 lines up the options. Per-tensor: one scale for the whole weight matrix. Per-channel: one scale per output channel (one row). Group quantization: one scale per small group inside a row, for example 16 consecutive values. The slide names two flavours of group quantization: per-vector quantization (VS-Quant) and the shared micro-exponent (MX) data types.
الشريحة 14 تعرض الخيارات بالترتيب. Per-tensor: scale واحد لمصفوفة الأوزان كلها. Per-channel: scale واحد لكل قناة خرج (صف واحد). Group quantization: scale واحد لكل مجموعة صغيرة داخل الصف، مثلاً 16 قيمة متتالية. وتذكر الشريحة نوعين منه: per-vector quantization أي VS-Quant، وأنواع البيانات ذات shared micro-exponent (MX).
الرسم يُظهر ثلاث شبكات أوزان. في per-tensor كتلة واحدة لها scale واحد. في per-channel كل صف له scale بدقة FP16. وفي group يُقسَم الصف إلى مجموعات، لكل مجموعة Sq صحيح، مع γ عشري واحد للـ tensor. كلما صغرت المجموعة غطّى كل scale مدى محلياً صغيراً فتتطابق شبكة 4-bit مع البيانات أفضل، والثمن هو تخزين عدد أكبر من الـ scales.
Why group quantization: accuracy vs hardware
لماذا التكميم بالمجموعات: الدقة مقابل العتاد
Slide 16's headline is the whole motivation: achieve a balance between quantization accuracy and hardware efficiency. At 4 bits there are only 16 levels, so one outlier in a 4,096-wide row stretches the per-channel scale and crushes every other value onto a few levels. Smaller groups isolate the damage. NVIDIA's Blackwell GPUs build this into the hardware as micro-tensor scaling to keep FP4 accurate, and FP4 is worth the trouble: the FP4 tensor core gives 2× the theoretical throughput of the FP8/FP6/INT8 tensor core.
عنوان الشريحة 16 هو كل الدافع: تحقيق توازن بين دقة quantization وكفاءة العتاد. عند 4 بت يوجد 16 مستوى فقط، فقيمة شاذة واحدة في صف طوله 4,096 تمدّ الـ scale الخاص بالقناة وتضغط كل القيم الأخرى على مستويات قليلة. المجموعات الصغيرة تعزل هذا الضرر. ومعالجات Blackwell من NVIDIA تبني ذلك في العتاد باسم micro-tensor scaling للحفاظ على دقة FP4، والأمر يستحق: فـ FP4 tensor core يعطي ضعف الإنتاجية النظرية مقارنة بـ FP8/FP6/INT8 tensor core.
| Per Blackwell GPU (slide 16)لكل GPU من Blackwell (الشريحة 16) | B200 | B100 |
|---|---|---|
| FP4 tensor coreنواة tensor core بدقة FP4 | 18 petaFLOPS | 14 petaFLOPS |
| FP8/FP6 tensor coreنواة tensor core بدقة FP8/FP6 | 9 petaFLOPS | 7 petaFLOPS |
| INT8 tensor coreنواة tensor core بدقة INT8 | 9 petaOPS | 7 petaOPS |
| FP16/BF16 tensor coreنواة tensor core بدقة FP16/BF16 | 4.5 petaFLOPS | 3.5 petaFLOPS |
الجدول لكل معالج Blackwell: في B200 يعطي FP4 قيمة 18 petaFLOPS مقابل 9 لـ FP8/FP6 و9 petaOPS لـ INT8 و4.5 لـ FP16/BF16. وفي B100 القيم 14 و7 و7 و3.5. كل خطوة نزول في الدقة تضاعف الإنتاجية. وعلى مستوى HGX B200 بثمانية معالجات: 144 مقابل 72 PetaFLOPS.
VS-Quant: a two-level scale
VS-Quant: scale على مستويين
Ordinary linear quantization is r = S(q − Z). VS-Quant (per-vector scaled quantization, Dai et al.) splits the scale into two factors:
الـ linear quantization العادي هو r = S(q − Z). أما VS-Quant (per-vector scaled quantization من Dai et al.) فيقسم الـ scale إلى عاملين:
تقول المعادلة: القيمة الحقيقية r تساوي γ مضروباً في Sq مضروباً في (q − Z).
| Factorالعامل | Typeالنوع | Granularityدقة التقسيم | Costالكلفة |
|---|---|---|---|
| γ | floating pointعدد عشري (floating point) | coarse: one per tensor (or per channel)خشنة: واحد لكل tensor (أو لكل قناة) | expensive, but there are very fewمكلف، لكن عدده قليل جداً |
| Sq | small integer (e.g. 4-bit)عدد صحيح صغير (مثلاً 4 بت) | fine: one per vector of 16 elementsدقيقة: واحد لكل متجه من 16 عنصراً | cheap integer multiply, but there are manyضرب صحيح رخيص، لكن عدده كبير |
الجدول: γ عدد عشري خشن الحبيبات، واحد لكل tensor (أو لكل قناة)، مكلف لكنه قليل العدد. وSq عدد صحيح صغير (مثلاً 4-bit) دقيق الحبيبات، واحد لكل متجه من 16 عنصراً، رخيص لأن ضربه ضرب صحيح، لكنه كثير العدد.
That is the rule from slide 17: less expensive integer scale factors at finer granularity, more expensive floating-point scale factors at coarser granularity. In the matrix multiply, the integer dot product of one vector is multiplied by its integer Sq, and only at the end does the float γ get applied once.
هذه هي قاعدة الشريحة 17: scale صحيح رخيص عند الحبيبات الدقيقة، وscale عشري مكلف عند الحبيبات الخشنة. ففي ضرب المصفوفات يُضرب حاصل الضرب النقطي الصحيح لكل متجه في Sq الصحيح الخاص به، ولا يُطبَّق γ العشري إلا مرة واحدة في النهاية.
Dequantize one weight, symmetric (Z = 0): gamma = 0.01 (FP16, whole tensor) S_q = 5 (UINT4, this vector of 16) q = -3 (INT4) r = 0.01 x 5 x (-3 - 0) = -0.15 Same tensor, another vector with small values: S_q = 1, q = 7 -> r = 0.01 x 1 x 7 = 0.07 its step size is 0.01, five times finer than the first vector's step of 0.05.
المثال المحلول: وزن متماثل (Z = 0) مع γ = 0.01 وSq = 5 وq = −3، فيكون r = 0.01 × 5 × (−3) = −0.15. ومتجه آخر قيمه صغيرة له Sq = 1 وq = 7، فيكون r = 0.07، وخطوته 0.01، أدق بخمس مرات من خطوة المتجه الأول 0.05. كل متجه يحصل على شبكة تناسب مداه.
Effective bit width: the one formula
عرض البتات الفعلي: الصيغة الوحيدة
Every stored scale costs memory, but it is shared by a group. Spread its bits over the group:
كل scale مخزَّن يكلف ذاكرة، لكنه مشترك بين أفراد مجموعة. فوزّع بتاته على المجموعة:
تقول المعادلة: البتات الفعلية لكل عنصر تساوي بتات العنصر زائد مجموع بتات كل مستوى من الـ scales مقسومة على حجم المجموعة التي يشترك فيها.
Slide 17's example: 4-bit quantization with a 4-bit per-vector scale every 16 elements gives 4 + 4/16 = 4.25 bits.
مثال الشريحة 17: quantization بـ 4 بت مع scale بـ 4 بت لكل 16 عنصراً يعطي 4 + 4/16 = 4.25 بت.
The multi-level scaling table
جدول التحجيم متعدد المستويات
Slides 18 to 21 generalize this as r = (q − z) · sl0 · sl1 · …, where z = 0 means symmetric quantization. L0 is the innermost, smallest group. L1 is the next level up. Memorize this table and the arithmetic in the last column.
الشرائح من 18 إلى 21 تعمّم الفكرة: r = (q − z) · sl0 · sl1 · …، حيث z = 0 يعني symmetric quantization. وL0 هو المستوى الأعمق والمجموعة الأصغر، وL1 المستوى الذي فوقه. احفظ هذا الجدول وحساب العمود الأخير.
| Approachالطريقة | Data typeنوع البيانات | L0 groupمجموعة L0 | L0 scalescale في L0 | L1 groupمجموعة L1 | L1 scalescale في L1 | Effective bitsالبتات الفعلية |
|---|---|---|---|---|---|---|
| Per-channelلكل قناة (per-channel) | INT4 | per channelلكل قناة | FP16 | - | - | 4 |
| VSQ | INT4 | 16 | UINT4 | per channelلكل قناة | FP16 | 4 + 4/16 = 4.25 |
| MX4 | S1M2 | 2 | E1M0 | 16 | E8M0 | 3 + 1/2 + 8/16 = 4 |
| MX6 | S1M4 | 2 | E1M0 | 16 | E8M0 | 5 + 1/2 + 8/16 = 6 |
| MX9 | S1M7 | 2 | E1M0 | 16 | E8M0 | 8 + 1/2 + 8/16 = 9 |
الجدول: per-channel بعناصر INT4 وscale بدقة FP16 لكل قناة يعطي 4. وVSQ بعناصر INT4 وscale من نوع UINT4 لكل 16 ثم FP16 لكل قناة يعطي 4.25. وMX4 بعناصر S1M2 وE1M0 لكل 2 وE8M0 لكل 16 يعطي 3 + 1/2 + 8/16 = 4. وMX6 بعناصر S1M4 يعطي 6، وMX9 بعناصر S1M7 يعطي 9.
Decoding the MX type names
فك رموز أسماء أنواع MX
S1M2 means 1 sign bit and 2 mantissa (magnitude) bits, so 3 bits per element; there is no private exponent. E1M0 is a 1-bit exponent with no mantissa: a scale that is a power of two, shared by a pair of elements (the micro-exponent, a shift by 0 or 1). E8M0 is an 8-bit exponent with no mantissa: a power-of-two scale shared by 16 elements. Because both scales are powers of two, applying them is a shift, not a multiply.
S1M2 تعني بت إشارة واحد و2 بت mantissa (المقدار)، أي 3 بتات لكل عنصر، بلا exponent خاص. وE1M0 هو exponent من بت واحد بلا mantissa: scale هو قوة للعدد 2 يشترك فيه عنصران (هذا هو micro-exponent، أي إزاحة بمقدار 0 أو 1). وE8M0 هو exponent من 8 بتات بلا mantissa: scale هو قوة للعدد 2 يشترك فيه 16 عنصراً. ولأن الاثنين قوى للعدد 2، فتطبيقهما مجرد إزاحة shift وليس ضرباً.
MX4, one block of 16 elements:
elements 16 x S1M2 = 16 x 3 = 48 bits
L0 scales 8 x E1M0 = 8 x 1 = 8 bits (one per pair)
L1 scale 1 x E8M0 = 1 x 8 = 8 bits
total 64 bits
64 / 16 = 4 bits per element = 3 + 1/2 + 8/16
VSQ on a 4096 x 4096 INT4 matrix:
elements 16,777,216 x 4 bits = 8,388,608 B
S_q 16,777,216/16 = 1,048,576 scales x 4 bits
= 524,288 B
gamma 4,096 channels x FP16 = 8,192 B
per-element view: 4 + 4/16 + 16/4096 = 4.2539
slide rounds the last term away -> 4.25
المثال المحلول: كتلة MX4 من 16 عنصراً فيها 16 × 3 = 48 بت للعناصر، و8 × 1 = 8 بتات لـ E1M0 (واحد لكل زوج)، و8 بتات لـ E8M0، والمجموع 64 بت، أي 64 / 16 = 4 بت لكل عنصر. وفي VSQ على مصفوفة 4096 × 4096: العناصر 8,388,608 B، وSq عددها 1,048,576 بحجم 524,288 B، وγ لكل قناة 8,192 B فقط. فلكل عنصر 4 + 4/16 + 16/4096 = 4.2539، والشريحة تُهمل الحد الأخير فتكتب 4.25.
Per-channel is listed as 4, not 4 + 16. The FP16 scale is shared by a whole row of thousands of weights, so 16 / 4,096 ≈ 0.004 bits. Its overhead is negligible and the table counts it as zero. The same reason lets VSQ ignore its L1 FP16 term.
Per-channel مكتوب 4 وليس 4 + 16. فالـ scale بدقة FP16 يشترك فيه صف كامل من آلاف الأوزان، فيكون 16 / 4,096 ≈ 0.004 بت. هذا العبء مهمل والجدول يعدّه صفراً. وللسبب نفسه يُهمل VSQ حد FP16 في المستوى L1.
Divide the scale bits by the group size, never add them raw. 4 + 4 = 8 is wrong for VSQ; 4 + 4/16 = 4.25 is right. And for MX, the element is S1M2 = 3 bits, not 4: forgetting the sign bit or counting M2 as the whole element both break the sum.
اقسم بتات الـ scale على حجم المجموعة، ولا تجمعها كما هي. فـ 4 + 4 = 8 خطأ في VSQ، والصحيح 4 + 4/16 = 4.25. وفي MX العنصر S1M2 حجمه 3 بتات وليس 4: نسيان بت الإشارة أو اعتبار M2 هو العنصر كله يُفسد المجموع.
MX-n ends in n because 1/2 + 8/16 = 1. The two shared scales always add exactly one bit, so MX4, MX6 and MX9 have 3, 5 and 8-bit elements.
الرقم في اسم MX-n هو n لأن 1/2 + 8/16 = 1. فالمستويان المشتركان يضيفان بتاً واحداً بالضبط دائماً، ولذلك عناصر MX4 وMX6 وMX9 حجمها 3 و5 و8 بتات.
Check yourself
اختبر نفسك
A scheme stores INT4 weights with an 8-bit integer scale for every group of 16 weights, plus an FP16 scale per output channel. What is the effective bit width as the slides count it?
مخطط يخزّن أوزاناً بدقة INT4 مع scale صحيح بـ 8 بتات لكل مجموعة من 16 وزناً، وscale بدقة FP16 لكل قناة خرج. ما effective bit width بطريقة عدّ الشرائح؟
4 + 8/16 = 4.5, and the per-channel FP16 term is negligible. Option A uses a 4-bit group scale. Option B adds the 8 scale bits without dividing. Option D adds 16/16 for the FP16 scale as if it were shared by only 16 weights.
4 + 8/16 = 4.5، وحد FP16 لكل قناة مهمل. الخيار A يستخدم scale بـ 4 بتات. والخيار B يجمع البتات 8 دون قسمة. والخيار D يضيف 16/16 كأن FP16 يشترك فيه 16 وزناً فقط.
In VS-Quant, r = γ · Sq · (q − Z). Which statement is correct?
في VS-Quant لدينا r = γ · Sq · (q − Z). أي عبارة صحيحة؟
Cheap integer scales go at the fine granularity, expensive float scales at the coarse one. Option A swaps them. Option C would make the overhead 16 bits per vector. Sq multiplies; it has nothing to do with Z.
الـ scales الصحيحة الرخيصة تكون عند الحبيبات الدقيقة، والعشرية المكلفة عند الخشنة. الخيار A يعكسهما. والخيار C يجعل العبء 16 بتاً لكل متجه. وSq عامل ضرب ولا علاقة له بـ Z.
MX6 uses S1M4 elements, an E1M0 scale per 2 elements and an E8M0 scale per 16 elements. How many bits does each element itself store, and what is the effective width?
MX6 يستخدم عناصر S1M4، وscale من نوع E1M0 لكل عنصرين، وE8M0 لكل 16 عنصراً. كم بتاً يخزّن العنصر نفسه، وما العرض الفعلي؟
S1M4 is 1 sign + 4 mantissa = 5 bits. 5 + 1/2 + 8/16 = 6. Option A forgets the sign bit. Option C adds 1 + 8 without dividing by the group sizes.
S1M4 هو بت إشارة زائد 4 بتات mantissa، أي 5 بتات. و5 + 1/2 + 8/16 = 6. الخيار A ينسى بت الإشارة، والخيار C يجمع 1 + 8 دون قسمة على أحجام المجموعات.
Why does the table list per-channel INT4 with an FP16 scale as exactly 4 bits?
لماذا يكتب الجدول أن per-channel INT4 مع scale بدقة FP16 يساوي 4 بتات بالضبط؟
16 bits spread over, say, 4,096 weights is about 0.004 bits each. The scale is still stored in FP16; it just costs almost nothing per element.
16 بتاً موزعة على 4,096 وزناً مثلاً تساوي حوالي 0.004 بت لكل وزن. والـ scale ما زال مخزَّناً بدقة FP16، لكنه لا يكلف شيئاً تقريباً لكل عنصر.
On a Blackwell B200 GPU, how does the FP4 tensor core throughput compare with the FP8/FP6/INT8 tensor core?
في معالج Blackwell B200، كيف تقارن إنتاجية FP4 tensor core بـ FP8/FP6/INT8 tensor core؟
Slide 16: FP4 tensor core provides 2× the theoretical throughput. Per B200 GPU that is 18 vs 9 petaFLOPS; FP16/BF16 is 4.5, so FP4 is 4× FP16, which is where option B comes from.
الشريحة 16: FP4 tensor core يعطي ضعف الإنتاجية النظرية، أي 18 مقابل 9 petaFLOPS لكل B200. أما FP16/BF16 فهو 4.5، فيكون FP4 أربعة أضعاف FP16، ومن هنا جاء الخيار B.