Majid Al-RaimiSegmentation, generative models and LLMsالتقطيع (Segmentation) والنماذج التوليدية ونماذج LLM

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 دقيقة
Understoodما فهمته
0/5 conceptsمفاهيم

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في نهاية هذا الجزء ستستطيع

  1. 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.
  2. 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).
  3. 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.
  4. 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.
  5. 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. رمِّز مرة واحدة بتكلفة عالية، ووجِّه بالتلميحات مرات كثيرة بتكلفة زهيدة.

The image encoder is the big block. It fills once per image, then the prompt encoder and decoder answer any number of prompts at almost no costمُرمِّز الصور هو الكتلة الكبيرة. يُملأ مرة واحدة لكل صورة، ثم يجيب مُرمِّز التلميحات والمفكِّك عن أي عدد من التلميحات بتكلفة شبه معدومة

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. لا شيء آخر في خط المعالجة يتحرك.

SimulatorمحاكيSwap the block that dominatesاستبدل الكتلة المهيمنة
Image encoderمُرمِّز الصورة

Hover, tap or focus a block to see what it costs and whether EfficientViT-SAM touches it.مرّر المؤشر فوق كتلة أو انقر عليها أو ركّز عليها لترى كلفتها وهل يغيّرها EfficientViT-SAM.

A100 TensorRT FP16 throughputالإنتاجية على A100 TensorRT FP1611 img/s
SAM-ViT-H baseline 11 img/sخط الأساس SAM-ViT-H 11 img/sscale to 800 img/sالمقياس حتى 800 img/s
Speedupالتسريع1.0x11 ÷ 11 img/s
Encoder MACs cutتقليل MACs في المشفّر1.0x2973 GMACs divided by the new encoder2973 GMACs مقسومة على كلفة المُرمِّز الجديد
Zero-shot COCO mAPmAP على COCO دون تدريب مسبق عليها (zero-shot)46.5the baselineخط الأساس

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)mAPmAPSpeedup vs SAM-ViT-Hالتسريع مقارنة بـ SAM-ViT-H
SAM-ViT-HSAM-ViT-H641.1 M641.1 M2973 G2973 G111146.546.51x1x
EfficientViT-SAM-XL1EfficientViT-SAM-XL1203.3 M203.3 M322 G322 G18218247.847.816.5x16.5x
EfficientViT-SAM-XL0EfficientViT-SAM-XL0117.0 M117.0 M185 G185 G27827847.547.525.3x25.3x
EfficientViT-SAM-L2EfficientViT-SAM-L261.3 M61.3 M69 G69 G53853846.646.648.9x48.9x
EfficientViT-SAM-L1EfficientViT-SAM-L147.7 M47.7 M49 G49 G63863846.246.258.0x58.0x
EfficientViT-SAM-L0EfficientViT-SAM-L034.8 M34.8 M35 G35 G76276245.745.769.3x69.3x
EfficientSAMEfficientSAM25.3 M25.3 M247 G247 G18318344.444.416.6x16.6x
EdgeSAMEdgeSAM9.6 M9.6 M20 G20 G44944942.142.140.8x40.8x
MobileSAMMobileSAM9.8 M9.8 M39 G39 G27827838.738.725.3x25.3x
Zero-shot COCO instance segmentation, A100 with TensorRT FP16 (EfficientViT-SAM, Table 1)تقسيم المثيلات في COCO بنمط zero-shot، على A100 مع TensorRT بصيغة FP16 (EfficientViT-SAM، الجدول 1)

Worked exampleمثال محلول

Compute reduction versus measured speedupتقليل الحوسبة مقابل التسريع المقاس

  1. MAC ratioنسبة الـ MACs

    SAM-ViT-H to L2: 2973 / 69 ≈ 43.1x fewer encoder MACs.
    من SAM-ViT-H إلى L2: 2973 / 69 ≈ 43.1x أقل في MACs المُرمِّز.
  2. Throughput ratioنسبة الإنتاجية (throughput)

    538 / 11 ≈ 48.9x more images per second.
    538 / 11 ≈ 48.9x صورًا أكثر في الثانية.
  3. 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.
  4. 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، وحدد أيها يعمل مرة واحدة لكل صورة.

Image encoder (runs once per image and dominates the cost), prompt encoder, lightweight mask decoder.
مُرمِّز الصور (يعمل مرة واحدة لكل صورة ويهيمن على التكلفة)، ومُرمِّز التلميحات، ومفكِّك الأقنعة الخفيف.

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؟

It replaces only the image encoder with EfficientViT and keeps the prompt encoder and mask decoder. L2 runs at 538 versus 11 img/s with 46.6 versus 46.5 zero-shot COCO mAP.
يستبدل مُرمِّز الصور وحده بـ EfficientViT ويُبقي مُرمِّز التلميحات ومفكِّك الأقنعة. تعمل L2 بـ 538 مقابل 11 img/s مع 46.6 مقابل 46.5 في zero-shot COCO mAP.

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

  1. 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 طوال الوقت.
  2. 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.
  3. 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، وهو ما يطابق الإجمالي المعلن.
  4. 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وحدات A100GPU-hoursGPU-hoursWall clockالزمن الفعليCostالتكلفة
Stable Diffusion, 2022Stable Diffusion، 2022256256about 150,000نحو 150,000about 24 daysنحو 24 يومًاabout $600,000نحو $600,000
MosaicML SD2 base, 2023MosaicML SD2 base، 2023128128about 21,000نحو 21,0006.8 days6.8 أيامunder $42,000أقل من $42,000
The original run next to MosaicML's SD2 base runالدورة الأصلية إلى جانب دورة MosaicML لنموذج SD2 base

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حمل العملMACsMACsRatioالنسبة
ViT-HViT-H0.6 B0.6 B518 x 518 image, one forward passصورة 518 x 518، تمريرة أمامية واحدة1.02 T1.02 Tbaselineخط الأساس
Llama 3 8BLlama 3 8B8 B8 B1,024-token context, 512 output tokensسياق من 1,024 token، و512 token للمخرجات11.2 T11.2 T11x ViT-H11x ViT-H
FLUX.1FLUX.112 B12 B1K x 1K image, one denoising stepصورة 1K x 1K، خطوة إزالة ضوضاء واحدة37.2 T37.2 T36x ViT-H, 3.3x Llama 336x ViT-H, 3.3x Llama 3
CogVideoXCogVideoX5.6 B5.6 B480 x 720, 49 frames, one denoising step480 x 720، 49 إطارًا، خطوة إزالة ضوضاء واحدة332 T332 T8.9x FLUX.1, 326x ViT-H8.9x FLUX.1, 326x ViT-H
MACs for one pass, from slide 12 (log axis on the slide)MACs لتمريرة واحدة، من الشريحة 12 (محور لوغاريتمي في الشريحة)

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 آخر.

MACs per pass≈Nparams Ntokens+c Ntokens2 d\text{MACs per pass} \approx N_{\text{params}}\,N_{\text{tokens}} + c\,N_{\text{tokens}}^{2}\,d
Why tokens, not parameters, set the bill: a linear term and a quadratic attention termلماذا تحدد الرموز (tokens) الكلفة لا المعاملات: حد خطي وحد تربيعي للانتباه

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.

SimulatorمحاكيFLUX.1 cost versus resolutionكلفة FLUX.1 مقابل الدقة (resolution)
1024 × 1024
05001000150020001024153620482560307235844096MACs (T), one denoising stepdashed: quadratic in side lengthsolid: fit to the slide, dots: slide readings
Pixelsعدد البكسلات1,048,5761024 squared, 1.0x the 1024 imageمربع 1024، أي 1.0x من صورة 1024
Latent tokenstokens الكامنة4,096(side ÷ 16) squared, typical latent patching(side ÷ 16) تربيع، وهو تقسيم الـ latent إلى رقع المعتاد
MACs per stepMACs لكل خطوة37.2T1.0x the 1024 cost1.0x من كلفة 1024
Quadratic referenceالمرجع التربيعي37.2Tif cost only followed pixel countلو كانت الكلفة تتبع عدد البكسلات فقط
Token-linear shareالحصة الخطية في عدد tokens31.6Tlinear layers, grows with tokensالطبقات الخطية، تنمو مع عدد tokens
Attention shareحصة attention5.6Tgrows with tokens squaredتنمو مع مربع عدد tokens
50-step image1,860Tper-step MACs times sampler stepsMACs الخطوة الواحدة مضروبة في عدد خطوات الـ sampler

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ملاءمة منحنى الشريحة

  1. 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.
  2. 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.
  3. 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).
  4. 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؟

150,000 / 256 ≈ 586 hours, about 24 days. $600,000 / 150,000 = $4 per GPU-hour.
150,000 / 256 ≈ 586 hours، أي نحو 24 يومًا. $600,000 / 150,000 = $4 لكل GPU-hour.

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 معامل؟

It denoises a stack of latent frames per step, about four times FLUX.1's token count. Compute follows tokens (and tokens squared for attention), not parameter count.
لأنه يزيل الضوضاء من كومة من الإطارات الكامنة في كل خطوة، أي نحو أربعة أضعاف عدد tokens في FLUX.1. الحوسبة تتبع الـ tokens (ومربعها في حالة الـ attention)، لا عدد المعاملات.

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، ولماذا الفرق؟

Pixels grow 16x, MACs about 52x. The linear layers scale with tokens, but attention scales with tokens squared, so the total is super-quadratic in side length.
تنمو البكسلات 16x، وتنمو الـ MACs نحو 52x. الطبقات الخطية تتدرج مع الـ tokens، لكن الـ attention يتدرج مع مربعها، لذا فإن الإجمالي أسرع من التربيعي بالنسبة لطول الضلع.

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 لكنها خاطئة: أربعة شرائط، وأربع سفن، وأربع سماوات مختلفة. ولّدت كل رقعة صورتها الخاصة لأنه لم تكن هناك رقعة تستطيع رؤية الأخريات.

Four isolated patches each paint their own ship. Let each patch read its neighbours' activations from the previous step and one ship spans the frameأربع رقع معزولة ترسم كل منها سفينتها الخاصة. دع كل رقعة تقرأ تنشيطات (activations) جاراتها من الخطوة السابقة فتمتد سفينة واحدة عبر الإطار

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 T1x1x12.3 s12.3 s1x1xreference imageالصورة المرجعية
Naive patches, 4 GPUsرقع بسيطة، 4 وحدات GPU190 T190 T4.8x lessأقل بـ 4.8x3.14 s3.14 s3.9x3.9xduplicated subjectsتكرار العناصر
DistriFusion, 4 GPUsDistriFusion، 4 وحدات GPU227 T227 T4.0x lessأقل بـ 4.0x4.16 s4.16 s3.0x3.0xno artifactsبلا تشوهات
DistriFusion, 8 GPUs (paper, not on the slide)DistriFusion، 8 وحدات GPU (من الورقة، ليست في الشريحة)113 T113 T8.0x lessأقل بـ 8.0x2.74 s2.74 s4.5x4.5xno artifactsبلا تشوهات
SDXL at 1280 x 1920, 50-step Euler sampler, A100 GPUs (DistriFusion teaser; slide 13 shows the first three rows)SDXL بدقة 1280 x 1920، مُعايِن Euler من 50 خطوة، وحدات A100 (الشكل التشويقي لـ DistriFusion؛ تعرض الشريحة 13 الصفوف الثلاثة الأولى)

Worked exampleمثال محلول

Where the work wentأين ذهب العمل

  1. 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 المفقودة هي بالضبط السياق المفقود.
  2. 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. الحوسبة الكاملة محفوظة ومقسومة ببساطة على أربعة.
  3. 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.
  4. 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 وتكلفة خطوات الإحماء المتزامنة.
parallel efficiency=speedupdevices=3.04=75%\text{parallel efficiency} = \frac{\text{speedup}}{\text{devices}} = \frac{3.0}{4} = 75\%
Naive patches reach 3.9 / 4 = 98% by skipping work; DistriFusion pays 25% for keeping the picture wholeالرقع الساذجة تبلغ 3.9 / 4 = 98% بتخطي العمل؛ أما DistriFusion فتدفع 25% للحفاظ على الصورة كاملة

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وحدات A100Speedup over one GPUالتسريع مقارنة بـ GPU واحدةMarginal speedupالتسريع الحدّيParallel efficiencyكفاءة التوازي
111x1xreferenceالمرجع100%100%
221.8x1.8x1.8x1.8x90%90%
443.4x3.4x1.9x1.9x85%85%
886.1x6.1x1.8x1.8x76%76%
DistriFusion on SDXL at 3840 x 3840, A100s (paper; same 50-step Euler sampler as the table above, a larger image). Marginal column divides each speedup by the one above itDistriFusion على SDXL بدقة 3840 x 3840، وحدات A100 (من الورقة؛ مُعايِن Euler نفسه من 50 خطوة كما في الجدول أعلاه، مع صورة أكبر). عمود التسريع الحدّي يقسم كل تسريع على الذي فوقه

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?ما التشوه الذي ينتجه توازي الرقع البسيط، ولماذا؟

Duplicated subjects (four ships for one prompt), because the patches never see each other and each generates its own composition.
تكرار العناصر (أربع سفن لتلميح واحد)، لأن الرقع لا ترى بعضها أبدًا فتولّد كل منها تكوينها الخاص.

Recall

Why is 190 T times 4 less than the original 907 T?لماذا يكون 190 T مضروبًا في 4 أقل من 907 T الأصلية؟

Naive patches skip the cross-patch attention, so they do less total work. DistriFusion's 227 T × 4 = 908 T preserves the whole computation.
لأن الرقع البسيطة تتخطى الـ attention بين الرقع، فتؤدي عملًا إجماليًا أقل. أما 227 T × 4 = 908 T في DistriFusion فتحفظ الحوسبة كاملة.

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).

Kernel optimisation lifts 5 fps to 18 fps and still misses the 30 fps line. Only the redesigned model crosses itتحسين النوى يرفع 5 fps إلى 18 fps ومع ذلك لا يبلغ خط 30 fps. النموذج المعاد تصميمه وحده يتجاوزه

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 لكل إطار، وكل ما يفعله النموذج يجب أن يتسع داخل تلك الميزانية.

tframe=1000 msfpst_{\text{frame}} = \frac{1000\ \text{ms}}{\text{fps}}
Frame time from frame rateزمن الإطار من معدل الإطارات

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؟
MinkowskiNetMinkowskiNet5 fps5 fps200 ms200 msnoneلا شيءno, 167 ms overلا، يتجاوزها بـ 167 ms
MinkowskiNet, optimised sparse kernelsMinkowskiNet مع نوى متناثرة محسّنة18 fps18 fps55.6 ms55.6 mssystem: 3.6xالنظام: 3.6xno, 22 ms overلا، يتجاوزها بـ 22 ms
Fast-LiDARNetFast-LiDARNet47 fps47 fps21.3 ms21.3 msalgorithm: 2.6x more, 9.4x totalالخوارزمية: 2.6x إضافية، 9.4x إجمالًاyes, 12 ms to spareنعم، مع فائض 12 ms
Three configurations from slide 14ثلاثة إعدادات من الشريحة 14

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 مع مضاعِف كل منهما ومعدلات الإطارات الناتجة.

Sparse-convolution kernel optimisation, 3.6x (5 to 18 fps), and hardware-aware model design, 2.6x (18 to 47 fps), 9.4x in total.
تحسين نوى الالتفاف المتناثر، 3.6x (من 5 إلى 18 fps)، وتصميم النموذج المراعي للعتاد، 2.6x (من 18 إلى 47 fps)، أي 9.4x إجمالًا.

Recall

What is the frame budget at 30 fps, and what is MinkowskiNet's frame time at 5 fps?ما ميزانية الإطار عند 30 fps، وما زمن إطار MinkowskiNet عند 5 fps؟

1000 / 30 ≈ 33.3 ms budget; 1000 / 5 = 200 ms per frame.
الميزانية 1000 / 30 ≈ 33.3 ms؛ و1000 / 5 = 200 ms لكل إطار.

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 parameters climb about 10,000x while GPU memory climbs about 5x on the same FP16 axis. The gap at 2022 is 13xتصعد معاملات النماذج نحو 10,000x بينما تصعد ذاكرة GPU نحو 5x على محور FP16 نفسه. الفجوة في 2022 تبلغ 13x
ModelالنموذجYearالسنةParametersالمعاملاتFP16 weightsأوزان FP16A100 80 GB GPUsوحدات A100 80 GB
TransformerTransformer201720170.05 B0.05 B0.1 GB0.1 GB11
GPTGPT201820180.11 B0.11 B0.22 GB0.22 GB11
BERT-LargeBERT-Large201820180.34 B0.34 B0.68 GB0.68 GB11
GPT-2GPT-2201920191.5 B1.5 B3 GB3 GB11
Megatron-LMMegatron-LM201920198.3 B8.3 B16.6 GB16.6 GB11
T-NLGT-NLG2020202017 B17 B34 GB34 GB11
GPT-3GPT-320202020175 B175 B350 GB350 GB55
MT-NLGMT-NLG2021 (paper 2022)2021 (الورقة 2022)530 B530 B1,060 GB1,060 GB1414
Models on the chart, FP16 weight memory and A100 80 GB count for weights aloneالنماذج على المخطط، وذاكرة الأوزان بصيغة FP16، وعدد وحدات A100 80 GB للأوزان وحدها
AcceleratorالمسرّعMemoryالذاكرةFP16 parameters it holdsمعاملات FP16 التي يسعها
TPU v2TPU v216 GB16 GB8 B8 B
V100V10032 GB32 GB16 B16 B
TPU v3TPU v332 GB32 GB16 B16 B
A100A10040 GB40 GB20 B20 B
A100A10080 GB80 GB40 B40 B
Accelerators on the chartالمسرّعات على المخطط

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)، الذي تغطيه المحاضرات اللاحقة بعمق، هو ببساطة فن النزول في هذه القائمة دون خسارة الدقة.

weight bytes=Nparams×bytes per param,GPUs=⌈weight bytesGPU bytes⌉\text{weight bytes} = N_{\text{params}} \times \text{bytes per param}, \qquad \text{GPUs} = \left\lceil \frac{\text{weight bytes}}{\text{GPU bytes}} \right\rceil
Weights only; activations and the KV cache come on topالأوزان فقط؛ وتُضاف فوقها التنشيطات وذاكرة KV cache

Worked exampleمثال محلول

MT-NLG on A100 80 GB GPUsMT-NLG على وحدات A100 80 GB

  1. 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 للأوزان وحدها.
  2. 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.
  3. 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.
  4. 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، وهذا لا يترك أي مساحة لأي شيء آخر.
SimulatorمحاكيParameters to bytes to GPUsمن المعاملات إلى البايتات إلى وحدات GPU
Precisionالدقة العددية
Weight memoryذاكرة الأوزان1,060 GB530 B × 2 bytes per parameter530 B × 2 بايت لكل معامل
A100 80 GB GPUsعدد وحدات A100 80 GB14ceil of GB ÷ 80, weights onlyالتقريب لأعلى لـ GB ÷ 80، للأوزان فقط
A100 40 GB GPUsعدد وحدات A100 40 GB27ceil of GB ÷ 40, weights onlyالتقريب لأعلى لـ GB ÷ 40، للأوزان فقط
One A100 80 GBوحدة A100 80 GB واحدةDoes not fitلا يتسع
needs 1,060 GBيحتاج 1,060 GBof 80 GBمن 80 GB
Phone, 4 GB RAM: 265 phonesهاتف بذاكرة 4 GB RAM: عدد الهواتف 265Does not fitلا يتسع
Microcontroller, 1 MB weight storageمتحكم دقيق بسعة 1 MB لتخزين الأوزانDoes not fitلا يتسع

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 سحابية)، فلماذا تصر المحاضرة على تشغيلها على الحواسيب المحمولة والسيارات والروبوتات؟ ثلاثة أسباب، كل منها اتجاه بحثي في هذا المقرر.

  1. 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)، مثل إكمال الشيفرة ومساعدات المكتب والدردشة داخل الألعاب، تعمل محليًا على الجهاز الذي يستخدمها. ينخفض زمن الاستجابة، وتعمل الخدمة في سيارة أو روبوت بعيدًا عن أي مركز بيانات.
  2. Resource-constrained, low-power devices that are not always connected. An edge LLM must work when the link is slow or absent.أجهزة محدودة الموارد ومنخفضة الطاقة ليست متصلة دائمًا. يجب أن يعمل edge LLM عندما يكون الاتصال بطيئًا أو غائبًا.
  3. 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 يحتاج للأوزان وحدها؟

530 B × 2 bytes = 1,060 GB; 1,060 / 80 = 13.25, so 14 GPUs before activations or the KV cache.
530 B × 2 bytes = 1,060 GB؛ 1,060 / 80 = 13.25، إذن 14 وحدة GPU قبل التنشيطات أو الـ KV cache.

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 عبر المخطط؟

8 B parameters. Model size grew about 10,000x and GPU memory about 5x.
8 B معامل. نما حجم النماذج نحو 10,000x وذاكرة الـ GPU نحو 5x.

Recall

Give the three reasons on slide 16 for running LLMs at the edge.اذكر الأسباب الثلاثة في الشريحة 16 لتشغيل نماذج LLM على الحافة.

Local copilot services on laptops, cars and robots; resource-constrained low-power devices that are not always connected; privacy of personal data that should not be uploaded.
خدمات مساعدة محلية على الحواسيب المحمولة والسيارات والروبوتات؛ وأجهزة محدودة الموارد منخفضة الطاقة ليست متصلة دائمًا؛ وخصوصية البيانات الشخصية التي لا ينبغي رفعها.

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المصادر