Majid Al-RaimiNeural network efficiency metricsمقاييس كفاءة الشبكات العصبية

COE 592Lecture 03المحاضرة 03

Neural network efficiency metricsمقاييس كفاءة الشبكات العصبية

How to measure whether a neural network is small, fast and green enough for embedded hardware: latency versus throughput, the energy cost of moving data, parameter counts and model size by bit width, peak activations as the real memory bottleneck, and MACs, FLOPs and OPs as the computation budget, all worked through AlexNet layer by layer.كيف تقيس ما إذا كانت الشبكة العصبية صغيرة وسريعة وموفرة للطاقة بما يكفي للعتاد المضمّن: زمن الاستجابة (latency) مقابل الإنتاجية (throughput)، وكلفة الطاقة لنقل البيانات، وعدد المعاملات وحجم النموذج حسب عرض البت، وذروة التنشيطات بوصفها عنق الزجاجة الحقيقي للذاكرة، وMACs وFLOPs وOPs بوصفها ميزانية الحساب، وكل ذلك محلول على AlexNet طبقة بطبقة.

Partsالأجزاء
4
Conceptsالمفاهيم
18
Slidesالشرائح
29
Readingمدة القراءة
108 min108 دقائق
Understoodما فهمته
0/18 conceptsمفاهيم
Read the full guideاقرأ الشرح الكاملEvery part on one long page: 4 parts, 18 concepts, about 108 min.كل الأجزاء في صفحة واحدة طويلة: 4 أجزاء، و18 مفهومًا، في نحو 108 دقائق.

AOverviewنظرة عامة

Accuracy tells you whether a network is right. This lecture gives you the five numbers that tell you whether it can run at all on the board in front of you: how many bytes it stores, how many it must hold while computing, how many multiply-accumulates it performs, how long that takes on a given chip, and how much charge it draws. Every result later in the course, from pruning to quantization to neural architecture search, is a ratio of two of these numbers.

الدقة (accuracy) تخبرك هل الشبكة تعطي الإجابة الصحيحة. أما هذه المحاضرة فتعطيك الأرقام الخمسة التي تخبرك هل يمكن تشغيلها أصلا على اللوحة التي أمامك: كم بايت تخزن، وكم بايت يجب أن تحتفظ به أثناء الحساب، وكم عملية ضرب وتجميع (multiply-accumulate) تنفذ، وكم يستغرق ذلك على شريحة معينة، وكم من الطاقة تستهلك. كل نتيجة لاحقة في المقرر، من التقليم (pruning) إلى التكميم (quantization) إلى البحث عن معمارية الشبكة (neural architecture search)، هي نسبة بين رقمين من هذه الأرقام.

As a PhD student you need them in three places. Exams ask you to count parameters, activations and MACs for a layer list, convert the counts into megabytes and milliseconds, and argue from the max latency model and the 45 nm energy table. Your research project puts a detector on an embedded board, and its evaluation section is unreadable without these metrics stated under the right conditions. And any efficient system you design or review, on a Jetson or a microcontroller, is judged first by whether its weights fit in flash, its peak activations fit in SRAM and its latency fits inside one frame period.

كطالب دكتوراه تحتاج هذه الأرقام في ثلاثة مواضع. الاختبارات تطلب منك عد المعاملات (parameters) والتنشيطات (activations) وMACs لقائمة من الطبقات، وتحويل هذه الأعداد إلى ميغابايت وميلي ثانية، والاستدلال بنموذج الزمن القائم على max وبجدول الطاقة عند 45 nm. ومشروعك البحثي يضع كاشفا (detector) على لوحة مدمجة، وقسم التقييم فيه لا يمكن فهمه دون ذكر هذه المقاييس تحت الشروط الصحيحة. وأي نظام كفء تصممه أو تراجعه، على Jetson أو على متحكم دقيق (microcontroller)، يحكم عليه أولا بثلاثة أسئلة: هل تتسع أوزانه في ذاكرة flash، وهل تتسع ذروة تنشيطاته في SRAM، وهل يقع زمنه داخل فترة إطار واحد.

From the efficiency triangle to the four metrics that predict itمن مثلث الكفاءة إلى المقاييس الأربعة التي تتنبأ به

The path has five stops. You place every metric in the efficiency triangle, memory-related or computation-related, and see which of storage, latency and energy it predicts. You learn why latency and throughput are different questions, why a latency is meaningless without its hardware, runtime, precision and batch size, and why the milliseconds of an inference are a max of compute time and memory time rather than a sum. You count what a network stores, then what it must hold in memory, then what it must compute, with AlexNet worked layer by layer at each step. The lecture ends where it began: the count of operations divided by the rate of a chip is the compute term of that latency model.

للمسار خمس محطات. تضع كل مقياس في مثلث الكفاءة، إما مرتبطا بالذاكرة أو مرتبطا بالحساب، وترى أي التكاليف الثلاث يتنبأ بها: التخزين أو الزمن (latency) أو الطاقة. تتعلم لماذا الزمن والإنتاجية (throughput) سؤالان مختلفان، ولماذا لا معنى لأي زمن دون ذكر العتاد وبيئة التشغيل (runtime) والدقة العددية (precision) وحجم الدفعة (batch size)، ولماذا تكون ميلي ثواني الاستدلال هي القيمة العظمى (max) بين زمن الحساب وزمن الذاكرة وليست مجموعهما. تعد ما تخزنه الشبكة، ثم ما يجب أن تحتفظ به في الذاكرة، ثم ما يجب أن تحسبه، مع حل AlexNet طبقة بطبقة في كل خطوة. وتنتهي المحاضرة حيث بدأت: عدد العمليات مقسوما على معدل الشريحة هو حد الحساب في نموذج الزمن ذاك.

Numbers you will own by the endالأرقام التي ستتقنها في النهاية

AlexNet is the running example, and by the last part you will have derived every one of these figures yourself rather than quoted them. They are the anchors the exam and the reference sheet return to.

AlexNet هو المثال المستمر، وبنهاية الجزء الأخير ستكون قد اشتققت كل رقم من هذه الأرقام بنفسك بدلا من نقله. إنها نقاط الارتكاز التي يعود إليها الاختبار وورقة المرجع.

AlexNet, one 224 x 224 image, from the four parts of this lectureAlexNet، صورة واحدة بحجم 224 x 224، من الأجزاء الأربعة لهذه المحاضرة

Parametersالمعاملات
60,954,656, about 61M60,954,656، أي نحو 61M
Model sizeحجم النموذج
244 MB at 32-bit, 61 MB at 8-bit244 MB عند 32-bit، و61 MB عند 8-bit
Peak activationsذروة التنشيطات
440,928 values at conv1440,928 قيمة عند conv1
MACs per imageMACs لكل صورة
724,406,816, about 1.45 GFLOPs724,406,816، أي نحو 1.45 GFLOPs
Weights from DRAMالأوزان من DRAM
39 mJ, 17x the 2.3 mJ of arithmetic39 mJ، أي 17x طاقة العمليات الحسابية البالغة 2.3 mJ

Success looks likeعلامات النجاح

  • Place any efficiency metric in the memory or computation group and name which of storage, latency and energy it predicts.أن تضع أي مقياس كفاءة في مجموعة الذاكرة أو مجموعة الحساب، وتسمي أي التكاليف يتنبأ بها: التخزين أو الزمن أو الطاقة.
  • Compute latency and throughput for a batched design and explain with numbers why neither implies the other.أن تحسب الزمن والإنتاجية لتصميم يعمل بالدفعات (batched) وتشرح بالأرقام لماذا لا يستلزم أحدهما الآخر.
  • Write Latency ≈ max(T_computation, T_memory) with its sub-formulas, label each term NN or hardware specification, and decide compute-bound versus memory-bound.أن تكتب Latency ≈ max(T_computation, T_memory) مع صيغه الفرعية، وتصنف كل حد على أنه مواصفة الشبكة (NN) أو مواصفة العتاد، وتقرر هل النموذج محدود بالحساب (compute-bound) أم محدود بالذاكرة (memory-bound).
  • Count parameters for linear, convolution, grouped and depthwise layers, total a network, and convert the count to model size at any bit width.أن تعد المعاملات للطبقات الخطية (linear) والالتفافية (convolution) والمجمعة (grouped) والعمقية (depthwise)، وتجمعها لشبكة كاملة، وتحول العدد إلى حجم النموذج عند أي عرض بت (bit width).
  • Compute total and peak activations for a layer list and say whether the model fits a microcontroller whose SRAM holds activations and whose flash holds weights.أن تحسب مجموع التنشيطات وذروتها لقائمة طبقات، وتقول هل يتسع النموذج في متحكم دقيق تحمل ذاكرة SRAM فيه التنشيطات وتحمل ذاكرة flash فيه الأوزان.
  • Count MACs per layer, convert to FLOPs and OPs, and estimate T_computation on a chip from its OPS.أن تعد MACs لكل طبقة، وتحولها إلى FLOPs وOPs، وتقدر T_computation على شريحة من معدل OPS الخاص بها.
  • Argue from the 45 nm energy table that one DRAM access costs about two hundred integer multiplies, so efficient design is above all a design for moving fewer bytes.أن تستدل من جدول الطاقة عند 45 nm على أن وصولا واحدا إلى DRAM يكلف تقريبا ما تكلفه مئتا عملية ضرب صحيحة، وبالتالي فالتصميم الكفء هو قبل كل شيء تصميم ينقل بايتات أقل.

How to study this lectureكيف تذاكر هذه المحاضرة

  1. Read the parts in order. Each one feeds the next: the costs of part one are what parts two to four learn to predict, and the final part closes the loop back to the latency model.اقرأ الأجزاء بالترتيب. كل جزء يغذي الذي بعده: التكاليف في الجزء الأول هي ما تتعلم الأجزاء من الثاني إلى الرابع التنبؤ به، والجزء الأخير يغلق الحلقة عائدا إلى نموذج الزمن.
  2. Keep a pencil next to AlexNet. Every worked example hides one layer behind a question; compute it before you reveal it, then check yourself in the layer calculators.أبق قلما بجانب AlexNet. كل مثال محلول يخفي طبقة واحدة خلف سؤال؛ احسبها قبل أن تكشفها، ثم تحقق من نفسك في حاسبات الطبقات.
  3. Answer every recall prompt in your head before opening it. The numbers that stick are the ones you retrieved, not the ones you read.أجب عن كل سؤال استرجاع في ذهنك قبل أن تفتحه. الأرقام التي ترسخ هي التي استرجعتها، لا التي قرأتها.
  4. Take each quiz and read the explanation even when you are right; the wrong options are the exam traps.حل كل اختبار قصير واقرأ الشرح حتى عندما تكون إجابتك صحيحة؛ فالخيارات الخاطئة هي فخاخ الامتحان.
  5. Mark a concept understood only when you could redo its formula and its AlexNet number from a blank page. Unmarked concepts show you where to return.لا تضع على مفهوم علامة "فهمته" إلا عندما تستطيع إعادة صيغته ورقمه في AlexNet من صفحة فارغة. المفاهيم غير المعلّمة تريك أين يجب أن تعود.
  6. Keep the glossary open for terms and the reference sheet for the formula table, the energy table and the AlexNet totals when you solve problems.أبق المسرد مفتوحا للمصطلحات، وورقة المرجع مفتوحة لجدول الصيغ وجدول الطاقة ومجاميع AlexNet عندما تحل المسائل.
  7. Come back after a few days and redo the counts cold on a different network, such as your project detector. Spaced practice on a new example is what turns a formula into a skill.عد بعد بضعة أيام وأعد العد من الذاكرة على شبكة مختلفة، مثل الكاشف في مشروعك. التمرين المتباعد على مثال جديد هو ما يحول الصيغة إلى مهارة.

Sourcesالمصادر

BThe 4 partsالأجزاء الـ4

  1. 01Latency, throughput and energyزمن الاستجابة والإنتاجية والطاقةThe efficiency triangle of storage, latency and energy, what latency and throughput each measure, why one does not imply the other, the analytical latency model, and why data movement dominates energy.مثلث الكفاءة (التخزين وزمن الاستجابة والطاقة)، وما يقيسه كل من زمن الاستجابة (latency) والإنتاجية (throughput)، ولماذا لا يستلزم أحدهما الآخر، ونموذج زمن الاستجابة التحليلي، ولماذا يهيمن نقل البيانات على استهلاك الطاقة.5 concepts5 مفاهيمSlides 1-9الشرائح 1-930 min30 دقيقة
    1. 1.1Smaller, faster, greener: three goals, three costs, two resourcesأصغر وأسرع وأكثر خضرة: ثلاثة أهداف وثلاث تكاليف ومَوردان
    2. 1.2Latency is the delay for one task, and the number is meaningless without its conditionsالـ latency هو زمن التأخير لمهمة واحدة، والرقم بلا معنى من دون ظروف قياسه
    3. 1.3Throughput is a rate, and batching raises it without lowering latencyالـ throughput معدّل، والـ batching يرفعه من دون أن يخفض الـ latency
    4. 1.4Latency as max(T_computation, T_memory): the network supplies numerators, the hardware denominatorsالـ latency بوصفه max(T_computation, T_memory): الشبكة تقدّم البسوط والعتاد يقدّم المقامات
    5. 1.5Energy is spent moving data, not multiplying itالطاقة تُصرف على نقل البيانات لا على ضربها
  2. 02Parameters and model sizeالمعاملات وحجم النموذجCounting weights for linear, convolution, grouped and depthwise layers, totaling AlexNet to 61M parameters, and converting parameter count into storage at different bit widths.عدّ الأوزان في الطبقات الخطية والالتفافية والمجمّعة والعمقية، وجمعها في AlexNet لتبلغ 61M معاملًا، وتحويل عدد المعاملات إلى مساحة تخزين عند عروض بت مختلفة.4 concepts4 مفاهيمSlides 10-17الشرائح 10-1724 min24 دقيقة
    1. 2.1#Parameters counts synapses, and a weight tensor is where they liveعدد المعاملات يعدّ المشابك، وموتّر الأوزان هو المكان الذي تُخزَّن فيه
    2. 2.2Convolution, grouped and depthwise: one formula and a single division by gالالتفاف العادي والمجمّع والعمقي: صيغة واحدة وقسمة واحدة على g
    3. 2.3AlexNet layer by layer: 61M parameters, 96 percent of them in three linear layersAlexNet طبقة بطبقة: 61M معامل، 96 بالمئة منها في ثلاث طبقات خطية
    4. 2.4Model size is parameters times bit width, and the units hide a factor of eightحجم النموذج هو عدد المعاملات مضروبًا في عرض البت، والوحدات تُخفي معاملًا قدره ثمانية
  3. 03Activations and peak memoryالتنشيطات وذروة الذاكرةWhy activations rather than parameters are the memory bottleneck in inference and training, how memory is spread across layers of MobileNetV2 and MCUNet, and how to compute total and peak activations for AlexNet.لماذا تكون التنشيطات لا المعاملات هي عنق الزجاجة للذاكرة في الاستدلال والتدريب، وكيف تتوزع الذاكرة على طبقات MobileNetV2 وMCUNet، وكيف نحسب مجموع التنشيطات وذروتها في AlexNet.4 concepts4 مفاهيمSlides 18-22الشرائح 18-2224 min24 دقيقة
    1. 3.1Shrinking the weights did not shrink the peak: activations bound inference memoryتقليص الأوزان لم يقلّص الذروة: الـ activations هي التي تحدّ ذاكرة الـ inference
    2. 3.2Training keeps every activation alive: 707 MB against 102 MBالتدريب يُبقي كل activation في الذاكرة: 707 MB مقابل 102 MB
    3. 3.3Early layers are activation heavy, late layers are weight heavyالطبقات الأولى ثقيلة بالـ activations، والطبقات الأخيرة ثقيلة بالأوزان
    4. 3.4Counting AlexNet activations: total versus peakعدّ activations في AlexNet: المجموع الكلي مقابل الذروة
  4. 04MACs, FLOPs and operationsعمليات MAC وFLOP والعملياتCounting computation as multiply-accumulate operations for matrix products and each layer type, AlexNet's 724M MACs, and converting to FLOPs, FLOPS, OPs and OPS.عدّ الحساب بوصفه عمليات ضرب وتجميع (MAC) لضرب المصفوفات ولكل نوع من الطبقات، و724M عملية MAC في AlexNet، والتحويل إلى FLOPs وFLOPS وOPs وOPS.5 concepts5 مفاهيمSlides 23-29الشرائح 23-2930 min30 دقيقة
    1. 4.1One MAC, one matrix product: the unit of neural network computeعملية MAC واحدة وضرب مصفوفات واحد: وحدة الحساب في الشبكات العصبية
    2. 4.2MACs per layer: every weight fires once per output positionعدد MACs لكل طبقة: كل وزن يُستخدم مرة واحدة لكل موضع في المخرج
    3. 4.3AlexNet's 724M MACs: convolution owns compute, linear owns parametersالـ 724M MACs في AlexNet: الالتفاف يستحوذ على الحساب والطبقات الخطية تستحوذ على المعاملات
    4. 4.4From MACs to FLOPs and OPs, and from counts to ratesمن MACs إلى FLOPs و OPs، ومن العدد إلى المعدل
    5. 4.5The reading list behind this lectureقائمة المراجع التي تستند إليها هذه المحاضرة

CGlossary and referenceالمصطلحات والمرجع