COE 592Lecture 4.2المحاضرة 4.2Part 04الجزء 04
AMC: pruning ratios as a reinforcement learning problemAMC: نسب التقليم بوصفها مسألة تعلم معزز
Given an overall compression target, AMC lets a DDPG agent choose each layer's sparsity, rewarded by accuracy under a FLOPs or latency constraint, and beats hand-tuned and uniformly scaled MobileNets on a real phone.بإعطاء هدف ضغط إجمالي، يترك AMC وكيلًا من نوع DDPG يختار تناثر كل طبقة، ويكافئه بالدقة تحت قيد على FLOPs أو زمن الاستجابة، ويتفوق على نماذج MobileNet المضبوطة يدويًا والمصغّرة بانتظام على هاتف حقيقي.
- Conceptsالمفاهيم
- 4
- Slidesالشرائح
- 24-32
- Readingمدة القراءة
- 24 min24 دقيقة
Why this part mattersلماذا يهمّ هذا الجزء
Your research models will have to meet a latency or FLOPs budget on one specific device, and someone has to decide how much of that budget each layer gives up. Part 03 showed the hand method. This part shows the first method that learns the answer, and it is the one the exam will ask you to formulate.
AMC (He et al., ECCV 2018) is the canonical example of turning a hand-tuned hyperparameter search into a learned policy. You will see why the search is hard, how the four ingredients of reinforcement learning map onto pruning, what the agent discovered on ResNet-50 that no expert had written down, and a table of phone measurements that settles the argument between counting FLOPs and measuring time.
ستحتاج نماذجك البحثية إلى الالتزام بميزانية زمن استجابة (latency) أو FLOPs على جهاز محدد، ولا بد أن يقرر أحدٌ ما مقدار ما تتنازل عنه كل طبقة من هذه الميزانية. عرض الجزء 03 الطريقة اليدوية. أما هذا الجزء فيعرض أول طريقة تتعلّم الإجابة بنفسها، وهي الطريقة التي سيطلب منك الامتحان صياغتها.
يُعد AMC (He et al., ECCV 2018) المثال المرجعي على تحويل بحث يدوي عن معامل فائق (hyperparameter) إلى سياسة متعلَّمة (learned policy). سترى لماذا البحث صعب، وكيف تنطبق المكونات الأربعة للتعلم المعزز (reinforcement learning) على التقليم، وما الذي اكتشفه الوكيل في ResNet-50 ولم يكتبه أي خبير من قبل، وجدولًا من قياسات على هاتف يحسم الجدل بين عدّ FLOPs وقياس الزمن فعليًا.
By the end you canفي نهاية هذا الجزء ستستطيع
- Explain why per-layer ratio selection is a combinatorial search and why sensitivity analysis is sub-optimal.أن تشرح لماذا يُعد اختيار النسبة لكل طبقة بحثًا تركيبيًا، ولماذا يعطي تحليل الحساسية نتيجة دون المثلى.
- Name AMC's state, action, agent and reward, and say why the action is continuous and the reward is minus error under a constraint.أن تسمّي الحالة والفعل والوكيل والمكافأة في AMC، وأن توضح لماذا الفعل متصل ولماذا المكافأة هي سالب الخطأ تحت قيد.
- Describe what DDPG's actor and critic each do in one AMC episode.أن تصف ما يفعله كل من الممثل (actor) والناقد (critic) في DDPG خلال حلقة واحدة من AMC.
- Read the ResNet-50 density plot: peaks at 1x1, crests at 3x3, 5x versus 3.4x at equal accuracy.أن تقرأ مخطط الكثافة لـ ResNet-50: قمم عند طبقات 1x1، وقيعان عند طبقات 3x3، و5x مقابل 3.4x عند الدقة نفسها.
- Interpret the MobileNet table: measured time versus FLOPs targets, and why both beat uniform 0.75 shrinking.أن تفسّر جدول MobileNet: هدف الزمن المقاس مقابل هدف FLOPs، ولماذا يتفوق كلاهما على التصغير المنتظم 0.75.
Take a ResNet-50 and allow each of its roughly fifty prunable layers to keep one of ten possible fractions of its weights. That is 10^50 ways to spend one overall budget. The Sensitivity analysis of part 03 escapes the explosion by never looking at combinations at all: it prunes one layer at a time, runs 50 x 10 = 500 single-layer experiments, and reads each layer's Pruning ratio off its own curve where it crosses the accuracy threshold.
خذ شبكة ResNet-50 واسمح لكل طبقة من طبقاتها القابلة للتقليم، وعددها نحو خمسين، بأن تحتفظ بواحد من عشرة كسور ممكنة من أوزانها. هذا يعطي 10^50 طريقة لإنفاق ميزانية إجمالية واحدة. أما sensitivity analysis (تحليل الحساسية) في الجزء 03 فيتجنب هذا الانفجار بألا ينظر إلى التركيبات أبدًا: فهو يقلّم طبقة واحدة في كل مرة، ويجري 50 x 10 = 500 تجربة على طبقة منفردة، ويقرأ pruning ratio (نسبة التقليم) لكل طبقة من منحناها الخاص عند النقطة التي يقطع فيها حدّ الدقة.
The saving comes from a hidden assumption: that the accuracy lost by pruning several layers at once is the sum of what each loses alone. The AMC authors tested exactly this and report that the sensitivity approach "assumes that errors of different pruned layers can be summed up linearly, which does not stand according to our experiments" (He et al., 2018). That is the Layer interaction that slide 24 says the analysis ignores. Pruning layer 3 changes what layer 4 receives, so the curve you measured for layer 4 on a dense network is the wrong curve once layer 3 is thin. The ratios are usable, but they are sub-optimal, and they belong to the network they were measured on. Change the architecture and every curve must be measured again.
يأتي هذا التوفير من افتراض خفي: أن الدقة المفقودة عند تقليم عدة طبقات معًا تساوي مجموع ما تفقده كل طبقة وحدها. اختبر مؤلفو AMC هذا الافتراض تحديدًا، وذكروا أن نهج الحساسية "يفترض أن أخطاء الطبقات المقلّمة المختلفة يمكن جمعها خطيًا، وهذا لا يصمد وفق تجاربنا" (He et al., 2018). هذا هو layer interaction (تفاعل الطبقات) الذي تقول الشريحة 24 إن التحليل يتجاهله. تقليم الطبقة 3 يغيّر ما تستقبله الطبقة 4، لذا فإن المنحنى الذي قسته للطبقة 4 على شبكة كثيفة يصبح المنحنى الخطأ بمجرد أن تصبح الطبقة 3 رفيعة. النسب صالحة للاستخدام، لكنها دون المثلى، وهي تخص الشبكة التي قيست عليها. غيّر المعمارية، وسيلزم قياس كل منحنى من جديد.
Worked exampleمثال محلول
Counting the search spaceعدّ فضاء البحث
Combinationsالتركيبات
Fifty layers, ten candidate ratios each: 10^50 full configurations. No amount of GPU time enumerates that.خمسون طبقة، ولكل منها عشر نسب مرشحة: 10^50 إعدادًا كاملًا. لا يكفي أي قدر من وقت GPU لتعدادها كلها.What sensitivity analysis actually triesما يجرّبه تحليل الحساسية فعليًا
One layer at a time: 50 x 10 = 500 pruned networks, each with only one layer changed. It then picks the ratios by a threshold, never trying the chosen combination until the very end.طبقة واحدة في كل مرة: 50 x 10 = 500 شبكة مقلّمة، في كل منها طبقة واحدة فقط متغيرة. ثم يختار النسب بحدّ عتبة، دون أن يجرّب التركيبة المختارة إلا في النهاية تمامًا.What is never measuredما لا يُقاس أبدًا
Any configuration in which two or more layers are pruned together. The compounding of part 03 (both layers at once losing more than either alone) lives entirely in the unmeasured region.أي إعداد تُقلَّم فيه طبقتان أو أكثر معًا. فالتراكم الذي رأيناه في الجزء 03 (أن تقليم الطبقتين معًا يُفقد أكثر مما تُفقده أي منهما وحدها) يقع بالكامل في المنطقة غير المقاسة.A first-order estimate, not an optimumتقدير من الرتبة الأولى، لا حلّ أمثل
Sensitivity analysis is a valid linear approximation. The per-layer rates it produces are a starting point, not the best allocation of the budget.تحليل الحساسية تقريب خطي صالح. المعدلات التي ينتجها لكل طبقة نقطة بداية، وليست أفضل توزيع للميزانية.
The bottleneck is peopleعنق الزجاجة هو البشر
Slide 25 shows the practical consequence. Conventionally the allocation relies on human expertise and trial and error. Three customers with three engineers is a workable shop. Many customers overwhelm even a team of engineers (the red cross and the alarmed manager in the middle column), and every new model, new target device or new budget restarts the trial and error from scratch, because rules such as prune the first layer less and the fully connected layers more are, in the paper's words, "non-optimal, and doesn't transfer from one model to another" (He et al., 2018). The right column serves the same crowd with one engineer and an engine that takes the model and the constraint and returns the compressed network.
تعرض الشريحة 25 النتيجة العملية. تقليديًا، يعتمد توزيع النسب على خبرة البشر وعلى التجربة والخطأ. ثلاثة عملاء مع ثلاثة مهندسين ورشة قابلة للعمل. لكن كثرة العملاء تُغرق حتى فريقًا من المهندسين (العلامة الحمراء والمدير القلق في العمود الأوسط)، وكل نموذج جديد أو جهاز مستهدف جديد أو ميزانية جديدة يعيد التجربة والخطأ من الصفر، لأن قواعد مثل قلّم الطبقة الأولى أقل والطبقات المتصلة بالكامل (fully connected) أكثر هي، بكلمات الورقة، "غير مثلى، ولا تنتقل من نموذج إلى آخر" (He et al., 2018). أما العمود الأيمن فيخدم الحشد نفسه بمهندس واحد ومحرك يأخذ النموذج والقيد ويعيد الشبكة المضغوطة.
Slide 26 names the ambition: a push-the-button solution. Today an efficient network needs someone who is both a machine learning expert and a hardware expert. The goal is that a non-expert plus a hardware-centric AutoML tool reaches the same efficient network. This is the definition of Automated pruning in this lecture: an algorithm, not a person, chooses the per-layer ratios for an overall target, and it does so with the target hardware in the loop.
تسمّي الشريحة 26 الطموح: حلّ بضغطة زر (push-the-button). اليوم تحتاج الشبكة الفعالة إلى شخص خبير في تعلم الآلة وخبير في العتاد معًا. والهدف أن يصل غير الخبير، مع أداة AutoML متمحورة حول العتاد، إلى الشبكة الفعالة نفسها. هذا هو تعريف automated pruning (التقليم المؤتمت) في هذه المحاضرة: خوارزمية، لا شخص، تختار النسب لكل طبقة لتحقيق هدف إجمالي، وتفعل ذلك والعتاد المستهدف داخل الحلقة.
| Methodالطريقة | Who chooses the ratiosمن يختار النسب | Costالتكلفة | Interaction modelledهل يُنمذَج التفاعل | Transfers to a new modelهل تنتقل إلى نموذج جديد |
|---|---|---|---|---|
| Human expert rulesقواعد الخبير البشري | An engineer, by trial and errorمهندس، بالتجربة والخطأ | Days of experiments per modelأيام من التجارب لكل نموذج | Only in the engineer's headفقط في ذهن المهندس | No, rules are written per modelلا، القواعد تُكتب لكل نموذج على حدة |
| Sensitivity analysisتحليل الحساسية | A curve per layer plus one thresholdمنحنى لكل طبقة مع عتبة واحدة | Layers x ratios single-layer runsتجارب على طبقة منفردة بعدد الطبقات x النسب | No, one layer at a timeلا، طبقة واحدة في كل مرة | No, curves belong to one networkلا، المنحنيات تخص شبكة واحدة |
| Learned policy (AMC)سياسة متعلَّمة (AMC) | A DDPG agent, layer by layerوكيل DDPG، طبقة بعد طبقة | Hundreds of pruned networks, no retrainingمئات الشبكات المقلّمة، دون إعادة تدريب | Yes, the reward sees the whole networkنعم، المكافأة ترى الشبكة كاملة | Same method, new search per model and budgetالطريقة نفسها، مع بحث جديد لكل نموذج وميزانية |
Recall
An overall compression target is given. Why is choosing the per-layer ratios still a hard problem, and what does sensitivity analysis do about it?لديك هدف ضغط إجمالي. لماذا يبقى اختيار النسب لكل طبقة مسألة صعبة، وماذا يفعل تحليل الحساسية حيالها؟
Quick checkاختبار سريع
Why do the ratios from sensitivity analysis end up sub-optimal?لماذا تكون النسب الناتجة عن تحليل الحساسية دون المثلى في النهاية؟
Follow one pass of AMC over MobileNet. Layer t-1 has just been pruned at 30%. The agent now looks at layer t: it receives a short vector describing that layer, its index, its channel counts, its kernel size, its FLOPs, how many FLOPs earlier layers already gave up and how many remain in later layers. It answers with one number, say 50%. The environment removes half of that layer's channels by magnitude and presents layer t+1. When the last layer is done, the whole pruned network is evaluated on a held-out set, and a single number comes back: minus the error. That number is the only feedback the agent ever gets, and it arrives once per pass.
تتبّع مرورًا واحدًا لـ AMC على MobileNet. الطبقة t-1 قُلّمت للتو بنسبة 30%. ينظر الوكيل الآن إلى الطبقة t: يستقبل متجهًا قصيرًا يصف تلك الطبقة، فيه رقمها، وعدد قنواتها، وحجم نواتها (kernel)، وFLOPs الخاصة بها، وكم من FLOPs تخلّت عنه الطبقات السابقة، وكم بقي في الطبقات اللاحقة. ويجيب برقم واحد، لنقل 50%. تزيل البيئة نصف قنوات تلك الطبقة بحسب المقدار (magnitude) وتعرض الطبقة t+1. وعند الانتهاء من الطبقة الأخيرة، تُقيَّم الشبكة المقلّمة كاملة على مجموعة محجوزة، ويعود رقم واحد: سالب الخطأ. هذا الرقم هو التغذية الراجعة الوحيدة التي يحصل عليها الوكيل، ويصل مرة واحدة في كل مرور.
That story contains every ingredient of a reinforcement learning problem, which is what slide 27 means by "pruning as a reinforcement learning problem". The paper's own description: the agent "processes the network in a layer-wise manner", "receives a layer embedding s_t", "outputs a precise compression ratio a_t", and after every layer is compressed the "validation accuracy of the pruned model with all layers compressed is evaluated without fine-tuning, which is an efficient delegate of the fine-tuned accuracy" (He et al., 2018). Only the best network found after the search is fine-tuned.
تحتوي هذه القصة على كل مكونات مسألة تعلم معزز، وهذا ما تعنيه الشريحة 27 بعبارة "التقليم بوصفه مسألة تعلم معزز". وصف الورقة نفسها: الوكيل "يعالج الشبكة طبقة بعد طبقة"، و"يستقبل تضمين الطبقة s_t"، و"يُخرج نسبة ضغط دقيقة a_t"، وبعد ضغط كل الطبقات "تُقيَّم دقة التحقق (validation accuracy) للنموذج المقلّم بكل طبقاته المضغوطة دون ضبط دقيق، وهي بديل فعّال عن الدقة بعد الضبط الدقيق" (He et al., 2018). لا يُضبط ضبطًا دقيقًا إلا أفضل شبكة وُجدت بعد البحث.
The four RL ingredients in AMC, plus two words the exam expects around themمكونات التعلم المعزز الأربعة في AMC، مع مصطلحين إضافيين يتوقعهما الامتحان حولها
- Stateالحالة (State)
- The Layer embedding of layer t: eleven features (t, n, c, h, w, stride, k, FLOPs[t], reduced, rest, a[t-1]), each scaled to [0, 1]. The slide's [N, C, H, W, i, ...] abbreviates this list.layer embedding (تضمين الطبقة) للطبقة t: إحدى عشرة خاصية (t, n, c, h, w, stride, k, FLOPs[t], reduced, rest, a[t-1])، كل منها مُقيّسة إلى [0, 1]. والصيغة [N, C, H, W, i, ...] في الشريحة اختصار لهذه القائمة.
- Actionالفعل (Action)
- One continuous number, the sparsity ratio a_t in (0, 1], for the current layer only.رقم متصل واحد، هو نسبة التفرّق a_t ضمن (0, 1]، للطبقة الحالية فقط.
- Agentالوكيل (Agent)
- DDPG, an actor-critic method: the actor proposes a_t from s_t, the critic estimates the value Q(s_t, a_t) of that choice.DDPG، طريقة من نوع ممثل وناقد (actor-critic): يقترح الممثل a_t انطلاقًا من s_t، ويقدّر الناقد القيمة Q(s_t, a_t) لهذا الاختيار.
- Environmentالبيئة (Environment)
- Channel pruning of the pretrained network, one layer per step, using magnitude selection inside the layer.channel pruning (تقليم القنوات) للشبكة المدرّبة مسبقًا، طبقة واحدة في كل خطوة، باستخدام الاختيار بالمقدار (magnitude) داخل الطبقة.
- Rewardالمكافأة (Reward)
- R = -Error when the FLOPs or latency budget holds, effectively minus infinity otherwise (slide 29). For accuracy-guaranteed search, R = -Error x log(FLOPs) (slide 28).R = -Error عندما تتحقق ميزانية FLOPs أو زمن الاستجابة، وسالب ما لا نهاية فعليًا في غير ذلك (الشريحة 29). وللبحث المضمون الدقة (accuracy-guaranteed) تكون R = -Error x log(FLOPs) (الشريحة 28).
- Episodeالحلقة (Episode)
- One full pass over all layers, producing one pruned network and one reward. The signal is validation accuracy before fine-tuning, on a few thousand training images.مرور كامل واحد على كل الطبقات، ينتج شبكة مقلّمة واحدة ومكافأة واحدة. والإشارة هي دقة التحقق (validation accuracy) قبل الضبط الدقيق، على بضعة آلاف من صور التدريب.
Why the action must be continuous, and why an actor and a criticلماذا يجب أن يكون الفعل متصلًا، ولماذا ممثل وناقد
A pruning ratio is a real number, and the compressed model's accuracy is very sensitive to it. A discrete agent would need a grid fine enough to tell 48% from 52%, which explodes the number of actions, and a grid also throws away the order between neighbouring ratios (He et al., 2018), so the agent could not exploit the fact that neighbouring ratios behave alike. DDPG (Lillicrap et al., 2015) is the standard actor-critic method for continuous control: it concurrently learns a Q-function and a policy and can only be used with continuous action spaces (OpenAI Spinning Up). Sutton and Barto give the naming: when a value function is used "to assess, or criticize, the policy's action selections, then the value function is called a critic and the policy is called an actor". In AMC the critic learns, from replayed transitions, how much reward a state and ratio pair leads to; the actor is then nudged by gradient ascent on that estimate to propose ratios the critic scores higher. The critic judges, the actor proposes, and neither ever sees a gradient of the pruned network itself.
نسبة التقليم عدد حقيقي، ودقة النموذج المضغوط حساسة جدًا لها. سيحتاج وكيل متقطع (discrete) إلى شبكة قيم دقيقة بما يكفي للتمييز بين 48% و52%، وهذا يُفجّر عدد الأفعال، كما أن الشبكة المتقطعة تُضيّع الترتيب بين النسب المتجاورة (He et al., 2018)، فلا يستطيع الوكيل الاستفادة من أن النسب المتجاورة تتصرف بشكل متشابه. DDPG (Lillicrap et al., 2015) هي الطريقة القياسية من نوع ممثل وناقد (actor-critic) للتحكم المتصل: تتعلم دالة Q وسياسة في آنٍ واحد، ولا يمكن استخدامها إلا مع فضاءات أفعال متصلة (OpenAI Spinning Up). ويعطي Sutton وBarto أصل التسمية: عندما تُستخدم دالة قيمة "لتقييم اختيارات السياسة للأفعال، أو نقدها، تُسمّى دالة القيمة ناقدًا وتُسمّى السياسة ممثلًا". في AMC يتعلم الناقد، من انتقالات مُعاد تشغيلها (replayed transitions)، مقدار المكافأة التي يؤدي إليها زوج من الحالة والنسبة؛ ثم يُدفع الممثل بالصعود التدرجي (gradient ascent) على هذا التقدير ليقترح نسبًا يمنحها الناقد درجة أعلى. الناقد يحكم، والممثل يقترح، ولا يرى أي منهما تدرجًا (gradient) للشبكة المقلّمة نفسها أبدًا.
Why the reward is minus error under a constraintلماذا المكافأة هي سالب الخطأ تحت قيد
Reinforcement learning maximizes reward, so maximizing -Error is minimizing error. The budget appears as a constraint rather than a bonus on purpose: if the agent were paid for shrinking, it would keep shrinking past the target and lose accuracy for nothing. With a hard constraint there is no reward for finishing under budget, so the agent "can precisely arrive at the target compression ratio" (He et al., 2018). The minus infinity branch is the slide's compact way of saying an infeasible network earns nothing useful.
التعلم المعزز يعظّم المكافأة، لذا فإن تعظيم -Error يعني تقليل الخطأ. تظهر الميزانية كقيد لا كمكافأة إضافية عن قصد: لو كوفئ الوكيل على التصغير، لاستمر في التصغير متجاوزًا الهدف وخسر الدقة بلا مقابل. ومع قيد صارم لا توجد مكافأة على الانتهاء تحت الميزانية، فيستطيع الوكيل "الوصول بدقة إلى نسبة الضغط المستهدفة" (He et al., 2018). وفرع سالب ما لا نهاية هو طريقة الشريحة المختصرة للقول إن الشبكة غير الممكنة (التي تخرق القيد) لا تكسب شيئًا مفيدًا.
A wasted episode teaches the critic nothing, so the paper never lets one happen. Before each action it computes the duty: the share of the removal target alpha W_all that this layer must carry, given what earlier layers already removed (W_reduced) and the most the remaining layers could remove at the cap a_max (0.8 for convolutions and 0.98 for fully connected layers in fine-grained pruning; 0.8 for every layer in channel pruning). If the actor's proposal is too timid, it is raised to the duty. The budget is therefore met by construction, and the minus infinity case is a formal backstop, not a common outcome.
الحلقة المهدرة لا تعلّم الناقد شيئًا، لذا لا تسمح الورقة بحدوثها أبدًا. قبل كل فعل تحسب الحصة الواجبة (duty): نصيب هدف الإزالة alpha W_all الذي يجب أن تتحمله هذه الطبقة، بالنظر إلى ما أزالته الطبقات السابقة (W_reduced) وأقصى ما يمكن أن تزيله الطبقات المتبقية عند السقف a_max (0.8 للالتفافات و0.98 للطبقات المتصلة بالكامل في التقليم الدقيق الحبيبات (fine-grained)؛ و0.8 لكل الطبقات في تقليم القنوات). إذا كان اقتراح الممثل متحفظًا أكثر من اللازم، يُرفع إلى الحصة الواجبة. وهكذا تتحقق الميزانية بحكم البناء، وتكون حالة سالب ما لا نهاية صمام أمان شكليًا، لا نتيجة شائعة.
Slide 28 shows the other protocol. When the goal is the smallest model with no accuracy loss, the budget is unknown in advance, so the reward itself must push on size. The bubble chart on the slide (Canziani et al., 2016) shows that top-1 accuracy rises roughly with the logarithm of the operation count, so multiplying -Error by log(FLOPs) gives, in the paper's words, "a small incentive for reducing FLOPs" while staying "sensitive to Error". The ResNet-50 and MobileNet results in the next two concepts use the constrained reward, not this one.
تعرض الشريحة 28 البروتوكول الآخر. عندما يكون الهدف أصغر نموذج دون أي خسارة في الدقة، تكون الميزانية مجهولة مسبقًا، لذا يجب أن تضغط المكافأة نفسها باتجاه الحجم. مخطط الفقاعات في الشريحة (Canziani et al., 2016) يبيّن أن دقة top-1 ترتفع تقريبًا مع لوغاريتم عدد العمليات، لذا فإن ضرب -Error في log(FLOPs) يعطي، بكلمات الورقة، "حافزًا صغيرًا لتقليل FLOPs" مع البقاء "حساسًا للخطأ". نتائج ResNet-50 وMobileNet في المفهومين التاليين تستخدم المكافأة المقيّدة، لا هذه.
The constraint need not be FLOPs. The paper notes that the resource can be "FLOPs or the actual inference time on mobile device", and slide 29 adds the mechanism: a pre-built Latency lookup table of measured per-layer times on the target phone, the same device-in-the-loop idea NetAdapt uses in part 05. Substituting measured time for FLOPs turns a FLOPs-constrained search into a latency-constrained one, and the MobileNet table at the end of this part shows why that matters.
لا يلزم أن يكون القيد FLOPs. تذكر الورقة أن المورد يمكن أن يكون "FLOPs أو زمن الاستدلال الفعلي على الجهاز المحمول"، وتضيف الشريحة 29 الآلية: جدول بحث مُعدّ مسبقًا latency lookup table فيه أزمنة مقاسة لكل طبقة على الهاتف المستهدف، وهي فكرة الجهاز داخل الحلقة نفسها التي يستخدمها NetAdapt في الجزء 05. استبدال FLOPs بالزمن المقاس يحوّل بحثًا مقيدًا بـFLOPs إلى بحث مقيد بزمن الاستجابة، وجدول MobileNet في نهاية هذا الجزء يبيّن لماذا يهم ذلك.
- L1a=0.5020M, 3x3
- L2?60M, 3x3
- L3?100M, 3x3
- L4?80M, 1x1
- L5?40M, 3x3
| Featureالسمة | Rawالقيمة الخام | Scaled to [0, 1]بعد التحجيم إلى [0, 1] |
|---|---|---|
| t | 1 | 0.00 |
| n | 32 | 0.13 |
| c | 3 | 0.02 |
| k | 3x3 | 1.00 |
| FLOPs[t] | 20M | 0.20 |
| reduced | 0M | 0.00 |
| rest | 280M | 0.93 |
| a[t-1] | none | 0.00 |
Toy numbers. Error is 30 + 100 x sum of s_j a_j^2 with sensitivities 0.20, 0.06, 0.04, 0.05, 0.10, so the first and last layers are expensive to prune. The budget bar projects the unpruned layers at full cost until you act on them.أرقام تجريبية. الخطأ يساوي 30 + 100 x sum of s_j a_j^2 بحساسيات 0.20, 0.06, 0.04, 0.05, 0.10، لذا فتقليم الطبقتين الأولى والأخيرة مكلف. يحسب شريط الميزانية الطبقات غير المقلّمة بكامل تكلفتها إلى أن تتخذ فيها فعلًا.
Recall
Name the four RL ingredients of AMC and what each is concretely.سمِّ مكونات التعلم المعزز الأربعة في AMC، وما هو كل منها تحديدًا.
Recall
Why is the reward minus error rather than accuracy, and why is it given only at the end of the episode?لماذا المكافأة هي سالب الخطأ لا الدقة، ولماذا تُعطى فقط في نهاية الحلقة؟
Recall
Why must the action space be continuous?لماذا يجب أن يكون فضاء الأفعال متصلًا؟
Recall
What does AMC not learn?ما الذي لا يتعلمه AMC؟
Quick checkاختبار سريع
Which fact makes AMC choose DDPG rather than a discrete-action agent?ما الحقيقة التي تجعل AMC يختار DDPG بدلًا من وكيل بأفعال متقطعة؟
Quick checkاختبار سريع
Under a FLOPs budget, what reward does the agent get when the pruned model breaks the budget?تحت ميزانية FLOPs، ما المكافأة التي يحصل عليها الوكيل عندما يخرق النموذج المقلّم الميزانية؟
Slide 30 puts the agent up against Song Han's own hand-pruned ResNet-50 from his PhD thesis. The human expert kept 29% of the weights, a 3.4x reduction. The agent kept 20%, a 5x reduction, at the same accuracy: 76.13% top-1 for the original and 76.11% for AMC (He et al., 2018). This experiment uses fine-grained weight pruning, not channel pruning, and it is run as Iterative pruning in four rounds at 50%, 35%, 25% and 20% overall density with 30 fine-tuning epochs after each round, which is the schedule part 06 explains.
تضع الشريحة 30 الوكيل في مواجهة شبكة ResNet-50 التي قلّمها Song Han بيده في أطروحة الدكتوراه. احتفظ الخبير البشري بـ29% من الأوزان، أي تقليل بمقدار 3.4x. واحتفظ الوكيل بـ20%، أي تقليل بمقدار 5x، عند الدقة نفسها: 76.13% في top-1 للأصلية و76.11% لـ AMC (He et al., 2018). تستخدم هذه التجربة تقليم الأوزان الدقيق الحبيبات (fine-grained)، لا تقليم القنوات، وتُنفَّذ بوصفها iterative pruning (تقليمًا تكراريًا) على أربع جولات عند كثافة إجمالية 50% و35% و25% و20%، مع 30 حقبة من fine-tuning (الضبط الدقيق) بعد كل جولة، وهو الجدول الذي يشرحه الجزء 06.
| Regionالمنطقة | Human expertالخبير البشري | AMCAMC |
|---|---|---|
| Conv1Conv1 | 50%50% | 43%43% |
| ResBlock1ResBlock1 | 31%31% | 28%28% |
| ResBlock2ResBlock2 | 31%31% | 28%28% |
| ResBlock3ResBlock3 | 30%30% | 23%23% |
| ResBlock4ResBlock4 | 30%30% | 19%19% |
| FCFC | 20%20% | 10%10% |
| Totalالإجمالي | 29%29% | 20%20% |
Worked exampleمثال محلول
From density to compression ratioمن الكثافة إلى نسبة الضغط
Human expertالخبير البشري
Density 29%, so compression 1 / 0.29 = 3.4x. The thesis records the rules behind it: first layer 50%, residual blocks about 30%, fully connected layer 20% (Han, 2017).الكثافة 29%، إذن الضغط 1 / 0.29 = 3.4x. وتسجّل الأطروحة القواعد وراء ذلك: الطبقة الأولى 50%، والكتل المتبقية (residual blocks) نحو 30%، والطبقة المتصلة بالكامل 20% (Han, 2017).AMCAMC
Density 20%, so compression 1 / 0.20 = 5.0x, with the biggest gains in the late blocks (30% to 19% in ResBlock4) and the classifier (20% to 10%).الكثافة 20%، إذن الضغط 1 / 0.20 = 5.0x، وأكبر المكاسب في الكتل المتأخرة (من 30% إلى 19% في ResBlock4) وفي المصنّف (من 20% إلى 10%).Same accuracy, 1.5x fewer weightsالدقة نفسها، وأوزان أقل بمقدار 1.5x
76.13% versus 76.11% top-1, a difference well inside run-to-run noise, for 5x instead of 3.4x.76.13% مقابل 76.11% في top-1، وهو فرق يقع ضمن ضجيج التكرار من تشغيل لآخر، مقابل 5x بدلًا من 3.4x.
What the agent noticed inside a residual blockما الذي لاحظه الوكيل داخل الكتلة المتبقية
The per-region bars hide the interesting pattern, which slide 31 shows layer by layer. ResNet-50 is built from bottleneck blocks: a 1x1 convolution that reduces the channel count, a 3x3 convolution, and a 1x1 convolution that restores it (He et al., 2016). Walk along the layer index and the kept density forms a sawtooth. The peaks, where the agent kept more, are the 1x1 layers. The crests, where it cut deep, are the 3x3 layers. The paper draws the conclusion directly: the agent "automatically learns that 3x3 convolution has more redundancy than 1x1 convolution and can be pruned more" (He et al., 2018). Nobody told it about kernel shapes; the kernel size k is just one of the eleven features in the state.
الأعمدة حسب المنطقة تخفي النمط المثير، وتعرضه الشريحة 31 طبقة بطبقة. تتكون ResNet-50 من كتل عنق الزجاجة (bottleneck): التفاف 1x1 يقلّل عدد القنوات، ثم التفاف 3x3، ثم التفاف 1x1 يعيده (He et al., 2016). امشِ على رقم الطبقة وستجد أن الكثافة المحتفظ بها ترسم شكل أسنان المنشار. القمم، حيث احتفظ الوكيل بأكثر، هي طبقات 1x1. والقيعان، حيث قطع بعمق، هي طبقات 3x3. وتستخلص الورقة النتيجة مباشرة: الوكيل "يتعلم تلقائيًا أن التفاف 3x3 فيه تكرار (redundancy) أكثر من التفاف 1x1 ويمكن تقليمه أكثر" (He et al., 2018). لم يخبره أحد عن أشكال الأنوية؛ فحجم النواة k مجرد واحدة من الخصائص الإحدى عشرة في الحالة.
The finding makes sense once you think about where redundancy lives. A 1x1 kernel mixes channels and has no spatial extent, so every weight is a distinct channel-to-channel connection with nothing next to it to stand in for it. A 3x3 kernel has nine spatial taps per channel pair, many of which are near zero after training, and it also holds most of a block's weights: in a stage-3 bottleneck the 3x3 layer carries about 590K of the block's 1.1M parameters against 262K for each 1x1 layer (Han, 2017). Cutting the 3x3 layers hard is where the compression is, and it is also where accuracy is cheapest to spend, which is exactly the trade the reward rewards.
تصبح النتيجة منطقية حين تفكر في مكان وجود التكرار. نواة 1x1 تمزج القنوات وليس لها امتداد مكاني، فكل وزن فيها اتصال مميز بين قناة وقناة، ولا يوجد بجواره ما ينوب عنه. أما نواة 3x3 ففيها تسع نقاط مكانية لكل زوج من القنوات، وكثير منها قريب من الصفر بعد التدريب، كما أنها تحمل معظم أوزان الكتلة: في كتلة عنق زجاجة من المرحلة 3 تحمل طبقة 3x3 نحو 590K من أصل 1.1M معامل في الكتلة، مقابل 262K لكل طبقة 1x1 (Han, 2017). قطع طبقات 3x3 بقوة هو حيث يوجد الضغط، وهو أيضًا حيث تكون الدقة أرخص ما يمكن إنفاقه، وهذه بالضبط المقايضة التي تكافئها المكافأة.
Recall
What did AMC learn about 3x3 versus 1x1 convolutions in ResNet-50, and what did that buy?ماذا تعلّم AMC عن التفافات 3x3 مقابل 1x1 في ResNet-50، وماذا كسب من ذلك؟
Quick checkاختبار سريع
Inside the residual blocks of ResNet-50, which layers did the agent keep densest?داخل الكتل المتبقية في ResNet-50، أي الطبقات أبقاها الوكيل الأكثف؟
The final slide moves from weights to milliseconds. MobileNet is run with TF-Lite on a Samsung Galaxy S7 Edge with a Qualcomm Snapdragon SoC, single core, batch size 1, which is the latency-oriented setting of a phone serving one image at a time. Four models are measured: the full 1.0 MobileNet, two AMC results and the 0.75 MobileNet baseline, which is the same architecture with every layer's width scaled by 75%.
تنتقل الشريحة الأخيرة من الأوزان إلى الميلي ثواني. تُشغَّل MobileNet باستخدام TF-Lite على هاتف Samsung Galaxy S7 Edge بشريحة Qualcomm Snapdragon SoC، على نواة واحدة، وبحجم دفعة 1، وهو الإعداد الموجّه لزمن الاستجابة لهاتف يخدم صورة واحدة في كل مرة. تُقاس أربعة نماذج: 1.0 MobileNet الكاملة، ونتيجتان من AMC، وخط الأساس 0.75 MobileNet، وهي المعمارية نفسها مع تحجيم عرض كل طبقة إلى 75%.
| Modelالنموذج | MACMAC | Top-1Top-1 | Latencyزمن الاستجابة | Speedupالتسريع | Memoryالذاكرة |
|---|---|---|---|---|---|
| 1.0 MobileNet | 569M | 70.6% | 119.0 ms | 1x | 20.1 MB |
| AMC (50% FLOPs) | 285M | 70.5% | 64.4 ms | 1.8x | 14.3 MB |
| AMC (50% Time) | 272M | 70.2% | 59.7 ms | 2.0x | 13.2 MB |
| 0.75 MobileNet | 325M | 68.4% | 69.5 ms | 1.7x | 14.8 MB |
Worked exampleمثال محلول
Checking the tableالتحقق من الجدول
Speedupsمعاملات التسريع
119.0 / 64.4 = 1.85 (shown as 1.8x), 119.0 / 59.7 = 1.99 (2.0x), 119.0 / 69.5 = 1.71 (1.7x).119.0 / 64.4 = 1.85 (معروضة 1.8x)، و119.0 / 59.7 = 1.99 (2.0x)، و119.0 / 69.5 = 1.71 (1.7x).MAC fractionsنسب MAC
285 / 569 = 0.50, 272 / 569 = 0.48, 325 / 569 = 0.57. The width multiplier scales cost by roughly alpha^2 = 0.5625 (Howard et al., 2017), which matches the 0.57.285 / 569 = 0.50، و272 / 569 = 0.48، و325 / 569 = 0.57. مضاعِف العرض (width multiplier) يحجّم التكلفة بنحو alpha^2 = 0.5625 (Howard et al., 2017)، وهذا يطابق 0.57.Accuracy deltas from 70.6%فروق الدقة عن 70.6%
-0.1, -0.4 and -2.2 points.-0.1 و-0.4 و-2.2 نقطة.Both AMC rows dominate the uniform baselineكلا صفّي AMC يتفوقان على خط الأساس المنتظم
Each AMC model has fewer MACs, lower latency, less memory and higher accuracy than 0.75 MobileNet. Halving FLOPs gave 1.85x, not 2x; targeting time came closest, at 1.99x.كل نموذج من AMC فيه MACs أقل، وزمن استجابة أقل، وذاكرة أقل، ودقة أعلى من 0.75 MobileNet. تنصيف FLOPs أعطى 1.85x، لا 2x؛ واستهداف الزمن كان الأقرب، عند 1.99x.
Reading the two AMC rows against each otherقراءة صفّي AMC أحدهما مقابل الآخر
- Latencyزمن الاستجابة
- 50% Time is 4.7 ms faster (59.7 versus 64.4 ms)50% Time أسرع بـ4.7 ms (59.7 مقابل 64.4 ms)
- Accuracyالدقة
- 50% Time loses 0.3 points (70.2% versus 70.5%)50% Time يخسر 0.3 نقطة (70.2% مقابل 70.5%)
- MACs
- 272M versus 285M: the time target also ends up slightly smaller272M مقابل 285M: هدف الزمن ينتهي أيضًا بنموذج أصغر قليلًا
- Against 0.75 MobileNetمقابل 0.75 MobileNet
- Both are at least 1.8 points more accurate, at least 5 ms faster, with fewer MACsكلاهما أدق بـ1.8 نقطة على الأقل، وأسرع بـ5 ms على الأقل، مع MACs أقل
Two lessons in one tableدرسان في جدول واحد
First, FLOPs are a proxy. Halving the multiply-accumulates bought 1.85x, not 2x, because a phone does not spend time in proportion to arithmetic. MobileNet's depthwise layers have a low ratio of computation to memory traffic, so trimming them saves fewer milliseconds than the MAC count suggests; the paper reports about 2x speedup on the 1x1 convolutions but less on the depthwise ones (He et al., 2018). When the agent is instead constrained by measured time from the lookup table, it removes work where the phone is actually slow, and the search lands at 59.7 ms, a 1.99x speedup that all but hits the 2x target. That allocation is less accuracy-friendly, which is the 0.3 point cost. You choose the target you care about, and you pay in the other currency.
أولًا، FLOPs مجرد بديل تقريبي. تنصيف عمليات الضرب والجمع (multiply-accumulates) أعطى 1.85x، لا 2x، لأن الهاتف لا يقضي وقته بالتناسب مع الحساب. طبقات depthwise في MobileNet نسبة الحساب فيها إلى حركة الذاكرة منخفضة، لذا فتقليصها يوفّر ميلي ثواني أقل مما يوحي به عدد MAC؛ وتذكر الورقة تسريعًا بنحو 2x على التفافات 1x1 وأقل من ذلك على طبقات depthwise (He et al., 2018). وعندما يُقيَّد الوكيل بدلًا من ذلك بالزمن المقاس من جدول البحث، فإنه يزيل العمل حيث يكون الهاتف بطيئًا فعلًا، فيصل البحث إلى 59.7 ms، أي تسريع 1.99x يكاد يصيب هدف 2x. هذا التوزيع أقل رفقًا بالدقة، وهذه هي تكلفة الـ0.3 نقطة. أنت تختار الهدف الذي يهمك، وتدفع بالعملة الأخرى.
Second, non-uniform beats uniform. Uniform shrinking with the width multiplier is a single knob turned on every layer, and the thinner model must be trained from scratch (Howard et al., 2017). AMC prunes a pretrained network with a different ratio per layer, keeps 2.1 (50% FLOPs) or 1.8 (50% Time) more points of accuracy with fewer MACs than 0.75 MobileNet, and does it after a short fine-tune. In the accuracy versus latency plane the AMC points sit above and to the left, which is the definition of a better Pareto frontier.
ثانيًا، غير المنتظم يتفوق على المنتظم. uniform shrinking (التصغير المنتظم) باستخدام مضاعِف العرض مقبض واحد يُدار على كل طبقة، ويجب تدريب النموذج الأرفع من الصفر (Howard et al., 2017). أما AMC فيقلّم شبكة مدرّبة مسبقًا بنسبة مختلفة لكل طبقة، ويحتفظ بـ2.1 (50% FLOPs) أو 1.8 (50% Time) نقطة دقة إضافية مع MACs أقل من 0.75 MobileNet، ويفعل ذلك بعد ضبط دقيق قصير. في مستوى الدقة مقابل زمن الاستجابة تقع نقاط AMC في الأعلى وإلى اليسار، وهذا هو تعريف جبهة Pareto أفضل.
Recall
In the MobileNet table, why does 50% Time beat 50% FLOPs on latency but lose 0.3 points?في جدول MobileNet، لماذا يتفوق 50% Time على 50% FLOPs في زمن الاستجابة لكنه يخسر 0.3 نقطة؟
Quick checkاختبار سريع
Why does AMC (50% Time) run faster than AMC (50% FLOPs) on the Galaxy S7 Edge?لماذا يعمل AMC (50% Time) أسرع من AMC (50% FLOPs) على Galaxy S7 Edge؟
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- An overall compression ratio fixes the sum; allocating it across layers is a search whose objective is only observable by trying it.نسبة الضغط الإجمالية تحدد المجموع فقط؛ أما توزيعها على الطبقات فهو بحث لا يمكن رؤية دالة هدفه إلا بتجربته.
- Sensitivity analysis assumes per-layer losses add. Layers interact, so its ratios are sub-optimal and do not transfer between models.يفترض تحليل الحساسية أن خسائر الطبقات تُجمع جمعًا. لكن الطبقات تتفاعل، لذا تكون نسبه دون المثلى ولا تنتقل من نموذج إلى آخر.
- AMC: state = layer embedding of 11 scaled features, action = continuous sparsity ratio, agent = DDPG, reward = minus error once all layers are pruned, budget enforced as a constraint.في AMC: الحالة = تضمين الطبقة من 11 خاصية مُقيّسة، والفعل = نسبة تفرّق (sparsity) متصلة، والوكيل = DDPG، والمكافأة = سالب الخطأ بعد تقليم كل الطبقات، مع فرض الميزانية كقيد.
- Continuous actions because ratios are real numbers and grids lose ordering; the critic scores Q(s, a), the actor proposes a.الأفعال متصلة لأن النسب أعداد حقيقية والشبكات المتقطعة تُضيّع الترتيب؛ الناقد يقيّم Q(s, a) والممثل يقترح a.
- AMC learns only the ratios. Magnitude selection inside each layer and one final fine-tune are unchanged.يتعلم AMC النسب فقط. اختيار الأوزان بالمقدار (magnitude) داخل كل طبقة وضبط دقيق (fine-tune) نهائي واحد يبقيان كما هما.
- ResNet-50: 20% density (5x) versus the expert's 29% (3.4x) at 76.1% top-1; 3x3 layers are pruned harder than 1x1 layers.في ResNet-50: كثافة 20% (5x) مقابل 29% للخبير (3.4x) عند دقة top-1 تساوي 76.1%؛ وتُقلَّم طبقات 3x3 بقوة أكبر من طبقات 1x1.
- MobileNet on a Galaxy S7 Edge: 50% FLOPs gives 64.4 ms at 70.5%, 50% time gives 59.7 ms at 70.2%, both beating 0.75 MobileNet at 69.5 ms and 68.4%.MobileNet على Galaxy S7 Edge: هدف 50% FLOPs يعطي 64.4 ms عند 70.5%، وهدف 50% Time يعطي 59.7 ms عند 70.2%، وكلاهما يتفوق على 0.75 MobileNet عند 69.5 ms و68.4%.
- Targeting measured time lands within a whisker of the speed goal; targeting FLOPs is only a proxy.استهداف الزمن المقاس يصل إلى هدف السرعة تقريبًا تمامًا؛ أما استهداف FLOPs فهو مجرد بديل تقريبي (proxy).
Sourcesالمصادر
- AMC: AutoML for Model Compression and Acceleration on Mobile DevicesPaperECCV 2018, He, Lin, Liu, Wang, Li and HanEleven-feature state, continuous action, rewards, Algorithm 1, ResNet-50 density, Pixel 1 MobileNet table. DOI 10.1007/978-3-030-01234-2_48.حالة من إحدى عشرة خاصية، وفعل متصل، والمكافآت، وAlgorithm 1، وكثافة ResNet-50، وجدول MobileNet على Pixel 1. DOI 10.1007/978-3-030-01234-2_48.(opens in a new tab)(يفتح في تبويب جديد)
- 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 4: Pruning and Sparsity Part IIDocsMIT HAN Lab, Fall 2023Source of slides 27 to 32 and of the Galaxy S7 Edge measurements.مصدر الشرائح من 27 إلى 32 وقياسات Galaxy S7 Edge.(opens in a new tab)(يفتح في تبويب جديد)
- Continuous control with deep reinforcement learningPaperLillicrap et al., 2015DDPG: an actor-critic, model-free algorithm for continuous action spaces.DDPG: خوارزمية من نوع ممثل وناقد (actor-critic) لا تعتمد على نموذج (model-free)، لفضاءات الأفعال المتصلة.(opens in a new tab)(يفتح في تبويب جديد)
- Deep Deterministic Policy GradientDocsOpenAI Spinning UpLearns a Q-function and a policy concurrently; only for continuous actions; off-policy; actor trained by ascent on Q.تتعلم دالة Q وسياسة في آنٍ واحد؛ للأفعال المتصلة فقط؛ خارج السياسة (off-policy)؛ ويُدرَّب الممثل بالصعود على Q.(opens in a new tab)(يفتح في تبويب جديد)
- Reinforcement Learning: An Introduction, 2nd editionBookMIT Press 2018, Sutton and BartoChapter 13: the critic assesses the policy's action selections, the policy is the actor.الفصل 13: الناقد يقيّم اختيارات السياسة للأفعال، والسياسة هي الممثل.(opens in a new tab)(يفتح في تبويب جديد)
- Efficient Methods and Hardware for Deep LearningPaperStanford PhD thesis 2017, Song HanTable 3.8: human-expert ResNet-50 densities, 3.4x; per-layer parameter counts of a bottleneck block.Table 3.8: كثافات ResNet-50 لدى الخبير البشري، 3.4x؛ وعدد المعاملات لكل طبقة في كتلة عنق الزجاجة (bottleneck).(opens in a new tab)(يفتح في تبويب جديد)
- MobileNets: Efficient Convolutional Neural Networks for Mobile Vision ApplicationsPaperHoward et al., 2017Table 6: 1.0 MobileNet 569M and 70.6%, 0.75 MobileNet 325M and 68.4%; the width multiplier thins every layer uniformly and needs retraining.Table 6: 1.0 MobileNet بـ569M و70.6%، و0.75 MobileNet بـ325M و68.4%؛ مضاعِف العرض يرقّق كل طبقة بشكل منتظم ويحتاج إلى إعادة تدريب.(opens in a new tab)(يفتح في تبويب جديد)
- Deep Residual Learning for Image RecognitionPaperHe, Zhang, Ren and Sun, CVPR 2016The bottleneck block: 1x1 reduce, 3x3, 1x1 restore.كتلة عنق الزجاجة (bottleneck): 1x1 للتقليل، ثم 3x3، ثم 1x1 للاستعادة.(opens in a new tab)(يفتح في تبويب جديد)
- An Analysis of Deep Neural Network Models for Practical ApplicationsPaperCanziani, Paszke and Culurciello, 2016The accuracy versus operations bubble chart on slide 28; accuracy rises roughly with log operations.مخطط الفقاعات للدقة مقابل عدد العمليات في الشريحة 28؛ ترتفع الدقة تقريبًا مع لوغاريتم عدد العمليات.(opens in a new tab)(يفتح في تبويب جديد)
- mit-han-lab/amcDocsGitHubReference implementation of AMC.التنفيذ المرجعي لـAMC.(opens in a new tab)(يفتح في تبويب جديد)