Hosting LLMs at Scale
Chi Wang and Peiheng Hu

#LLM
🤖 مدلهای زبانی بزرگ (LLMها) موتور استدلال هوش مصنوعی مدرن هستن.
🚀 امروز به یک نقطه عطف مهم رسیدیم؛ در حالی که همه در حال استقرار AI در مقیاس گسترده هستن، موضوع Inference به مرکز کل استک هوش مصنوعی تبدیل شده. به عصر Inference خوش اومدی.
⚠️ اما بدون بهینهسازی مناسب، سرویسدهی به LLMها میتونه هم هزینهبر باشه و هم کند. کتاب Hands-On LLM Serving and Optimization یک راهنمای جامع برای درک چالشهای استقرار و بهینهسازی LLMها در مقیاس بزرگه.
🛠️ در این کتاب کاملاً عملی و مهندسیمحور، چی وانگ و پیهِنگ هو با استفاده از مثالهای واقعی، کد و راهکارهای کاربردی، بهت یاد میدن چطور زیرساختهایی بسازی که مثل یک کارخانه تولید توکن هوش مصنوعی (AI Token Factory) پایدار، سریع و مقرونبهصرفه کار کنن.
💡 فرقی نمیکنه در حال ساخت زیرساخت LLM Inference باشی یا اپلیکیشنهایی توسعه بدی که از این زیرساخت استفاده میکنن؛ درک عمیق از LLM Serving باعث میشه به یک مهندس آمادهتر و مؤثرتر تبدیل بشی؛ مخصوصاً حالا که AI داره روش ساختن و کار کردن ما رو متحول میکنه.
📚 در این کتاب یاد میگیری:
🧱 مبانی Model Serving شامل مفاهیم پایه، الگوهای طراحی و بهترین شیوههای صنعت رو یاد بگیری.
🌍 چالشهای رایج میزبانی LLMها در مقیاس بزرگ رو درک کنی.
⚖️ بین Latency و Throughput تعادل ایجاد کنی تا نیازهای اپلیکیشنهای مبتنی بر AI و الزامات کسبوکار رو برآورده کنی.
💰 با استفاده از تکنیکهای عملی و کدهای واقعی، LLMها رو با هزینه مناسب میزبانی کنی.
📑 فهرست مطالب
فصل 1: مقدمهای بر Model Serving و بهینهسازی
فصل 2: سرویسدهی مدلهای زبانی بزرگ
فصل 3: طراحی سیستمهای Model Serving؛ بررسی عمیق
فصل 4: بهترین شیوههای Model Serving
فصل 5: چالشهای سرویسدهی به LLMها
فصل 6: تکنیکهای ضروری بهینهسازی LLM
فصل 7: تکنیکهای پیشرفته بهینهسازی LLM
فصل 8: فریمورکهای سرویسدهی LLM
فصل 9: بهینهسازی LLM در عمل
فصل 10: پیشرفتهای جدید در سرویسدهی LLM
🎯 هدف این کتاب چیست؟
🔍 این کتاب سعی داره یکی از مهمترین شکافهای اکوسیستم GenAI رو پر کنه؛ یعنی فاصله بین داشتن یک LLM و اجرای کارآمد، پایدار و اقتصادی اون در سیستمهای واقعی.
📚 هدف نویسندهها اینه که یک پایه محکم برای موضوعات زیر در اختیارت بذارن:
🧠 درک اینکه Model Serving واقعاً چیه و چرا LLMها مسئله سرویسدهی رو کاملاً متحول کردهاند.
⚙️ فهمیدن نحوه اجرای LLMها و اجزایی مثل Attention، Prefill و Decode و اینکه این مکانیزمها چطور روی Latency، Throughput و هزینه تأثیر میذارن.
🏗️ ساخت سیستمهای سرویسدهی از صفر تا صد تا معماری، کشینگ (Caching)، زمانبندی (Scheduling) و تصمیمات طراحی پشت فریمورکها رو بهتر درک کنی.
📊 اندازهگیری درست عملکرد سیستم و گرفتن تصمیمهای مهندسی مبتنی بر داده بهجای حدس و گمان.
🚀 استفاده از تکنیکهای اصلی بهینهسازی؛ از Batching، Quantization و Kernel Fusion گرفته تا Continuous Batching، Prefix Caching و Speculative Decoding.
🔧 انتخاب و استفاده آگاهانه از فریمورکهای مدرن LLM Serving بهجای برخورد با اونها بهعنوان ابزارهای Black Box.
🔗 اتصال مفاهیم سرویسدهی به سناریوهای واقعی مثل سیستمهای چت، پایپلاینهای RAG، ایجنتها، استقرارهای سازمانی و معماریهای کلاد یا Self-Hosted.
👥 این کتاب برای چه کسانی مناسبه؟
🤖 مهندسان و پژوهشگران ML/AI که مدلهای LLM رو آموزش داده یا Fine-Tune کردهاند و حالا باید اونها رو به کاربران واقعی سرویس بدن.
⚙️ مهندسان Backend و Platform که ناگهان مسئولیت سرویس LLMها رو برعهده گرفتن؛ چه در دیتاسنتر داخلی، چه در کلاد و چه در محیطهای هیبریدی.
📊 مهندسان داده و MLOps که باید پلتفرمهای فعلی ML رو برای پشتیبانی از LLMها، ایجنتها و بارهای کاری RAG گسترش بدن.
🏗️ لیدهای فنی و معماران نرمافزار که مسئول انتخاب معماری، فریمورکها، استراتژیهای GPU و تصمیمگیری بین کلاد و Self-Hosting هستن.
🚀 بنیانگذاران استارتاپها و کسبوکارهای کوچک که در حال ساخت پلتفرمهای ایجنتی یا محصولات مبتنی بر AI هستن و میخوان هزینه میزبانی رو کاهش بدن و کنترل بیشتری روی عملکرد و هزینهها داشته باشن.
🎓 دانشجوها و مهندسانی که مفاهیم پایه LLMها رو بلدن و حالا میخوان یاد بگیرن سیستمهای واقعی در محیط پروداکشن چطور طراحی، بهینهسازی و مدیریت میشن.
📌 نویسندهها فرض میکنن که با خواندن کدهای Python راحت هستی، مفاهیم پایه یادگیری عمیق رو میشناسی و آشنایی کلی با Transformers و LLMها داری. لازم نیست متخصص کرنلهای GPU یا پژوهشگر سیستمهای توزیعشده باشی، اما باید آماده کار با معیارهای عملکرد، دیاگرامهای معماری و طراحی عملی سیستمها باشی.
🚫 این کتاب چه چیزی نیست؟
📚 یک مقدمه عمومی درباره یادگیری ماشین یا یادگیری عمیق نیست.
🤖 یک مرور کلی از جنس «GenAI چیست؟» یا «LLMها چه کارهایی انجام میدن؟» نیست.
📋 یک فهرست کامل از همه محصولات یا فریمورکهای موجود در بازار نیست.
🧪 یک بررسی آکادمیک از تمام الگوریتمهای بهینهسازی موجود نیست.
📖 اگر تازه وارد دنیای Machine Learning یا Transformers شدی، نویسندهها پیشنهاد میکنن این کتاب رو در کنار کتاب Hands-On Large Language Models نوشته جی علامر و مارتن گروتندورست مطالعه کنی و این کتاب رو بهعنوان راهنمای سرویسدهی و طراحی سیستمهای LLM در نظر بگیری.
💬 نظر متخصصان درباره کتاب
🧠 یکی از نقاط قوت این کتاب ساختار منظم و مرحلهبهمرحله اونه. کتاب از مفاهیم پایه Model Serving شروع میکنه و اصول طراحی سیستمهایی رو توضیح میده که در اکثر سیستمهای یادگیری ماشین کاربرد دارن. بعد از اون سراغ چالشهای اختصاصی LLMها میره. همین رویکرد باعث شده کتاب هم برای افراد تازهوارد قابل استفاده باشه و هم برای مهندسان باتجربهای که روی سیستمهای بزرگ کار میکنن.
—کایمینگ شیونگ - همبنیانگذار Recursive AI و معاون ارشد سابق تحقیقات هوش مصنوعی در Salesforce
🚀 این کتاب همون راهنمایی بود که دنیای LLM Serving مدتها بهش نیاز داشت. پوشش کامل چالشهای سرویسدهی و تکنیکهای بهینهسازی مثل Scaling Attention، Multi-Node Inferencing و Disaggregation همراه با مثالهای واقعی، اون رو به یک منبع ضروری برای هر کسی تبدیل کرده که در حال توسعه زیرساختهای AI در مقیاس بزرگه.
—وینی کوان - مدیر مهندسی در Broadcom
🔧 این کتاب فاصله بین تئوری LLMها و واقعیت محیط پروداکشن رو پر میکنه. از Semantic Routing گرفته تا Multi-LoRA Serving، همه چیز رو پوشش میده و مدل ذهنی لازم برای طراحی و بهینهسازی سیستمهای واقعی رو در اختیار مهندسان ML قرار میده.
—مینگ-چیا (مارکوس) تسای - مهندس ارشد Saviynt
🏗️ این کتاب دیدگاهی کاملاً عملی درباره معماریهای Model Serving و تکنیکهای بهینهسازی موردنیاز برای ساخت سیستمهای LLM Inference مقیاسپذیر و کارآمد ارائه میده. رویکرد عملی کتاب باعث شده مفاهیم پیچیده بهشکل قابل فهمی توضیح داده بشن.
—پاتریس کاستونگوای - رهبر مهندسی در حوزه LLM Inference
✍️ درباره نویسندگان
👨💻 چی وانگ مدیر مهندسی در گروه Einstein AI شرکت Salesforce است و بیش از ۱۸ سال تجربه در حوزه هوش مصنوعی و سیستمهای توزیعشده دارد. او توسعه پلتفرمهای بزرگ AI را رهبری میکند؛ پلتفرمهایی که آموزش مدل، Inference و بهینهسازی را برای صدها تیم داخلی فراهم کردهاند و قابلیتهای AI مورد استفاده میلیونها مشتری Salesforce را تأمین میکنند.
⚙️ در Salesforce، چی وانگ مسئول چندین تیم مهندسی در حوزه Model Inference، بهینهسازی مدل و پلتفرمهای داده است. فعالیتهای او شامل ساخت زیرساختهای چندمستاجره AI، مقیاسدهی سیستمهای پردازشی توزیعشده و بهبود عملکرد و بهرهوری هزینهای بارهای کاری LLM در محیط پروداکشن است.
🏆 او مخترع اصلی ۱۲ پتنت در حوزههایی مثل Model Serving، بهینهسازی مدل، کنترل دسترسی به داده و طراحی سیستمهای بزرگمقیاس است. همچنین بهعنوان یک نویسنده فنی، روی سادهسازی مفاهیم پیچیده AI برای مهندسان تمرکز دارد.
👨💻 پیهِنگ هو یک مهندس برجسته یادگیری ماشین با بیش از ۱۰ سال تجربه صنعتی در ساخت سیستمهای AI در مقیاس بزرگ است. او در حال حاضر در NVIDIA فعالیت میکند و تمرکزش روی Distributed LLM Inference و توسعه موتورهای پرسرعت استنتاج روی جدیدترین GPUهای انویدیاست.
🎓 او مدرک کارشناسی ارشد خود را در رشته Computational Science and Engineering از Harvard University و مدرک کارشناسی را در رشته Industrial Engineering Operations Research از Georgia Institute of Technology دریافت کرده است.
🚀 پیش از پیوستن به NVIDIA، بهعنوان عضو ارشد کادر فنی در Salesforce فعالیت میکرد و توسعه تنها پلتفرم یکپارچه سرویسدهی این شرکت را رهبری کرده بود؛ پلتفرمی که هزاران مدل اختصاصی مشتریان را مدیریت میکرد و بهینهسازیهای LLM انجامشده برای Agentforce از طریق آن میلیونها دلار در هزینه زیرساخت AI صرفهجویی کرد.
☁️ قبل از Salesforce نیز بهعنوان مهندس ارشد ML در Microsoft Azure فعالیت داشت و راهکارهای پردازش توزیعشده یادگیری ماشین را برای تحلیل و تشخیص تهدیدهای امنیتی کلاد طراحی کرده بود؛ سیستمهایی که میلیاردها تراکنش را در هر ساعت پردازش میکردند.
Large language models (LLMs) are the reasoning engines of modern AI. Today, a major inflection point has arrived: as the world races to deploy AI at scale, model inference has moved to the center of the stack. Welcome to the inference era.
Without proper optimization, however, LLMs can be expensive and slow to serve. Hands-On LLM Serving and Optimization is a comprehensive guide to the complexities of deploying and optimizing LLMs at scale.
In this hands-on, engineering-focused book, authors Chi Wang and Peiheng Hu combine practical examples, code, and strategies for building robust, performant, and cost-efficient AI token factories. Whether youâre building the LLM inference infrastructure or the applications that consume it, a deep understanding of LLM serving will make you a more effective, future-ready engineer as AI transforms how we work and build.
Table of Contents
Chapter 1. Introduction To Model Serving And Optimization
Chapter 2. Large Language Model Serving
Chapter 3. Model Serving System Design: A Deep Dive
Chapter 4. Model Serving Best Practices
Chapter 5. Challenges When Serving LLMs
Chapter 6. Essential LLM Optimization Techniques
Chapter 7. Advanced LLM Optimization Techniques
Chapter 8. LLM Serving Frameworks
Chapter 9. LLM Optimization In Practice
Chapter 10. Advancements In LLM Serving
What This Book Aims to Do
This book aims to close a critical gap in the GenAI ecosystem: moving from having an LLM to running LLMs efficiently, reliably, and affordably in real systems.
Our goal is to give you a clear foundation for:
Who Should Read This Book
This book is for practitioners who need to move beyond demos and make LLM-powered systems work reliably, efficiently, and at scale. You are likely part of one (or more) of the following groups:ML/AI engineers and researchers who have trained or fine-tuned LLM models and now need to serve them efficiently to real users
We assume you are comfortable reading Python, are familiar with basic deep-learning concepts, and have at least a passing understanding of transformers and LLMs. You do not need to be a GPU-kernel expert or distributed-systems researcher, but you should be prepared to work with performance metrics, architecture diagrams, and practical system design.
What This Book Isn’t
This book is not:
If you’re new to machine learning or transformers, we encourage you to pair this book with a more general introduction to deep learning or LLMs, such as Hands-On Large Learning Models, by Jay Alammar and Maarten Grootendorst (O’Reilly, 2024), and treat this book as your serving and systems companion.
"One of the strengths of this book is its structured approach. It begins with the fundamentals of model serving—covering core system-design principles that apply broadly across machine learning systems—before moving into the unique challenges of LLMs. This progression makes the book accessible to readers who are new to model serving, while still offering depth for experienced practitioners working with large-scale systems."
— Caiming Xiong, Co-founder of Recursive AI Startup and ex-SVP of AI Research & Applied Research, Salesforce
"The missing manual for LLM serving and inference — comprehensive coverage of LLM serving challenges and optimization techniques such as scaling attention, multi-node inferencing, and disaggregation, with real-world examples. Essential reading for anyone scaling AI infrastructure."
— Winnie Kwon, Engineering Manager, Broadcom
"This book bridges the gap between LLM theory and production reality—from semantic routing to Multi-LoRA serving, it equips any ML engineer with the mental models needed to build and optimize real-world inference systems."
— Ming-Chia (Marcus) Tsai, Senior Principal Engineer, Saviynt
"This book delivers real-world insight into the model serving architectures and optimization techniques required to build scalable, efficient LLM inference systems. Its hands-on approach makes complex LLM serving concepts accessible for anyone."
— Patrice Castonguay, Engineering Leader in LLM Inference
About the Author
Chi Wang is a director of engineering at Salesforce's Einstein AI group, with over 18 years of experience in artificial intelligence and distributed systems. He leads the development of large-scale AI platforms that enable model training, inference, and optimization for hundreds of internal teams and power AI capabilities used by millions of Salesforce customers. At Salesforce, Chi oversees multiple engineering teams focused on model inference and optimization, and data science platforms. His work spans building multi-tenant AI infrastructure, scaling distributed compute systems, and improving the performance and cost-efficiency of large language model workloads in production. Chi is the lead inventor on 12 patents across areas including model serving and optimization, data access control, and large-scale system design. He is also a passionate technical writer, focused on making complex AI systems practical and accessible for engineers.
Peiheng Hu is an accomplished machine learning engineer with over 10 years of industry experience and expertise in building large-scale AI systems. He currently works at NVIDIA, where he focuses on the cutting-edge distributed LLM inference, pushing the boundaries of high-performance inference engines on the latest NVIDIA GPUs. He holds a master of science in computational science and engineering from Harvard University and a bachelor of science in industrial engineering operations research from Georgia Institute of Technology. Previously, Peiheng served as a principal member of technical staff at Salesforce, where he led the development of the company's only unified serving platform, handling thousands of per-tenant models and LLM optimizations for Agentforce that saved millions in AI infrastructure expenses. Prior to that, he was a senior ML engineer at Microsoft Azure, where he architected distributed ML processing solutions for cloud security detection and analytics, handling billions of transactions per hour.









