COE 592Lecture 5.2المحاضرة 5.2Part 04الجزء 04
Symmetric Quantization and Bias Handlingالتكميم المتماثل ومعالجة الانحياز (Bias)
Symmetric quantization fixes Z = 0 and uses the range [-|r|max, |r|max], which makes the S formula simpler and removes the runtime Z_W q_X term. Bias then enters the fully-connected layer and is quantized with Z_b = 0 and S_b = S_W S_X, so that it shares the accumulator's scale.التكميم المتماثل يثبّت Z = 0 ويستخدم المدى [-|r|max, |r|max]، مما يبسّط صيغة S ويزيل الحد Z_W q_X وقت التشغيل. ثم يدخل الانحياز (bias) في الطبقة المتصلة كليًا ويُكمَّم بـZ_b = 0 وS_b = S_W S_X، ليشارك المُجمِّع (accumulator) مقياسه نفسه.
- Conceptsالمفاهيم
- 4
- Slidesالشرائح
- 15-19
- Readingمدة القراءة
- 24 min24 دقيقة
Why this part mattersلماذا يهمّ هذا الجزء
The previous part ended with a question: the matrix multiply has a term, Z_W q_X, that depends on the input and so must be computed at every inference. Can we make it vanish? This part answers yes, by choosing a weight zero point of exactly 0. That one choice is called symmetric quantization, and it changes the scale formula, the integer pipeline, and how the bias gets folded in.
These slides are dense with exam material. Expect to compute a symmetric scale for a given bit width, to defend why weights get Z_W = 0 while activations do not, and to explain why the bias is stored as a 32-bit integer with scale S_W S_X. The running 4x4 weight matrix from slide 8, with values from -1.08 to 2.12, carries every worked number.
انتهى الجزء السابق بسؤال: في ضرب المصفوفات حدّ هو Z_W q_X يعتمد على المُدخل، ولذلك يجب حسابه في كل عملية استدلال. هل يمكن أن نجعله يختفي؟ يجيب هذا الجزء بنعم، وذلك باختيار نقطة صفر للأوزان تساوي 0 تمامًا. هذا الاختيار الواحد يسمى التكميم المتماثل (symmetric quantization)، وهو يغيّر صيغة المقياس، ومسار الحساب بالأعداد الصحيحة، وطريقة دمج الانحياز (bias).
هذه الشرائح مليئة بمادة الامتحان. توقّع أن يُطلب منك حساب مقياس متماثل لعرض بتات معيّن، وأن تدافع عن سبب حصول الأوزان على Z_W = 0 بينما لا تحصل عليه مخرجات التنشيط، وأن تشرح لماذا يُخزَّن الانحياز كعدد صحيح بـ32 بت بمقياس S_W S_X. مصفوفة الأوزان المرافقة 4x4 من الشريحة 8، بقيمها من -1.08 إلى 2.12، تحمل كل الأرقام المحلولة.
By the end you canفي نهاية هذا الجزء ستستطيع
- State what symmetric quantization fixes (Z = 0, range [-|r|max, |r|max]) and when it fits the data.أن تذكر ما الذي يثبّته التكميم المتماثل (Z = 0، والمدى [-|r|max, |r|max]) ومتى يناسب البيانات.
- Compute the full range symmetric scale S = |r|max / 2^(N-1) for any bit width, and explain why +|r|max gets clipped.أن تحسب مقياس المدى الكامل المتماثل S = |r|max / 2^(N-1) لأي عرض بتات، وأن تشرح لماذا تُقصّ القيمة +|r|max.
- Contrast full range mode with restricted range mode and with asymmetric quantization on the same tensor.أن تقارن نمط المدى الكامل بنمط المدى المقيّد وبالتكميم غير المتماثل على نفس الموتر.
- Explain why weights use Z_W = 0 while ReLU activations keep Z_X different from 0.أن تشرح لماذا تستخدم الأوزان Z_W = 0 بينما تحتفظ مخرجات ReLU بقيمة Z_X لا تساوي 0.
- Derive the fully-connected layer with bias and justify Z_b = 0, S_b = S_W S_X and a 32-bit bias.أن تشتق الطبقة كاملة الاتصال مع الانحياز (bias) وتبرر اختيار Z_b = 0 وS_b = S_W S_X وتخزين الانحياز بـ32 بت.
Take two tensors. One is a layer of trained weights, with values scattered from about -2 to about +2 and most of them near 0. The other is the output of a ReLU, every value between 0 and 6. Both need to become 8-bit codes. Should both get the same kind of integer grid?
خذ موترين. الأول طبقة من الأوزان المدرّبة، قيمها منتشرة من حوالي -2 إلى حوالي +2 ومعظمها قريب من 0. والثاني مخرجات ReLU، كل قيمها بين 0 و6. كلاهما يجب أن يتحول إلى رموز بـ8 بت. فهل يجب أن يحصل الاثنان على نفس النوع من شبكة الأعداد الصحيحة؟
So far we have used asymmetric quantization: the float range [r_min, r_max] is stretched onto the code range [q_min, q_max], and the zero point Z lands wherever real 0 happens to fall. In the left half of slide 15 that is somewhere in the middle of the dots, and for the running matrix at 2 bits it was Z = -1. Symmetric quantization removes that freedom. It declares Z = 0 up front and, to make that consistent, quantizes a range centred on zero: [-|r|max, |r|max], where |r|max is the largest absolute value in the tensor.
حتى الآن استخدمنا asymmetric quantization (التكميم غير المتماثل): يُمدّ مدى القيم العشرية [r_min, r_max] على مدى الرموز [q_min, q_max]، وتقع zero point (نقطة الصفر) Z حيثما صادف أن وقع الصفر الحقيقي 0. في النصف الأيسر من الشريحة 15 يقع ذلك في مكان ما وسط النقاط، وفي المصفوفة المرافقة عند 2 بت كانت Z = -1. Symmetric quantization (التكميم المتماثل) يلغي هذه الحرية. فهو يعلن Z = 0 مسبقًا، ولكي يكون ذلك متسقًا يكمّم مدى متمركزًا حول الصفر: [-|r|max, |r|max]، حيث |r|max هي أكبر قيمة مطلقة في الموتر.
The integer side does not change. The codes are still signed N-bit integers with q_min and q_max taken from the table on the slide:
جانب الأعداد الصحيحة لا يتغير. الرموز ما زالت أعدادًا صحيحة بإشارة من N-bit، وقيمتا q_min and q_max مأخوذتان من الجدول الموجود في الشريحة:
| Bit width Nعرض البتات N | q_min = -2^(N-1)q_min = -2^(N-1) | q_max = 2^(N-1) - 1q_max = 2^(N-1) - 1 | Levelsعدد المستويات |
|---|---|---|---|
| 22 | -2-2 | 11 | 44 |
| 33 | -4-4 | 33 | 88 |
| 44 | -8-8 | 77 | 1616 |
| 88 | -128-128 | 127127 | 256256 |
Notice the range is already lopsided: there is one more negative code than positive. Keep that in mind; it is the root of the clipping problem in the next concept.
لاحظ أن المدى غير متوازن أصلًا: فيه رمز سالب واحد زيادة على عدد الرموز الموجبة. تذكّر هذا، فهو أصل مشكلة القصّ (clipping) في المفهوم التالي.
Who should be symmetric?من الذي يجب أن يكون متماثلًا؟
The answer depends on the shape of the data. Trained weights have a bell-shaped distribution centred near 0, so a range centred on 0 fits them well and almost no codes go to waste. ReLU outputs are the opposite: every value is 0 or positive. A symmetric grid would reserve the entire negative half of its codes for values that never occur.
الإجابة تعتمد على شكل البيانات. الأوزان المدرّبة لها bell-shaped distribution (توزيع على شكل جرس) متمركز قرب 0، لذلك يناسبها مدى متمركز حول 0، ولا يكاد يضيع أي رمز. مخرجات ReLU عكس ذلك: كل قيمة إما 0 أو موجبة. الشبكة المتماثلة ستحجز النصف السالب كله من رموزها لقيم لا تظهر أبدًا.
Worked exampleمثال محلول
ReLU6 activations in [0, 6] as INT8مخرجات ReLU6 في المدى [0, 6] بصيغة INT8
Symmetric, full rangeمتماثل، بالمدى الكامل
|r|max = 6, so S = 6 / 128 = 0.0469. Only codes 0 to 127 are ever used; the 128 negative codes are dead.|r|max = 6، إذن S = 6 / 128 = 0.0469. الرموز من 0 إلى 127 فقط هي التي تُستخدم فعليًا، أما الرموز السالبة وعددها 128 فميتة.Asymmetricغير متماثل
S = (6 - 0) / (127 - (-128)) = 6 / 255 = 0.0235 and Z = round(q_min - r_min / S) = round(-128 - 0) = -128. All 256 codes cover real data.S = (6 - 0) / (127 - (-128)) = 6 / 255 = 0.0235 و Z = round(q_min - r_min / S) = round(-128 - 0) = -128. كل الرموز وعددها 256 تغطي بيانات حقيقية.Resultالنتيجة
Asymmetric gives a step about half as large (0.0235 versus 0.0469), so the worst-case rounding error S / 2 is halved. That is why activations keep a zero point.غير المتماثل يعطي خطوة بحجم النصف تقريبًا (0.0235 مقابل 0.0469)، لذلك ينخفض أسوأ خطأ تقريب S / 2 إلى النصف. ولهذا تحتفظ مخرجات التنشيط بنقطة صفر.
Recall
Why is Z_W = 0 a good choice for weights but Z_X = 0 a poor choice for ReLU activations?لماذا يكون Z_W = 0 اختيارًا جيدًا للأوزان بينما يكون Z_X = 0 اختيارًا سيئًا لمخرجات ReLU؟
Run the running matrix through a symmetric quantizer. Its largest magnitude is 2.12, so the range is [-2.12, 2.12]. How big is one step?
مرّر المصفوفة المرافقة عبر مكمِّم متماثل. أكبر قيمة مطلقة فيها هي 2.12، لذلك المدى هو [-2.12, 2.12]. فكم حجم الخطوة الواحدة؟
Slide 16 puts the two scale formulas side by side. The asymmetric one is the familiar endpoint match from part two:
الشريحة 16 تضع صيغتي المقياس جنبًا إلى جنب. صيغة غير المتماثل هي مطابقة الطرفين المألوفة من الجزء الثاني:
The symmetric one comes from matching only the negative end. With Z = 0, the endpoint equation r_min = S(q_min - Z) becomes -|r|max = S q_min, and q_min = -2^(N-1):
أما صيغة المتماثل فتأتي من مطابقة الطرف السالب فقط. مع Z = 0 تصبح معادلة الطرف r_min = S(q_min - Z) هي -|r|max = S q_min، وq_min = -2^(N-1):
This is full range mode: it uses every code from -2^(N-1) up to 2^(N-1) - 1. For the running matrix in INT8, S = 2.12 / 128 = 0.01656.
هذا هو full range mode (نمط المدى الكامل): يستخدم كل الرموز من -2^(N-1) حتى 2^(N-1) - 1. للمصفوفة المرافقة بصيغة INT8 يكون S = 2.12 / 128 = 0.01656.
The value at the top does not fitالقيمة في الأعلى لا تتسع
The scale was fixed by the negative end. Now quantize the positive end: q = round(2.12 / 0.01656) = 128. But q_max = 127. Code 128 does not exist, so the value is clamped to 127 and comes back as 127 x 0.01656 = 2.103. In general, +|r|max maps to 2^(N-1), one step past q_max, because the signed range has one more negative code than positive.
المقياس حُدّد بواسطة الطرف السالب. الآن كمّم الطرف الموجب: q = round(2.12 / 0.01656) = 128. لكن q_max = 127. الرمز 128 غير موجود، لذلك تُحصر القيمة (clamp) إلى 127 وتعود بقيمة 127 x 0.01656 = 2.103. وبشكل عام، تُحوَّل +|r|max إلى 2^(N-1)، أي خطوة واحدة بعد q_max، لأن المدى ذا الإشارة فيه رمز سالب واحد زيادة على الرموز الموجبة.
Restricted range modeنمط المدى المقيّد
Many deployed toolchains give up the lonely -128 code instead. In restricted range mode the codes run from -(2^(N-1) - 1) to 2^(N-1) - 1, which is [-127, 127] for INT8, and the scale divides by q_max instead:
كثير من سلاسل الأدوات المستخدمة فعليًا تتخلى بدلًا من ذلك عن الرمز الوحيد -128. في restricted range mode (نمط المدى المقيّد) تمتد الرموز من -(2^(N-1) - 1) إلى 2^(N-1) - 1، أي [-127, 127] في INT8، ويُقسم المقياس على q_max بدلًا من ذلك:
Now both +|r|max and -|r|max land exactly on a code, and nothing clips. The cost is one code out of 2^N. TensorFlow Lite stores int8 weights in [-127, 127] with zero point 0, and NVIDIA's int8 workflow (Wu et al.) makes the same choice, noting that losing one value of 256 is insignificant at 8 bits but must be reconsidered at lower bit widths.
الآن تقع كل من +|r|max و-|r|max على رمز بالضبط، ولا يُقصّ شيء. الثمن رمز واحد من أصل 2^N. يخزّن TensorFlow Lite أوزان int8 في [-127, 127] مع نقطة صفر 0، وسير عمل int8 من NVIDIA (Wu et al.) يتخذ الاختيار نفسه، مع ملاحظة أن خسارة قيمة واحدة من 256 لا تُذكر عند 8 بت، لكن يجب إعادة النظر فيها عند عروض بتات أقل.
Worked exampleمثال محلول
Three symmetric grids for the running matrix (|r|max = 2.12)ثلاث شبكات متماثلة للمصفوفة المرافقة (|r|max = 2.12)
INT8, full rangeINT8، بالمدى الكامل
S = 2.12 / 128 = 0.01656. 2.12 clips to 2.103.S = 2.12 / 128 = 0.01656. تُقصّ 2.12 إلى 2.103.INT8, restricted rangeINT8، بالمدى المقيّد
S = 2.12 / 127 = 0.01669. Slightly coarser, but 2.12 is code 127 exactly.S = 2.12 / 127 = 0.01669. أخشن قليلًا، لكن 2.12 هي الرمز 127 بالضبط.2-bit, full range2 بت، بالمدى الكامل
S = 2.12 / 2^1 = 1.06. Codes -2, -1, 0, 1 give the levels {-2.12, -1.06, 0, 1.06}. Quantize the top-left weight 2.09: 2.09 / 1.06 = 1.97, which rounds to 2, clips to q_max = 1, and comes back as 1.06.S = 2.12 / 2^1 = 1.06. الرموز -2, -1, 0, 1 تعطي المستويات {-2.12, -1.06, 0, 1.06}. كمّم الوزن في أعلى اليسار 2.09: 2.09 / 1.06 = 1.97، وهي تُقرّب إلى 2، ثم تُقصّ إلى q_max = 1، وتعود بقيمة 1.06.Resultالنتيجة
At 8 bits the two modes differ by less than one percent in S. At 2 bits the clipped weight is off by 2.09 - 1.06 = 1.03, about half its value. Compare the asymmetric 2-bit grid from part two (S = 1.07, Z = -1), which brings 2.09 back as 1.07 x (1 - (-1)) = 2.14, an error of only 0.05.عند 8 بت يختلف النمطان بأقل من واحد بالمئة في S. وعند 2 بت يبتعد الوزن المقصوص بمقدار 2.09 - 1.06 = 1.03، أي حوالي نصف قيمته. قارن ذلك بالشبكة غير المتماثلة بـ2 بت من الجزء الثاني (S = 1.07، Z = -1)، التي تعيد 2.09 بقيمة 1.07 x (1 - (-1)) = 2.14، بخطأ قدره 0.05 فقط.
The trade-off, on the same tensorالمقايضة على نفس الموتر
The running matrix is skewed: its values reach +2.12 but only -1.08. Asymmetric INT8 fits that exactly with S = 3.20 / 255 = 0.01255. Symmetric must cover [-2.12, 2.12] and uses S = 0.01656, about 32% coarser, and the codes below round(-1.08 / 0.01656) = -65 are never used: 63 of 256 codes, roughly a quarter, are wasted. Drag the slider below from a balanced range to a fully one-sided one and watch the symmetric grid stay frozen while the asymmetric one follows the data.
المصفوفة المرافقة منحرفة: قيمها تصل إلى +2.12 لكنها لا تنزل إلا إلى -1.08. التكميم غير المتماثل بـINT8 يطابق ذلك تمامًا بـS = 3.20 / 255 = 0.01255. أما المتماثل فيجب أن يغطي [-2.12, 2.12] ويستخدم S = 0.01656، أي أخشن بحوالي 32%، والرموز الأقل من round(-1.08 / 0.01656) = -65 لا تُستخدم أبدًا: 63 رمزًا من 256، أي ربع الرموز تقريبًا، تضيع. حرّك المنزلق أدناه من مدى متوازن إلى مدى في جهة واحدة بالكامل، وراقب كيف تبقى الشبكة المتماثلة ثابتة بينما تتبع الشبكة غير المتماثلة البيانات.
| Asymmetricغير متماثل | Symmetric (full range)متماثل (بالمدى الكامل) | |
|---|---|---|
| Zero pointنقطة الصفر | Z = round(q_min - r_min / S)Z = round(q_min - r_min / S) | Z = 0Z = 0 |
| Range quantizedالمدى المكمَّم | [r_min, r_max][r_min, r_max] | [-|r|max, |r|max][-|r|max, |r|max] |
| Scaleالمقياس | (r_max - r_min) / (q_max - q_min)(r_max - r_min) / (q_max - q_min) | |r|max / 2^(N-1)|r|max / 2^(N-1) |
| Skewed dataالبيانات المنحرفة | Uses every codeيستخدم كل الرموز | Wastes the empty sideيضيّع الجهة الفارغة |
| Runtime cost in matmulكلفة وقت التشغيل في ضرب المصفوفات | Extra input-dependent termحدّ إضافي يعتمد على المُدخل | Noneلا شيء |
| Typical useالاستخدام المعتاد | ReLU activationsمخرجات ReLU | Weightsالأوزان |
Quick checkاختبار سريع
With N = 4 bits and |r|max = 2.4, what is the full range symmetric scale S?إذا كان N = 4 بت و |r|max = 2.4، فما قيمة المقياس المتماثل بالمدى الكامل S؟
Recall
In full range mode, what code does +|r|max map to, and what happens to it?في نمط المدى الكامل، إلى أي رمز تتحول +|r|max، وماذا يحدث لها؟
Here is the payoff. Recall the full expansion of a quantized matrix multiplication from part three, with its four terms inside the bracket:
هنا تأتي الفائدة. تذكّر المفكوك الكامل لـquantized matrix multiplication (ضرب المصفوفات المكمّم) من الجزء الثالث، بحدوده الأربعة داخل القوس:
Sort the terms by what they depend on. q_W q_X is the real work: integer multiply-accumulates. Z_X q_W and Z_W Z_X involve only weights and fixed parameters, so they are precomputed offline. That leaves Z_W q_X: it contains the input, so it has to be recomputed for every new input, as an extra sum over the activations. Set Z_W = 0 and both Z_W q_X and Z_W Z_X disappear:
رتّب الحدود بحسب ما تعتمد عليه. q_W q_X هو العمل الحقيقي: عمليات ضرب وتجميع بالأعداد الصحيحة. Z_X q_W وZ_W Z_X لا تتضمنان إلا الأوزان ومعاملات ثابتة، لذلك تُحسبان مسبقًا (precomputed) خارج وقت التشغيل. يبقى Z_W q_X: فهو يحتوي على المُدخل، لذلك يجب إعادة حسابه لكل مُدخل جديد، كمجموع إضافي على قيم التنشيط. اجعل Z_W = 0 فيختفي كل من Z_W q_X وZ_W Z_X:
At inference time the only work inside the bracket is the N-bit integer product q_W q_X, summed in a 32-bit accumulator. The term Z_X q_W is a constant per output, added once. Outside the bracket, the rescale by S_W S_X / S_Y and the addition of Z_Y are unchanged from part three.
وقت الاستدلال، العمل الوحيد داخل القوس هو حاصل الضرب الصحيح بـN بت q_W q_X، الذي يُجمع في 32-bit accumulator (مجمّع بـ32 بت). الحد Z_X q_W ثابت لكل مخرج، ويُضاف مرة واحدة. وخارج القوس، تبقى rescale (إعادة القياس) بـS_W S_X / S_Y وإضافة Z_Y دون تغيير عن الجزء الثالث.
Worked exampleمثال محلول
One output of a two-term dot productمخرج واحد لضرب نقطي من حدّين
Set upالإعداد
Weights q_W = [3, -2] (symmetric, Z_W = 0), activations q_X = [10, 4] with Z_X = 2.الأوزان q_W = [3, -2] (متماثلة، Z_W = 0)، ومخرجات التنشيط q_X = [10, 4] مع Z_X = 2.Runtimeوقت التشغيل
q_W q_X = 3 x 10 + (-2) x 4 = 22.q_W q_X = 3 x 10 + (-2) x 4 = 22.Offlineمسبقًا خارج وقت التشغيل
Z_X q_W = 2 x (3 + (-2)) = 2, known before any input arrives.Z_X q_W = 2 x (3 + (-2)) = 2، وهو معروف قبل وصول أي مُدخل.Resultالنتيجة
Accumulator = 22 - 2 = 20. Check directly: 3 x (10 - 2) + (-2) x (4 - 2) = 24 - 4 = 20. Had the weights used Z_W = 1, the term Z_W (10 + 4) = 14 would also be needed, and its 10 + 4 changes with every input.المجمّع = 22 - 2 = 20. تحقّق مباشرة: 3 x (10 - 2) + (-2) x (4 - 2) = 24 - 4 = 20. لو استخدمت الأوزان Z_W = 1 لاحتجنا أيضًا إلى الحد Z_W (10 + 4) = 14، والجزء 10 + 4 فيه يتغير مع كل مُدخل.
Recall
Why ask for Z_W = 0 but not Z_X = 0?لماذا نطلب Z_W = 0 ولا نطلب Z_X = 0؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- Symmetric quantization fixes Z = 0 and quantizes the range [-|r|max, |r|max]; asymmetric keeps a free Z and fits [r_min, r_max].التكميم المتماثل يثبّت Z = 0 ويكمّم المدى [-|r|max, |r|max]، أما غير المتماثل فيترك Z حرًّا ويطابق المدى [r_min, r_max].
- Asymmetric: S = (r_max - r_min) / (q_max - q_min). Symmetric full range: S = r_min / (q_min - Z) = -|r|max / q_min = |r|max / 2^(N-1).غير المتماثل: S = (r_max - r_min) / (q_max - q_min). المتماثل بالمدى الكامل: S = r_min / (q_min - Z) = -|r|max / q_min = |r|max / 2^(N-1).
- Full range maps +|r|max to code 2^(N-1), one step past q_max = 2^(N-1) - 1, so the largest positive value is clipped.المدى الكامل يحوّل +|r|max إلى الرمز 2^(N-1)، أي خطوة واحدة بعد q_max = 2^(N-1) - 1، لذلك تُقصّ أكبر قيمة موجبة.
- Restricted range (not on the slides) uses S = |r|max / (2^(N-1) - 1) and codes [-127, 127] for INT8, giving up one code to stay symmetric.المدى المقيّد (غير موجود في الشرائح) يستخدم S = |r|max / (2^(N-1) - 1) والرموز [-127, 127] في INT8، فيتنازل عن رمز واحد ليبقى متماثلًا.
- Running matrix (|r|max = 2.12): INT8 full range S = 0.01656, restricted S = 0.01669, 2-bit S = 1.06 with levels {-2.12, -1.06, 0, 1.06}.المصفوفة المرافقة (|r|max = 2.12): INT8 بالمدى الكامل S = 0.01656، وبالمدى المقيّد S = 0.01669، وبـ2 بت S = 1.06 مع المستويات {-2.12, -1.06, 0, 1.06}.
- At 2 bits, 2.09 / 1.06 = 1.97 rounds to 2, clips to 1 and comes back as 1.06: an error of 1.03.عند 2 بت: 2.09 / 1.06 = 1.97 تُقرّب إلى 2، ثم تُقصّ إلى 1، وتعود بقيمة 1.06، أي بخطأ قدره 1.03.
- Weights are bell-shaped around 0, so they go symmetric. ReLU activations are one-sided, so they stay asymmetric with Z_X not 0.الأوزان على شكل جرس حول 0، لذلك تُكمَّم تكميمًا متماثلًا. مخرجات ReLU في جهة واحدة، لذلك تبقى غير متماثلة مع Z_X لا يساوي 0.
- With Z_W = 0: q_Y = (S_W S_X / S_Y)(q_W q_X - Z_X q_W) + Z_Y. Only q_W q_X runs at inference; Z_X q_W is precomputed.مع Z_W = 0: q_Y = (S_W S_X / S_Y)(q_W q_X - Z_X q_W) + Z_Y. وحده q_W q_X يُحسب أثناء الاستدلال، أما Z_X q_W فيُحسب مسبقًا.
- Bias uses Z_b = 0 and S_b = S_W S_X so q_b adds straight into the int32 accumulator: S_Y(q_Y - Z_Y) = S_W S_X(q_W q_X - Z_X q_W + q_b).الانحياز يستخدم Z_b = 0 وS_b = S_W S_X حتى يُضاف q_b مباشرة إلى المجمّع int32: S_Y(q_Y - Z_Y) = S_W S_X(q_W q_X - Z_X q_W + q_b).
- S_b is tiny, so q_b is large: S_W = 0.01, S_X = 0.05, b = 0.37 gives q_b = 740, which needs 32 bits.S_b صغير جدًا، لذلك يكون q_b كبيرًا: S_W = 0.01 وS_X = 0.05 وb = 0.37 تعطي q_b = 740، وهذا يحتاج 32 بت.
Sourcesالمصادر
- Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only InferencePaperJacob et al., CVPR 2018Section 2.4: int32 bias with S_bias = S1 S2 and Z_bias = 0, and why bias error acts as a systematic offset.القسم 2.4: انحياز int32 مع S_bias = S1 S2 و Z_bias = 0، ولماذا يعمل خطأ الانحياز كإزاحة منهجية.(opens in a new tab)(يفتح في تبويب جديد)
- LiteRT 8-bit quantization specificationDocsGoogle AI EdgeWeights symmetric in [-127, 127] with zero point 0, activations asymmetric, bias int32 with scale input_scale x weight_scale.الأوزان متماثلة في [-127, 127] مع نقطة صفر 0، ومخرجات التنشيط غير متماثلة، والانحياز int32 بمقياس input_scale x weight_scale.(opens in a new tab)(يفتح في تبويب جديد)
- Integer Quantization for Deep Learning Inference: Principles and Empirical EvaluationPaperWu, Judd, Zhang, Isaev, Micikevicius (NVIDIA), 2020Scale quantization with the restricted range [-127, 127], and why affine weights add an input-dependent term.تكميم المقياس (scale quantization) بالمدى المقيّد [-127, 127]، ولماذا تضيف الأوزان المُزاحة (affine) حدًّا يعتمد على المُدخل.(opens in a new tab)(يفتح في تبويب جديد)
- A White Paper on Neural Network QuantizationPaperNagel et al. (Qualcomm AI Research), 2021Section 2.4.1: symmetric weights and asymmetric activations avoid the data-dependent term; bias kept at 32 bits.القسم 2.4.1: الأوزان المتماثلة ومخرجات التنشيط غير المتماثلة تتجنب الحد المعتمد على البيانات، ويبقى الانحياز بـ 32 بت.(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 6: Quantization (Part II)ArticleSong Han, MITThe lecture these slides are adapted from.المحاضرة التي اقتُبست منها هذه الشرائح.(opens in a new tab)(يفتح في تبويب جديد)