📄 Page
1
Machine Learning Systems Vijay Janapa Reddi Introduction to
📄 Page
2
Machine Learning Systems Principles and Practices of Engineering Artificially Intelligent Systems Prof. Vijay Janapa Reddi School of Engineering and Applied Sciences Harvard University With heartfelt gratitude to the community for their invaluable contributions and steadfast support. September 4, 2025
📄 Page
3
Table of contents Abstract i Support Our Mission . . . . . . . . . . . . . . . . . . . . . . . . . . . i Why We Wrote This Book . . . . . . . . . . . . . . . . . . . . . . . . . ii Listen to the AI Podcast . . . . . . . . . . . . . . . . . . . . . . . . . . ii Global Outreach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii Want to Help Out? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii Frontmatter Author’s Note v About the Book vii Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii Purpose of the Book . . . . . . . . . . . . . . . . . . . . . . . . vii Context and Development . . . . . . . . . . . . . . . . . . . . . vii What to Expect . . . . . . . . . . . . . . . . . . . . . . . . . . . vii Learning Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Key Learning Outcomes . . . . . . . . . . . . . . . . . . . . . . ix Learning Objectives . . . . . . . . . . . . . . . . . . . . . . . . . ix AI Learning Companion . . . . . . . . . . . . . . . . . . . . . . x How to Use This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . x Book Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . x Suggested Reading Paths . . . . . . . . . . . . . . . . . . . . . . xi Modular Design . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Transparency and Collaboration . . . . . . . . . . . . . . . . . . . . . xi Copyright and Licensing . . . . . . . . . . . . . . . . . . . . . . . . . xii Join the Community . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii Book Changelog xiii Acknowledgements xv Funding Agencies and Companies . . . . . . . . . . . . . . . . . . . . xv Academic Support . . . . . . . . . . . . . . . . . . . . . . . . . xv Non-Profit and Institutional Support . . . . . . . . . . . . . . . xv Corporate Support . . . . . . . . . . . . . . . . . . . . . . . . . xvi i
📄 Page
4
Table of contents ii Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi SocratiQ AI xix Main Part I Foundations Chapter 1 Introduction 1 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 AI Pervasiveness . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 AI and ML Basics . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 AI Evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3.1 Symbolic AI Era . . . . . . . . . . . . . . . . . . . . . . 4 1.3.2 Expert Systems Era . . . . . . . . . . . . . . . . . . . . . 6 1.3.3 Statistical Learning Era . . . . . . . . . . . . . . . . . . . 7 1.3.4 Shallow Learning Era . . . . . . . . . . . . . . . . . . . 8 1.3.5 Deep Learning Era . . . . . . . . . . . . . . . . . . . . . 9 1.4 ML Systems Engineering . . . . . . . . . . . . . . . . . . . . . . 11 1.5 Defining ML Systems . . . . . . . . . . . . . . . . . . . . . . . . 13 1.6 Lifecycle of ML Systems . . . . . . . . . . . . . . . . . . . . . . 15 1.7 ML Systems in the Wild . . . . . . . . . . . . . . . . . . . . . . 17 1.8 ML Systems Impact on Lifecycle . . . . . . . . . . . . . . . . . . 18 1.8.1 Emerging Trends . . . . . . . . . . . . . . . . . . . . . . 19 1.9 Practical Applications . . . . . . . . . . . . . . . . . . . . . . . 20 1.9.1 FarmBeats: ML in Agriculture . . . . . . . . . . . . . . . 20 1.9.2 AlphaFold: Scientific ML . . . . . . . . . . . . . . . . . 22 1.9.3 Autonomous Vehicles . . . . . . . . . . . . . . . . . . . 24 1.10 Challenges in ML Systems . . . . . . . . . . . . . . . . . . . . . 26 1.10.1 Data-Related Challenges . . . . . . . . . . . . . . . . . . 26 1.10.2 Model-Related Challenges . . . . . . . . . . . . . . . . . 27 1.10.3 System-Related Challenges . . . . . . . . . . . . . . . . 27 1.10.4 Ethical Considerations . . . . . . . . . . . . . . . . . . . 28 1.11 Looking Ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1.12 Book Structure and Learning Path . . . . . . . . . . . . . . . . 30 1.13 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 31 Chapter 2 ML Systems 41 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 2.2 Cloud-Based Machine Learning . . . . . . . . . . . . . . . . . . 45 2.2.1 Characteristics . . . . . . . . . . . . . . . . . . . . . . . 46 2.2.2 Benefits . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.2.3 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.2.4 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.3 Edge Machine Learning . . . . . . . . . . . . . . . . . . . . . . 51
📄 Page
5
Table of contents iii 2.3.1 Characteristics . . . . . . . . . . . . . . . . . . . . . . . 52 2.3.2 Benefits . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 2.3.3 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . 53 2.3.4 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 53 2.4 Mobile Machine Learning . . . . . . . . . . . . . . . . . . . . . 55 2.4.1 Characteristics . . . . . . . . . . . . . . . . . . . . . . . 55 2.4.2 Benefits . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 2.4.3 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . 56 2.4.4 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 56 2.5 Tiny Machine Learning . . . . . . . . . . . . . . . . . . . . . . . 58 2.5.1 Characteristics . . . . . . . . . . . . . . . . . . . . . . . 59 2.5.2 Benefits . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2.5.3 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . 60 2.5.4 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 60 2.6 Hybrid Machine Learning . . . . . . . . . . . . . . . . . . . . . 61 2.6.1 Design Patterns . . . . . . . . . . . . . . . . . . . . . . . 62 2.6.2 Real-World Integration . . . . . . . . . . . . . . . . . . . 63 2.7 Shared Principles . . . . . . . . . . . . . . . . . . . . . . . . . . 66 2.7.1 Implementation Layer . . . . . . . . . . . . . . . . . . . 67 2.7.2 System Principles Layer . . . . . . . . . . . . . . . . . . 68 2.7.3 System Considerations Layer . . . . . . . . . . . . . . . 68 2.7.4 Principles to Practice . . . . . . . . . . . . . . . . . . . . 69 2.8 System Comparison . . . . . . . . . . . . . . . . . . . . . . . . 70 2.9 Deployment Decision Framework . . . . . . . . . . . . . . . . . 73 2.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 2.11 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 76 Chapter 3 DL Primer 87 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 3.2 The Evolution to Deep Learning . . . . . . . . . . . . . . . . . . 89 3.2.1 Rule-Based Programming . . . . . . . . . . . . . . . . . 89 3.2.2 Classical Machine Learning . . . . . . . . . . . . . . . . 91 3.2.3 Neural Networks and Representation Learning . . . . . 92 3.2.4 Neural System Implications . . . . . . . . . . . . . . . . 94 3.3 Biological to Artificial Neurons . . . . . . . . . . . . . . . . . . 96 3.3.1 Biological Intelligence . . . . . . . . . . . . . . . . . . . 96 3.3.2 Transition to Artificial Neurons . . . . . . . . . . . . . . 97 3.3.3 Artificial Intelligence . . . . . . . . . . . . . . . . . . . . 99 3.3.4 Computational Translation . . . . . . . . . . . . . . . . 99 3.3.5 System Requirements . . . . . . . . . . . . . . . . . . . 100 3.3.6 Evolution and Impact . . . . . . . . . . . . . . . . . . . 101 3.4 Neural Network Fundamentals . . . . . . . . . . . . . . . . . . 104 3.4.1 Basic Architecture . . . . . . . . . . . . . . . . . . . . . 104 3.4.2 Weights and Biases . . . . . . . . . . . . . . . . . . . . . 108 3.4.3 Network Topology . . . . . . . . . . . . . . . . . . . . . 109 3.5 Learning Process . . . . . . . . . . . . . . . . . . . . . . . . . . 113 3.5.1 Training Overview . . . . . . . . . . . . . . . . . . . . . 114
📄 Page
6
Table of contents iv 3.5.2 Forward Propagation . . . . . . . . . . . . . . . . . . . 114 3.5.3 Loss Functions . . . . . . . . . . . . . . . . . . . . . . . 118 3.5.4 Backward Propagation . . . . . . . . . . . . . . . . . . . 121 3.5.5 Optimization Process . . . . . . . . . . . . . . . . . . . 124 3.6 Prediction Phase . . . . . . . . . . . . . . . . . . . . . . . . . . 126 3.6.1 Inference Basics . . . . . . . . . . . . . . . . . . . . . . . 127 3.6.2 Pre-processing . . . . . . . . . . . . . . . . . . . . . . . 129 3.6.3 Inference . . . . . . . . . . . . . . . . . . . . . . . . . . 130 3.6.4 Post-processing . . . . . . . . . . . . . . . . . . . . . . . 134 3.7 Case Study: USPS Postal Service . . . . . . . . . . . . . . . . . 135 3.7.1 Real-world Problem . . . . . . . . . . . . . . . . . . . . 135 3.7.2 System Development . . . . . . . . . . . . . . . . . . . . 136 3.7.3 Complete Pipeline . . . . . . . . . . . . . . . . . . . . . 137 3.7.4 Results and Impact . . . . . . . . . . . . . . . . . . . . . 138 3.7.5 Key Takeaways . . . . . . . . . . . . . . . . . . . . . . . 139 3.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 3.9 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 140 Chapter 4 DNN Architectures 147 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 4.2 Multi-Layer Perceptrons: Dense Pattern Processing . . . . . . . 149 4.2.1 Pattern Processing Needs . . . . . . . . . . . . . . . . . 149 4.2.2 Algorithmic Structure . . . . . . . . . . . . . . . . . . . 150 4.2.3 Computational Mapping . . . . . . . . . . . . . . . . . 151 4.2.4 System Implications . . . . . . . . . . . . . . . . . . . . 152 4.3 Convolutional Neural Networks: Spatial Pattern Processing . . 154 4.3.1 Pattern Processing Needs . . . . . . . . . . . . . . . . . 154 4.3.2 Algorithmic Structure . . . . . . . . . . . . . . . . . . . 155 4.3.3 Computational Mapping . . . . . . . . . . . . . . . . . 156 4.3.4 System Implications . . . . . . . . . . . . . . . . . . . . 158 4.4 Recurrent Neural Networks: Sequential Pattern Processing . . 159 4.4.1 Pattern Processing Needs . . . . . . . . . . . . . . . . . 160 4.4.2 Algorithmic Structure . . . . . . . . . . . . . . . . . . . 160 4.4.3 Computational Mapping . . . . . . . . . . . . . . . . . 161 4.4.4 System Implications . . . . . . . . . . . . . . . . . . . . 163 4.5 Attention Mechanisms: Dynamic Pattern Processing . . . . . . 164 4.5.1 Pattern Processing Needs . . . . . . . . . . . . . . . . . 165 4.5.2 Basic Attention Mechanism . . . . . . . . . . . . . . . . 166 4.5.3 Transformers and Self-Attention . . . . . . . . . . . . . 169 4.6 Architectural Building Blocks . . . . . . . . . . . . . . . . . . . 173 4.6.1 From Perceptron to Multi-Layer Networks . . . . . . . . 174 4.6.2 From Dense to Spatial Processing . . . . . . . . . . . . . 174 4.6.3 The Evolution of Sequence Processing . . . . . . . . . . 175 4.6.4 Modern Architectures: Synthesis and Innovation . . . . 175 4.7 System-Level Building Blocks . . . . . . . . . . . . . . . . . . . 177 4.7.1 Core Computational Primitives . . . . . . . . . . . . . . 177 4.7.2 Memory Access Primitives . . . . . . . . . . . . . . . . 179
📄 Page
7
Table of contents v 4.7.3 Data Movement Primitives . . . . . . . . . . . . . . . . 181 4.7.4 System Design Impact . . . . . . . . . . . . . . . . . . . 183 4.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 4.9 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 185 Part II Principles Chapter 5 AI Workflow 195 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 5.1.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . 198 5.1.2 Traditional vs. AI Lifecycles . . . . . . . . . . . . . . . . 198 5.2 Lifecycle Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 5.3 Problem Definition . . . . . . . . . . . . . . . . . . . . . . . . . 202 5.3.1 Requirements and System Impact . . . . . . . . . . . . . 202 5.3.2 Definition Workflow . . . . . . . . . . . . . . . . . . . . 203 5.3.3 Scale and Distribution . . . . . . . . . . . . . . . . . . . 203 5.3.4 Systems Thinking . . . . . . . . . . . . . . . . . . . . . . 203 5.3.5 Lifecycle Implications . . . . . . . . . . . . . . . . . . . 204 5.4 Data Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 5.4.1 Data Requirements and Impact . . . . . . . . . . . . . . 205 5.4.2 Data Infrastructure . . . . . . . . . . . . . . . . . . . . . 206 5.4.3 Scale and Distribution . . . . . . . . . . . . . . . . . . . 206 5.4.4 Data Validation . . . . . . . . . . . . . . . . . . . . . . . 207 5.4.5 Systems Thinking . . . . . . . . . . . . . . . . . . . . . . 207 5.4.6 Lifecycle Implications . . . . . . . . . . . . . . . . . . . 208 5.5 Model Development . . . . . . . . . . . . . . . . . . . . . . . . 209 5.5.1 Model Requirements and Impact . . . . . . . . . . . . . 209 5.5.2 Development Workflow . . . . . . . . . . . . . . . . . . 210 5.5.3 Scale and Distribution . . . . . . . . . . . . . . . . . . . 210 5.5.4 Systems Thinking . . . . . . . . . . . . . . . . . . . . . . 211 5.5.5 Lifecycle Implications . . . . . . . . . . . . . . . . . . . 211 5.6 Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 5.6.1 Deployment Requirements and Impact . . . . . . . . . . 213 5.6.2 Deployment Workflow . . . . . . . . . . . . . . . . . . . 213 5.6.3 Scale and Distribution . . . . . . . . . . . . . . . . . . . 213 5.6.4 Robustness and Reliability . . . . . . . . . . . . . . . . . 214 5.6.5 Systems Thinking . . . . . . . . . . . . . . . . . . . . . . 214 5.6.6 Lifecycle Implications . . . . . . . . . . . . . . . . . . . 215 5.7 Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 5.7.1 Monitoring Requirements and Impact . . . . . . . . . . 216 5.7.2 Maintenance Workflow . . . . . . . . . . . . . . . . . . 217 5.7.3 Scale and Distribution . . . . . . . . . . . . . . . . . . . 217 5.7.4 Proactive Maintenance . . . . . . . . . . . . . . . . . . . 218 5.7.5 Systems Thinking . . . . . . . . . . . . . . . . . . . . . . 218 5.7.6 Lifecycle Implications . . . . . . . . . . . . . . . . . . . 219 5.8 AI Lifecycle Roles . . . . . . . . . . . . . . . . . . . . . . . . . . 220
📄 Page
8
Table of contents vi 5.8.1 Collaboration in AI . . . . . . . . . . . . . . . . . . . . . 220 5.8.2 Role Interplay . . . . . . . . . . . . . . . . . . . . . . . . 220 5.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 5.10 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 223 Chapter 6 Data Engineering 233 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 6.2 Problem Definition . . . . . . . . . . . . . . . . . . . . . . . . . 236 6.2.1 Keyword Spotting Example . . . . . . . . . . . . . . . . 237 6.3 Pipeline Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 6.4 Data Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 6.4.1 Existing Datasets . . . . . . . . . . . . . . . . . . . . . . 242 6.4.2 Web Scraping . . . . . . . . . . . . . . . . . . . . . . . . 243 6.4.3 Crowdsourcing . . . . . . . . . . . . . . . . . . . . . . . 245 6.4.4 Anonymization Techniques . . . . . . . . . . . . . . . . 248 6.4.5 Synthetic Data Creation . . . . . . . . . . . . . . . . . . 249 6.4.6 Continuing the KWS Example . . . . . . . . . . . . . . . 251 6.5 Data Ingestion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 6.5.1 Ingestion Patterns . . . . . . . . . . . . . . . . . . . . . 252 6.5.2 ETL and ELT Comparison . . . . . . . . . . . . . . . . . 252 6.5.3 Data Source Integration . . . . . . . . . . . . . . . . . . 254 6.5.4 Validation Techniques . . . . . . . . . . . . . . . . . . . 254 6.5.5 Error Management . . . . . . . . . . . . . . . . . . . . . 254 6.5.6 Continuing the KWS Example . . . . . . . . . . . . . . . 255 6.6 Data Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 6.6.1 Cleaning Techniques . . . . . . . . . . . . . . . . . . . . 257 6.6.2 Data Quality Assessment . . . . . . . . . . . . . . . . . 258 6.6.3 Transformation Techniques . . . . . . . . . . . . . . . . 258 6.6.4 Feature Engineering . . . . . . . . . . . . . . . . . . . . 258 6.6.5 Processing Pipeline Design . . . . . . . . . . . . . . . . 259 6.6.6 Scalability Considerations . . . . . . . . . . . . . . . . . 260 6.6.7 Continuing the KWS Example . . . . . . . . . . . . . . . 260 6.7 Data Labeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 6.7.1 Types of Labels . . . . . . . . . . . . . . . . . . . . . . . 263 6.7.2 Annotation Techniques . . . . . . . . . . . . . . . . . . . 265 6.7.3 Label Quality Assessment . . . . . . . . . . . . . . . . . 266 6.7.4 AI in Annotation . . . . . . . . . . . . . . . . . . . . . . 267 6.7.5 Labeling Challenges . . . . . . . . . . . . . . . . . . . . 269 6.7.6 Continuing the KWS Example . . . . . . . . . . . . . . . 270 6.8 Data Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 6.8.1 Storage System Types . . . . . . . . . . . . . . . . . . . 272 6.8.2 Storage Considerations . . . . . . . . . . . . . . . . . . . 274 6.8.3 Performance Factors . . . . . . . . . . . . . . . . . . . . 275 6.8.4 Storage in ML Lifecycle . . . . . . . . . . . . . . . . . . 276 6.8.5 Feature Storage . . . . . . . . . . . . . . . . . . . . . . . 278 6.8.6 Caching Techniques . . . . . . . . . . . . . . . . . . . . 280 6.8.7 Data Access Patterns . . . . . . . . . . . . . . . . . . . . 281
📄 Page
9
Table of contents vii 6.8.8 Continuing the KWS Example . . . . . . . . . . . . . . . 282 6.9 Data Governance . . . . . . . . . . . . . . . . . . . . . . . . . . 283 6.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 6.11 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 287 Chapter 7 AI Frameworks 297 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 7.2 Evolution History . . . . . . . . . . . . . . . . . . . . . . . . . . 299 7.2.1 Evolution Timeline . . . . . . . . . . . . . . . . . . . . . 299 7.2.2 Early Numerical Libraries . . . . . . . . . . . . . . . . . 299 7.2.3 First-Generation Frameworks . . . . . . . . . . . . . . . 300 7.2.4 Emergence of Deep Learning Frameworks . . . . . . . . 301 7.2.5 Hardware Impact on Design . . . . . . . . . . . . . . . 302 7.3 Fundamental Concepts . . . . . . . . . . . . . . . . . . . . . . . 304 7.3.1 Computational Graphs . . . . . . . . . . . . . . . . . . . 305 7.3.2 Automatic Differentiation . . . . . . . . . . . . . . . . . 311 7.3.3 Data Structures . . . . . . . . . . . . . . . . . . . . . . . 325 7.3.4 Programming Models . . . . . . . . . . . . . . . . . . . 331 7.3.5 Execution Models . . . . . . . . . . . . . . . . . . . . . 333 7.3.6 Core Operations . . . . . . . . . . . . . . . . . . . . . . 340 7.4 Framework Architecture . . . . . . . . . . . . . . . . . . . . . . 343 7.4.1 APIs and Abstractions . . . . . . . . . . . . . . . . . . . 344 7.5 Framework Ecosystem . . . . . . . . . . . . . . . . . . . . . . . 346 7.5.1 Core Libraries . . . . . . . . . . . . . . . . . . . . . . . . 346 7.5.2 Extensions and Plugins . . . . . . . . . . . . . . . . . . 347 7.5.3 Development Tools . . . . . . . . . . . . . . . . . . . . . 348 7.6 System Integration . . . . . . . . . . . . . . . . . . . . . . . . . 348 7.6.1 Hardware Integration . . . . . . . . . . . . . . . . . . . 348 7.6.2 Software Stack . . . . . . . . . . . . . . . . . . . . . . . 349 7.6.3 Deployment Considerations . . . . . . . . . . . . . . . . 349 7.6.4 Workflow Orchestration . . . . . . . . . . . . . . . . . . 350 7.7 Major Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . 351 7.7.1 TensorFlow Ecosystem . . . . . . . . . . . . . . . . . . . 351 7.7.2 PyTorch . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 7.7.3 JAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 7.7.4 Framework Comparison . . . . . . . . . . . . . . . . . . 354 7.8 Framework Specialization . . . . . . . . . . . . . . . . . . . . . 355 7.8.1 Cloud-Based Frameworks . . . . . . . . . . . . . . . . . 357 7.8.2 Edge-Based Frameworks . . . . . . . . . . . . . . . . . . 358 7.8.3 Mobile-Based Frameworks . . . . . . . . . . . . . . . . 359 7.8.4 TinyML Frameworks . . . . . . . . . . . . . . . . . . . . 360 7.9 Framework Selection . . . . . . . . . . . . . . . . . . . . . . . . 362 7.9.1 Model Requirements . . . . . . . . . . . . . . . . . . . . 362 7.9.2 Software Dependencies . . . . . . . . . . . . . . . . . . 363 7.9.3 Hardware Constraints . . . . . . . . . . . . . . . . . . . 364 7.9.4 Additional Selection Factors . . . . . . . . . . . . . . . . 364 7.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
📄 Page
10
Table of contents viii 7.11 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 366 Chapter 8 AI Training 377 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378 8.2 Training Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 379 8.2.1 System Evolution . . . . . . . . . . . . . . . . . . . . . . 379 8.2.2 System Role . . . . . . . . . . . . . . . . . . . . . . . . . 381 8.2.3 Systems Thinking . . . . . . . . . . . . . . . . . . . . . . 382 8.3 Mathematical Foundations . . . . . . . . . . . . . . . . . . . . . 383 8.3.1 Neural Network Computation . . . . . . . . . . . . . . 384 8.3.2 Optimization Algorithms . . . . . . . . . . . . . . . . . 391 8.3.3 Backpropagation Mechanics . . . . . . . . . . . . . . . . 397 8.3.4 System Implications . . . . . . . . . . . . . . . . . . . . 400 8.4 Pipeline Architecture . . . . . . . . . . . . . . . . . . . . . . . . 401 8.4.1 Architectural Overview . . . . . . . . . . . . . . . . . . 401 8.4.2 Data Pipeline . . . . . . . . . . . . . . . . . . . . . . . . 403 8.4.3 Forward Pass . . . . . . . . . . . . . . . . . . . . . . . . 407 8.4.4 Backward Pass . . . . . . . . . . . . . . . . . . . . . . . 410 8.4.5 Parameter Updates and Optimizers . . . . . . . . . . . . 411 8.5 Pipeline Optimizations . . . . . . . . . . . . . . . . . . . . . . . 414 8.5.1 Prefetching and Overlapping . . . . . . . . . . . . . . . 415 8.5.2 Mixed-Precision Training . . . . . . . . . . . . . . . . . 420 8.5.3 Gradient Accumulation and Checkpointing . . . . . . . 424 8.5.4 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . 430 8.6 Distributed Systems . . . . . . . . . . . . . . . . . . . . . . . . 431 8.6.1 Data Parallelism . . . . . . . . . . . . . . . . . . . . . . 432 8.6.2 Model Parallelism . . . . . . . . . . . . . . . . . . . . . 437 8.6.3 Hybrid Parallelism . . . . . . . . . . . . . . . . . . . . . 442 8.6.4 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . 447 8.7 Optimization Techniques . . . . . . . . . . . . . . . . . . . . . . 449 8.7.1 Identifying Bottlenecks . . . . . . . . . . . . . . . . . . 449 8.7.2 System-Level Optimizations . . . . . . . . . . . . . . . . 450 8.7.3 Software-Level Optimizations . . . . . . . . . . . . . . . 451 8.7.4 Scaling Techniques . . . . . . . . . . . . . . . . . . . . . 451 8.8 Specialized Hardware Training . . . . . . . . . . . . . . . . . . 452 8.8.1 GPUs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 8.8.2 TPUs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 8.8.3 FPGAs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 8.8.4 ASICs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 8.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459 8.10 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 460 Part III Performance Chapter 9 Efficient AI 469 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
📄 Page
11
Table of contents ix 9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470 9.2 AI Scaling Laws . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 9.2.1 Fundamental Principles . . . . . . . . . . . . . . . . . . 471 9.2.2 Empirical Scaling Laws . . . . . . . . . . . . . . . . . . 473 9.2.3 Scaling Regimes . . . . . . . . . . . . . . . . . . . . . . 476 9.2.4 System Design . . . . . . . . . . . . . . . . . . . . . . . 478 9.2.5 Scaling vs. Efficiency . . . . . . . . . . . . . . . . . . . . 479 9.2.6 Scaling Breakdown . . . . . . . . . . . . . . . . . . . . . 480 9.2.7 Toward Efficient Scaling . . . . . . . . . . . . . . . . . . 482 9.3 The Pillars of AI Efficiency . . . . . . . . . . . . . . . . . . . . . 484 9.3.1 Algorithmic Efficiency . . . . . . . . . . . . . . . . . . . 484 9.3.2 Compute Efficiency . . . . . . . . . . . . . . . . . . . . . 487 9.3.3 Data Efficiency . . . . . . . . . . . . . . . . . . . . . . . 490 9.4 System Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . 494 9.4.1 Defining System Efficiency . . . . . . . . . . . . . . . . 494 9.4.2 Efficiency Interdependencies . . . . . . . . . . . . . . . 494 9.4.3 Scalability and Sustainability . . . . . . . . . . . . . . . 498 9.5 Efficiency Trade-offs and Challenges . . . . . . . . . . . . . . . 500 9.5.1 Trade-offs Source . . . . . . . . . . . . . . . . . . . . . . 500 9.5.2 Common Trade-offs . . . . . . . . . . . . . . . . . . . . 502 9.6 Managing Trade-offs . . . . . . . . . . . . . . . . . . . . . . . . 505 9.6.1 Contextual Prioritization . . . . . . . . . . . . . . . . . 505 9.6.2 Test-Time Compute . . . . . . . . . . . . . . . . . . . . . 506 9.6.3 Co-Design . . . . . . . . . . . . . . . . . . . . . . . . . . 507 9.6.4 Automation . . . . . . . . . . . . . . . . . . . . . . . . . 507 9.6.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 508 9.7 Efficiency-First Mindset . . . . . . . . . . . . . . . . . . . . . . 509 9.7.1 End-to-End Perspective . . . . . . . . . . . . . . . . . . 509 9.7.2 Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . 510 9.7.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 511 9.8 Broader Challenges . . . . . . . . . . . . . . . . . . . . . . . . . 512 9.8.1 Optimization Limits . . . . . . . . . . . . . . . . . . . . 513 9.8.2 Moore’s Law Case Study . . . . . . . . . . . . . . . . . . 514 9.8.3 Equity Concerns . . . . . . . . . . . . . . . . . . . . . . 515 9.8.4 Balancing Innovation and Efficiency . . . . . . . . . . . 517 9.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 9.10 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 520 Chapter 10 Model Optimizations 529 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 10.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530 10.2 Real-World Models . . . . . . . . . . . . . . . . . . . . . . . . . 532 10.2.1 Practical Models . . . . . . . . . . . . . . . . . . . . . . 532 10.2.2 Accuracy-Efficiency Balance . . . . . . . . . . . . . . . . 533 10.2.3 Optimization System Constraints . . . . . . . . . . . . . 534 10.3 Model Optimization Dimensions . . . . . . . . . . . . . . . . . 535 10.3.1 Model Representation . . . . . . . . . . . . . . . . . . . 536 10.3.2 Numerical Precision . . . . . . . . . . . . . . . . . . . . 536
📄 Page
12
Table of contents x 10.3.3 Architectural Efficiency . . . . . . . . . . . . . . . . . . 536 10.3.4 Tripartite Framework . . . . . . . . . . . . . . . . . . . . 537 10.4 Model Representation Optimization . . . . . . . . . . . . . . . 538 10.4.1 Pruning . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 10.4.2 Knowledge Distillation . . . . . . . . . . . . . . . . . . . 553 10.4.3 Structured Approximations . . . . . . . . . . . . . . . . 559 10.4.4 Neural Architecture Search . . . . . . . . . . . . . . . . 567 10.5 Numerical Precision Optimization . . . . . . . . . . . . . . . . 572 10.5.1 Efficiency Numerical Precision . . . . . . . . . . . . . . 573 10.5.2 Numeric Encoding and Storage . . . . . . . . . . . . . . 575 10.5.3 Numerical Precision Format Comparison . . . . . . . . 576 10.5.4 Precision Reduction Trade-offs . . . . . . . . . . . . . . 578 10.5.5 Precision Reduction Strategies . . . . . . . . . . . . . . 579 10.5.6 Extreme Precision Reduction . . . . . . . . . . . . . . . 593 10.5.7 Quantization vs. Model Representation . . . . . . . . . 595 10.6 Architectural Efficiency Optimization . . . . . . . . . . . . . . . 597 10.6.1 Hardware-Aware Design . . . . . . . . . . . . . . . . . 597 10.6.2 Dynamic Computation and Adaptation . . . . . . . . . 603 10.6.3 Sparsity Exploitation . . . . . . . . . . . . . . . . . . . . 610 10.7 AutoML and Model Optimization . . . . . . . . . . . . . . . . . 621 10.7.1 AutoML Optimizations . . . . . . . . . . . . . . . . . . 622 10.7.2 Optimization Strategies . . . . . . . . . . . . . . . . . . 623 10.7.3 AutoML Challenges and Considerations . . . . . . . . . 624 10.8 Software and Framework Support . . . . . . . . . . . . . . . . . 626 10.8.1 Optimization APIs . . . . . . . . . . . . . . . . . . . . . 626 10.8.2 Hardware Optimization Libraries . . . . . . . . . . . . . 628 10.8.3 Optimization Visualization . . . . . . . . . . . . . . . . 630 10.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632 10.10 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 634 Chapter 11 AI Acceleration 645 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 11.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646 11.2 Hardware Evolution . . . . . . . . . . . . . . . . . . . . . . . . 647 11.2.1 Specialized Computing . . . . . . . . . . . . . . . . . . 648 11.2.2 Specialized Computing Expansion . . . . . . . . . . . . 649 11.2.3 Domain-Specific Architectures . . . . . . . . . . . . . . 650 11.2.4 ML in Computational Domains . . . . . . . . . . . . . . 652 11.2.5 Application-Specific Accelerators . . . . . . . . . . . . . 652 11.3 AI Compute Primitives . . . . . . . . . . . . . . . . . . . . . . . 655 11.3.1 Vector Operations . . . . . . . . . . . . . . . . . . . . . 656 11.3.2 Matrix Operations . . . . . . . . . . . . . . . . . . . . . 659 11.3.3 Special Function Units . . . . . . . . . . . . . . . . . . . 662 11.3.4 Compute Units and Execution Models . . . . . . . . . . 665 11.4 AI Memory Systems . . . . . . . . . . . . . . . . . . . . . . . . 673 11.4.1 AI Memory Wall . . . . . . . . . . . . . . . . . . . . . . 674 11.4.2 Memory Hierarchy . . . . . . . . . . . . . . . . . . . . . 679 11.4.3 Host-Accelerator Communication . . . . . . . . . . . . 681
📄 Page
13
Table of contents xi 11.4.4 Model Memory Pressure . . . . . . . . . . . . . . . . . . 684 11.4.5 ML Accelerators Implications . . . . . . . . . . . . . . . 686 11.5 Neural Networks Mapping . . . . . . . . . . . . . . . . . . . . 687 11.5.1 Computation Placement . . . . . . . . . . . . . . . . . . 688 11.5.2 Memory Allocation . . . . . . . . . . . . . . . . . . . . . 691 11.5.3 Combinatorial Complexity . . . . . . . . . . . . . . . . 694 11.6 Optimization Strategies . . . . . . . . . . . . . . . . . . . . . . 698 11.6.1 Mapping Strategies Building Blocks . . . . . . . . . . . 698 11.6.2 Mapping Strategies Application . . . . . . . . . . . . . 716 11.6.3 Hybrid Mapping Strategies . . . . . . . . . . . . . . . . 720 11.6.4 Hybrid Strategies Hardware Implementations . . . . . 721 11.7 Compiler Support . . . . . . . . . . . . . . . . . . . . . . . . . . 722 11.7.1 ML vs Traditional Compilers . . . . . . . . . . . . . . . 723 11.7.2 ML Compilation Pipeline . . . . . . . . . . . . . . . . . 724 11.7.3 Graph Optimization . . . . . . . . . . . . . . . . . . . . 724 11.7.4 Kernel Selection . . . . . . . . . . . . . . . . . . . . . . 726 11.7.5 Memory Planning . . . . . . . . . . . . . . . . . . . . . 729 11.7.6 Computation Scheduling . . . . . . . . . . . . . . . . . 730 11.7.7 Compilation-Runtime Support . . . . . . . . . . . . . . 733 11.8 Runtime Support . . . . . . . . . . . . . . . . . . . . . . . . . . 734 11.8.1 ML vs Traditional Runtimes . . . . . . . . . . . . . . . . 734 11.8.2 Dynamic Kernel Execution . . . . . . . . . . . . . . . . 736 11.8.3 Runtime Kernel Selection . . . . . . . . . . . . . . . . . 737 11.8.4 Kernel Scheduling and Utilization . . . . . . . . . . . . 737 11.9 Multi-Chip AI Acceleration . . . . . . . . . . . . . . . . . . . . 738 11.9.1 Chiplet-Based Architectures . . . . . . . . . . . . . . . . 739 11.9.2 Multi-GPU Systems . . . . . . . . . . . . . . . . . . . . 740 11.9.3 TPU Pods . . . . . . . . . . . . . . . . . . . . . . . . . . 741 11.9.4 Wafer-Scale AI . . . . . . . . . . . . . . . . . . . . . . . 742 11.9.5 AI Systems Scaling Trajectory . . . . . . . . . . . . . . . 743 11.9.6 Computation and Memory Scaling Changes . . . . . . . 743 11.9.7 Execution Models Adaptation . . . . . . . . . . . . . . . 746 11.9.8 Navigating Multi-Chip AI Complexities . . . . . . . . . 749 11.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750 11.11 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 752 Chapter 12 Benchmarking AI 763 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763 12.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764 12.2 Historical Context . . . . . . . . . . . . . . . . . . . . . . . . . . 765 12.2.1 Performance Benchmarks . . . . . . . . . . . . . . . . . 765 12.2.2 Energy Benchmarks . . . . . . . . . . . . . . . . . . . . 766 12.2.3 Domain-Specific Benchmarks . . . . . . . . . . . . . . . 767 12.3 AI Benchmarks . . . . . . . . . . . . . . . . . . . . . . . . . . . 768 12.3.1 Algorithmic Benchmarks . . . . . . . . . . . . . . . . . 769 12.3.2 System Benchmarks . . . . . . . . . . . . . . . . . . . . 769 12.3.3 Data Benchmarks . . . . . . . . . . . . . . . . . . . . . . 771 12.3.4 Community Consensus . . . . . . . . . . . . . . . . . . 772
📄 Page
14
Table of contents xii 12.4 Benchmark Components . . . . . . . . . . . . . . . . . . . . . . 774 12.4.1 Problem Definition . . . . . . . . . . . . . . . . . . . . . 774 12.4.2 Standardized Datasets . . . . . . . . . . . . . . . . . . . 775 12.4.3 Model Selection . . . . . . . . . . . . . . . . . . . . . . . 776 12.4.4 Evaluation Metrics . . . . . . . . . . . . . . . . . . . . . 777 12.4.5 Benchmark Harness . . . . . . . . . . . . . . . . . . . . 778 12.4.6 System Specifications . . . . . . . . . . . . . . . . . . . 778 12.4.7 Run Rules . . . . . . . . . . . . . . . . . . . . . . . . . . 779 12.4.8 Result Interpretation . . . . . . . . . . . . . . . . . . . . 780 12.4.9 Example Benchmark . . . . . . . . . . . . . . . . . . . . 781 12.5 Benchmarking Granularity . . . . . . . . . . . . . . . . . . . . . 782 12.5.1 Micro Benchmarks . . . . . . . . . . . . . . . . . . . . . 782 12.5.2 Macro Benchmarks . . . . . . . . . . . . . . . . . . . . . 783 12.5.3 End-to-End Benchmarks . . . . . . . . . . . . . . . . . . 784 12.5.4 Trade-offs . . . . . . . . . . . . . . . . . . . . . . . . . . 785 12.6 Training Benchmarks . . . . . . . . . . . . . . . . . . . . . . . . 786 12.6.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . 787 12.6.2 Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . 791 12.6.3 Training Performance Evaluation . . . . . . . . . . . . . 794 12.7 Inference Benchmarks . . . . . . . . . . . . . . . . . . . . . . . 798 12.7.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . 800 12.7.2 Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . 802 12.7.3 Inference Performance Evaluation . . . . . . . . . . . . 805 12.7.4 MLPerf Inference Benchmarks . . . . . . . . . . . . . . 808 12.8 Energy Efficiency Measurement . . . . . . . . . . . . . . . . . . 810 12.8.1 Power Measurement Boundaries . . . . . . . . . . . . . 811 12.8.2 Performance vs Energy Efficiency . . . . . . . . . . . . . 812 12.8.3 Standardized Power Measurement . . . . . . . . . . . . 813 12.8.4 MLPerf Power Case Study . . . . . . . . . . . . . . . . . 814 12.9 Challenges & Limitations . . . . . . . . . . . . . . . . . . . . . 816 12.9.1 Environmental Conditions . . . . . . . . . . . . . . . . . 817 12.9.2 Hardware Lottery . . . . . . . . . . . . . . . . . . . . . 818 12.9.3 Benchmark Engineering . . . . . . . . . . . . . . . . . . 819 12.9.4 Bias & Over-Optimization . . . . . . . . . . . . . . . . . 819 12.9.5 Benchmark Evolution . . . . . . . . . . . . . . . . . . . 820 12.9.6 MLPerf’s Role . . . . . . . . . . . . . . . . . . . . . . . . 821 12.10 Beyond System Benchmarking . . . . . . . . . . . . . . . . . . . 823 12.10.1 Model Benchmarking . . . . . . . . . . . . . . . . . . . 823 12.10.2 Data Benchmarking . . . . . . . . . . . . . . . . . . . . 824 12.10.3 Benchmarking Trifecta . . . . . . . . . . . . . . . . . . . 826 12.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 827 12.12 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 828 Part IV Deployment Chapter 13 ML Operations 841 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841
📄 Page
15
Table of contents xiii 13.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842 13.2 Historical Context . . . . . . . . . . . . . . . . . . . . . . . . . . 843 13.2.1 DevOps . . . . . . . . . . . . . . . . . . . . . . . . . . . 843 13.2.2 MLOps . . . . . . . . . . . . . . . . . . . . . . . . . . . 843 13.3 MLOps Key Components . . . . . . . . . . . . . . . . . . . . . 845 13.3.1 Data Infrastructure and Preparation . . . . . . . . . . . 846 13.3.2 Continuous Pipelines and Automation . . . . . . . . . . 848 13.3.3 Model Deployment and Serving . . . . . . . . . . . . . 853 13.3.4 Infrastructure and Observability . . . . . . . . . . . . . 856 13.3.5 Governance and Collaboration . . . . . . . . . . . . . . 858 13.4 Hidden Technical Debt . . . . . . . . . . . . . . . . . . . . . . . 860 13.4.1 Boundary Erosion . . . . . . . . . . . . . . . . . . . . . 861 13.4.2 Correction Cascades . . . . . . . . . . . . . . . . . . . . 862 13.4.3 Undeclared Consumers . . . . . . . . . . . . . . . . . . 863 13.4.4 Data Dependency Debt . . . . . . . . . . . . . . . . . . 864 13.4.5 Feedback Loops . . . . . . . . . . . . . . . . . . . . . . . 865 13.4.6 Pipeline Debt . . . . . . . . . . . . . . . . . . . . . . . . 866 13.4.7 Configuration Debt . . . . . . . . . . . . . . . . . . . . . 867 13.4.8 Early-Stage Debt . . . . . . . . . . . . . . . . . . . . . . 868 13.4.9 Real-World Examples . . . . . . . . . . . . . . . . . . . 869 13.4.10 Managing Hidden Technical Debt . . . . . . . . . . . . 870 13.4.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 871 13.5 Roles and Responsibilities . . . . . . . . . . . . . . . . . . . . . 872 13.5.1 Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872 13.5.2 Intersections and Handoffs . . . . . . . . . . . . . . . . 884 13.5.3 Evolving Roles and Specializations . . . . . . . . . . . . 886 13.6 Operational System Design . . . . . . . . . . . . . . . . . . . . 888 13.6.1 Operational Maturity . . . . . . . . . . . . . . . . . . . 888 13.6.2 Maturity Levels . . . . . . . . . . . . . . . . . . . . . . . 889 13.6.3 System Design Implications . . . . . . . . . . . . . . . . 890 13.6.4 Patterns and Anti-Patterns . . . . . . . . . . . . . . . . . 890 13.6.5 Contextualizing MLOps . . . . . . . . . . . . . . . . . . 892 13.6.6 Looking Ahead . . . . . . . . . . . . . . . . . . . . . . . 893 13.6.7 Enterprise-Scale Infrastructure: AI Factories . . . . . . . 893 13.7 Case Studies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 894 13.7.1 Oura Ring Case Study . . . . . . . . . . . . . . . . . . . 895 13.7.2 Model Development and Evaluation . . . . . . . . . . . 896 13.7.3 Deployment and Iteration . . . . . . . . . . . . . . . . . 896 13.7.4 Lessons from MLOps Practice . . . . . . . . . . . . . . . 897 13.7.5 ClinAIOps Case Study . . . . . . . . . . . . . . . . . . . 898 13.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906 13.9 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 907 Chapter 14 On-Device Learning 915 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915 14.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916 14.2 Deployment Drivers . . . . . . . . . . . . . . . . . . . . . . . . 917 14.2.1 On-Device Learning Benefits . . . . . . . . . . . . . . . 917
📄 Page
16
Table of contents xiv 14.2.2 Application Domains . . . . . . . . . . . . . . . . . . . 919 14.2.3 Training Paradigms . . . . . . . . . . . . . . . . . . . . . 920 14.3 Design Constraints . . . . . . . . . . . . . . . . . . . . . . . . . 923 14.3.1 Model Constraints . . . . . . . . . . . . . . . . . . . . . 923 14.3.2 Data Constraints . . . . . . . . . . . . . . . . . . . . . . 925 14.3.3 Compute Constraints . . . . . . . . . . . . . . . . . . . . 926 14.4 Model Adaptation . . . . . . . . . . . . . . . . . . . . . . . . . 927 14.4.1 Weight Freezing . . . . . . . . . . . . . . . . . . . . . . 928 14.4.2 Residual and Low-Rank Updates . . . . . . . . . . . . . 930 14.4.3 Sparse Updates . . . . . . . . . . . . . . . . . . . . . . . 932 14.5 Data Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . 936 14.5.1 Few-Shot and Streaming . . . . . . . . . . . . . . . . . . 936 14.5.2 Experience Replay . . . . . . . . . . . . . . . . . . . . . 937 14.5.3 Data Compression . . . . . . . . . . . . . . . . . . . . . 939 14.5.4 Tradeoffs Summary . . . . . . . . . . . . . . . . . . . . 940 14.6 Federated Learning . . . . . . . . . . . . . . . . . . . . . . . . . 942 14.6.1 Federated Learning Motivation . . . . . . . . . . . . . . 943 14.6.2 Learning Protocols . . . . . . . . . . . . . . . . . . . . . 944 14.7 Practical System Design . . . . . . . . . . . . . . . . . . . . . . 951 14.8 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953 14.8.1 Heterogeneity . . . . . . . . . . . . . . . . . . . . . . . . 953 14.8.2 Data Fragmentation . . . . . . . . . . . . . . . . . . . . 954 14.8.3 Monitoring and Validation . . . . . . . . . . . . . . . . 955 14.8.4 Resource Management . . . . . . . . . . . . . . . . . . . 956 14.8.5 Deployment Risks . . . . . . . . . . . . . . . . . . . . . 958 14.8.6 Challenges Summary . . . . . . . . . . . . . . . . . . . 959 14.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960 14.10 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . . 962 Chapter 15 Robust AI 973 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973 15.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974 15.2 Real-World Applications . . . . . . . . . . . . . . . . . . . . . . 975 15.2.1 Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976 15.2.2 Edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 977 15.2.3 Embedded . . . . . . . . . . . . . . . . . . . . . . . . . 978 15.3 Hardware Faults . . . . . . . . . . . . . . . . . . . . . . . . . . 980 15.3.1 Transient Faults . . . . . . . . . . . . . . . . . . . . . . . 981 15.3.2 Permanent Faults . . . . . . . . . . . . . . . . . . . . . . 984 15.3.3 Intermittent Faults . . . . . . . . . . . . . . . . . . . . . 988 15.3.4 Detection and Mitigation . . . . . . . . . . . . . . . . . 991 15.3.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 997 15.4 Model Robustness . . . . . . . . . . . . . . . . . . . . . . . . . 998 15.4.1 Adversarial Attacks . . . . . . . . . . . . . . . . . . . . 998 15.4.2 Data Poisoning . . . . . . . . . . . . . . . . . . . . . . .1004 15.4.3 Distribution Shifts . . . . . . . . . . . . . . . . . . . . .1010 15.4.4 Detection and Mitigation . . . . . . . . . . . . . . . . .1015 15.5 Software Faults . . . . . . . . . . . . . . . . . . . . . . . . . . .1023
📄 Page
17
Table of contents xv 15.5.1 Characteristics . . . . . . . . . . . . . . . . . . . . . . .1024 15.5.2 Mechanisms . . . . . . . . . . . . . . . . . . . . . . . . .1024 15.5.3 Impact on ML . . . . . . . . . . . . . . . . . . . . . . . .1025 15.5.4 Detection and Mitigation . . . . . . . . . . . . . . . . .1026 15.6 Tools and Frameworks . . . . . . . . . . . . . . . . . . . . . . .1029 15.6.1 Fault and Error Models . . . . . . . . . . . . . . . . . .1029 15.6.2 Hardware-Based Fault Injection . . . . . . . . . . . . . .1031 15.6.3 Software-Based Fault Injection . . . . . . . . . . . . . .1034 15.6.4 Bridging Hardware-Software Gap . . . . . . . . . . . .1038 15.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1041 15.8 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . .1043 Chapter 16 Security & Privacy 1051 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1051 16.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1052 16.2 Definitions and Distinctions . . . . . . . . . . . . . . . . . . . .1053 16.2.1 Security Defined . . . . . . . . . . . . . . . . . . . . . .1053 16.2.2 Privacy Defined . . . . . . . . . . . . . . . . . . . . . . .1053 16.2.3 Security versus Privacy . . . . . . . . . . . . . . . . . .1054 16.2.4 Interactions and Trade-offs . . . . . . . . . . . . . . . .1054 16.3 Historical Incidents . . . . . . . . . . . . . . . . . . . . . . . . .1055 16.3.1 Stuxnet . . . . . . . . . . . . . . . . . . . . . . . . . . .1055 16.3.2 Jeep Cherokee Hack . . . . . . . . . . . . . . . . . . . .1057 16.3.3 Mirai Botnet . . . . . . . . . . . . . . . . . . . . . . . . .1057 16.4 Secure Design Priorities . . . . . . . . . . . . . . . . . . . . . .1059 16.4.1 Device-Level Security . . . . . . . . . . . . . . . . . . .1059 16.4.2 System-Level Isolation . . . . . . . . . . . . . . . . . . .1059 16.4.3 Large-Scale Network Exploitation . . . . . . . . . . . .1060 16.4.4 Toward Secure Design . . . . . . . . . . . . . . . . . . .1060 16.5 Threats to ML Models . . . . . . . . . . . . . . . . . . . . . . .1061 16.5.1 Model Theft . . . . . . . . . . . . . . . . . . . . . . . . .1063 16.5.2 Data Poisoning . . . . . . . . . . . . . . . . . . . . . . .1067 16.5.3 Adversarial Attacks . . . . . . . . . . . . . . . . . . . .1069 16.5.4 Case Study: Traffic Sign Detection Model Trickery . . .1071 16.6 Threats to ML Hardware . . . . . . . . . . . . . . . . . . . . . .1073 16.6.1 Hardware Bugs . . . . . . . . . . . . . . . . . . . . . . .1074 16.6.2 Physical Attacks . . . . . . . . . . . . . . . . . . . . . .1075 16.6.3 Fault Injection Attacks . . . . . . . . . . . . . . . . . . .1076 16.6.4 Side-Channel Attacks . . . . . . . . . . . . . . . . . . .1079 16.6.5 Leaky Interfaces . . . . . . . . . . . . . . . . . . . . . .1082 16.6.6 Counterfeit Hardware . . . . . . . . . . . . . . . . . . .1083 16.6.7 Supply Chain Risks . . . . . . . . . . . . . . . . . . . .1084 16.6.8 Case Study: The Supermicro Hardware Security Con- troversy . . . . . . . . . . . . . . . . . . . . . . . . . . .1085 16.7 Defensive Strategies . . . . . . . . . . . . . . . . . . . . . . . .1086 16.7.1 Data Privacy Techniques . . . . . . . . . . . . . . . . . .1087 16.7.2 Secure Model Design . . . . . . . . . . . . . . . . . . . .1090 16.7.3 Secure Model Deployment . . . . . . . . . . . . . . . .1091
📄 Page
18
Table of contents xvi 16.7.4 System-level Monitoring . . . . . . . . . . . . . . . . . .1093 16.7.5 Hardware-based Security . . . . . . . . . . . . . . . . .1098 16.7.6 Toward Trustworthy Systems . . . . . . . . . . . . . . .1108 16.8 Offensive Capabilities . . . . . . . . . . . . . . . . . . . . . . .1110 16.8.1 Case Study: Deep Learning for SCA . . . . . . . . . . .1112 16.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1114 16.10 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . .1115 Part V Responsibility Chapter 17 Responsible AI 1127 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1127 17.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1128 17.2 Core Principles . . . . . . . . . . . . . . . . . . . . . . . . . . .1129 17.3 Princples in Practice . . . . . . . . . . . . . . . . . . . . . . . .1130 17.3.1 Transparency and Explainability . . . . . . . . . . . . .1131 17.3.2 Fairness in Machine Learning . . . . . . . . . . . . . . .1132 17.3.3 Privacy and Data Governance . . . . . . . . . . . . . . .1134 17.3.4 Designing for Safety and Robustness . . . . . . . . . . .1136 17.3.5 Accountability and Governance . . . . . . . . . . . . . .1137 17.4 Deployment Contexts . . . . . . . . . . . . . . . . . . . . . . .1139 17.4.1 System Explainability . . . . . . . . . . . . . . . . . . .1140 17.4.2 Fairness Constraints . . . . . . . . . . . . . . . . . . . .1141 17.4.3 Privacy Architectures . . . . . . . . . . . . . . . . . . .1142 17.4.4 Safety and Robustness . . . . . . . . . . . . . . . . . . .1143 17.4.5 Governance Structures . . . . . . . . . . . . . . . . . . .1144 17.4.6 Design Tradeoffs . . . . . . . . . . . . . . . . . . . . . .1146 17.5 Technical Foundations . . . . . . . . . . . . . . . . . . . . . . .1148 17.5.1 Bias Detection and Mitigation . . . . . . . . . . . . . . .1149 17.5.2 Privacy Preservation . . . . . . . . . . . . . . . . . . . .1151 17.5.3 Machine Unlearning . . . . . . . . . . . . . . . . . . . .1153 17.5.4 Adversarial Robustness . . . . . . . . . . . . . . . . . .1155 17.5.5 Explainability and Interpretability . . . . . . . . . . . .1157 17.5.6 Model Performance Monitoring . . . . . . . . . . . . . .1160 17.6 Sociotechnical and Ethical Systems Considerations . . . . . . .1162 17.6.1 System Feedback Loops . . . . . . . . . . . . . . . . . .1163 17.6.2 Human-AI Collaboration and Oversight . . . . . . . . .1164 17.6.3 Normative Pluralism and Value Conflicts . . . . . . . .1165 17.6.4 Transparency and Contestability . . . . . . . . . . . . .1167 17.6.5 Institutional Embedding of Responsibility . . . . . . . .1168 17.7 Implementation Challenges . . . . . . . . . . . . . . . . . . . .1170 17.7.1 Organizational Structures and Incentives . . . . . . . .1170 17.7.2 Data Constraints and Quality Gaps . . . . . . . . . . . .1171 17.7.3 Balancing Competing Objectives . . . . . . . . . . . . .1173 17.7.4 Scalability and Maintenance . . . . . . . . . . . . . . . .1175 17.7.5 Standardization and Evaluation Gaps . . . . . . . . . .1176 17.8 AI Safety and Value Alignment . . . . . . . . . . . . . . . . . .1178
📄 Page
19
Table of contents xvii 17.8.1 Autonomous Systems and Trust . . . . . . . . . . . . . .1181 17.8.2 AIs Economic Impact . . . . . . . . . . . . . . . . . . . .1182 17.8.3 AI Literacy and Communication . . . . . . . . . . . . .1183 17.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1185 17.10 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . .1186 Chapter 18 Sustainable AI 1197 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1197 18.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1198 18.2 Ethical Responsibility . . . . . . . . . . . . . . . . . . . . . . . .1199 18.2.1 Long-Term Viability . . . . . . . . . . . . . . . . . . . .1199 18.2.2 Ethical Issues . . . . . . . . . . . . . . . . . . . . . . . .1200 18.2.3 Case Study: DeepMind’s Energy Efficiency . . . . . . .1202 18.3 AI Carbon Footprint . . . . . . . . . . . . . . . . . . . . . . . .1204 18.3.1 Emissions & Consumption . . . . . . . . . . . . . . . .1204 18.3.2 Updated Analysis . . . . . . . . . . . . . . . . . . . . .1207 18.3.3 Carbon Emission Scopes . . . . . . . . . . . . . . . . . .1207 18.3.4 Training vs. Inference Impact . . . . . . . . . . . . . . .1209 18.4 Beyond Carbon . . . . . . . . . . . . . . . . . . . . . . . . . . .1212 18.4.1 Water Usage . . . . . . . . . . . . . . . . . . . . . . . . .1213 18.4.2 Hazardous Chemicals . . . . . . . . . . . . . . . . . . .1215 18.4.3 Resource Depletion . . . . . . . . . . . . . . . . . . . . .1216 18.4.4 Waste Generation . . . . . . . . . . . . . . . . . . . . . .1217 18.4.5 Biodiversity Impact . . . . . . . . . . . . . . . . . . . . .1219 18.5 Semiconductor Life Cycle . . . . . . . . . . . . . . . . . . . . .1220 18.5.1 Design Phase . . . . . . . . . . . . . . . . . . . . . . . .1221 18.5.2 Manufacturing Phase . . . . . . . . . . . . . . . . . . .1223 18.5.3 Use Phase . . . . . . . . . . . . . . . . . . . . . . . . . .1225 18.5.4 Disposal Phase . . . . . . . . . . . . . . . . . . . . . . .1227 18.6 Mitigating Environmental Impact . . . . . . . . . . . . . . . . .1229 18.6.1 Sustainable Development . . . . . . . . . . . . . . . . .1230 18.6.2 Infrastructure Optimization . . . . . . . . . . . . . . . .1233 18.6.3 Addressing Full Environmental Footprint . . . . . . . .1238 18.6.4 Case Study: Google’s Framework . . . . . . . . . . . . .1243 18.7 Embedded AI and E-Waste . . . . . . . . . . . . . . . . . . . .1245 18.7.1 E-Waste Crisis . . . . . . . . . . . . . . . . . . . . . . . .1246 18.7.2 Disposable Electronics . . . . . . . . . . . . . . . . . . .1247 18.7.3 AI Hardware Obsolescence . . . . . . . . . . . . . . . .1249 18.8 Policy and Regulation . . . . . . . . . . . . . . . . . . . . . . .1252 18.8.1 Measurement and Reporting . . . . . . . . . . . . . . .1253 18.8.2 Restriction Mechanisms . . . . . . . . . . . . . . . . . .1254 18.8.3 Government Incentives . . . . . . . . . . . . . . . . . .1255 18.8.4 Self-Regulation . . . . . . . . . . . . . . . . . . . . . . .1256 18.8.5 Global Impact . . . . . . . . . . . . . . . . . . . . . . . .1258 18.9 Public Engagement . . . . . . . . . . . . . . . . . . . . . . . . .1260 18.9.1 AI Awareness . . . . . . . . . . . . . . . . . . . . . . . .1260 18.9.2 Messaging and Discourse . . . . . . . . . . . . . . . . .1261 18.9.3 Transparency and Trust . . . . . . . . . . . . . . . . . .1262
📄 Page
20
Table of contents xviii 18.9.4 Engagement and Awareness . . . . . . . . . . . . . . . .1263 18.9.5 Equitable AI Access . . . . . . . . . . . . . . . . . . . .1264 18.10 Future Challenges . . . . . . . . . . . . . . . . . . . . . . . . . .1266 18.10.1 Future Directions . . . . . . . . . . . . . . . . . . . . . .1266 18.10.2 Challenges . . . . . . . . . . . . . . . . . . . . . . . . .1267 18.10.3 Towards Sustainable AI . . . . . . . . . . . . . . . . . .1268 18.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1269 18.12 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . .1271 Chapter 19 AI for Good 1283 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1283 19.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1284 19.2 Global Challenges . . . . . . . . . . . . . . . . . . . . . . . . . .1285 19.3 Key AI Applications . . . . . . . . . . . . . . . . . . . . . . . .1287 19.3.1 Agriculture . . . . . . . . . . . . . . . . . . . . . . . . .1287 19.3.2 Healthcare . . . . . . . . . . . . . . . . . . . . . . . . .1288 19.3.3 Disaster Response . . . . . . . . . . . . . . . . . . . . .1288 19.3.4 Environmental Conservation . . . . . . . . . . . . . . .1289 19.3.5 AI’s Holistic Impact . . . . . . . . . . . . . . . . . . . .1289 19.4 Global Development Perspective . . . . . . . . . . . . . . . . .1290 19.5 Engineering Challenges . . . . . . . . . . . . . . . . . . . . . .1292 19.5.1 Resource Paradox . . . . . . . . . . . . . . . . . . . . . .1292 19.5.2 Data Dilemma . . . . . . . . . . . . . . . . . . . . . . .1293 19.5.3 Scale Challenge . . . . . . . . . . . . . . . . . . . . . . .1294 19.5.4 Sustainability Challenge . . . . . . . . . . . . . . . . . .1294 19.6 Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . .1296 19.6.1 Hierarchical Processing . . . . . . . . . . . . . . . . . .1296 19.6.2 Progressive Enhancement . . . . . . . . . . . . . . . . .1302 19.6.3 Distributed Knowledge . . . . . . . . . . . . . . . . . .1308 19.6.4 Adaptive Resource . . . . . . . . . . . . . . . . . . . . .1313 19.7 Selection Framework . . . . . . . . . . . . . . . . . . . . . . . .1319 19.7.1 Selection Dimensions . . . . . . . . . . . . . . . . . . .1320 19.7.2 Implementation Guidance . . . . . . . . . . . . . . . . .1321 19.7.3 Comparison Analysis . . . . . . . . . . . . . . . . . . .1322 19.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1323 19.9 Self-Check Answers . . . . . . . . . . . . . . . . . . . . . . . .1324 Part VI Frontiers Chapter 20 Conclusion 1335 20.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1335 20.2 ML Dataset Importance . . . . . . . . . . . . . . . . . . . . . .1336 20.3 AI Framework Navigation . . . . . . . . . . . . . . . . . . . . .1337 20.4 ML Training Basics . . . . . . . . . . . . . . . . . . . . . . . . .1338 20.5 AI System Efficiency . . . . . . . . . . . . . . . . . . . . . . . .1339 20.6 ML Architecture Optimization . . . . . . . . . . . . . . . . . .1339 20.7 AI Hardware Advancements . . . . . . . . . . . . . . . . . . . .1340