Lecture 03 · NN Efficiency Metrics
المحاضرة 03 · مقاييس كفاءة الشبكات العصبية
Latency = max(compute, memory) and the energy table
Latency = max(compute, memory) وجدول الطاقة
P1 MUSTA one-line model that splits latency into what the network asks for and what the chip can deliver, and a table of picojoules showing that moving data costs far more than computing on it.
نموذج من سطر واحد يقسم الـ latency إلى ما تطلبه الشبكة وما يستطيع المعالج تقديمه، وجدول بالـ picojoules يبيّن أن نقل البيانات أغلى بكثير من الحساب عليها.
The latency model
نموذج الـ latency
Slide 8 writes latency as the larger of two times, because a processor fetches data and computes at the same time (the two overlap), so whichever takes longer sets the pace:
تكتب الشريحة 8 الـ latency على أنه الأكبر بين زمنين، لأن المعالج يجلب البيانات ويحسب في الوقت نفسه (يتداخلان)، فالأبطأ منهما هو الذي يحدد الإيقاع:
Latency ≈ max( Tcomputation, Tmemory )
Tcomputation ≈ number of operations in the NN modelnumber of operations the processor can do per second
Tmemory ≈ Tdata movement of activations + Tdata movement of weights
Tweights ≈ NN model sizememory bandwidth of processor Tactivations ≈ input activation size + output activation sizememory bandwidth of processor
The slide colours every fraction the same way: every numerator is an NN specification (operations, model size, activation size: things you change by redesigning the network), and every denominator is a hardware specification (OPS, bandwidth: things you change by buying a different chip).
تلوّن الشريحة كل كسر بالطريقة نفسها: كل بسط هو NN specification (عدد العمليات، model size، حجم activations: أشياء تغيّرها بإعادة تصميم الشبكة)، وكل مقام هو hardware specification (OPS، bandwidth: أشياء تغيّرها بشراء معالج آخر).
Compute-bound or memory-bound
محدود بالحساب (compute-bound) أم محدود بالذاكرة (memory-bound)
Whichever term wins the max names the bottleneck:
الحد الذي يفوز في max هو اسم عنق الزجاجة:
Compute-bound: Tcomp > Tmem
محدود بالحساب (compute-bound): Tcomp > Tmem
The arithmetic units are the bottleneck. A faster processor (more OPS) or fewer operations (fewer MACs) cuts latency.
وحدات الحساب هي عنق الزجاجة. معالج أسرع (OPS أكثر) أو عمليات أقل (MACs أقل) يقلّل الـ latency.
Memory-bound: Tmem > Tcomp
محدود بالذاكرة (memory-bound): Tmem > Tcomp
The memory bus is the bottleneck. More OPS does nothing. You need fewer bytes (smaller weights via pruning or quantization, smaller activations) or more bandwidth.
ناقل الذاكرة هو عنق الزجاجة. زيادة OPS لا تفيد شيئاً. تحتاج بايتات أقل (أوزان أصغر عبر pruning أو quantization، activations أصغر) أو bandwidth أكبر.
A CNN needs 1 GOP per image, has 12.5 M weights, and moves 20 MB of input plus output activations. The chip has 10 GB/s of memory bandwidth. Try three configurations.
شبكة CNN تحتاج 1 GOP لكل صورة، ولديها 12.5 M وزن، وتنقل 20 MB من activations (مدخلات ومخرجات). المعالج لديه bandwidth قدره 10 GB/s. جرّب ثلاث حالات.
Fixed: T_act = 20 MB / 10 GB/s = 2 ms
(1) 100 GOPS chip, 32-bit weights
T_comp = 1 GOP / 100 GOPS = 10 ms
T_w = 12.5 M x 4 B = 50 MB / 10 GB/s = 5 ms
T_mem = 5 + 2 = 7 ms
latency = max(10, 7) = 10 ms compute-bound
(2) 200 GOPS chip (2x faster), 32-bit weights
T_comp = 1 / 200 = 5 ms
T_mem = 5 + 2 = 7 ms
latency = max(5, 7) = 7 ms memory-bound
2x the OPS bought only 10 -> 7 ms (1.43x)
(3) 200 GOPS chip, 8-bit weights (quantized)
T_w = 12.5 MB / 10 GB/s = 1.25 ms
T_mem = 1.25 + 2 = 3.25 ms
latency = max(5, 3.25) = 5 ms compute-bound again
Step (2) is the lesson: once memory-bound, a faster processor stops helping. Step (3) shows the fix is on the NN side: shrink the numerator of Tw.
الخطوة (2) هي الدرس: بمجرد أن يصبح النظام memory-bound يتوقف المعالج الأسرع عن المساعدة. والخطوة (3) تبيّن أن الحل من جهة الشبكة: تصغير بسط Tw.
Max, not sum. Writing latency = Tcomp + Tmem = 17 ms in step (1) is the classic error. The slide uses max because fetching and computing overlap. Inside Tmem, however, weights and activations are added, because they share the same memory bus.
Max وليس مجموعاً. كتابة latency = Tcomp + Tmem = 17 ms في الخطوة (1) هي الخطأ الكلاسيكي. الشريحة تستخدم max لأن الجلب والحساب يتداخلان. لكن داخل Tmem نفسه يُجمع زمن الأوزان وزمن activations، لأنهما يتشاركان ناقل الذاكرة نفسه.
Activation size is input plus output. Slide 8's numerator for Tactivations is input activation size + output activation size, not just the output.
حجم activations هو المدخل زائد المخرج. بسط Tactivations في الشريحة 8 هو input activation size + output activation size، وليس المخرج وحده.
The energy table (slide 9)
جدول الطاقة (الشريحة 9)
Slide 9's headline is a causal chain: data movement → more memory references → more energy. The table (Horowitz, ISSCC 2014) gives rough costs at 45 nm, 0.9 V:
عنوان الشريحة 9 سلسلة سببية: data movement → more memory reference → more energy. والجدول (Horowitz, ISSCC 2014) يعطي تكاليف تقريبية عند 45 nm, 0.9 V:
| Operation (32-bit)العملية (32-bit) | Energy [pJ]الطاقة [pJ] | Relative to int ADDنسبةً إلى int ADD |
|---|---|---|
| int ADD | 0.1 | 1x |
| float ADD | 0.9 | 9x |
| Register fileملف المسجّلات (register file) | 1 | 10x |
| int MULT | 3.1 | 31x |
| float MULT | 3.7 | 37x |
| SRAM cacheذاكرة SRAM المخبئية (cache) | 5 | 50x |
| DRAM memoryذاكرة DRAM | 640 | 6400x |
يعرض الجدول تكلفة الطاقة لكل عملية 32-bit. ما يجب ملاحظته: العمليات الحسابية كلها بين 0.1 و3.7 pJ، والوصول إلى SRAM قريب منها (5 pJ)، أما الوصول إلى DRAM فيقفز إلى 640 pJ، أي أكثر بمرتبتين من الحساب. هذه القفزة هي سبب كل تقنيات الضغط في المقرر.
"One DRAM read buys about 200 multiplies." 640 / 3.1 ≈ 206, which the slide rounds to the 200x arrow.
"قراءة واحدة من DRAM تعادل حوالي 200 عملية ضرب." 640 / 3.1 ≈ 206، وتقرّبها الشريحة إلى سهم 200x.
Three ratios to have ready: DRAM / int MULT ≈ 206; DRAM / SRAM = 640 / 5 = 128; float ADD / int ADD = 0.9 / 0.1 = 9.
ثلاث نسب جاهزة في ذهنك: DRAM / int MULT ≈ 206؛ DRAM / SRAM = 640 / 5 = 128؛ float ADD / int ADD = 0.9 / 0.1 = 9.
Same 12.5 M-weight CNN, 32-bit weights, about 0.5 G multiply-accumulates per image. Estimate energy per image.
نفس الشبكة بـ 12.5 M وزن، أوزان 32-bit، وحوالي 0.5 G عملية multiply-accumulate لكل صورة. قدّر الطاقة لكل صورة.
Weights read once from DRAM 12.5e6 x 640 pJ = 8.0e9 pJ = 8.0 mJ Same weights read from on-chip SRAM instead 12.5e6 x 5 pJ = 6.25e7 pJ = 0.0625 mJ (128x less) Integer MACs (MULT 3.1 + ADD 0.1 = 3.2 pJ each) 0.5e9 x 3.2 pJ = 1.6e9 pJ = 1.6 mJ DRAM weight traffic / all the arithmetic = 8.0 / 1.6 = 5x
Fetching each weight once from DRAM costs five times more than every multiply and add in the network. Quantizing to 8-bit cuts the DRAM bytes 4x, and pruning removes weights entirely, which is why both techniques save energy and not only storage.
جلب كل وزن مرة واحدة من DRAM يكلّف خمسة أضعاف كل عمليات الضرب والجمع في الشبكة. الـ quantization إلى 8-bit يقلّل بايتات DRAM بمقدار 4x، والـ pruning يحذف أوزاناً بالكامل، ولهذا توفّر التقنيتان الطاقة وليس التخزين فقط.
Data movement dominates energy, not arithmetic. If asked "which costs more energy, a 32-bit float multiply or a 32-bit DRAM read?", the read wins by about 173x (640 / 3.7). Switching float to int arithmetic saves little (3.7 to 3.1 pJ for MULT); keeping data on-chip saves a lot.
نقل البيانات هو المهيمن على الطاقة، وليس الحساب. إذا سُئلت "أيهما أكثر استهلاكاً: ضرب float بـ 32-bit أم قراءة 32-bit من DRAM؟" فالقراءة تفوز بحوالي 173x (640 / 3.7). التحويل من float إلى int يوفّر قليلاً (3.7 إلى 3.1 pJ للضرب)؛ أما إبقاء البيانات داخل الشريحة فيوفّر كثيراً.
The numbers are per 32-bit operation at 45 nm. They are rough, process-specific values for comparing orders of magnitude, not exact costs for a modern chip.
الأرقام لكل عملية 32-bit عند 45 nm. هي قيم تقريبية خاصة بتقنية تصنيع معينة، للمقارنة بين المراتب العددية، وليست تكاليف دقيقة لمعالج حديث.
Check yourself
اختبر نفسك
Tcomputation = 4 ms, Tweights = 3 ms, Tactivations = 2 ms. What is the latency estimate and the bottleneck?
Tcomputation = 4 ms، Tweights = 3 ms، Tactivations = 2 ms. ما تقدير الـ latency وما عنق الزجاجة؟
B. Tmemory = 3 + 2 = 5 ms (weights and activations share the bus, so they add). Latency ≈ max(4, 5) = 5 ms, memory-bound. A forgets to add the activation time. C sums everything. D uses only the weights term.
B. Tmemory = 3 + 2 = 5 ms (الأوزان والتنشيطات تتشارك الناقل، لذا يُجمع زمناهما). Latency ≈ max(4, 5) = 5 ms، أي محدود بالذاكرة. الخيار A ينسى إضافة زمن التنشيطات. والخيار C يجمع كل شيء. والخيار D يستخدم حد الأوزان وحده.
A model is memory-bound on its current chip. Which change is least likely to reduce latency?
نموذج يعمل بحالة memory-bound على معالجه الحالي. أي تغيير هو الأقل احتمالاً لتقليل الـ latency؟
C. More OPS shrinks Tcomputation, which is already the smaller term, so the max does not move. A and D shrink the NN-spec numerator of Tweights; B grows the hardware-spec denominator. All three shrink Tmemory.
C. زيادة OPS تقلّص Tcomputation، وهو أصلاً الحد الأصغر، لذا لا تتغير قيمة max. الخياران A وD يقلّصان بسط Tweights الذي يحدده تصميم الشبكة، والخيار B يكبّر المقام الذي يحدده العتاد. والثلاثة كلها تقلّص Tmemory.
From slide 9, roughly how many 32-bit integer multiplies cost the same energy as one 32-bit DRAM access?
بحسب الشريحة 9، كم عملية ضرب int بـ 32-bit تقريباً تكلّف طاقة وصول واحد بـ 32-bit إلى DRAM؟
A. 640 pJ / 3.1 pJ ≈ 206, the slide's 200x arrow. B is the DRAM / SRAM ratio (640 / 5). C is DRAM relative to an int ADD (640 / 0.1). D is float ADD relative to int ADD.
A. 640 pJ / 3.1 pJ ≈ 206، وهو سهم 200x في الشريحة. الخيار B هو نسبة DRAM / SRAM (640 / 5). والخيار C هو DRAM نسبةً إلى int ADD (640 / 0.1). والخيار D هو float ADD نسبةً إلى int ADD.
In slide 8's latency model, which quantity is a hardware specification?
في نموذج الـ latency في الشريحة 8، أي كمية هي hardware specification؟
D. Every denominator (OPS, memory bandwidth) is hardware; every numerator (operations, model size, activation sizes) is NN specification. A, B and C are all numerators, so you change them by redesigning, pruning or quantizing the network.
D. كل مقام (OPS، وعرض نطاق الذاكرة) خاصية للعتاد، وكل بسط (العمليات، وحجم النموذج، وأحجام التنشيطات) خاصية لتصميم الشبكة العصبية. الخيارات A وB وC كلها بسوط، لذا تغيّرها بإعادة تصميم الشبكة أو تقليمها أو تكميمها.