Machine Learning Fundamentals: Optimizers, Scaling Laws, and Clustering
MetaMachine Learning Engineer · OnsiteLast updated
Tests deep conceptual mastery of modern ML core foundations: AdamW vs. Adam weight decay mechanics, compute-optimal Chinchilla scaling laws, and the mathematical equivalence between Hard Expectation-Maximization in GMMs and k-means clustering.
Scenario
As a Machine Learning Engineer working on foundational model pre-training and downstream clustering pipelines, you are tasked with making principled architectural, optimization, and resource-allocation decisions. Walk through the following three technical problems in detail.
Part 1: Optimization Mechanics (Adam vs. AdamW)
Consider training a large transformer model. In standard implementations of Adam with L2 regularization, the weight decay penalty is implemented by adding lambda * theta_t directly to the gradient vector g_t before computing the first (m_t) and second (v_t) moment estimates:
- Write out the update equations for standard Adam with L2 regularization versus decoupled weight decay (AdamW).
- Explain mathematically why adding L2 regularization to
g_tfails to act as true weight decay for parameters that have large historical gradient magnitudes versus small historical gradient magnitudes. - What empirical issue does this cause when training deep models with varied parameter update frequencies (e.g., rare embedding tokens vs. frequent attention projection weights)?
Part 2: Compute-Optimal Scaling Laws
You are allocated a fixed compute budget of C = 6 * 10^23 FLOPs for pre-training a dense decoder-only transformer. Assume standard Chinchilla scaling rules where FLOPs are approximated by C approx 6 * N * D, where N is the number of non-embedding parameters and D is the number of training tokens.
- Under the Chinchilla optimal compute allocation (where
NandDscale approximately in equal proportion, i.e.,N proportional to C^0.5andD proportional to C^0.5), calculate the optimal parameter countNand token countDgiven that a balanced model withN = 10^9parameters requires roughlyD = 20 * 10^9tokens (a 1:20 ratio). - If an engineering constraint requires serving the model at low latency with a strict memory footprint limit of
N <= 1.5 * 10^9parameters, how would you reallocate the remaining compute budget? What trade-offs in downstream loss and training stability occur when scaling tokens far past the compute-optimal frontier (inference-optimal regime)?
Part 3: Clustering Mechanics & Derivations
Analyze the relationship between the Expectation-Maximization (EM) algorithm for Gaussian Mixture Models (GMMs) and the classic k-means clustering algorithm.
- Formulate the GMM posterior probability
gamma_ik = P(z_i = k | x_i, theta)where all covariance matrices are isotropic and identical:Sigma_k = sigma^2 * Ifor all clustersk, with uniform cluster priorspi_k = 1 / K. - Show what happens to the posterior responsibility
gamma_ikin the limit assigma^2 -> 0. Prove how the EM updates for the cluster means reduce exactly to Lloyd's algorithm for k-means.
Hints
Hint 1
For Part 1, inspect the denominator of the Adam step: notice how the effective decay rate is scaled by the square root of the second moment estimate in L2 regularization but not in AdamW.
Hint 2
For Part 2, express C as a function of N using the token-to-parameter ratio D = 20 * N to solve for N, and consider the concept of inference-optimal models like LLaMA.
Hint 3
For Part 3, rewrite the softmax in the posterior responsibility by pulling the exponential terms together; take the limit of the exponent as sigma^2 approaches zero.
Follow-up questions
- How does the learning rate schedule (e.g., cosine decay with warmup) interact with the decoupled weight decay factor in AdamW over the course of training?
- If your model architecture uses mixture-of-experts (MoE), how does the FLOPs approximation `C approx 6 * N * D` change, and how does it impact optimal token allocation?
- When would you prefer soft assignments from GMMs over hard assignments from k-means in a user-embedding representation pipeline, and how do non-spherical covariance matrices affect sample complexity?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.