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، وقبل كل شيء البايتات المنقولة |
| 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 وOPS | Counts on paper, rates from the datasheetالأعداد على الورق، والمعدلات من ورقة البيانات (datasheet) | The computation share of latency and energyحصة الحساب من الزمن والطاقة |
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الوحدة | ms | image/s |
| Measured atتقاس عند | Batch size 1حجم دفعة 1 | Whatever 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يرفعها: عدد أكبر من المدخلات ينتهي كل ثانية |
| Designالتصميم | How inputs are handledطريقة معالجة المدخلات | Latencyالزمن | Inputs per batchالمدخلات في كل دفعة | Throughputالإنتاجية |
|---|---|---|---|---|
| Design 1التصميم 1 | One image at a timeصورة واحدة في كل مرة | 50 ms | 1 | 1 / 0.050 = 20 image/s |
| Design 2التصميم 2 | Four images togetherأربع صور معا | 100 ms | 4 | 4 / 0.100 = 40 image/s |
| Server, batch 1خادم، دفعة 1 | One requestطلب واحد | 2 ms | 1 | 500 image/s |
| Server, batch 32خادم، دفعة 32 | Thirty-two requestsاثنان وثلاثون طلبا | 8 ms | 32 | 4000 image/s |
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النموذج | mIoUmIoU | Parametersالمعاملات | MACsMACs | Orin latencyالزمن على Orin | A100 throughputالإنتاجية على A100 |
|---|---|---|---|---|---|
| SegFormer-B5 | 82.4 | 85M | 1460G | 638 ms | 12 image/s |
| EfficientViT-L1 | 82.7 | 40M | 282G | 45.9 ms | 122 image/s |
| Ratioالنسبة | +0.3 | 2.1x fewer2.1x أقل | 5.2x fewer5.2x أقل | 13.9x faster13.9x أسرع | 10x more10x أكثر |
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: الزمن والإنتاجية والطاقة
| Termالحد | Numerator: NN specificationالبسط: مواصفة الشبكة | Denominator: hardware specificationالمقام: مواصفة العتاد |
|---|---|---|
| T_computation | Number 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عرض نطاق الذاكرة |
| Configurationالإعداد | T_computationT_computation | T_memoryT_memory | Latencyالزمن | Regimeالنظام |
|---|---|---|---|---|
| 100 GOPS, 32-bit weights100 GOPS، أوزان 32-bit | 10 ms | 5 + 2 = 7 ms | 10 ms | Compute-boundمحدود بالحساب |
| 200 GOPS, 32-bit weights200 GOPS، أوزان 32-bit | 5 ms | 5 + 2 = 7 ms | 7 ms | Memory-boundمحدود بالذاكرة |
| 200 GOPS, 8-bit weights200 GOPS، أوزان 8-bit | 5 ms | 1.25 + 2 = 3.25 ms | 5 ms | Compute-boundمحدود بالحساب |
| Modelالنموذج | T_computationT_computation | T_memoryT_memory | Floorالحد الأدنى | Measuredالمقاس | Miss, utilisationالفجوة، ونسبة الاستغلال |
|---|---|---|---|---|---|
| EfficientViT-L1 | 564 / 43 000 = 13.1 ms | 0.39 + 0.45 = 0.84 ms | 13.1 ms | 45.9 ms | 3.5x, about 29%3.5x، نحو 29% |
| SegFormer-B5 | 2920 / 43 000 = 68 ms | 0.83 + 0.45 = 1.3 ms | 68 ms | 638 ms | 9.4x, about 11%9.4x، نحو 11% |
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 MULT | 640 / 3.1 ≈ 206 | The slide's 200xقيمة 200x في الشريحة |
| DRAM over one int MACDRAM على عملية MAC صحيحة واحدة | 640 / 3.2 = 200 | Exact reading of the slide iconالقراءة الدقيقة لأيقونة الشريحة |
| DRAM over SRAMDRAM على SRAM | 640 / 5 = 128 | Why on-chip storage is worth two decadesلماذا يستحق التخزين على الشريحة مرتبتين عشريتين |
| float ADD over int ADDfloat ADD على int ADD | 0.9 / 0.1 = 9 | The seed for quantizationالبذرة التي ينطلق منها التكميم |
| DRAM over int ADDDRAM على int ADD | 640 / 0.1 = 6400 | Three orders of magnitude (Han et al.)ثلاث مراتب عشرية (Han et al.) |
| Itemالبند | Countالعدد | Energy eachطاقة الواحدة | Totalالمجموع |
|---|---|---|---|
| Integer MACsعمليات MAC صحيحة | 724M | 3.1 + 0.1 = 3.2 pJ | 2.32 mJ |
| Weights read once from DRAMالأوزان مقروءة مرة واحدة من DRAM | 61M | 640 pJ | 39.0 mJ |
| Same weights read from SRAMالأوزان نفسها مقروءة من SRAM | 61M | 5 pJ | 0.31 mJ |
| Float MACs instead of integerعمليات MAC عائمة بدلا من الصحيحة | 724M | 3.7 + 0.9 = 4.6 pJ | 3.33 mJ |
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#Parameters | MACsMACs | MACs per parameterMACs لكل معامل |
|---|---|---|---|
| Linearخطية (Linear) | c_o · c_i | c_o · c_i | 1 |
| Convolutionالتفافية (Convolution) | c_o · c_i · k_h · k_w | c_o · c_i · k_h · k_w · h_o · w_o | h_o · w_o |
| Grouped convolutionالتفاف مجمع (Grouped convolution) | c_o · c_i · k_h · k_w / g | c_o · c_i · k_h · k_w · h_o · w_o / g | h_o · w_o |
| Depthwise convolutionالتفاف عمقي (Depthwise convolution) | c_o · k_h · k_w | c_o · k_h · k_w · h_o · w_o | h_o · w_o |
| Poolingتجميع (Pooling) | 0 | 0 |
| Layerالطبقة | Countالعد | #Parameters#Parameters | Ratioالنسبة |
|---|---|---|---|
| Standard, g = 1قياسية، g = 1 | 256 · 256 · 9 | 589,824 | 1 |
| Grouped, g = 2مجمعة، g = 2 | 256 · 256 · 9 / 2 | 294,912 | 1/2 |
| Grouped, g = 8مجمعة، g = 8 | 256 · 256 · 9 / 8 | 73,728 | 1/8 |
| Depthwise, g = 256عمقية، g = 256 | 256 · 9 | 2,304 | 1/256 |
| Layerالطبقة | Countالعد | MACsMACs |
|---|---|---|
| Standard 3 × 3قياسية 3 × 3 | 64 · 32 · 9 · 112 · 112 | 231,211,008 |
| Depthwise 3 × 3عمقية 3 × 3 | 32 · 9 · 112 · 112 | 3,612,672 |
| Pointwise 1 × 1نقطية 1 × 1 | 64 · 32 · 112 · 112 | 25,690,112 |
| Separable over standardالقابلة للفصل (separable) على القياسية | 1 / 64 + 1 / 9 | 0.1267, about 7.9x fewer0.1267، أي نحو 7.9x أقل |
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 × W | Activationsالتنشيطات | #Parameters#Parameters | MACsMACs | MACs per parameterMACs لكل معامل |
|---|---|---|---|---|---|
| Imageالصورة | 3 × 224 × 224 | 150,528 | 0 | 0 | |
| conv1, 11 × 11, stride 4, pad 2conv1، 11 × 11، خطوة 4، حشو 2 | 96 × 55 × 55 | 290,400 | 34,848 | 105,415,200 | 3,025 |
| maxpool | 96 × 27 × 27 | 69,984 | 0 | 0 | |
| conv2, 5 × 5, pad 2, g = 2conv2، 5 × 5، حشو 2، g = 2 | 256 × 27 × 27 | 186,624 | 307,200 | 223,948,800 | 729 |
| maxpool | 256 × 13 × 13 | 43,264 | 0 | 0 | |
| conv3, 3 × 3, pad 1conv3، 3 × 3، حشو 1 | 384 × 13 × 13 | 64,896 | 884,736 | 149,520,384 | 169 |
| conv4, 3 × 3, pad 1, g = 2conv4، 3 × 3، حشو 1، g = 2 | 384 × 13 × 13 | 64,896 | 663,552 | 112,140,288 | 169 |
| conv5, 3 × 3, pad 1, g = 2conv5، 3 × 3، حشو 1، g = 2 | 256 × 13 × 13 | 43,264 | 442,368 | 74,760,192 | 169 |
| maxpool | 256 × 6 × 6 | 9,216 | 0 | 0 | |
| fc6, 9,216 → 4096 | 4096 | 4,096 | 37,748,736 | 37,748,736 | 1 |
| fc7, 4096 → 4096 | 4096 | 4,096 | 16,777,216 | 16,777,216 | 1 |
| fc8, 4096 → 1000 | 1000 | 1,000 | 4,096,000 | 4,096,000 | 1 |
| 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,264 | 60,954,656 | 724,406,816 |
Model size from bit widthحجم النموذج من عرض البت
| Data typeنوع البيانات | Size in bitsالحجم بالبت | Size (decimal MB)الحجم (MB عشري) | Slide roundingتقريب الشريحة |
|---|---|---|---|
| fp32 | 1,950.5 Mbit | 243.8 MB | 244 MB |
| fp16 or bf16fp16 أو bf16 | 975.3 Mbit | 121.9 MB | 122 MB |
| int8 | 487.6 Mbit | 61.0 MB | 61 MB |
| int4 | 243.8 Mbit | 30.5 MB | 30.5 MB |
| 1-bit | 61.0 Mbit | 7.6 MB | 7.6 MB |
- 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الأوزان | Flash | Read only, written once at flashingقراءة فقط، تكتب مرة واحدة عند التحميل (flashing) | Model sizeحجم النموذج | Larger, about 1 MB to 2 MBأكبر، نحو 1 MB إلى 2 MB |
| Activationsالتنشيطات | SRAM | Written and read on every inferenceتكتب وتقرأ في كل استدلال | Peak #activationsذروة #activations | Smaller, 256 kB to 512 kBأصغر، من 256 kB إلى 512 kB |
| Modelالنموذج | Param memory (flash)ذاكرة المعاملات (flash) | Peak activation (SRAM)ذروة التنشيط (SRAM) | Fits F746?يتسع في F746؟ | Fits H743?يتسع في H743؟ |
|---|---|---|---|---|
| ResNet-18 | 11.2 MB | 0.9 MB | Noلا | Noلا |
| MobileNetV2-0.75 | 2.5 MB | 1.7 MB | Noلا | Noلا |
| MCUNet | 1.9 MB | 0.49 MB | Noلا | Yesنعم |
| Ratio ResNet-18 to MobileNetV2النسبة من ResNet-18 إلى MobileNetV2 | 4.6x smaller4.6x أصغر | 1.8x larger1.8x أكبر |
| Modelالنموذج | Weightsالأوزان | Activationsالتنشيطات | Activations over weightsالتنشيطات على الأوزان |
|---|---|---|---|
| ResNet-50 | 102 MB | 707 MB | About 7xنحو 7x |
| MobileNetV2-1.4 | About 24 MBنحو 24 MB | About 640 MBنحو 640 MB | About 27xنحو 27x |
| Ratioالنسبة | 4.3x smaller4.3x أصغر | 1.1x smaller1.1x أصغر |
| 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_i | Sum of all activations × batch size, plus weights, gradients and optimizer stateمجموع كل التنشيطات × حجم الدفعة، مضافا إليه الأوزان والتدرجات وحالة المحسّن (optimizer state) |
| 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؛ وهنا يؤتي التقليم والتكميم ثمارهما |
Total and peak activationsمجموع التنشيطات وذروتها
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-bit | 32-bit32-bit |
|---|---|---|---|
| Peakالذروة | 440,928 | 441 kB | 1.76 MB |
| Totalالمجموع | 932,264 | 932 kB | 3.73 MB |
| MobileNetV2 first convأول طبقة التفافية في MobileNetV2 | 150,528 + 401,408 = 551,936 | 552 kB (539 KiB) | 2.21 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 والعمليات
| Termالمصطلح | Kindالنوع | Meaningالمعنى | Belongs toيخص |
|---|---|---|---|
| MAC | Countعدد | One multiply accumulated into a sumعملية ضرب واحدة تراكم في مجموع | A model, per inferenceالنموذج، لكل استدلال |
| FLOP | Countعدد | One floating point multiply or add; a MAC is twoعملية ضرب أو جمع واحدة بالفاصلة العائمة؛ وعملية MAC الواحدة تساوي اثنتين | A model, per inferenceالنموذج، لكل استدلال |
| OP | Countعدد | One operation of any data type; a MAC is twoعملية واحدة بأي نوع بيانات؛ وعملية MAC الواحدة تساوي اثنتين | A model, per inferenceالنموذج، لكل استدلال |
| FLOPS | Rateمعدل | Floating point operations per secondعمليات الفاصلة العائمة في الثانية | A processorالمعالج |
| OPS | Rateمعدل | Operations per second, any data typeالعمليات في الثانية، بأي نوع بيانات | A processorالمعالج |
| Processorالمعالج | Count ÷ rateالعدد ÷ المعدل | T_computationT_computation |
|---|---|---|
| 1 GFLOPS | 1.449 × 10^9 / 10^9 | 1,449 ms |
| 100 GFLOPS | 1.449 × 10^9 / 10^11 | 14.5 ms |
| 1 TFLOPS | 1.449 × 10^9 / 10^12 | 1.45 ms |
| 67 TOPS (Orin Nano, INT8 sparse peak)67 TOPS (Orin Nano، ذروة INT8 مع التناثر) | 1.449 × 10^9 / 6.7 × 10^13 | 0.022 ms |
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 بالضبط. أظهر عامل الاثنين.