COE 592Lecture 01المحاضرة 01Part 02الجزء 02
Segmentation, generative models and LLMsالتقطيع (Segmentation) والنماذج التوليدية ونماذج LLM
Promptable segmentation, diffusion models, 3D perception and large language models push computation and memory far beyond classification, and each has an efficient counterpart that recovers speed without losing quality.التقطيع القابل للتوجيه بالأوامر (promptable segmentation) ونماذج الانتشار (diffusion) والإدراك ثلاثي الأبعاد والنماذج اللغوية الكبيرة تدفع الحساب والذاكرة إلى ما يتجاوز التصنيف بكثير، ولكل منها نظير كفء يستعيد السرعة دون فقدان الجودة.
- Conceptsالمفاهيم
- 5
- Slidesالشرائح
- 9-16
- Readingمدة القراءة
- 30 min30 دقيقة
Why this part mattersلماذا يهمّ هذا الجزء
Part 01 measured the price of accuracy on ImageNet. This part follows the same question into the models that define the field today: promptable segmentation, image and video diffusion, 3D perception in a moving car, and large language models. In every case the same move rescues the system: find the block that dominates the cost, then attack that block and only that block.
Every research direction in this course (quantisation, pruning, distillation, efficient attention, distributed inference) is motivated by one of the five cases here, and this is also how you scope a PhD project on embedded ML. Exam questions turn the slide numbers into arithmetic: bytes per parameter, speedup versus MAC ratio, frame budgets in milliseconds. Each concept below ends with that arithmetic worked out so you can do it from memory.
قاس الجزء 01 ثمن الدقة على ImageNet. هذا الجزء يتتبع السؤال نفسه في النماذج التي تحدد هذا المجال اليوم: التقسيم القابل للتوجيه بالتلميحات (promptable segmentation)، ونماذج الانتشار (diffusion) للصور والفيديو، والإدراك ثلاثي الأبعاد في سيارة متحركة، ونماذج اللغة الكبيرة. وفي كل حالة تنقذ الخطوة نفسها النظام: اعثر على الكتلة التي تهيمن على التكلفة، ثم هاجم تلك الكتلة وحدها دون غيرها.
كل اتجاه بحثي في هذا المقرر (التكميم quantisation، والتقليم pruning، والتقطير distillation، والـ attention الفعّال، والاستدلال الموزّع distributed inference) مدفوع بإحدى الحالات الخمس هنا، وهكذا أيضًا تحدد نطاق مشروع دكتوراه في تعلم الآلة المدمج (embedded ML). أسئلة الاختبار تحوّل أرقام الشرائح إلى حسابات: البايتات لكل معامل، والتسريع مقابل نسبة الـ MACs، وميزانيات الإطارات بالملّي ثانية. ينتهي كل مفهوم أدناه بهذه الحسابات محلولة حتى تتمكن من إجرائها من الذاكرة.
By the end you canفي نهاية هذا الجزء ستستطيع
- Name SAM's three blocks, say which one dominates the cost, and explain what EfficientViT-SAM swaps to reach 48.9x.سمِّ الكتل الثلاث في SAM، وحدد أيها يهيمن على التكلفة، واشرح ما الذي يستبدله EfficientViT-SAM ليصل إلى 48.9x.
- Explain why compute follows tokens and denoising steps rather than parameters, and why diffusion cost is super-quadratic in resolution.اشرح لماذا تتبع الحوسبة عدد الـ tokens وخطوات إزالة الضوضاء (denoising steps) لا عدد المعاملات، ولماذا تنمو تكلفة الانتشار (diffusion) أسرع من التربيعي (super-quadratic) مع الدقة (resolution).
- Compare naive patch parallelism with DistriFusion on MACs, latency and artifacts, and account for the gap between 4.0x less work and 3.0x speedup.قارن توازي الرقع البسيط (naive patch parallelism) مع DistriFusion من حيث MACs وزمن الاستجابة (latency) والتشوهات، وفسّر الفجوة بين عمل أقل بـ 4.0x وتسريع قدره 3.0x.
- Turn frames per second into a frame time and show which of Fast-LiDARNet's two levers crosses the 30 fps line.حوّل عدد الإطارات في الثانية (fps) إلى زمن إطار (frame time)، وبيّن أي رافعتي Fast-LiDARNet هي التي تتجاوز خط 30 fps.
- Convert parameters and precision into bytes and GPU counts, and give the three reasons LLMs must also run at the edge.حوّل عدد المعاملات والدقة العددية (precision) إلى بايتات وعدد من وحدات GPU، واذكر الأسباب الثلاثة التي تجعل تشغيل نماذج LLM على الحافة (edge) ضروريًا أيضًا.
Picture a head-mounted camera looking at a door, a small label reading id 27, 52 cm, and a green mask painted over one region. A single click on the door produced that mask. That is what promptable means. The user supplies a hint, a point, a box or a phrase, and the model returns the object the hint refers to. The Segment Anything Model (SAM) from Kirillov et al. was trained on SA-1B, over one billion masks on 11 million images, so it can do this for objects it has never been told about.
تخيّل كاميرا مثبتة على الرأس تنظر إلى باب، وملصقًا صغيرًا مكتوبًا فيه id 27, 52 cm، وقناعًا أخضر مرسومًا فوق منطقة واحدة. نقرة واحدة على الباب أنتجت هذا القناع. هذا هو معنى promptable (قابل للتوجيه بالتلميح). يقدّم المستخدم تلميحًا، نقطة أو صندوقًا أو عبارة، فيعيد النموذج الكائن الذي يشير إليه التلميح. نموذج Segment Anything Model (SAM) من Kirillov et al. دُرِّب على SA-1B، أي أكثر من مليار قناع على 11 million صورة، ولذلك يستطيع فعل ذلك مع كائنات لم يُخبَر عنها قط.
The architecture matters more than the demo. SAM is three blocks. An image encoder, a ViT-H pre-trained with masked autoencoding, reads the image once and produces an image embedding. A prompt encoder turns sparse prompts (points, boxes, text) and dense prompts (masks) into prompt embeddings. A lightweight mask decoder combines the two and outputs a valid mask. The paper is explicit about the asymmetry: the image encoder runs once per image, and given a precomputed embedding, the prompt encoder and mask decoder run in a web browser, on a CPU, in about 50 ms. Encode once, expensively; prompt many times, cheaply.
البنية أهم من العرض التوضيحي. يتكون SAM من ثلاث كتل. مُرمِّز الصور (image encoder)، وهو ViT-H مدرّب مسبقًا بطريقة masked autoencoding، يقرأ الصورة مرة واحدة وينتج تضمينًا للصورة (image embedding). ومُرمِّز التلميحات (prompt encoder) يحوّل التلميحات المتناثرة (sparse: نقاط، صناديق، نص) والتلميحات الكثيفة (dense: أقنعة) إلى تضمينات للتلميحات. ومفكِّك أقنعة خفيف (mask decoder) يدمج الاثنين ويُخرج قناعًا صالحًا. الورقة صريحة بشأن هذا التفاوت: مُرمِّز الصور يعمل مرة واحدة لكل صورة، وبوجود تضمين محسوب مسبقًا يعمل مُرمِّز التلميحات ومفكِّك الأقنعة داخل متصفح ويب، على CPU، في نحو 50 ms. رمِّز مرة واحدة بتكلفة عالية، ووجِّه بالتلميحات مرات كثيرة بتكلفة زهيدة.
SAM's three blocksالكتل الثلاث في SAM
- Image encoderمُرمِّز الصور
- ViT-H, 641.1 M parameters, 2973 GMACs per image, runs once per imageViT-H، 641.1 M معامل، 2973 GMACs لكل صورة، يعمل مرة واحدة لكل صورة
- Prompt encoderمُرمِّز التلميحات
- Points, boxes and text (sparse), masks (dense); tinyنقاط وصناديق ونص (sparse)، وأقنعة (dense)؛ صغير جدًا
- Mask decoderمفكِّك الأقنعة
- Fuses image and prompt embeddings into a valid mask; with the prompt encoder, about 50 ms on a browser CPUيدمج تضمينات الصورة والتلميحات في قناع صالح؛ ومع مُرمِّز التلميحات يستغرق نحو 50 ms على CPU المتصفح
Attack the block that dominatesهاجم الكتلة المهيمنة
Once you see that the encoder holds 2973 GMACs and the rest is a 50 ms CPU job, the efficiency strategy writes itself. EfficientViT-SAM (Zhang, Cai and Han) keeps SAM's prompt encoder and mask decoder unchanged and replaces only the image encoder with EfficientViT, the multi-scale linear attention backbone from Cai et al. (ICCV 2023). Training happens in two stages: first the new encoder is distilled from SAM's ViT-H encoder as the teacher, then the whole model is trained end to end on SA-1B. Nothing else in the pipeline moves.
بمجرد أن ترى أن المُرمِّز يحمل 2973 GMACs وأن الباقي مهمة على CPU مدتها 50 ms، تتضح استراتيجية الكفاءة من تلقاء نفسها. يُبقي EfficientViT-SAM (Zhang, Cai and Han) مُرمِّز التلميحات ومفكِّك الأقنعة في SAM دون تغيير، ويستبدل مُرمِّز الصور وحده بـ EfficientViT، وهو العمود الفقري (backbone) القائم على attention خطي متعدد المقاييس من Cai et al. (ICCV 2023). يجري التدريب على مرحلتين: أولًا يُقطَّر (distilled) المُرمِّز الجديد من مُرمِّز ViT-H الخاص بـ SAM بوصفه المعلّم، ثم يُدرَّب النموذج كله من البداية إلى النهاية على SA-1B. لا شيء آخر في خط المعالجة يتحرك.
Hover, tap or focus a block to see what it costs and whether EfficientViT-SAM touches it.مرّر المؤشر فوق كتلة أو انقر عليها أو ركّز عليها لترى كلفتها وهل يغيّرها EfficientViT-SAM.
Numbers from Table 1 of the EfficientViT-SAM paper. The prompt encoder and mask decoder are identical in every configuration, which is why swapping only the encoder moves the whole bar.الأرقام من Table 1 في ورقة EfficientViT-SAM. مُرمِّز التلقين ومُفكِّك القناع متطابقان في كل الإعدادات، ولهذا يكفي استبدال مُرمِّز الصورة وحده لتحريك الشريط كله.
The fair way to judge the swap is accuracy against speed on the same hardware: zero-shot COCO mAP against A100 throughput with TensorRT in FP16. Zero-shot here has a precise meaning: the models were never trained on COCO, and they are evaluated with boxes from a ViTDet detector as prompts. Two speedups get quoted, and they belong to different models. The 16.5x figure is EfficientViT-SAM-XL1, which is faster and more accurate than SAM (47.8 versus 46.5 mAP). The 48.9x headline belongs to EfficientViT-SAM-L2, which matches SAM at 46.6 mAP while running 538 images per second instead of 11. The full table from the paper makes the families visible.
الطريقة العادلة للحكم على هذا الاستبدال هي الدقة مقابل السرعة على العتاد نفسه: zero-shot COCO mAP مقابل throughput (الإنتاجية) على A100 مع TensorRT بصيغة FP16. لمصطلح zero-shot هنا معنى دقيق: النماذج لم تُدرَّب قط على COCO، وتُقيَّم باستخدام صناديق من كاشف ViTDet بوصفها تلميحات. يُستشهد بتسريعين، وهما يخصان نموذجين مختلفين. رقم 16.5x يخص EfficientViT-SAM-XL1، وهو أسرع من SAM وأدق منه (47.8 مقابل 46.5 mAP). أما الرقم الرئيسي 48.9x فيخص EfficientViT-SAM-L2، الذي يساوي SAM عند 46.6 mAP بينما يعالج 538 صورة في الثانية بدلًا من 11. الجدول الكامل من الورقة يُظهر العائلات بوضوح.
| Modelالنموذج | Encoder paramsمعاملات المُرمِّز | Encoder MACsMACs المُرمِّز | Throughput (img/s)الإنتاجية (img/s) | mAPmAP | Speedup vs SAM-ViT-Hالتسريع مقارنة بـ SAM-ViT-H |
|---|---|---|---|---|---|
| SAM-ViT-HSAM-ViT-H | 641.1 M641.1 M | 2973 G2973 G | 1111 | 46.546.5 | 1x1x |
| EfficientViT-SAM-XL1EfficientViT-SAM-XL1 | 203.3 M203.3 M | 322 G322 G | 182182 | 47.847.8 | 16.5x16.5x |
| EfficientViT-SAM-XL0EfficientViT-SAM-XL0 | 117.0 M117.0 M | 185 G185 G | 278278 | 47.547.5 | 25.3x25.3x |
| EfficientViT-SAM-L2EfficientViT-SAM-L2 | 61.3 M61.3 M | 69 G69 G | 538538 | 46.646.6 | 48.9x48.9x |
| EfficientViT-SAM-L1EfficientViT-SAM-L1 | 47.7 M47.7 M | 49 G49 G | 638638 | 46.246.2 | 58.0x58.0x |
| EfficientViT-SAM-L0EfficientViT-SAM-L0 | 34.8 M34.8 M | 35 G35 G | 762762 | 45.745.7 | 69.3x69.3x |
| EfficientSAMEfficientSAM | 25.3 M25.3 M | 247 G247 G | 183183 | 44.444.4 | 16.6x16.6x |
| EdgeSAMEdgeSAM | 9.6 M9.6 M | 20 G20 G | 449449 | 42.142.1 | 40.8x40.8x |
| MobileSAMMobileSAM | 9.8 M9.8 M | 39 G39 G | 278278 | 38.738.7 | 25.3x25.3x |
Worked exampleمثال محلول
Compute reduction versus measured speedupتقليل الحوسبة مقابل التسريع المقاس
MAC ratioنسبة الـ MACs
SAM-ViT-H to L2: 2973 / 69 ≈ 43.1x fewer encoder MACs.من SAM-ViT-H إلى L2: 2973 / 69 ≈ 43.1x أقل في MACs المُرمِّز.Throughput ratioنسبة الإنتاجية (throughput)
538 / 11 ≈ 48.9x more images per second.538 / 11 ≈ 48.9x صورًا أكثر في الثانية.Compareالمقارنة
The measured speedup is larger than the MAC ratio. MACs are a hardware-neutral proxy; the real number also depends on memory access patterns and how well TensorRT kernels run linear attention.التسريع المقاس أكبر من نسبة الـ MACs. الـ MACs مؤشر تقريبي محايد تجاه العتاد؛ أما الرقم الحقيقي فيعتمد أيضًا على أنماط الوصول إلى الذاكرة ومدى كفاءة نوى TensorRT في تشغيل الـ linear attention.Resultالنتيجة
43x less arithmetic bought 49x more throughput. MACs predict the direction, not the exact size, of a speedup.حسابات أقل بـ 43x اشترت إنتاجية أعلى بـ 49x. تتنبأ الـ MACs باتجاه التسريع، لا بحجمه الدقيق.
The table carries a second lesson. EfficientSAM has 25.3 M encoder parameters, eight times fewer than XL1's 203.3 M, and yet the two run at the same throughput (183 versus 182 img/s), with EfficientSAM losing 3.4 mAP. Model size is about memory; speed is about MACs, memory traffic and kernels. Keep the three apart.
يحمل الجدول درسًا ثانيًا. لدى EfficientSAM عدد 25.3 M من معاملات المُرمِّز، أي أقل بثماني مرات من 203.3 M في XL1، ومع ذلك يعمل الاثنان بالإنتاجية نفسها (183 مقابل 182 img/s)، ويخسر EfficientSAM 3.4 mAP. حجم النموذج (model size) يتعلق بالذاكرة؛ أما السرعة فتتعلق بالـ MACs وحركة البيانات في الذاكرة والنوى. أبقِ الثلاثة منفصلة.
Quick checkاختبار سريع
Which block of SAM does EfficientViT-SAM replace to get its speedup?أي كتلة في SAM يستبدلها EfficientViT-SAM ليحقق تسريعه؟
Quick checkاختبار سريع
What does zero-shot mean for the COCO mAP on slide 10?ما معنى zero-shot بالنسبة لـ COCO mAP في الشريحة 10؟
Recall
Name SAM's three blocks and say which one runs once per image.سمِّ الكتل الثلاث في SAM، وحدد أيها يعمل مرة واحدة لكل صورة.
Recall
What does EfficientViT-SAM change, what does it keep, and what are the throughput and mAP of its 48.9x variant against SAM-ViT-H?ما الذي يغيّره EfficientViT-SAM، وما الذي يُبقيه، وما الإنتاجية والـ mAP لنسخته ذات التسريع 48.9x مقارنة بـ SAM-ViT-H؟
Type "teddy bears working as mad scientists", "a bowl of soup as a planet on a 1960s poster" or "an astronaut riding a horse on Mars" into Midjourney and a finished picture comes back. A diffusion model produced each one from a sentence, by starting from noise and removing a little of it at every step until an image appears. The results look effortless. The bill is not. Emad Mostaque, then CEO of Stability AI, said that training Stable Diffusion used 256 A100 GPUs for about 150,000 GPU-hours at a cost of about $600,000, the figure the lecture uses as Stable Diffusion's training cost.
اكتب "teddy bears working as mad scientists" (دببة محشوة تعمل علماءَ مجانين)، أو "a bowl of soup as a planet on a 1960s poster" (وعاء حساء على هيئة كوكب في ملصق من ستينيات القرن الماضي)، أو "an astronaut riding a horse on Mars" (رائد فضاء يمتطي حصانًا على المريخ) في Midjourney فتعود إليك صورة مكتملة. أنتج نموذج انتشار (diffusion model) كل واحدة منها من جملة، بأن بدأ من ضوضاء وأزال جزءًا صغيرًا منها في كل خطوة حتى تظهر صورة. تبدو النتائج بلا جهد، لكن الفاتورة ليست كذلك. قال Emad Mostaque، الرئيس التنفيذي لـ Stability AI آنذاك، إن تدريب Stable Diffusion استخدم 256 وحدة A100 لنحو 150,000 GPU-hours بتكلفة نحو $600,000، وهو الرقم الذي تستخدمه المحاضرة بوصفه تكلفة تدريب Stable Diffusion.
Worked exampleمثال محلول
What $600,000 of training looks likeكيف يبدو تدريب بقيمة $600,000
Wall-clock timeالزمن الفعلي (wall-clock)
150,000 GPU-hours / 256 GPUs ≈ 586 hours, which is about 24.4 days with every GPU busy the whole time.150,000 GPU-hours / 256 GPUs ≈ 586 hours، أي نحو 24.4 يومًا مع انشغال كل GPU طوال الوقت.Price per GPU-hourالسعر لكل GPU-hour
$600,000 / 150,000 GPU-hours = $4.00 per A100-hour.$600,000 / 150,000 GPU-hours = $4.00 لكل ساعة A100.Cross-checkتحقق متقاطع
256 GPUs × 24 h × 24.4 days ≈ 149,900 GPU-hours, matching the stated total.256 GPUs × 24 h × 24.4 days ≈ 149,900 GPU-hours، وهو ما يطابق الإجمالي المعلن.Resultالنتيجة
One training run: a rack of 256 accelerators for most of a month. Nobody iterates on that budget casually, which is why efficient training and inference are research topics rather than polish.دورة تدريب واحدة: رفّ من 256 مسرّعًا لمعظم شهر. لا أحد يكرر التجارب بهذه الميزانية باستخفاف، ولهذا فإن التدريب والاستدلال الفعّالين موضوعات بحثية لا مجرد تحسينات شكلية.
Stable Diffusion training run, 2022دورة تدريب Stable Diffusion، عام 2022
- GPUsوحدات GPU
- 256 × A100256 × A100
- GPU-hours
- about 150,000نحو 150,000
- Wall clockالزمن الفعلي
- about 24 daysنحو 24 يومًا
- Costالتكلفة
- about $600,000نحو $600,000
- Implied priceالسعر الضمني
- about $4 per GPU-hourنحو $4 لكل GPU-hour
| Runالدورة | A100sوحدات A100 | GPU-hoursGPU-hours | Wall clockالزمن الفعلي | Costالتكلفة |
|---|---|---|---|---|
| Stable Diffusion, 2022Stable Diffusion، 2022 | 256256 | about 150,000نحو 150,000 | about 24 daysنحو 24 يومًا | about $600,000نحو $600,000 |
| MosaicML SD2 base, 2023MosaicML SD2 base، 2023 | 128128 | about 21,000نحو 21,000 | 6.8 days6.8 أيام | under $42,000أقل من $42,000 |
Why parameters are not the costلماذا لا تمثل المعاملات التكلفة
Training is paid once. Inference is paid on every request, so compare what one forward pass costs in MACs across four very different models. The natural expectation is that the biggest model costs the most. The numbers say otherwise, and the reason is the most important idea in this concept.
يُدفع ثمن التدريب مرة واحدة. أما الاستدلال فيُدفع ثمنه مع كل طلب، لذا قارن تكلفة تمريرة أمامية واحدة بالـ MACs عبر أربعة نماذج مختلفة جدًا. التوقع الطبيعي أن النموذج الأكبر هو الأعلى تكلفة. لكن الأرقام تقول غير ذلك، والسبب هو أهم فكرة في هذا المفهوم.
| Modelالنموذج | Parametersالمعاملات | Workloadحمل العمل | MACsMACs | Ratioالنسبة |
|---|---|---|---|---|
| ViT-HViT-H | 0.6 B0.6 B | 518 x 518 image, one forward passصورة 518 x 518، تمريرة أمامية واحدة | 1.02 T1.02 T | baselineخط الأساس |
| Llama 3 8BLlama 3 8B | 8 B8 B | 1,024-token context, 512 output tokensسياق من 1,024 token، و512 token للمخرجات | 11.2 T11.2 T | 11x ViT-H11x ViT-H |
| FLUX.1FLUX.1 | 12 B12 B | 1K x 1K image, one denoising stepصورة 1K x 1K، خطوة إزالة ضوضاء واحدة | 37.2 T37.2 T | 36x ViT-H, 3.3x Llama 336x ViT-H, 3.3x Llama 3 |
| CogVideoXCogVideoX | 5.6 B5.6 B | 480 x 720, 49 frames, one denoising step480 x 720، 49 إطارًا، خطوة إزالة ضوضاء واحدة | 332 T332 T | 8.9x FLUX.1, 326x ViT-H8.9x FLUX.1, 326x ViT-H |
FLUX.1 has 12 B parameters and CogVideoX has 5.6 B, yet CogVideoX needs 8.9x the MACs per step. Llama 3 8B has more parameters than ViT-H by a factor of thirteen but costs eleven times more, not thirteen, and FLUX.1 with 1.5x the parameters of Llama 3 costs 3.3x as much. Parameters alone predict none of these ratios. What predicts them is how many tokens each model pushes through those parameters. A dense transformer spends roughly one multiply-accumulate (two FLOPs) per parameter per token in its linear layers, and on top of that attention compares every token with every other token.
لدى FLUX.1 12 B معامل ولدى CogVideoX 5.6 B، ومع ذلك يحتاج CogVideoX إلى 8.9x من الـ MACs لكل خطوة. ولدى Llama 3 8B معاملات أكثر من ViT-H بثلاثة عشر ضعفًا، لكنه يكلّف أكثر بأحد عشر ضعفًا لا ثلاثة عشر، وFLUX.1 الذي يملك 1.5x من معاملات Llama 3 يكلّف 3.3x. المعاملات وحدها لا تتنبأ بأي من هذه النسب. ما يتنبأ بها هو عدد الـ tokens التي يمررها كل نموذج عبر تلك المعاملات. ينفق الـ transformer الكثيف تقريبًا عملية ضرب وتجميع واحدة (أي اثنتين من FLOPs) لكل معامل لكل token في طبقاته الخطية، وفوق ذلك يقارن الـ attention كل token بكل token آخر.
Now the numbers make sense. ViT-H sees one 518 × 518 image cut into 14-pixel patches, 37 × 37 = 1,369 tokens: 632 M × 1,370 ≈ 0.87 T for the linear layers, and the attention term adds the rest of the 1.02 T. Llama 3 processes about 1,500 tokens. FLUX.1 works on the latent of a 1K × 1K image, about 4,000 tokens. CogVideoX compresses 49 frames of 480 × 720 video into 13 latent frames and denoises them all at once, about 17,500 tokens, roughly four times FLUX.1. Because the attention term grows with the square of that count, the bill grows far more than four times, and the smaller parameter count cannot save it. Read the linear term as the weights each token actually passes through, not the headline parameter count: for FLUX.1 the naive 12 B × 4,096 ≈ 49 T overshoots the 37.2 T bar because image and text tokens use separate weights in its double-stream blocks. One accounting rule explains the ordering of the chart: compute is parameters times tokens, plus attention.
الآن تصبح الأرقام منطقية. يرى ViT-H صورة واحدة بحجم 518 × 518 مقطّعة إلى رقع بحجم 14-pixel، أي 37 × 37 = 1,369 token: 632 M × 1,370 ≈ 0.87 T للطبقات الخطية، ويضيف حد الـ attention بقية الـ 1.02 T. يعالج Llama 3 نحو 1,500 token. ويعمل FLUX.1 على الفضاء الكامن (latent) لصورة 1K × 1K، أي نحو 4,000 token. ويضغط CogVideoX 49 إطارًا من فيديو 480 × 720 إلى 13 إطارًا كامنًا ويزيل الضوضاء منها كلها دفعة واحدة، أي نحو 17,500 token، قرابة أربعة أضعاف FLUX.1. ولأن حد الـ attention ينمو مع مربع هذا العدد، تنمو الفاتورة أكثر بكثير من أربعة أضعاف، ولا يستطيع العدد الأصغر من المعاملات إنقاذها. اقرأ الحد الخطي على أنه الأوزان التي يمر بها كل token فعلًا، لا عدد المعاملات المعلن: في FLUX.1 يتجاوز التقدير الساذج 12 B × 4,096 ≈ 49 T عمود 37.2 T لأن tokens الصورة والنص تستخدم أوزانًا منفصلة في كتل التدفق المزدوج (double-stream blocks). قاعدة محاسبية واحدة تفسر ترتيب المخطط: الحوسبة هي المعاملات مضروبة في الـ tokens، زائد الـ attention.
One more multiplier hides in the words "single step" under the FLUX.1 and CogVideoX bars. A diffusion model repeats its forward pass once per denoising step. With a 50-step sampler, one 1K FLUX.1 image costs 37.2 T × 50 = 1,860 T MACs, and a CogVideoX clip costs 332 T × 50 = 16,600 T. A classifier pays its bar once; a generator pays it fifty times.
يختبئ مضاعِف آخر في عبارة "single step" (خطوة واحدة) تحت عمودي FLUX.1 وCogVideoX. يكرر نموذج الانتشار تمريرته الأمامية مرة لكل خطوة إزالة ضوضاء (denoising step). مع مُعايِن (sampler) من 50 خطوة، تكلّف صورة FLUX.1 واحدة بدقة 1K مقدار 37.2 T × 50 = 1,860 T MACs، ويكلّف مقطع CogVideoX مقدار 332 T × 50 = 16,600 T. المصنِّف يدفع ثمن عموده مرة واحدة؛ أما النموذج التوليدي فيدفعه خمسين مرة.
Resolution is worse than quadraticالدقة (resolution) أسوأ من التربيعي
Now hold the model fixed and vary only the image side length for FLUX.1, from 1024 to 4096. Going four times wider makes the image sixteen times larger in pixels, so a quadratic law would predict sixteen times the MACs. From the slide's left chart, one step at 1K x 1K costs 37.2 T, and the curve on the right ends near 1,950 T at 4096: a factor of about 52, far above the 16x a quadratic law predicts. This is what the lecture calls super-quadratic scaling, and the formula above explains it. Tokens grow with pixels (16x), the linear term grows with tokens (16x), and the attention term grows with tokens squared (256x). The blend lands at about 52x.
ثبّت النموذج الآن وغيّر فقط طول ضلع الصورة في FLUX.1، من 1024 إلى 4096. جعل الصورة أعرض بأربع مرات يجعلها أكبر بست عشرة مرة في البكسلات، لذا يتنبأ قانون تربيعي بستة عشر ضعفًا من الـ MACs. من المخطط الأيسر في الشريحة، تكلّف خطوة واحدة عند 1K x 1K مقدار 37.2 T، وينتهي المنحنى على اليمين قرب 1,950 T عند 4096: أي عامل يقارب 52، أعلى بكثير من 16x التي يتنبأ بها القانون التربيعي. هذا ما تسميه المحاضرة super-quadratic scaling (تدرّج أسرع من التربيعي)، والصيغة أعلاه تفسّره. تنمو الـ tokens مع البكسلات (16x)، وينمو الحد الخطي مع الـ tokens (16x)، وينمو حد الـ attention مع مربع الـ tokens (256x). والمزيج يستقر عند نحو 52x.
The solid curve is 31.6 (s/1024)^2 + 5.6 (s/1024)^4 trillion MACs, fitted to the two end points of the slide chart. It is a teaching model of the slide curve, not a profile of FLUX.1 itself.المنحنى المتصل هو 31.6 (s/1024)^2 + 5.6 (s/1024)^4 تريليون MACs، وقد طُوِّع ليمر بنقطتي الطرفين في رسم الشريحة. إنه نموذج تعليمي لمنحنى الشريحة، وليس قياسًا فعليًا لـ FLUX.1 نفسه.
FLUX.1 MACs per step read off the slide chart, by image sideMACs لكل خطوة في FLUX.1 مقروءة من مخطط الشريحة، حسب طول ضلع الصورة
- 1024
- about 37 Tنحو 37 T
- 1536
- about 94 Tنحو 94 T
- 2048
- about 207 Tنحو 207 T
- 2560
- about 406 Tنحو 406 T
- 3072
- about 728 Tنحو 728 T
- 3584
- about 1,226 Tنحو 1,226 T
- 4096
- about 1,950 Tنحو 1,950 T
Worked exampleمثال محلول
Fitting the slide curveملاءمة منحنى الشريحة
Modelالنموذج
Let r = side / 1024 and write MACs(r) = A r² + B r⁴: a token-linear part and an attention part.لنفرض r = side / 1024 ونكتب MACs(r) = A r² + B r⁴: جزء خطي في الـ tokens وجزء للـ attention.Fit the end pointsملاءمة النقطتين الطرفيتين
A + B = 37.2 at r = 1 and 16A + 256B = 1950 at r = 4, so B ≈ 5.6 T and A ≈ 31.6 T.A + B = 37.2 عند r = 1 و16A + 256B = 1950 عند r = 4، إذن B ≈ 5.6 T وA ≈ 31.6 T.Check the middleتحقق من الوسط
At 2048: 4 × 31.6 + 16 × 5.6 ≈ 216 T (chart about 207 T). At 3072: 9 × 31.6 + 81 × 5.6 ≈ 741 T (chart about 728 T).عند 2048: 4 × 31.6 + 16 × 5.6 ≈ 216 T (المخطط نحو 207 T). وعند 3072: 9 × 31.6 + 81 × 5.6 ≈ 741 T (المخطط نحو 728 T).Resultالنتيجة
At 1024 attention is about 15% of the cost. At 4096 it is about three quarters. This is why efficient attention (the EfficientViT backbone from the previous concept, FlashAttention, linear attention) is a research area of its own.عند 1024 يشكّل الـ attention نحو 15% من التكلفة. وعند 4096 يشكّل نحو ثلاثة أرباعها. ولهذا فإن الـ attention الفعّال (العمود الفقري EfficientViT من المفهوم السابق، وFlashAttention، والـ linear attention) مجال بحثي قائم بذاته.
Quick checkاختبار سريع
Why does one CogVideoX step cost more MACs than one FLUX.1 step?لماذا تكلّف خطوة واحدة من CogVideoX عددًا من MACs أكبر من خطوة واحدة من FLUX.1؟
Quick checkاختبار سريع
FLUX.1 MACs rise from about 37 T at 1024 to about 1,950 T at 4096, roughly 52x, while pixels grow 16x. What best explains that?ترتفع MACs في FLUX.1 من نحو 37 T عند 1024 إلى نحو 1,950 T عند 4096، أي قرابة 52x، بينما تنمو البكسلات 16x. ما أفضل تفسير لذلك؟
Recall
256 A100s for 150,000 GPU-hours: how many days is that, and what price per GPU-hour does $600,000 imply?256 وحدة A100 لمدة 150,000 GPU-hours: كم يومًا يعادل ذلك، وما السعر لكل GPU-hour الذي يعنيه مبلغ $600,000؟
Recall
Why does CogVideoX with 5.6 B parameters need 8.9x the MACs of FLUX.1 with 12 B parameters?لماذا يحتاج CogVideoX بمعاملاته البالغة 5.6 B إلى 8.9x من MACs نموذج FLUX.1 ذي 12 B معامل؟
Recall
From 1024 to 4096, how much do pixels grow and how much do FLUX.1 MACs grow, and why the difference?من 1024 إلى 4096، بكم تنمو البكسلات وبكم تنمو MACs في FLUX.1، ولماذا الفرق؟
Ask SDXL for a "Romantic painting of a ship sailing in a stormy sea" at high resolution. One GPU paints one ship in 12.3 s. The obvious way to go faster is to cut the canvas into four vertical strips, hand each strip to its own GPU, and let them work without talking. The result is 3.9x faster and wrong: four strips, four ships, four different skies. Each patch generated its own picture because no patch could see the others.
اطلب من SDXL "Romantic painting of a ship sailing in a stormy sea" (لوحة رومانسية لسفينة تبحر في بحر عاصف) بدقة عالية. يرسم GPU واحد سفينة واحدة في 12.3 s. الطريقة البديهية للإسراع هي تقطيع اللوحة إلى أربعة شرائط عمودية، وتسليم كل شريط إلى GPU خاص به، وتركها تعمل دون أن تتواصل. النتيجة أسرع بـ 3.9x لكنها خاطئة: أربعة شرائط، وأربع سفن، وأربع سماوات مختلفة. ولّدت كل رقعة صورتها الخاصة لأنه لم تكن هناك رقعة تستطيع رؤية الأخريات.
DistriFusion (Li et al., CVPR 2024) keeps the split and restores the context. The trick rests on a property of diffusion: consecutive denoising steps produce similar activations, because each step removes only a little noise. So a patch can attend to its neighbours' activations from the previous step instead of waiting for the current one. The paper calls this displaced patch parallelism. The first few denoising steps (the warm-up: the first step plus four more in the paper) run synchronous patch parallelism so everyone starts from the same picture; after that, communication runs asynchronously and hides behind computation. No retraining is needed. The latency drops to 4.16 s, 3.0x faster than one GPU, and the ship is one ship.
يُبقي DistriFusion (Li et al., CVPR 2024) على التقسيم ويستعيد السياق. تعتمد الحيلة على خاصية في الـ diffusion: خطوات إزالة الضوضاء المتتالية (denoising steps) تنتج تنشيطات متشابهة، لأن كل خطوة تزيل قدرًا ضئيلًا من الضوضاء فقط. لذلك تستطيع الرقعة أن تنتبه (attend) إلى تنشيطات جاراتها من الخطوة السابقة بدلًا من انتظار الخطوة الحالية. تسمي الورقة ذلك displaced patch parallelism (توازي الرقع المُزاح). أول بضع خطوات لإزالة الضوضاء (الإحماء warm-up: الخطوة الأولى وأربع خطوات أخرى في الورقة) تعمل بتوازي رقع متزامن حتى يبدأ الجميع من الصورة نفسها؛ وبعد ذلك يجري التواصل بشكل غير متزامن ويختبئ خلف الحوسبة. لا حاجة لإعادة التدريب. ينخفض زمن الاستجابة (latency) إلى 4.16 s، أي أسرع بـ 3.0x من GPU واحد، والسفينة سفينة واحدة.
| Setupالإعداد | MACs per deviceMACs لكل جهاز | Work per deviceالعمل لكل جهاز | Latencyزمن الاستجابة | Speedupالتسريع | Qualityالجودة |
|---|---|---|---|---|---|
| Original, 1 GPUالأصلي، GPU واحدة | 907 T907 T | 1x1x | 12.3 s12.3 s | 1x1x | reference imageالصورة المرجعية |
| Naive patches, 4 GPUsرقع بسيطة، 4 وحدات GPU | 190 T190 T | 4.8x lessأقل بـ 4.8x | 3.14 s3.14 s | 3.9x3.9x | duplicated subjectsتكرار العناصر |
| DistriFusion, 4 GPUsDistriFusion، 4 وحدات GPU | 227 T227 T | 4.0x lessأقل بـ 4.0x | 4.16 s4.16 s | 3.0x3.0x | no artifactsبلا تشوهات |
| DistriFusion, 8 GPUs (paper, not on the slide)DistriFusion، 8 وحدات GPU (من الورقة، ليست في الشريحة) | 113 T113 T | 8.0x lessأقل بـ 8.0x | 2.74 s2.74 s | 4.5x4.5x | no artifactsبلا تشوهات |
Worked exampleمثال محلول
Where the work wentأين ذهب العمل
Naive totalالإجمالي في الطريقة البسيطة
190 T × 4 = 760 T, less than the original 907 T. Naive patches skip all cross-patch attention, so the total work drops. The missing 147 T is exactly the missing context.190 T × 4 = 760 T، أقل من 907 T الأصلية. الرقع البسيطة تتخطى كل attention بين الرقع، لذا ينخفض إجمالي العمل. والـ 147 T المفقودة هي بالضبط السياق المفقود.DistriFusion totalإجمالي DistriFusion
227 T × 4 = 908 T ≈ 907 T. The full computation is preserved and simply divided by four.227 T × 4 = 908 T ≈ 907 T. الحوسبة الكاملة محفوظة ومقسومة ببساطة على أربعة.Ideal latencyزمن الاستجابة المثالي
12.3 s / 4 ≈ 3.08 s if four GPUs were perfectly parallel. Naive lands at 3.14 s, DistriFusion at 4.16 s.12.3 s / 4 ≈ 3.08 s لو كانت وحدات GPU الأربع متوازية تمامًا. الطريقة البسيطة تصل إلى 3.14 s، وDistriFusion إلى 4.16 s.Resultالنتيجة
DistriFusion does 4.0x less work per GPU but runs only 3.0x faster. The difference is the cost of exchanging activations between GPUs and of the synchronous warm-up steps.يؤدي DistriFusion عملًا أقل بـ 4.0x لكل GPU لكنه أسرع بـ 3.0x فقط. الفرق هو تكلفة تبادل التنشيطات بين وحدات GPU وتكلفة خطوات الإحماء المتزامنة.
The pattern is general in distributed systems: splitting work across machines helps only when the compute you save exceeds the communication you add. Here the saving is large because a high-resolution diffusion step is enormous (MACs in the hundreds of trillions), and the communication is hidden behind it. The paper also runs a scaling study on a larger image, 3840 × 3840, shown in the table below. Read down the efficiency column: every added GPU still helps, but each device contributes less than the last, because the communication grows while the per-device work shrinks.
هذا النمط عام في الأنظمة الموزعة: توزيع العمل على عدة أجهزة لا يفيد إلا عندما تتجاوز الحوسبةُ التي توفرها التواصلَ الذي تضيفه. هنا التوفير كبير لأن خطوة الانتشار عالية الدقة ضخمة (MACs بمئات التريليونات)، والتواصل مختبئ خلفها. تجري الورقة أيضًا دراسة تدرّج على صورة أكبر، 3840 × 3840، مبيّنة في الجدول أدناه. اقرأ عمود الكفاءة (efficiency) من الأعلى إلى الأسفل: كل GPU مضافة ما زالت تفيد، لكن كل جهاز يساهم بأقل من سابقه، لأن التواصل ينمو بينما يتقلص العمل لكل جهاز.
| A100sوحدات A100 | Speedup over one GPUالتسريع مقارنة بـ GPU واحدة | Marginal speedupالتسريع الحدّي | Parallel efficiencyكفاءة التوازي |
|---|---|---|---|
| 11 | 1x1x | referenceالمرجع | 100%100% |
| 22 | 1.8x1.8x | 1.8x1.8x | 90%90% |
| 44 | 3.4x3.4x | 1.9x1.9x | 85%85% |
| 88 | 6.1x6.1x | 1.8x1.8x | 76%76% |
Quick checkاختبار سريع
DistriFusion cuts MACs per GPU 4.0x but latency only 3.0x. What explains the gap?يخفض DistriFusion عدد MACs لكل GPU بمقدار 4.0x لكنه يخفض زمن الاستجابة بمقدار 3.0x فقط. ما الذي يفسر الفجوة؟
Quick checkاختبار سريع
Where does a DistriFusion patch get context about its neighbours?من أين تحصل رقعة DistriFusion على السياق المتعلق بجاراتها؟
Recall
What artifact does naive patch parallelism produce, and why?ما التشوه الذي ينتجه توازي الرقع البسيط، ولماذا؟
Recall
Why is 190 T times 4 less than the original 907 T?لماذا يكون 190 T مضروبًا في 4 أقل من 907 T الأصلية؟
A 2015 Toyota Prius V with a roof-mounted Velodyne LiDAR drives a wooded test track. A network reads raw 3D point clouds and produces steering. A car does not care how elegant the network is; it cares whether the answer arrives before the deadline the system sets. Three measurements tell the story: MinkowskiNet at 5 fps is "too slow to drive", the same network with optimised kernels reaches 18 fps, and Fast-LiDARNet reaches 47 fps, above the 30 fps line the slide marks as real time.
سيارة Toyota Prius V موديل 2015 مزودة بجهاز Velodyne LiDAR مثبت على السقف تسير في مضمار اختبار مُشجَّر. تقرأ شبكةٌ سحبَ النقاط ثلاثية الأبعاد الخام (point clouds) وتنتج أوامر التوجيه. لا تهتم السيارة بمدى أناقة الشبكة؛ ما يهمها هو أن تصل الإجابة قبل الموعد النهائي الذي يحدده النظام. ثلاثة قياسات تحكي القصة: MinkowskiNet عند 5 fps "أبطأ من أن يقود" (too slow to drive)، والشبكة نفسها مع نوى محسّنة تصل إلى 18 fps، وFast-LiDARNet تصل إلى 47 fps، فوق خط 30 fps الذي تحدده الشريحة بوصفه الزمن الحقيقي (real time).
The most useful way to read fps is to invert it into a frame time. A stream at 30 fps gives you 33.3 ms per frame, and everything the model does must fit inside that budget.
أنفع طريقة لقراءة الـ fps هي قلبها إلى زمن إطار (frame time). تدفق بمعدل 30 fps يمنحك 33.3 ms لكل إطار، وكل ما يفعله النموذج يجب أن يتسع داخل تلك الميزانية.
Frame times behind the barsأزمنة الإطارات وراء الأعمدة
- Budget at 30 fpsالميزانية عند 30 fps
- 33.3 ms33.3 ms
- MinkowskiNet, 5 fps
- 200 ms, 167 ms over budget200 ms، تتجاوز الميزانية بـ 167 ms
- Optimised kernels, 18 fpsنوى محسّنة، 18 fps
- 55.6 ms, 22 ms over budget55.6 ms، تتجاوز الميزانية بـ 22 ms
- Fast-LiDARNet, 47 fps
- 21.3 ms, 12 ms to spare21.3 ms، مع فائض 12 ms
The paper (Liu, Amini, Zhu, Karaman, Han and Rus, ICRA 2021) is explicit about the two levers. Their optimised sparse convolution kernel gives a 3.6x acceleration, and their hardware-aware model design reduces latency by another 2.6x. The two multiply: 3.6 × 2.6 ≈ 9.4, which is 47 / 5. The first lever is pure systems work: the same network, the same accuracy, better code for the sparse operations point clouds need. The second is algorithmic: a smaller architecture chosen with the hardware in mind. This pairing is what the lecture means by algorithm and system co-design. Neither lever alone reaches the line. Kernels take the network from 200 ms to 55.6 ms and still miss by 22 ms; the redesign brings it to 21.3 ms.
الورقة (Liu, Amini, Zhu, Karaman, Han and Rus, ICRA 2021) صريحة بشأن الرافعتين. نواة الالتفاف المتناثر (sparse convolution kernel) المحسّنة لديهم تعطي تسريعًا قدره 3.6x، وتصميم النموذج المراعي للعتاد (hardware-aware) يخفض زمن الاستجابة بمقدار 2.6x أخرى. الرافعتان تتضاعفان: 3.6 × 2.6 ≈ 9.4، وهو 47 / 5. الرافعة الأولى عمل أنظمة بحت: الشبكة نفسها، والدقة نفسها، وشيفرة أفضل للعمليات المتناثرة التي تحتاجها سحب النقاط. والثانية خوارزمية: بنية أصغر مختارة مع مراعاة العتاد. هذا الاقتران هو ما تعنيه المحاضرة بـ algorithm and system co-design (التصميم المشترك للخوارزمية والنظام). ولا تصل أي رافعة وحدها إلى الخط. النوى تنقل الشبكة من 200 ms إلى 55.6 ms وتظل متأخرة بـ 22 ms؛ وإعادة التصميم توصلها إلى 21.3 ms.
| Configurationالإعداد | Rateالمعدل | Frame timeزمن الإطار | Leverالرافعة | Inside 33.3 ms?داخل 33.3 ms؟ |
|---|---|---|---|---|
| MinkowskiNetMinkowskiNet | 5 fps5 fps | 200 ms200 ms | noneلا شيء | no, 167 ms overلا، يتجاوزها بـ 167 ms |
| MinkowskiNet, optimised sparse kernelsMinkowskiNet مع نوى متناثرة محسّنة | 18 fps18 fps | 55.6 ms55.6 ms | system: 3.6xالنظام: 3.6x | no, 22 ms overلا، يتجاوزها بـ 22 ms |
| Fast-LiDARNetFast-LiDARNet | 47 fps47 fps | 21.3 ms21.3 ms | algorithm: 2.6x more, 9.4x totalالخوارزمية: 2.6x إضافية، 9.4x إجمالًا | yes, 12 ms to spareنعم، مع فائض 12 ms |
Quick checkاختبار سريع
Kernel optimisation lifts MinkowskiNet to 18 fps. Why is that still not enough?يرفع تحسين النوى MinkowskiNet إلى 18 fps. لماذا لا يكفي ذلك؟
Recall
Name Fast-LiDARNet's two levers with their multipliers and the resulting frame rates.سمِّ رافعتي Fast-LiDARNet مع مضاعِف كل منهما ومعدلات الإطارات الناتجة.
Recall
What is the frame budget at 30 fps, and what is MinkowskiNet's frame time at 5 fps?ما ميزانية الإطار عند 30 fps، وما زمن إطار MinkowskiNet عند 5 fps؟
MT-NLG, the largest model on the lecture's chart, has 530 billion parameters. Store each one in FP16, two bytes, and the weights alone occupy 530 × 10⁹ × 2 = 1,060 GB. The largest GPU of that period, an A100 with 80 GB, holds 40 billion FP16 parameters. The gap between the two is 1,060 / 80 = 13.25, so 14 GPUs of weights before a single activation is computed.
لدى MT-NLG، أكبر نموذج على مخطط المحاضرة، 530 مليار معامل. خزّن كل واحد منها بصيغة FP16، أي بايتين، فتشغل الأوزان وحدها 530 × 10⁹ × 2 = 1,060 GB. أكبر GPU في تلك الفترة، وهي A100 بذاكرة 80 GB، تسع 40 مليار معامل بصيغة FP16. الفجوة بين الاثنين 1,060 / 80 = 13.25، أي 14 وحدة GPU من الأوزان قبل حساب تنشيط واحد.
To compare a model with a chip, put both on one log axis of model size by converting GPU bytes into a parameter count at FP16, which is what the lecture's assumption "data are FP16" means. 16 GB becomes 8 B parameters, 32 GB becomes 16 B, 80 GB becomes 40 B. On that shared axis the two curves tell the story of the large language model era: model size climbs from 0.05 B to 530 B, about 10,000x in roughly four years, while GPU memory climbs from 16 GB to 80 GB, 5x. Models have outgrown the chips they run on, and the distance keeps widening.
لمقارنة نموذج برقاقة، ضع الاثنين على محور لوغاريتمي واحد لحجم النموذج (model size) بتحويل بايتات الـ GPU إلى عدد معاملات بصيغة FP16، وهذا ما يعنيه افتراض المحاضرة "data are FP16". تصبح 16 GB مساوية لـ 8 B معامل، و32 GB مساوية لـ 16 B، و80 GB مساوية لـ 40 B. على هذا المحور المشترك يروي المنحنيان قصة عصر نماذج اللغة الكبيرة (large language model): يصعد حجم النموذج من 0.05 B إلى 530 B، أي نحو 10,000x في قرابة أربع سنوات، بينما تصعد ذاكرة الـ GPU من 16 GB إلى 80 GB، أي 5x. لقد تجاوزت النماذج الرقائق التي تعمل عليها، والمسافة تواصل الاتساع.
| Modelالنموذج | Yearالسنة | Parametersالمعاملات | FP16 weightsأوزان FP16 | A100 80 GB GPUsوحدات A100 80 GB |
|---|---|---|---|---|
| TransformerTransformer | 20172017 | 0.05 B0.05 B | 0.1 GB0.1 GB | 11 |
| GPTGPT | 20182018 | 0.11 B0.11 B | 0.22 GB0.22 GB | 11 |
| BERT-LargeBERT-Large | 20182018 | 0.34 B0.34 B | 0.68 GB0.68 GB | 11 |
| GPT-2GPT-2 | 20192019 | 1.5 B1.5 B | 3 GB3 GB | 11 |
| Megatron-LMMegatron-LM | 20192019 | 8.3 B8.3 B | 16.6 GB16.6 GB | 11 |
| T-NLGT-NLG | 20202020 | 17 B17 B | 34 GB34 GB | 11 |
| GPT-3GPT-3 | 20202020 | 175 B175 B | 350 GB350 GB | 55 |
| MT-NLGMT-NLG | 2021 (paper 2022)2021 (الورقة 2022) | 530 B530 B | 1,060 GB1,060 GB | 1414 |
| Acceleratorالمسرّع | Memoryالذاكرة | FP16 parameters it holdsمعاملات FP16 التي يسعها |
|---|---|---|
| TPU v2TPU v2 | 16 GB16 GB | 8 B8 B |
| V100V100 | 32 GB32 GB | 16 B16 B |
| TPU v3TPU v3 | 32 GB32 GB | 16 B16 B |
| A100A100 | 40 GB40 GB | 20 B20 B |
| A100A100 | 80 GB80 GB | 40 B40 B |
Parameters to bytes to GPUsمن المعاملات إلى البايتات إلى وحدات GPU
Every memory question in this course starts with one multiplication. Parameters times bytes per parameter gives the weight memory; divide by the memory of one device and round up to get the device count. The bytes per parameter depend on the numeric format: 4 for FP32, 2 for FP16 or BF16, 1 for INT8, 0.5 for INT4. Quantisation, which later lectures cover in depth, is simply the art of moving down that list without losing accuracy.
كل سؤال عن الذاكرة في هذا المقرر يبدأ بعملية ضرب واحدة. المعاملات مضروبة في البايتات لكل معامل تعطي ذاكرة الأوزان؛ اقسمها على ذاكرة جهاز واحد وقرّب إلى الأعلى لتحصل على عدد الأجهزة. تعتمد البايتات لكل معامل على الصيغة العددية (numeric format): 4 لـ FP32، و2 لـ FP16 أو BF16، و1 لـ INT8، و0.5 لـ INT4. التكميم (quantisation)، الذي تغطيه المحاضرات اللاحقة بعمق، هو ببساطة فن النزول في هذه القائمة دون خسارة الدقة.
Worked exampleمثال محلول
MT-NLG on A100 80 GB GPUsMT-NLG على وحدات A100 80 GB
FP16FP16
530 B × 2 bytes = 1,060 GB; 1,060 / 80 = 13.25, so 14 GPUs for the weights alone.530 B × 2 bytes = 1,060 GB؛ 1,060 / 80 = 13.25، إذن 14 وحدة GPU للأوزان وحدها.INT8INT8
530 B × 1 byte = 530 GB; 530 / 80 = 6.6, so 7 GPUs.530 B × 1 byte = 530 GB؛ 530 / 80 = 6.6، إذن 7 وحدات GPU.INT4INT4
530 B × 0.5 byte = 265 GB; 265 / 80 = 3.3, so 4 GPUs.530 B × 0.5 byte = 265 GB؛ 265 / 80 = 3.3، إذن 4 وحدات GPU.Resultالنتيجة
Every halving of precision halves the shelf. The same rule says an 80 GB card holds at most 40 B FP16 parameters, and that leaves zero room for anything else.كل تنصيف للدقة العددية ينصّف الرف. والقاعدة نفسها تقول إن بطاقة 80 GB تسع على الأكثر 40 B معامل بصيغة FP16، وهذا لا يترك أي مساحة لأي شيء آخر.
Weights only. Activations and the KV cache add memory that grows with batch size and context length, so a model that just fits here does not run. GB means 10^9 bytes. The 4 GB is the RAM slide 23 gives mobile AI (its activation-memory row), which holds weights and activations together; the 1 MB is the flash weight storage it gives a microcontroller.الأوزان فقط. التنشيطات (activations) وKV cache تضيف ذاكرة تنمو مع حجم الدفعة (batch size) وطول السياق، لذا فالنموذج الذي يتسع هنا بالكاد لن يعمل فعليًا. تعني GB هنا 10^9 بايت. قيمة 4 GB هي ذاكرة RAM التي تنسبها الشريحة 23 إلى mobile AI (في صف ذاكرة التنشيطات)، وهي تحمل الأوزان والتنشيطات معًا؛ أما 1 MB فهي سعة ذاكرة flash لتخزين الأوزان التي تنسبها إلى المتحكم الدقيق.
Try Llama 3 8B in the calculator. In FP16 it needs 16 GB, four times the 4 GB of RAM slide 23 gives a phone. Slide 23 lists that 4 GB as activation memory and 256 GB as weight storage; in practice LLM inference loads the weights into that same RAM, so the 4 GB is the binding limit. In INT4 the model needs 4 GB, exactly at the line, with nothing left for activations. Now try the 2017 Transformer at 0.05 B against a microcontroller's 1 MB of weight storage: 100 MB in FP16, a hundred times over. The gap between what models need and what edge hardware has is the subject of part 03.
جرّب Llama 3 8B في الحاسبة. بصيغة FP16 يحتاج إلى 16 GB، أي أربعة أضعاف ذاكرة RAM البالغة 4 GB التي تعطيها الشريحة 23 للهاتف. تذكر الشريحة 23 هذه الـ 4 GB بوصفها ذاكرة تنشيطات و256 GB بوصفها تخزينًا للأوزان؛ لكن في الممارسة يحمّل استدلال نماذج LLM الأوزان في ذاكرة RAM نفسها، لذا فإن الـ 4 GB هي القيد الحاكم. وبصيغة INT4 يحتاج النموذج إلى 4 GB، عند الخط تمامًا، دون أن يبقى شيء للتنشيطات. جرّب الآن Transformer عام 2017 بحجم 0.05 B مقابل 1 MB من تخزين الأوزان (weight storage) في متحكم دقيق: 100 MB بصيغة FP16، أي أكثر من المتاح بمئة مرة. الفجوة بين ما تحتاجه النماذج وما يملكه عتاد الحافة هي موضوع الجزء 03.
Why run them at the edge anywayلماذا نشغّلها على الحافة رغم ذلك
If LLMs barely fit in a rack of cloud GPUs, why does the lecture insist on running them on laptops, cars and robots? Three reasons, each one a research direction in this course.
إذا كانت نماذج LLM بالكاد تتسع في رف من وحدات cloud GPUs (وحدات GPU سحابية)، فلماذا تصر المحاضرة على تشغيلها على الحواسيب المحمولة والسيارات والروبوتات؟ ثلاثة أسباب، كل منها اتجاه بحثي في هذا المقرر.
- Copilot services, such as code completion, office assistants and in-game chat, running locally on the machine that uses them. Latency drops, and the service works in a car or a robot far from any data center.خدمات المساعدة (copilot)، مثل إكمال الشيفرة ومساعدات المكتب والدردشة داخل الألعاب، تعمل محليًا على الجهاز الذي يستخدمها. ينخفض زمن الاستجابة، وتعمل الخدمة في سيارة أو روبوت بعيدًا عن أي مركز بيانات.
- Resource-constrained, low-power devices that are not always connected. An edge LLM must work when the link is slow or absent.أجهزة محدودة الموارد ومنخفضة الطاقة ليست متصلة دائمًا. يجب أن يعمل edge LLM عندما يكون الاتصال بطيئًا أو غائبًا.
- Privacy of user data. Prompts contain code, documents and conversations, and a local model never uploads them.خصوصية بيانات المستخدم. تحتوي التلميحات (prompts) على شيفرة ومستندات ومحادثات، والنموذج المحلي لا يرفعها أبدًا.
This is the design space for an on-device assistant, and it is why the rest of the course is about shrinking the memory (quantisation, pruning), the compute (efficient attention, distillation) and the deployment (compilers, kernels) of exactly the models on this chart. For a PhD project on embedded ML, the two-slope chart is the problem statement.
هذا هو فضاء التصميم لمساعد يعمل على الجهاز، ولهذا يدور بقية المقرر حول تقليص الذاكرة (التكميم، التقليم)، والحوسبة (الـ attention الفعّال، التقطير)، والنشر (المترجمات compilers، النوى) لهذه النماذج بالذات الموجودة على هذا المخطط. ولمشروع دكتوراه في تعلم الآلة المدمج، فإن مخطط المنحدرين هو بيان المشكلة.
Quick checkاختبار سريع
A 175 B parameter model is stored in INT8. What is its weight memory?نموذج من 175 B معامل مخزّن بصيغة INT8. ما ذاكرة أوزانه؟
Quick checkاختبار سريع
Why can 16 GB of GPU memory be drawn as 8 B parameters?لماذا يمكن رسم 16 GB من ذاكرة GPU على أنها 8 B معامل؟
Recall
What is the FP16 weight memory of MT-NLG, and how many A100 80 GB GPUs does it need for weights alone?ما ذاكرة أوزان MT-NLG بصيغة FP16، وكم وحدة A100 80 GB يحتاج للأوزان وحدها؟
Recall
How many FP16 parameters fit in 16 GB, and how much did model size and GPU memory grow over the chart?كم معاملًا بصيغة FP16 يتسع في 16 GB، وبكم نما حجم النماذج وذاكرة GPU عبر المخطط؟
Recall
Give the three reasons on slide 16 for running LLMs at the edge.اذكر الأسباب الثلاثة في الشريحة 16 لتشغيل نماذج LLM على الحافة.
Recapالخلاصة
If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا
- SAM is an image encoder that runs once per image and dominates the cost, plus a prompt encoder and a lightweight mask decoder that together run in about 50 ms on a CPU.يتكون SAM من مُرمِّز صور (image encoder) يعمل مرة واحدة لكل صورة ويهيمن على التكلفة، إضافة إلى مُرمِّز للتلميحات (prompt encoder) ومفكِّك أقنعة خفيف (mask decoder) يعملان معًا في نحو 50 ms على CPU.
- EfficientViT-SAM replaces only the image encoder: 538 versus 11 img/s (48.9x) at 46.6 versus 46.5 zero-shot COCO mAP.يستبدل EfficientViT-SAM مُرمِّز الصور وحده: 538 مقابل 11 img/s (48.9x) عند 46.6 مقابل 46.5 في zero-shot COCO mAP.
- Training Stable Diffusion took 256 A100s for 150k GPU-hours, about 24 days and about $600,000, so about $4 per GPU-hour.استغرق تدريب Stable Diffusion عدد 256 وحدة A100 لمدة 150k GPU-hours، أي نحو 24 يومًا وبتكلفة نحو $600,000، أي قرابة $4 لكل GPU-hour.
- Compute follows tokens times steps: CogVideoX with 5.6 B parameters needs 332 T MACs per step, 8.9x FLUX.1's 37.2 T with 12 B parameters.الحوسبة تتبع عدد الـ tokens مضروبًا في عدد الخطوات: يحتاج CogVideoX بمعاملاته البالغة 5.6 B إلى 332 T MACs لكل خطوة، أي 8.9x من 37.2 T التي يحتاجها FLUX.1 بمعاملاته البالغة 12 B.
- FLUX.1 MACs grow about 52x from 1024 to 4096 while pixels grow 16x, because attention is quadratic in token count.تنمو MACs في FLUX.1 بنحو 52x من 1024 إلى 4096 بينما تنمو البكسلات 16x، لأن الـ attention تربيعي في عدد الـ tokens.
- DistriFusion on 4 GPUs: 227 T MACs per device (4.0x less), 4.16 s (3.0x faster), no duplicated subjects. Naive patches are 3.9x faster but fragment the image.DistriFusion على 4 وحدات GPU: 227 T MACs لكل جهاز (أقل بـ 4.0x)، و4.16 s (أسرع بـ 3.0x)، ودون تكرار للعناصر. الرقع البسيطة أسرع بـ 3.9x لكنها تفتت الصورة.
- Fast-LiDARNet: kernel optimisation 3.6x, model redesign 2.6x, 5 to 47 fps against a 30 fps (33.3 ms) budget.Fast-LiDARNet: تحسين النوى (kernels) يعطي 3.6x، وإعادة تصميم النموذج 2.6x، من 5 إلى 47 fps مقابل ميزانية 30 fps (33.3 ms).
- Model size grew about 10,000x in four years while GPU memory grew about 5x; 530 B FP16 parameters are 1,060 GB, or 14 A100 80 GB GPUs for weights alone.نما حجم النماذج نحو 10,000x في أربع سنوات بينما نمت ذاكرة GPU نحو 5x؛ و530 B معامل بصيغة FP16 تساوي 1,060 GB، أي 14 وحدة A100 80 GB للأوزان وحدها.
- Edge LLMs exist for local copilots on laptops, cars and robots, for low-power devices that are not always connected, and for privacy.توجد نماذج LLM على الحافة من أجل مساعدات (copilots) محلية على الحواسيب المحمولة والسيارات والروبوتات، ومن أجل أجهزة منخفضة الطاقة ليست متصلة دائمًا، ومن أجل الخصوصية.
Sourcesالمصادر
- Segment AnythingPaperKirillov et al., ICCV 2023Three components, SA-1B (1 B masks on 11 M images), prompt encoder and decoder in about 50 ms on a browser CPUثلاثة مكونات، وSA-1B (مليار قناع على 11 M صورة)، ومُرمِّز التلميحات والمفكِّك في نحو 50 ms على CPU المتصفح(opens in a new tab)(يفتح في تبويب جديد)
- EfficientViT-SAM: Accelerated Segment Anything Model Without Accuracy LossPaperZhang, Cai and Han, arXiv 2024Table 1: params, MACs, A100 TensorRT FP16 throughput and zero-shot COCO mAP; 48.9xالجدول 1: المعاملات وMACs وإنتاجية A100 مع TensorRT بصيغة FP16 وzero-shot COCO mAP؛ 48.9x(opens in a new tab)(يفتح في تبويب جديد)
- EfficientViT-SAM demoDocsMIT HAN LabThe link printed on slide 10; the demo host is intermittently offline, the arXiv paper is the durable sourceالرابط المطبوع في الشريحة 10؛ خادم العرض التوضيحي يتوقف أحيانًا، وورقة arXiv هي المصدر الدائم(opens in a new tab)(يفتح في تبويب جديد)
- Training cost for Stable Diffusion was just $600,000ArticleThe Decoder, 8 September 2022Emad Mostaque's 256 A100, 150k GPU-hour, $600k figuresأرقام Emad Mostaque: 256 وحدة A100، و150k GPU-hours، و$600k(opens in a new tab)(يفتح في تبويب جديد)
- How We Trained Stable Diffusion for Less than $50k (Part 3)ArticleDatabricks (MosaicML)Measured run: 21,000 A100-hours, 6.79 days on 128 A100s, under $42,000دورة مقاسة: 21,000 A100-hours، و6.79 أيام على 128 وحدة A100، بأقل من $42,000(opens in a new tab)(يفتح في تبويب جديد)
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScalePaperDosovitskiy et al., ICLR 2021Table 1: ViT-H has 632 M parametersالجدول 1: لدى ViT-H عدد 632 M معامل(opens in a new tab)(يفتح في تبويب جديد)
- FLUX.1 [dev] model cardDocsBlack Forest Labs, Hugging Face12 billion parameter rectified flow transformerنموذج rectified flow transformer من 12 مليار معامل(opens in a new tab)(يفتح في تبويب جديد)
- CogVideoX-5b model cardDocsZhipu AI, Hugging Face720 x 480, 6 s at 8 fps, 49 frames720 x 480، و6 s عند 8 fps، و49 إطارًا(opens in a new tab)(يفتح في تبويب جديد)
- CogVideoX: Text-to-Video Diffusion Models with An Expert TransformerPaperYang et al., arXiv 2024(opens in a new tab)(يفتح في تبويب جديد)
- The Llama 3 Herd of ModelsPaperMeta AI, arXiv 20248B, 70B and 405B modelsنماذج 8B و70B و405B(opens in a new tab)(يفتح في تبويب جديد)
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessPaperDao et al., NeurIPS 2022Attention time and memory are quadratic in sequence lengthزمن الـ attention وذاكرته تربيعيان في طول التسلسل(opens in a new tab)(يفتح في تبويب جديد)
- DistriFusion: Distributed Parallel Inference for High-Resolution Diffusion ModelsPaperLi et al., CVPR 2024Displaced patch parallelism; 1.8x, 3.4x and 6.1x on 2, 4 and 8 A100sتوازي الرقع المُزاح (displaced patch parallelism)؛ 1.8x و3.4x و6.1x على 2 و4 و8 وحدات A100(opens in a new tab)(يفتح في تبويب جديد)
- DistriFusion repository and teaser figureDocsMIT HAN Lab, GitHub907 T / 12.3 s, 190 T / 3.14 s, 227 T / 4.16 s, 113 T / 2.74 s; SDXL 1280 x 1920, 50-step Euler907 T / 12.3 s، و190 T / 3.14 s، و227 T / 4.16 s، و113 T / 2.74 s؛ SDXL بدقة 1280 x 1920، ومُعايِن Euler من 50 خطوة(opens in a new tab)(يفتح في تبويب جديد)
- Efficient and Robust LiDAR-Based End-to-End NavigationPaperLiu, Amini, Zhu, Karaman, Han and Rus, ICRA 20213.6x from kernels, 2.6x from model design, 47 fps on GTX 1080Ti, 11 fps on Jetson AGX Xavier3.6x من النوى، و2.6x من تصميم النموذج، و47 fps على GTX 1080Ti، و11 fps على Jetson AGX Xavier(opens in a new tab)(يفتح في تبويب جديد)
- Using DeepSpeed and Megatron to Train Megatron-Turing NLG 530BPaperSmith et al., arXiv 2022530 billion parameters530 مليار معامل(opens in a new tab)(يفتح في تبويب جديد)
- Language Models are Few-Shot LearnersPaperBrown et al., NeurIPS 2020GPT-3, 175 B parametersGPT-3، بعدد 175 B معامل(opens in a new tab)(يفتح في تبويب جديد)
- Megatron-LM: Training Multi-Billion Parameter Language Models Using Model ParallelismPaperShoeybi et al., arXiv 2019Up to 8.3 billion parametersما يصل إلى 8.3 مليار معامل(opens in a new tab)(يفتح في تبويب جديد)
- BERT: Pre-training of Deep Bidirectional TransformersPaperDevlin et al., NAACL 2019BERT-Large, 340 M parametersBERT-Large، بعدد 340 M معامل(opens in a new tab)(يفتح في تبويب جديد)
- Turing-NLG: A 17-billion-parameter language model by MicrosoftArticleMicrosoft Research Blog, 13 February 2020(opens in a new tab)(يفتح في تبويب جديد)
- NVIDIA A100 Tensor Core GPUDocsNVIDIA40 GB and 80 GB variantsنسختا 40 GB و80 GB(opens in a new tab)(يفتح في تبويب جديد)
- NVIDIA V100 datasheetDocsNVIDIA32 GB or 16 GB HBM232 GB أو 16 GB من HBM2(opens in a new tab)(يفتح في تبويب جديد)
- TPU v3DocsGoogle Cloud documentation32 GiB HBM2 per chip32 GiB من HBM2 لكل رقاقة(opens in a new tab)(يفتح في تبويب جديد)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 1DocsMIT HAN LabOrigin of the MAC comparison, resolution curve and model-size charts on slides 12 and 15مصدر مقارنة MACs ومنحنى الدقة ومخططات حجم النماذج في الشريحتين 12 و15(opens in a new tab)(يفتح في تبويب جديد)