Majid Al-RaimiReference sheetالورقة المرجعية

COE 592Lecture 03المحاضرة 03Referenceالمرجع

Reference sheetالورقة المرجعية

Neural network efficiency metrics compressed onto one page: the definitions, formulas and numbers to have in your head before a quiz or exam.محاضرة «مقاييس كفاءة الشبكات العصبية» مضغوطة في صفحة واحدة: التعريفات والمعادلات والأرقام التي يجب أن تكون حاضرة في ذهنك قبل الاختبار القصير أو الامتحان.

Efficiency triangleمثلث الكفاءة

Three goals, three costs, two resources. Memory feeds all three costs; computation feeds latency and energy. Part 01: Latency, throughput and energy

ثلاثة أهداف، وثلاث تكاليف، وموردان. الذاكرة تغذي التكاليف الثلاث كلها؛ والحساب يغذي الزمن والطاقة. الجزء 01: الزمن والإنتاجية والطاقة

GoalالهدفCostالتكلفةResourceالموردMetrics that predict itالمقاييس التي تتنبأ بها
SmallerأصغرStorageالتخزينMemoryالذاكرة#parameters, model size#parameters، وحجم النموذج
FasterأسرعLatencyالزمنComputation and memoryالحساب والذاكرةMACs, OPs, model size, peak #activationsMACs وOPs وحجم النموذج وذروة #activations
Greenerأوفر طاقةEnergyالطاقةComputation and memoryالحساب والذاكرةMACs, OPs, and above all the bytes movedMACs وOPs، وقبل كل شيء البايتات المنقولة
Goal, cost, resource and the metrics that predict itالهدف والتكلفة والمورد والمقاييس التي تتنبأ بها
GroupالمجموعةMembersالأعضاءHow obtainedطريقة الحصول عليهاPredictsما تتنبأ به
Memory-relatedمرتبطة بالذاكرة#parameters, model size, total and peak #activations#parameters، وحجم النموذج، ومجموع #activations وذروتهاCounted on paper from layer shapesتعد على الورق من أشكال الطبقاتStorage, and the memory share of latency and energyالتخزين، وحصة الذاكرة من الزمن والطاقة
Computation-relatedمرتبطة بالحسابMACs, FLOPs and FLOPS, OPs and OPSMACs، وFLOPs وFLOPS، وOPs وOPSCounts on paper, rates from the datasheetالأعداد على الورق، والمعدلات من ورقة البيانات (datasheet)The computation share of latency and energyحصة الحساب من الزمن والطاقة
The two metric groupsمجموعتا المقاييس

Latency and throughputالزمن والإنتاجية

PropertyالخاصيةLatencyالزمن (Latency)Throughputالإنتاجية (Throughput)
DefinitionالتعريفDelay to complete one specific taskالتأخير حتى إنجاز مهمة واحدة محددةWork completed per unit timeالعمل المنجز في وحدة الزمن
Also calledتسمى أيضاResponse time, execution timeزمن الاستجابة، زمن التنفيذBandwidthعرض النطاق (bandwidth)
Unitالوحدةmsimage/s
Measured atتقاس عندBatch size 1حجم دفعة 1Whatever batch fills the processorأي دفعة تملأ المعالج
Who caresمن يهتم بهاA brake camera, an on-device detectorكاميرا مكابح، كاشف يعمل على الجهازA data center indexing video overnightمركز بيانات يفهرس الفيديو طوال الليل
Batchingالتجميع في دفعات (batching)Raises it: each input waits for the whole batchيرفعه: كل مدخل ينتظر الدفعة كاملةRaises it: more inputs finish per secondيرفعها: عدد أكبر من المدخلات ينتهي كل ثانية
Definitions side by sideالتعريفان جنبا إلى جنب
throughput=bTbatch,latency=Tbatch\text{throughput} = \frac{b}{T_{\text{batch}}}, \qquad \text{latency} = T_{\text{batch}}
b inputs processed together in one batch of duration T_batchb من المدخلات تُعالج معًا في دفعة واحدة مدتها T_batch
DesignالتصميمHow inputs are handledطريقة معالجة المدخلاتLatencyالزمنInputs per batchالمدخلات في كل دفعةThroughputالإنتاجية
Design 1التصميم 1One image at a timeصورة واحدة في كل مرة50 ms11 / 0.050 = 20 image/s
Design 2التصميم 2Four images togetherأربع صور معا100 ms44 / 0.100 = 40 image/s
Server, batch 1خادم، دفعة 1One requestطلب واحد2 ms1500 image/s
Server, batch 32خادم، دفعة 32Thirty-two requestsاثنان وثلاثون طلبا8 ms324000 image/s
Batching raises both latency and throughputالتجميع في دفعات يرفع الزمن والإنتاجية معا

The four conditions every reported latency must state (slide 5 footnote)الشروط الأربعة التي يجب أن يذكرها كل زمن منشور (حاشية الشريحة 5)

Hardwareالعتاد
NVIDIA Jetson AGX Orin: 43 dense FP16 TFLOPS on Tensor Cores, 204.8 GB/s LPDDR5NVIDIA Jetson AGX Orin: 43 TFLOPS كثيفة بدقة FP16 على Tensor Cores، وذاكرة LPDDR5 بعرض نطاق 204.8 GB/s
Runtimeبيئة التشغيل
TensorRT
Precisionالدقة العددية
fp16
Batch sizeحجم الدفعة
1
ModelالنموذجmIoUmIoUParametersالمعاملاتMACsMACsOrin latencyالزمن على OrinA100 throughputالإنتاجية على A100
SegFormer-B582.485M1460G638 ms12 image/s
EfficientViT-L182.740M282G45.9 ms122 image/s
Ratioالنسبة+0.32.1x fewer2.1x أقل5.2x fewer5.2x أقل13.9x faster13.9x أسرع10x more10x أكثر
SegFormer-B5 versus EfficientViT-L1 on Cityscapes at 1024 x 2048SegFormer-B5 مقابل EfficientViT-L1 على Cityscapes بدقة 1024 x 2048

The latency modelنموذج الزمن

Data movement and computation overlap on real hardware, so the layer finishes when the slower stream finishes. Numerators are NN specification, denominators are hardware specification. Part 01: Latency, throughput and energy

نقل البيانات والحساب يتداخلان على العتاد الحقيقي، لذلك تنتهي الطبقة عندما ينتهي التيار الأبطأ منهما. البسوط هي مواصفة الشبكة (NN specification)، والمقامات هي مواصفة العتاد (hardware specification). الجزء 01: الزمن والإنتاجية والطاقة

Latency≈max⁡(Tcomputation,  Tmemory)\text{Latency} \approx \max\left(T_{\text{computation}},\; T_{\text{memory}}\right)
Max, not sum: the two streams overlapالحد الأقصى لا المجموع: التدفقان متداخلان
Tcomputation≈operations in the modeloperations per second,Tmemory≈Tmove(activations)+Tmove(weights)T_{\text{computation}} \approx \frac{\text{operations in the model}}{\text{operations per second}}, \qquad T_{\text{memory}} \approx T_{\text{move}}(\text{activations}) + T_{\text{move}}(\text{weights})
The memory terms add because both cross the same busحدود الذاكرة تُجمع لأن كليهما يعبر الناقل نفسه
Tmove(weights)≈model sizebandwidth,Tmove(activations)≈input size+output sizebandwidthT_{\text{move}}(\text{weights}) \approx \frac{\text{model size}}{\text{bandwidth}}, \qquad T_{\text{move}}(\text{activations}) \approx \frac{\text{input size} + \text{output size}}{\text{bandwidth}}
Bytes over bytes per secondبايتات مقسومة على بايتات في الثانية
TermالحدNumerator: NN specificationالبسط: مواصفة الشبكةDenominator: hardware specificationالمقام: مواصفة العتاد
T_computationNumber of operations (MACs, OPs)عدد العمليات (MACs، OPs)Operations per second (OPS)العمليات في الثانية (OPS)
T_move(weights)Model sizeحجم النموذجMemory bandwidthعرض نطاق الذاكرة
T_move(activations)Input activation size + output activation sizeحجم تنشيطات المدخل + حجم تنشيطات المخرجMemory bandwidthعرض نطاق الذاكرة
Each term, and which part of the lecture counts its numeratorكل حد، وأي جزء من المحاضرة يعد بسطه
ConfigurationالإعدادT_computationT_computationT_memoryT_memoryLatencyالزمنRegimeالنظام
100 GOPS, 32-bit weights100 GOPS، أوزان 32-bit10 ms5 + 2 = 7 ms10 msCompute-boundمحدود بالحساب
200 GOPS, 32-bit weights200 GOPS، أوزان 32-bit5 ms5 + 2 = 7 ms7 msMemory-boundمحدود بالذاكرة
200 GOPS, 8-bit weights200 GOPS، أوزان 8-bit5 ms1.25 + 2 = 3.25 ms5 msCompute-boundمحدود بالحساب
Toy model: 1 GOP of work, 50 MB weights, 20 MB activations, 10 GB/sنموذج مبسط: عمل بحجم 1 GOP، وأوزان 50 MB، وتنشيطات 20 MB، وعرض نطاق 10 GB/s
ModelالنموذجT_computationT_computationT_memoryT_memoryFloorالحد الأدنىMeasuredالمقاسMiss, utilisationالفجوة، ونسبة الاستغلال
EfficientViT-L1564 / 43 000 = 13.1 ms0.39 + 0.45 = 0.84 ms13.1 ms45.9 ms3.5x, about 29%3.5x، نحو 29%
SegFormer-B52920 / 43 000 = 68 ms0.83 + 0.45 = 1.3 ms68 ms638 ms9.4x, about 11%9.4x، نحو 11%
Slide 5 predicted from Orin datasheet numbers, fp16, 43 TFLOPS, 204.8 GB/sالشريحة 5 متنبأ بها من أرقام ورقة بيانات Orin، بدقة fp16، و43 TFLOPS، و204.8 GB/s

Energy of data movementطاقة نقل البيانات

45 nm, 0.9 V, 32-bit operations, Horowitz ISSCC 2014 as tabulated by Han et al. 2015. Part 01: Latency, throughput and energy

عمليات 32-bit عند 45 nm و0.9 V، من Horowitz ISSCC 2014 كما جدولها Han et al. 2015. الجزء 01: الزمن والإنتاجية والطاقة

Rough energy per operation (slide 9)الطاقة التقريبية لكل عملية (الشريحة 9)

int ADD
0.1 pJ
float ADD
0.9 pJ
Register file accessالوصول إلى ملف السجلات
1 pJ
int MULT
3.1 pJ
float MULT
3.7 pJ
SRAM cache accessالوصول إلى ذاكرة SRAM المخبئية
5 pJ
DRAM memory accessالوصول إلى ذاكرة DRAM
640 pJ
RatioالنسبةArithmeticالحسابMeaningالمعنى
DRAM over int MULTDRAM على int MULT640 / 3.1 ≈ 206The slide's 200xقيمة 200x في الشريحة
DRAM over one int MACDRAM على عملية MAC صحيحة واحدة640 / 3.2 = 200Exact reading of the slide iconالقراءة الدقيقة لأيقونة الشريحة
DRAM over SRAMDRAM على SRAM640 / 5 = 128Why on-chip storage is worth two decadesلماذا يستحق التخزين على الشريحة مرتبتين عشريتين
float ADD over int ADDfloat ADD على int ADD0.9 / 0.1 = 9The seed for quantizationالبذرة التي ينطلق منها التكميم
DRAM over int ADDDRAM على int ADD640 / 0.1 = 6400Three orders of magnitude (Han et al.)ثلاث مراتب عشرية (Han et al.)
Ratios worth memorizingنسب تستحق الحفظ
ItemالبندCountالعددEnergy eachطاقة الواحدةTotalالمجموع
Integer MACsعمليات MAC صحيحة724M3.1 + 0.1 = 3.2 pJ2.32 mJ
Weights read once from DRAMالأوزان مقروءة مرة واحدة من DRAM61M640 pJ39.0 mJ
Same weights read from SRAMالأوزان نفسها مقروءة من SRAM61M5 pJ0.31 mJ
Float MACs instead of integerعمليات MAC عائمة بدلا من الصحيحة724M3.7 + 0.9 = 4.6 pJ3.33 mJ
One AlexNet inference: 724M MACs, 61M weightsاستدلال واحد لـ AlexNet: 724M من MACs، و61M من الأوزان

Counting formulas for parameters and MACsصيغ عد المعاملات وMACs

Bias is ignored throughout. Parameters never depend on n, h or w; MACs multiply by h_o · w_o because every filter is reapplied at every output position. Part 02: Parameters and model size, Part 04: MACs, FLOPs and operations

الانحياز (bias) مهمل في كل ما يلي. المعاملات لا تعتمد أبدا على n أو h أو w؛ أما MACs فتضرب في h_o · w_o لأن كل مرشح (filter) يعاد تطبيقه عند كل موضع في المخرج. الجزء 02: المعاملات وحجم النموذج، الجزء 04: MACs وFLOPs والعمليات

Notationالرموز

n
Batch sizeحجم الدفعة
c_i, c_o
Input and output channels (features for a linear layer)قنوات المدخل والمخرج (الخصائص features في الطبقة الخطية)
h_i, w_i, h_o, w_o
Input and output height and widthارتفاع المدخل والمخرج وعرضهما
k_h, k_w
Kernel height and widthارتفاع النواة (kernel) وعرضها
g
Number of groups in a grouped convolutionعدد المجموعات في الالتفاف المجمع (grouped convolution)
Layerالطبقة#Parameters#ParametersMACsMACsMACs per parameterMACs لكل معامل
Linearخطية (Linear)c_o · c_ic_o · c_i1
Convolutionالتفافية (Convolution)c_o · c_i · k_h · k_wc_o · c_i · k_h · k_w · h_o · w_oh_o · w_o
Grouped convolutionالتفاف مجمع (Grouped convolution)c_o · c_i · k_h · k_w / gc_o · c_i · k_h · k_w · h_o · w_o / gh_o · w_o
Depthwise convolutionالتفاف عمقي (Depthwise convolution)c_o · k_h · k_wc_o · k_h · k_w · h_o · w_oh_o · w_o
Poolingتجميع (Pooling)00
Per layer type, batch size 1حسب نوع الطبقة، بحجم دفعة 1
#Paramsgrouped=cog⋅cig⋅khkw⋅g=co⋅ci⋅kh⋅kwg\#\text{Params}_{\text{grouped}} = \frac{c_o}{g}\cdot\frac{c_i}{g}\cdot k_h k_w \cdot g = \frac{c_o \cdot c_i \cdot k_h \cdot k_w}{g}
Each group loses g squared, but there are g groups: one division by gكل مجموعة تخسر g تربيع، لكن هناك g مجموعة: أي قسمة واحدة على g
MACsMV=m⋅nMACsGEMM=m⋅n⋅ka←a+b⋅c\text{MACs}_{MV} = m \cdot n \qquad \text{MACs}_{GEMM} = m \cdot n \cdot k \qquad a \leftarrow a + b \cdot c
Matrix-vector, matrix-matrix, and the MAC itselfمصفوفة في متجه، ومصفوفة في مصفوفة، وعملية MAC نفسها
LayerالطبقةCountالعد#Parameters#ParametersRatioالنسبة
Standard, g = 1قياسية، g = 1256 · 256 · 9589,8241
Grouped, g = 2مجمعة، g = 2256 · 256 · 9 / 2294,9121/2
Grouped, g = 8مجمعة، g = 8256 · 256 · 9 / 873,7281/8
Depthwise, g = 256عمقية، g = 256256 · 92,3041/256
One 3 x 3 layer, 256 in and 256 out, under each groupingطبقة 3 x 3 واحدة، 256 قناة دخل و256 قناة خرج، تحت كل نوع من التجميع
LayerالطبقةCountالعدMACsMACs
Standard 3 × 3قياسية 3 × 364 · 32 · 9 · 112 · 112231,211,008
Depthwise 3 × 3عمقية 3 × 332 · 9 · 112 · 1123,612,672
Pointwise 1 × 1نقطية 1 × 164 · 32 · 112 · 11225,690,112
Separable over standardالقابلة للفصل (separable) على القياسية1 / 64 + 1 / 90.1267, about 7.9x fewer0.1267، أي نحو 7.9x أقل
MobileNet block at 112 x 112, 32 to 64 channels: MACsكتلة MobileNet عند 112 x 112، من 32 إلى 64 قناة: MACs

AlexNet, every columnAlexNet، كل الأعمدة

Input 3 × 224 × 224. The linear layers hold 96% of the weights and do 8% of the MACs; the convolutions are the reverse. Part 02, Part 03, Part 04

المدخل 3 × 224 × 224. الطبقات الخطية تحمل 96% من الأوزان وتنفذ 8% من MACs؛ والطبقات الالتفافية عكس ذلك. الجزء 02، الجزء 03، الجزء 04

LayerالطبقةOutput C × H × Wالمخرج C × H × WActivationsالتنشيطات#Parameters#ParametersMACsMACsMACs per parameterMACs لكل معامل
Imageالصورة3 × 224 × 224150,52800
conv1, 11 × 11, stride 4, pad 2conv1، 11 × 11، خطوة 4، حشو 296 × 55 × 55290,40034,848105,415,2003,025
maxpool96 × 27 × 2769,98400
conv2, 5 × 5, pad 2, g = 2conv2، 5 × 5، حشو 2، g = 2256 × 27 × 27186,624307,200223,948,800729
maxpool256 × 13 × 1343,26400
conv3, 3 × 3, pad 1conv3، 3 × 3، حشو 1384 × 13 × 1364,896884,736149,520,384169
conv4, 3 × 3, pad 1, g = 2conv4، 3 × 3، حشو 1، g = 2384 × 13 × 1364,896663,552112,140,288169
conv5, 3 × 3, pad 1, g = 2conv5، 3 × 3، حشو 1، g = 2256 × 13 × 1343,264442,36874,760,192169
maxpool256 × 6 × 69,21600
fc6, 9,216 → 409640964,09637,748,73637,748,7361
fc7, 4096 → 409640964,09616,777,21616,777,2161
fc8, 4096 → 100010001,0004,096,0004,096,0001
Five convolutionsالطبقات الالتفافية الخمس2,332,704 (3.8%)665,784,864 (91.9%)
Three linear layersالطبقات الخطية الثلاث58,621,952 (96.2%)58,621,952 (8.1%)
Totalالمجموع932,26460,954,656724,406,816
Output shape, output activations, parameters, MACs and uses per weight, per layerشكل المخرج، وتنشيطات المخرج، والمعاملات، وMACs، واستخدامات كل وزن، لكل طبقة

Model size from bit widthحجم النموذج من عرض البت

Model Size=#Parameters⋅Bit Width,SizeMB=#Parameters⋅bits8⋅106\text{Model Size} = \#\text{Parameters} \cdot \text{Bit Width}, \qquad \text{Size}_{\text{MB}} = \frac{\#\text{Parameters} \cdot \text{bits}}{8 \cdot 10^{6}}
The product is in bits; divide by 8 for bytes and by 10^6 for decimal MBالناتج بالبت؛ اقسم على 8 للبايت وعلى 10^6 للميغابايت العشري
Model Size=∑l#Paramsl⋅bitsl\text{Model Size} = \sum_{l} \#\text{Params}_l \cdot \text{bits}_l
Mixed precision: sum per layerالدقة المختلطة: اجمع لكل طبقة
Data typeنوع البياناتSize in bitsالحجم بالبتSize (decimal MB)الحجم (MB عشري)Slide roundingتقريب الشريحة
fp321,950.5 Mbit243.8 MB244 MB
fp16 or bf16fp16 أو bf16975.3 Mbit121.9 MB122 MB
int8487.6 Mbit61.0 MB61 MB
int4243.8 Mbit30.5 MB30.5 MB
1-bit61.0 Mbit7.6 MB7.6 MB
AlexNet at each bit width, exact count 60,954,656 and the slide's rounded 61MAlexNet عند كل عرض بت، بالعدد الدقيق 60,954,656 وبتقريب الشريحة 61M
  • 1 MB = 10^6 B and 1 MiB = 2^20 B (NIST). The slide's 244 MB is decimal, about 232.5 MiB. Say which you use.1 MB = 10^6 B و1 MiB = 2^20 B (حسب NIST). قيمة 244 MB في الشريحة عشرية، أي نحو 232.5 MiB. اذكر أيهما تستخدم.
  • The 8-bit size is simply N bytes. Forgetting the divide by 8 overstates the size eightfold and is the most common error on this question.الحجم عند 8-bit هو ببساطة N بايت. نسيان القسمة على 8 يضخم الحجم ثمانية أضعاف، وهو الخطأ الأكثر شيوعا في هذا السؤال.
  • Halving the bit width halves the size, not the accuracy; those are separate questions.تنصيف عرض البت ينصف الحجم، لا الدقة؛ فهذان سؤالان منفصلان.

Activations decide fitالتنشيطات تقرر الاتساع

SRAM constrains activations (read and write); flash constrains model size (read only). SRAM is the scarcer budget, so peak activation, not parameter count, decides whether a CNN runs on a microcontroller. Part 03: Activations and peak memory

ذاكرة SRAM تقيد التنشيطات (قراءة وكتابة)؛ وذاكرة flash تقيد حجم النموذج (قراءة فقط). وذاكرة SRAM هي الميزانية الأشح، لذلك فذروة التنشيط، لا عدد المعاملات، هي التي تقرر هل تعمل شبكة CNN على متحكم دقيق. الجزء 03: التنشيطات وذروة الذاكرة

TensorالموترLives inمكانهAccess patternنمط الوصولMetricالمقياسBudgetالميزانية
WeightsالأوزانFlashRead only, written once at flashingقراءة فقط، تكتب مرة واحدة عند التحميل (flashing)Model sizeحجم النموذجLarger, about 1 MB to 2 MBأكبر، نحو 1 MB إلى 2 MB
ActivationsالتنشيطاتSRAMWritten and read on every inferenceتكتب وتقرأ في كل استدلالPeak #activationsذروة #activationsSmaller, 256 kB to 512 kBأصغر، من 256 kB إلى 512 kB
Two budgets on a microcontrollerميزانيتان في المتحكم الدقيق
ModelالنموذجParam memory (flash)ذاكرة المعاملات (flash)Peak activation (SRAM)ذروة التنشيط (SRAM)Fits F746?يتسع في F746؟Fits H743?يتسع في H743؟
ResNet-1811.2 MB0.9 MBNoلاNoلا
MobileNetV2-0.752.5 MB1.7 MBNoلاNoلا
MCUNet1.9 MB0.49 MBNoلاYesنعم
Ratio ResNet-18 to MobileNetV2النسبة من ResNet-18 إلى MobileNetV24.6x smaller4.6x أصغر1.8x larger1.8x أكبر
Inference, int8, about 70 percent ImageNet top-1, against STM32F746 (1 MB flash, 320 kB SRAM) and STM32H743 (2 MB flash, 512 kB SRAM)الاستدلال، بدقة int8، ونحو 70 بالمئة top-1 على ImageNet، مقابل STM32F746 (1 MB flash و320 kB SRAM) وSTM32H743 (2 MB flash و512 kB SRAM)
ModelالنموذجWeightsالأوزانActivationsالتنشيطاتActivations over weightsالتنشيطات على الأوزان
ResNet-50102 MB707 MBAbout 7xنحو 7x
MobileNetV2-1.4About 24 MBنحو 24 MBAbout 640 MBنحو 640 MBAbout 27xنحو 27x
Ratioالنسبة4.3x smaller4.3x أصغر1.1x smaller1.1x أصغر
Training, fp32, batch size 16 (TinyTL)التدريب، بدقة fp32، وحجم دفعة 16 (TinyTL)
∂L∂Wi=aiT ∂L∂ai+1,∂L∂bi=∂L∂ai+1\frac{\partial L}{\partial W_i} = a_i^{\mathsf{T}}\,\frac{\partial L}{\partial a_{i+1}}, \qquad \frac{\partial L}{\partial b_i} = \frac{\partial L}{\partial a_{i+1}}
Backprop needs the stored input a_i for the weight gradient, but not for the bias gradientالانتشار العكسي يحتاج المدخل المخزن a_i لتدرّج الوزن، لا لتدرّج الانحياز
ModeالوضعWhich activations are heldالتنشيطات المحتفظ بهاMemory ruleقاعدة الذاكرة
InferenceالاستدلالInput and output of the layer running nowمدخل الطبقة العاملة الآن ومخرجهاLargest input + output pairأكبر زوج مدخل + مخرج
TrainingالتدريبEvery layer input a_i until dL/dW_i is computedكل مدخل طبقة a_i حتى يحسب dL/dW_iSum of all activations × batch size, plus weights, gradients and optimizer stateمجموع كل التنشيطات × حجم الدفعة، مضافا إليه الأوزان والتدرجات وحالة المحسّن (optimizer state)
What must be alive at onceما يجب أن يكون حيا في الذاكرة في الوقت نفسه
StageالمرحلةShapeالشكلDominant tensorالموتر المهيمنWhat it decidesما يقرره
Early layersالطبقات المبكرةLarge H × W, few channelsH × W كبير، وقنوات قليلةActivationsالتنشيطاتSRAM peak; patch-based inference fixes itذروة SRAM؛ والاستدلال القائم على الرقع (patch-based inference) يعالجها
Middle layersالطبقات الوسطىBoth smallكلاهما صغيرNeitherلا هذا ولا ذاكCheapest place for on-device trainingأرخص مكان للتدريب على الجهاز
Late layersالطبقات المتأخرةLarge C_o · C_i, tiny H × WC_o · C_i كبير، وH × W ضئيلWeightsالأوزانFlash budget; pruning and quantization pay hereميزانية flash؛ وهنا يؤتي التقليم والتكميم ثمارهما
Where memory sits across depth: resolution shrinks faster than channels growأين تقع الذاكرة عبر العمق: الدقة المكانية تتقلص أسرع مما تنمو القنوات

Total and peak activationsمجموع التنشيطات وذروتها

#acttotal=∣x0∣+∑i=1L∣ai∣,#actpeak≈max⁡i(∣ai−1∣+∣ai∣)\#\text{act}_{\text{total}} = |x_0| + \sum_{i=1}^{L} |a_i|, \qquad \#\text{act}_{\text{peak}} \approx \max_{i}\big(|a_{i-1}| + |a_i|\big)
Sum every tensor for the total; scan adjacent input + output pairs for the peakاجمع كل الموترات للحصول على الإجمالي؛ وافحص أزواج المدخل والمخرج المتجاورة للحصول على الذروة

AlexNet adjacent pair sums; the first pair winsمجاميع الأزواج المتجاورة في AlexNet؛ الزوج الأول هو الأكبر

conv1 (image + conv1 out)conv1 (الصورة + مخرج conv1)
150,528 + 290,400 = 440,928
pool1 (conv1 out + pool1 out)pool1 (مخرج conv1 + مخرج pool1)
290,400 + 69,984 = 360,384
conv2 (pool1 out + conv2 out)conv2 (مخرج pool1 + مخرج conv2)
69,984 + 186,624 = 256,608
pool2 (conv2 out + pool2 out)pool2 (مخرج conv2 + مخرج pool2)
186,624 + 43,264 = 229,888
conv3 to fc8من conv3 إلى fc8
All under 130,000; fc8 is 4,096 + 1,000 = 5,096كلها أقل من 130,000؛ وfc8 تساوي 4,096 + 1,000 = 5,096
QuantityالكميةValuesالقيم8-bit8-bit32-bit32-bit
Peakالذروة440,928441 kB1.76 MB
Totalالمجموع932,264932 kB3.73 MB
MobileNetV2 first convأول طبقة التفافية في MobileNetV2150,528 + 401,408 = 551,936552 kB (539 KiB)2.21 MB
Values to bytes (decimal kB and MB)من القيم إلى البايتات (kB وMB عشرية)
  • Assumptions behind the approximation: layer-by-layer execution, weights streamed from flash and not counted, no residual branches (else add all branches alive at once, sharing the input), no in-place tricks (a depthwise layer can run in N + 1 instead of 2N), plus real runtimes add scratch buffers.الافتراضات وراء هذا التقريب: تنفيذ طبقة بعد طبقة، والأوزان تبث من flash ولا تحسب، ولا فروع بقايا (residual) (وإلا فأضف كل الفروع الحية في الوقت نفسه، وهي تتشارك المدخل)، ولا حيل تنفيذ في المكان (in-place) (فالطبقة العمقية يمكن أن تعمل في N + 1 بدلا من 2N)، يضاف إلى ذلك أن بيئات التشغيل الحقيقية تضيف مخازن مؤقتة (scratch buffers).
  • The peak is a pair, never the largest single tensor. Forgetting the input undercounts AlexNet by a third.الذروة زوج من الموترات، وليست أبدا أكبر موتر منفرد. نسيان المدخل ينقص عد AlexNet بمقدار الثلث.
  • The total (932,264) is what training holds; inference holds only the peak pair (440,928, about 47% of the total).المجموع (932,264) هو ما يحتفظ به التدريب؛ أما الاستدلال فيحتفظ بزوج الذروة فقط (440,928، أي نحو 47% من المجموع).
  • Per-layer input + output is also the activation traffic in T_move(activations) of the latency model.مجموع مدخل كل طبقة ومخرجها هو أيضا حركة التنشيطات في T_move(activations) ضمن نموذج الزمن.

FLOPs, OPs and computation timeFLOPs وOPs وزمن الحساب

Counts belong to models, rates belong to chips. Divide a count by a rate and you have a time. Part 04: MACs, FLOPs and operations

الأعداد تخص النماذج، والمعدلات تخص الشرائح. اقسم العدد على المعدل تحصل على زمن. الجزء 04: MACs وFLOPs والعمليات

FLOPs=2⋅MACs,FLOPS=FLOPssecond,Tcomputation=FLOPs of the modelFLOPS of the processor\text{FLOPs} = 2 \cdot \text{MACs}, \qquad \text{FLOPS} = \frac{\text{FLOPs}}{\text{second}}, \qquad T_{computation} = \frac{\text{FLOPs of the model}}{\text{FLOPS of the processor}}
One multiply plus one add per MAC; OPs and OPS are the same with any data typeضرب واحد وجمع واحد لكل MAC؛ وOPs وOPS هي نفسها مع أي نوع بيانات
TermالمصطلحKindالنوعMeaningالمعنىBelongs toيخص
MACCountعددOne multiply accumulated into a sumعملية ضرب واحدة تراكم في مجموعA model, per inferenceالنموذج، لكل استدلال
FLOPCountعددOne floating point multiply or add; a MAC is twoعملية ضرب أو جمع واحدة بالفاصلة العائمة؛ وعملية MAC الواحدة تساوي اثنتينA model, per inferenceالنموذج، لكل استدلال
OPCountعددOne operation of any data type; a MAC is twoعملية واحدة بأي نوع بيانات؛ وعملية MAC الواحدة تساوي اثنتينA model, per inferenceالنموذج، لكل استدلال
FLOPSRateمعدلFloating point operations per secondعمليات الفاصلة العائمة في الثانيةA processorالمعالج
OPSRateمعدلOperations per second, any data typeالعمليات في الثانية، بأي نوع بياناتA processorالمعالج
Five terms, two kinds of quantityخمسة مصطلحات، ونوعان من الكميات
ProcessorالمعالجCount ÷ rateالعدد ÷ المعدلT_computationT_computation
1 GFLOPS1.449 × 10^9 / 10^91,449 ms
100 GFLOPS1.449 × 10^9 / 10^1114.5 ms
1 TFLOPS1.449 × 10^9 / 10^121.45 ms
67 TOPS (Orin Nano, INT8 sparse peak)67 TOPS (Orin Nano، ذروة INT8 مع التناثر)1.449 × 10^9 / 6.7 × 10^130.022 ms
AlexNet's 1.449G FLOPs on different processorsعدد FLOPs في AlexNet البالغ 1.449G على معالجات مختلفة

Proceduresالإجراءات

Six steps that cover every numeric question in this lectureست خطوات تغطي كل سؤال عددي في هذه المحاضرة

1. Parameters1. المعاملات
One formula instance per weighted layer, pooling is 0, write /g explicitly, sum. Add a share column if asked which layer dominates.صيغة واحدة لكل طبقة ذات أوزان، والتجميع (pooling) يساوي 0، واكتب /g صراحة، ثم اجمع. أضف عمودا للحصص إذا سئلت أي طبقة تهيمن.
2. Model size2. حجم النموذج
Bits first (N × bits), divide by 8 for bytes, then by 10^6, and say "decimal MB".البتات أولا (N × bits)، ثم اقسم على 8 لتحصل على البايتات، ثم على 10^6، وقل "MB عشري".
3. Activations3. التنشيطات
Write the C × H × W column, sum for the total, scan adjacent input + output pairs for the peak, multiply by bytes per value last. State the layer-by-layer assumption.اكتب عمود C × H × W، واجمعه لتحصل على المجموع، وافحص أزواج المدخل + المخرج المتجاورة لتحصل على الذروة، واضرب في عدد البايتات لكل قيمة في النهاية. اذكر افتراض التنفيذ طبقة بعد طبقة.
4. MACs4. MACs
Parameter formula with h_o · w_o appended; h_o · w_o = 1 for a linear layer; c_i drops out of depthwise.صيغة المعاملات مضافا إليها h_o · w_o؛ وh_o · w_o = 1 في الطبقة الخطية؛ وc_i يختفي من الطبقة العمقية (depthwise).
5. Time5. الزمن
FLOPs = 2 × MACs, then T_computation = FLOPs / FLOPS in milliseconds. Note that a peak rate gives a floor, not a prediction.FLOPs = 2 × MACs، ثم T_computation = FLOPs / FLOPS بالميلي ثانية. لاحظ أن معدل الذروة يعطي حدا أدنى، لا تنبؤا.
6. Regime6. النظام
Compare T_computation with T_memory; the larger one names the bound and the lever that helps.قارن T_computation مع T_memory؛ فالأكبر منهما يحدد نوع القيد والرافعة التي تفيد.

Slide errataأخطاء الشرائح

Answer with the corrected fact and name the slide if a question depends on it. Part 02, Part 03, Part 04

أجب بالمعلومة المصححة واذكر رقم الشريحة إذا كان السؤال يعتمد عليها. الجزء 02، الجزء 03، الجزء 04

What the slides get wrong or leave outما تخطئ فيه الشرائح أو تغفله

Slide 5الشريحة 5
46 ms is the rounded 45.9 ms; the 82.4 mIoU is single-scale, the paper's 84.0 is multi-scale.قيمة 46 ms هي 45.9 ms بعد التقريب؛ وقيمة mIoU البالغة 82.4 بمقياس واحد (single-scale)، أما 84.0 في الورقة فمتعددة المقاييس (multi-scale).
Slide 8الشريحة 8
The MIT original has a Load Input, Load Weight, Compute, Store Output pipeline above the formula. That overlap is the whole reason for max rather than plus.في النسخة الأصلية من MIT خط معالجة فوق الصيغة فيه Load Input وLoad Weight وCompute وStore Output. هذا التداخل هو السبب كله في استخدام max بدلا من الجمع.
Slide 9الشريحة 9
The 200x arrow is 640 / 3.1 ≈ 206 (int MULT) or 640 / 3.2 = 200 (int MAC). Memory rows are halved from Horowitz's 64-bit figures, via Han et al. 2015.سهم 200x هو 640 / 3.1 ≈ 206 (int MULT) أو 640 / 3.2 = 200 (int MAC). صفوف الذاكرة منصفة من أرقام Horowitz الخاصة بـ 64-bit، عن طريق Han et al. 2015.
Slides 15, 16الشريحتان 15 و16
conv1 is printed as 24,848; the product 96 · 3 · 11 · 11 is 34,848. Exact total 60,954,656; the rounded 61M stands.تطبع conv1 على أنها 24,848؛ والحاصل 96 · 3 · 11 · 11 يساوي 34,848. المجموع الدقيق 60,954,656؛ والتقريب 61M يبقى صحيحا.
Slide 18الشريحة 18
Right chart x-axis reads 14, 16, 16, 17, should be 14, 15, 16, 17. Peak activation grew 1.8x, it did not merely "not improve". The right chart is MCUNetV2 (2021) Figure 1, not MCUNet (2020).محور x في المخطط الأيمن يقرأ 14, 16, 16, 17، والصحيح 14, 15, 16, 17. ذروة التنشيط زادت 1.8x، ولم تكتف بأنها "لم تتحسن". والمخطط الأيمن هو Figure 1 من MCUNetV2 (2021)، لا من MCUNet (2020).
Slide 20الشريحة 20
The figure is Figure 11(a) of On-Device Training Under 256KB Memory (NeurIPS 2022), a per-layer training update cost, not an inference profile; the x-axis (layers 0 to 42) was cropped.الشكل هو Figure 11(a) من ورقة On-Device Training Under 256KB Memory (NeurIPS 2022)، وهو تكلفة تحديث التدريب لكل طبقة، وليس ملف استدلال؛ وقد اقتطع محور x (الطبقات من 0 إلى 42).
Slide 21الشريحة 21
The peak formula is stated without its assumptions: layer-by-layer execution, no residual branches, no in-place operations, no scratch buffers.صيغة الذروة مذكورة دون افتراضاتها: تنفيذ طبقة بعد طبقة، ولا فروع بقايا (residual)، ولا عمليات في المكان (in-place)، ولا مخازن مؤقتة (scratch buffers).
Slide 23الشريحة 23
The GEMM figure is loosely labelled. Read m · n · k as rows of C times columns of C times the shared dimension.شكل GEMM معنون بشكل غير دقيق. اقرأ m · n · k على أنها عدد صفوف C في عدد أعمدة C في البعد المشترك.
Slides 24, 25الشريحتان 24 و25
The grouped MAC formula appears in two factor orders; both equal c_o · c_i · k_h · k_w · h_o · w_o / g.صيغة MAC للالتفاف المجمع تظهر بترتيبين مختلفين للعوامل؛ وكلاهما يساوي c_o · c_i · k_h · k_w · h_o · w_o / g.
Slide 27الشريحة 27
"1.4G FLOPs" is 2 × 724,406,816 = 1,448,813,632, so 1.45G exactly. Show the factor of two.عبارة "1.4G FLOPs" هي 2 × 724,406,816 = 1,448,813,632، أي 1.45G بالضبط. أظهر عامل الاثنين.