Foundations of Machine Learning and Distributed Training
Machine learning, at its core, is the scientific discipline focused on building systems that can learn from data, identify patterns, and make decisions with minimal human intervention. Before we can appreciate the nuanced architecture of federated learning, we must establish a firm grasp of its foundational pillars: the canonical supervised learning paradigm, the mathematical machinery of loss functions and optimization, and the established distributed training paradigms that precede and inform the federated approach. This chapter serves as that essential groundwork, reviewing these concepts not as a superficial refresher but as a deep dive into the operational details that directly impact federated system design. We will move beyond definitions to examine the practical implications of algorithm choice, data distribution, and system topology, setting the stage for understanding why federated learning is not merely a distributed training variant but a fundamentally different problem class.
1.1 The Supervised Learning Paradigm: Formulation and Assumptions
The vast majority of production machine learning systems, and consequently the initial focus of federated learning, are built upon the framework of supervised learning. In this setting, we assume access to a labeled dataset $\mathcal{D} = \{(\mathbf{x}_i, y_i)\}_{i=1}^N$, where each instance $\mathbf{x}_i \in \mathcal{X}$ is a feature vector (e.g., pixel values of an image, word embeddings of a sentence) and $y_i \in \mathcal{Y}$ is its corresponding label (e.g., a class, a numeric value). The objective is to learn a model $f_\theta: \mathcal{X} \rightarrow \mathcal{Y}$, parameterized by $\theta$ (e.g., weights and biases of a neural network), that generalizes well to unseen data drawn from the same underlying data-generating distribution $P(\mathbf{x}, y)$.
This formulation rests on a critical, often implicit, i.i.d. (independent and identically distributed) assumption: the samples in $\mathcal{D}$ are drawn independently from $P(\mathbf{x}, y)$, and the training set is a representative sample of this distribution. This assumption is the bedrock of classical statistical learning theory (Vapnik, 1998) and underpins the convergence guarantees of most optimization algorithms. It allows us to reason about the population risk $R(\theta) = \mathbb{E}_{(\mathbf{x},y)\sim P}[\ell(f_\theta(\mathbf{x}), y)]$, which is the expected loss over the true distribution, by minimizing the empirical risk $\hat{R}(\theta) = \frac{1}{N}\sum_{i=1}^N \ell(f_\theta(\mathbf{x}_i), y_i)$ on our finite sample.
The i.i.d. assumption is violated in federated settings, where data is non-i.i.d. and non-independent across client devices. A single user's data (e.g., their typing history on a mobile keyboard) is inherently sequential and stylistically coherent, violating independence. More severely, data from different users exhibits statistical heterogeneity or client drift (Kairouz et al., 2021): the local distribution $P_j(\mathbf{x}, y)$ on client $j$ can differ significantly from both the global distribution $P(\mathbf{x}, y)$ and from other clients' distributions. For instance, a language model trained on a user's messaging app will reflect their unique lexicon, emoji usage, and conversational partners, making their local data distribution highly distinct. This heterogeneity is the primary source of statistical challenges in federated optimization, a theme we will revisit in Chapter 3.
1.1.1 A Concrete Example: Image Classification with CNNs
Consider a canonical task: training a Convolutional Neural Network (CNN) for image classification on the CIFAR-10 dataset (Krizhevsky, 2009). This dataset contains 60,000 32x32 color images across 10 classes (e.g., 'airplane', 'automobile', 'bird'). Under the i.i.d. assumption, we would randomly shuffle all images and create batches where each batch is a microcosm of the full class distribution. A model trained this way learns features (edges, textures, shapes) that are generally useful for distinguishing all 10 classes.
In a federated analog, imagine these images are stored on 1,000 different user devices, each having taken a personal set of photos. Device A might have mostly pictures of pets and landscapes, while Device B's photos are primarily of cars and urban scenes. The local data on each device is not only small but also highly skewed. A model initialized globally and trained only on Device A's data would quickly overfit to pets, becoming a poor generalist. The core challenge of federated learning is to orchestrate learning across these disparate, siloed, and biased datasets to produce a single model that performs adequately for everyone, without ever centralizing the raw images.
1.2 Loss Functions: Quantifying the Journey from Guess to Truth
The loss function $\ell(\hat{y}, y)$ is the compass that guides the learning algorithm. It quantifies the discrepancy between the model's prediction $\hat{y} = f_\theta(\mathbf{x})$ and the true label $y$. The choice of loss function is not arbitrary; it is intrinsically tied to the nature of the output space $\mathcal{Y}$ and the probabilistic assumptions we make about our model.
For regression tasks (predicting a continuous value, e.g., house price), the Mean Squared Error (MSE) is the de facto standard: $$\text{MSE} = \frac{1}{N}\sum_{i=1}^N (f_\theta(\mathbf{x}_i) - y_i)^2$$ MSE corresponds to the negative log-likelihood under the assumption that the prediction errors are independent and follow a Gaussian distribution with constant variance. Its squared nature penalizes large errors disproportionately, making it sensitive to outliers.
For binary classification (two classes, e.g., spam/not spam), the Binary Cross-Entropy (BCE) loss is used: $$\text{BCE} = -\frac{1}{N}\sum_{i=1}^N \left[ y_i \log(\sigma(f_\theta(\mathbf{x}_i))) + (1 - y_i) \log(1 - \sigma(f_\theta(\mathbf{x}_i))) \right]$$ where $\sigma(z) = 1/(1+e^{-z})$ is the sigmoid function, squashing the model's raw output (logit) to a probability $[0,1]$. BCE is derived from the negative log-likelihood of a Bernoulli distribution. It provides a smooth, well-behaved gradient that is crucial for optimization.
For multiclass classification (like CIFAR-10's 10 classes), we extend this with the Categorical Cross-Entropy loss, typically combined with a softmax activation in the final layer to produce a probability distribution over all classes: $$P(y=c|\mathbf{x}) = \text{softmax}(f_\theta(\mathbf{x}))_c = \frac{e^{f_\theta(\mathbf{x})_c}}{\sum_{k=1}^C e^{f_\theta(\mathbf{x})_k}}$$ $$\text{CCE} = -\frac{1}{N}\sum_{i=1}^N \sum_{c=1}^C \mathbb{1}(y_i = c) \log(P(y=c|\mathbf{x}_i))$$ This loss heavily penalizes confident wrong predictions, driving the model to not just predict the correct class but to do so with high certainty.
Practical Implication for Federated Learning: The loss function's smoothness and Lipschitz continuity properties directly influence the convergence rate of optimization algorithms, especially in the presence of noisy, stochastic updates from clients. Cross-entropy losses with softmax are generally well-behaved. However, in federated settings with severe class imbalance on clients (e.g., a client only has images of 'cats'), the local loss landscape can become extremely skewed. A client with only one class will see zero gradient for that class's logit if using standard cross-entropy, potentially causing model divergence. This necessitates robust loss functions or sampling strategies, a topic explored in Chapter 4.
1.3 Optimization: The Engine of Learning - From Batch GD to Adam
Having defined a loss function $\mathcal{L}(\theta) = \frac{1}{N}\sum_{i=1}^N \ell(f_\theta(\mathbf{x}_i), y_i)$, the learning problem becomes an optimization one: find $\theta^* = \arg\min_\theta \mathcal{L}(\theta)$. For complex, non-convex models like deep neural networks, this is achi