Sam Babichenko

Reading notes / High-dimensional SGD

Learning sparse parities with SGD

Barak et al., 2022

Context. Learning a kk-sparse parity y=χS(x)=∏i∈Sxiy=\chi_S(x)=\prod_{i\in S}x_i of uniform x∈{±1}nx\in\{\pm1\}^n is statistically easy (about klog⁡nk\log n samples) but costs any statistical-query algorithm, hence gradient descent with noisy gradients, nΩ(k)n^{\Omega(k)} queries, because χS\chi_S is orthogonal to every other parity, so a partly correct guess has zero correlation with the label. Yet small networks trained by plain SGD find SS, with training curves that sit at chance for a long time and then drop abruptly. One explanation is that SGD finds SS by luck; the paper argues, by proof and experiment, against it. The population gradient at a random initialization is not zero. On each relevant coordinate it is a degree-(k−1)(k-1) Fourier coefficient of the neuron's derivative, and on each irrelevant one a degree-(k+1)(k+1) coefficient, which is smaller. That bias is of size n−(k−1)/2n^{-(k-1)/2} (for sign initialization), so SGD performs a biased random walk that needs nO(k)n^{O(k)} samples to separate the relevant weights from the noise, and the loss does not reflect the progress until the relevant weights dominate. A parity is the extreme non-MSP target of the merged-staircase paper; this one shows what happens at finite nn from a random start.

Setting. SS with ∣S∣=k|S|=k is drawn at random, xx is uniform, and y=χS(x)y=\chi_S(x) (label noise is handled by scaling all correlations). Training is online with a fresh batch of BB examples per step, step sizes ηt\eta_t and weight decay λt\lambda_t, and the prediction is signf(x;θt)\mathrm{sign}f(x;\theta_t). Write f^(T)=E[f(x)χT(x)]\hat f(T)=\mathbb E[f(x)\chi_T(x)]. A function ff has a γ\gamma-Fourier gap at SS if ∣f^(S−)∣≥∣f^(S+)∣+γ|\hat f(S^-)|\ge|\hat f(S^+)|+\gamma for every (k−1)(k-1)-subset S−⊂SS^-\subset S and every (k+1)(k+1)-superset S+⊃SS^+\supset S.

Theorem (SGD on a ReLU MLP learns sparse parities). For k≥2k\ge2 even and n=Ω(k4log⁡(nk/ε))n=\Omega(k^4\log(nk/\varepsilon)) odd, there are a random initialization, step sizes and weight decays such that for every SS, SGD with the hinge loss on a two-layer ReLU network of width r=Ω(2kklog⁡(k/ε))r=\Omega(2^kk\log(k/\varepsilon)) and batch size B=Ω(nklog⁡(n/ε))B=\Omega(n^k\log(n/\varepsilon)) reaches expected loss at most ε\varepsilon (best iterate) within O(k3r2n/ε2)O(k^3r^2n/\varepsilon^2) iterations. The total work is nO(k)n^{O(k)}, matching the SQ lower bound up to the constant in the exponent. Theorem (low-width kernels cannot fit all parities): for an embedding Ψ\Psi into RD\mathbb R^D with sup⁡x∥Ψ(x)∥≤1\sup_x\|\Psi(x)\|\le1, if DR2<ε2(nk)DR^2\lt\varepsilon^2\binom nk some SS has hinge loss above 1−ε1-\varepsilon for every ∥w∥≤R\|w\|\le R; since a network's NTK has dimension equal to its parameter count, the small networks here can succeed only by learning features.

Theorems (disjoint-PolyNet). Split [n][n] into kk blocks of size n′=n/kn'=n/k, take f(x;w)=∏i≤k⟨wi,xPi⟩f(x;w)=\prod_{i\le k}\langle w_i,x_{P_i}\rangle, the correlation loss, and one relevant coordinate per block. (i) Plateau: for k≥3k\ge3, on the event that the relevant initial weights have positive product (for ±1\pm1, and with high probability for Gaussian initialization), with T(α)T(\alpha) the first time the error is at most α\alpha, T(1/2−γ)T(0)=1−O~((n′)1−k/2γ2/k−1),\frac{T(1/2-\gamma)}{T(0)}=1-\tilde O\big((n')^{1-k/2}\gamma^{2/k-1}\big), so gradient flow spends all but a vanishing fraction of its time with error above 49%49\%. (ii) SGD at any batch size: from ±1\pm1 initialization with an adaptive step, the error falls below ε\varepsilon within O(log⁡(nT/δ)log⁡(k/ε)(3n′−2)2k−1)O\big(\log(nT/\delta)\log(k/\varepsilon)(3n'-2)^{2k-1}\big) steps, with probability 1/21/2 over the initialization and 1−δ1-\delta over the samples.

Step 1

The population gradient of one neuron is a vector of Fourier coefficients, and a Fourier gap reveals SS. For a neuron σ(w⊤x)\sigma(w^\top x) and the correlation loss, coordinate ii of the population gradient is −E[χS(x)xi σ′(w⊤x)]-\mathbb E[\chi_S(x)x_i\,\sigma'(w^\top x)], and since xi2=1x_i^2=1 multiplying by xix_i removes ii from SS or adds it: gˉi=−h^(S∖{i})  (i∈S),gˉi=−h^(S∪{i})  (i∉S),h(x)=σ′(w⊤x).\bar g_i=-\hat h(S\setminus\{i\})\ \ (i\in S),\qquad \bar g_i=-\hat h(S\cup\{i\})\ \ (i\notin S),\qquad h(x)=\sigma'(w^\top x). If hh has a γ\gamma-Fourier gap at SS, any estimate within γ/2\gamma/2 in sup norm has its kk largest entries exactly on SS, and Hoeffding with a union bound gives one from O(log⁡n/γ2)O(\log n/\gamma^2) samples. The question becomes how large the gap is.

Step 2

For a ReLU with sign weights, the gap comes from the explicit Fourier spectrum of majority. With w∈{±1}nw\in\{\pm1\}^n and ∣b∣<1|b|\lt1, the ReLU derivative is a threshold, 1{w⊤x+b>0}=12+12Maj(w⊙x)\mathbf 1\{w^\top x+b>0\}=\frac12+\frac12\mathrm{Maj}(w\odot x) for odd nn, whose coefficients are known in closed form, depend only on ∣T∣|T|, vanish for even ∣T∣|T|, and satisfy ∣ξk+1∣∣ξk−1∣=k−1n−k,∣ξk−1∣−∣ξk+1∣ ≥ 0.03 (n−1)−(k−1)/2,\frac{|\xi_{k+1}|}{|\xi_{k-1}|}=\frac{k-1}{n-k},\qquad |\xi_{k-1}|-|\xi_{k+1}|\ \ge\ 0.03\,(n-1)^{-(k-1)/2}, with ξm=Maj^([m])\xi_m=\widehat{\mathrm{Maj}}([m]). So relevant gradients exceed irrelevant ones by a factor of about n/kn/k, and the gap is of order n−(k−1)/2n^{-(k-1)/2}, the per-sample signal SGD must accumulate. For even kk, k±1k\pm1 are odd and the gap is nonzero; for odd kk an unbiased threshold has no signal at all, which is why biases are needed in practice. (My brute-force check at n=15n=15, k=4k=4 gives gradient 0.00810.0081 on SS and 0.00220.0022 off it, ratio 3/113/11.)

Step 3

One large-batch step aligns neurons with SS, and a convex fit of the second layer gives the parity. Neurons come in pairs with opposite output weights, so f(x;θ0)≡0f(x;\theta_0)\equiv0 and the hinge loss has derivative −y-y; first-layer weights are random signs and biases sit on a grid. Weight decay λ0=1\lambda_0=1 removes the initialization, so each neuron's new weights are its rescaled batch gradient, which by Step 2 points at SS: a neuron whose initial signs on SS agree (probability 2−k+12^{-k+1}) gets weights about 12k\frac1{2k} on SS and at most Δ≈12n+τk∣ξk−1∣\Delta\approx\frac1{2n}+\frac{\tau}{k|\xi_{k-1}|} off it, with τ\tau the batch error. The off-SS errors add up inside the neuron with spread Δn\Delta\sqrt n, which must stay below about 1/(8k2)1/(8k^2) because the second layer adds kk such neurons with weights up to 8k8k, so τ≲∣ξk−1∣/n\tau\lesssim|\xi_{k-1}|/\sqrt n and B≈n/ξk−12≈nkB\approx n/\xi_{k-1}^2\approx n^k up to logs. An aligned neuron then computes a ramp σ(12k∑j∈Sxj+bi)\sigma(\frac1{2k}\sum_{j\in S}x_j+b_i); with width r≳k2klog⁡(k/δ)r\gtrsim k2^k\log(k/\delta) every bias level has one, and since χS\chi_S is a function of ∑j∈Sxj\sum_{j\in S}x_j, alternating second-layer weights of size at most 8k8k interpolate 2χS2\chi_S. With the first layer frozen the second-layer problem is convex, and standard SGD analysis gives loss ε\varepsilon in O(k3r2n/ε2)O(k^3r^2n/\varepsilon^2) steps.

Step 4

Why the small networks must be learning features. The paper cites the kernel bound from earlier work; for the hinge loss Bessel's inequality already gives it (this short argument is not in the paper). The (nk)\binom nk parities are orthonormal, so ∑S∥E[χSΨ]∥2≤E∥Ψ∥2≤1\sum_S\|\mathbb E[\chi_S\Psi]\|^2\le\mathbb E\|\Psi\|^2\le1, some SS has ∥E[χSΨ]∥≤(nk)−1/2\|\mathbb E[\chi_S\Psi]\|\le\binom nk^{-1/2}, and then E ℓ≥1−R(nk)−1/2>1−ε\mathbb E\,\ell\ge1-R\binom nk^{-1/2}\gt1-\varepsilon once R2<ε2(nk)R^2\lt\varepsilon^2\binom nk. The tangent kernel of a width-2O(k)2^{O(k)} network is such a small embedding. In the other direction the SQ bound nΩ(k)n^{\Omega(k)} applies to SGD with noisy gradients, so nO(k)n^{O(k)} is the right order.

Step 5

On a disjoint-PolyNet, gradient flow is an explosion ODE, and the loss changes only at the end. Here the population gradient vanishes off the relevant coordinates, so irrelevant weights uiu_i never move, and the relevant weights drive each other: v˙i=∏j≠ivj,ddtvi2=2∏j∣vj∣  for every i.\dot v_i=\prod_{j\ne i}v_j,\qquad \frac{d}{dt}v_i^2=2\prod_{j}|v_j|\ \text{ for every }i. All vi2v_i^2 move together, and Maclaurin's inequality sandwiches the common increment between two ODEs q˙=2(q+c)k/2\dot q=2(q+c)^{k/2}, which for k≥3k\ge3 blow up in finite time: going from ∣v∣=b|v|=b to ∞\infty takes at most b2−k/(k−2)b^{2-k}/(k-2). The loss lags because the error depends on v/∥u∥v/\|u\|, a parity of independent sign events, one per block, err ≥ 12−12∏i≤kerf(∣vi∣2 ∥ui∥2)−(Berry-Esseen error),\mathrm{err}\ \ge\ \frac12-\frac12\prod_{i\le k}\mathrm{erf}\Big(\frac{|v_i|}{\sqrt2\,\|u_i\|_2}\Big)-\text{(Berry-Esseen error)}, so with ∥ui∥2≈n′\|u_i\|_2\approx\sqrt{n'} it stays above 12−γ\frac12-\gamma until ∣vi∣≈γ1/kn′|v_i|\approx\gamma^{1/k}\sqrt{n'}, and the blow-up time from there gives the plateau fraction. Progress in vv is steady throughout, but v/∥u∥v/\|u\| stays near zero for almost the entire run.

Step 6

SGD on the disjoint-PolyNet tracks the flow with a normalized step. The stochastic gradient differs from the population one by a martingale increment bounded by ∏l≠i∥wl∥1\prod_{l\ne i}\|w_l\|_1, so normalizing the step by that product makes each increment at most 1/2Tlog⁡(2nT/δ)1/\sqrt{2T\log(2nT/\delta)}. Azuma-Hoeffding with a union bound keeps the irrelevant weights within 1/21/2 of their ±1\pm1 start, and on the positive-product event an induction shows each relevant weight keeps its sign and gains at least (3n′−2)−(k−1)/8Tlog⁡(2nT/δ)(3n'-2)^{-(k-1)}/\sqrt{8T\log(2nT/\delta)} per step, because the normalized drift is a product of ratios ∣vj∣/∥wj∥1≥1/(3n′−2)|v_j|/\|w_j\|_1\ge1/(3n'-2). The error is at most ε\varepsilon once ∣vi∣≈n′log⁡(k/ε)|v_i|\approx\sqrt{n'\log(k/\varepsilon)}, which takes T≈(3n′)2k−1log⁡(k/ε)T\approx(3n')^{2k-1}\log(k/\varepsilon) steps at any batch size.

Step 7

The experiments test random search against hidden progress. Success is robust across n≤30n\le30, k≤4k\le4, batch sizes from 1 to 1024, three initializations, three losses and fifteen architectures, from ReLU MLPs to single sinusoidal neurons and a small Transformer (trained with Adam), reaching full accuracy in at least 20% of runs within c nαk≤105c\,n^{\alpha k}\le10^5 steps. The timing rules out random search: memoryless search would succeed at a geometric time, most likely at t=0t=0, but over 10610^6 PolyNet runs no early successes appear; times are concentrated given the initialization; widening an MLP up to 3×1063\times10^6 neurons gives no rr-fold speedup, only a thinner upper tail; and the exponent worsens with nn. The hidden progress can be seen directly: ∥wt−w0∥∞\|w_t-w_0\|_\infty separates training on parity from training on noise long before the loss moves, and measured Fourier gaps under other initializations and activations are comparable to majority's and grow during training, which no theorem covers. With a finite sample and weight decay the networks grok, and a deep quadratic network learns a 4-parity that greedy layer-wise training provably cannot.

Consequences and limits. A flat loss curve does not mean that optimization has stalled: SGD can be amplifying a tiny, systematic gradient bias that has almost no effect on the loss until the relevant parameters dominate, and the abrupt drop comes at the end of steady progress. On parities this costs nO(k)n^{O(k)}, near the SQ limit, without any sparse prior, and it depends on Fourier anti-concentration of the neuron's derivative, so the activation, biases and initialization affect the computation as well as expressivity (non-smooth ReLUs give the strongest gaps). Measures such as ∥wt−w0∥∞\|w_t-w_0\|_\infty are a concrete way to look for hidden progress, in line with Nanda and Lieberum's reading of grokking. Limits: the MLP theorem needs even kk, sign initialization and a batch of size nkn^k in which the features appear in one step, then trains only the second layer, so it is a one-step feature-learning result; small-batch training and other initializations rest on measured, unproved Fourier gaps. The PolyNet theorems need one relevant coordinate per block and an adaptive step, and hold on an event of probability 1/21/2. The fitted exponents come from small nn, and noiseless parities are easy outside SQ, by Gaussian elimination.

Terms

χS(x)=∏i∈Sxi\chi_S(x)=\prod_{i\in S}x_i
kk-sparse parity; orthogonal to every other χS′\chi_{S'}
SQ lower bound
nΩ(k)n^{\Omega(k)} noisy correlation queries; covers SGD with noisy gradients
γ\gamma-Fourier gap at SS
∣f^(S−)∣≥∣f^(S+)∣+γ|\hat f(S^-)|\ge|\hat f(S^+)|+\gamma for all (k∓1)(k\mp1)-sets S∓S^\mp
Gradient coordinate
gˉi=−h^(S△{i})\bar g_i=-\hat h(S\triangle\{i\}), h=σ′(w⊤x)h=\sigma'(w^\top x): degree k−1k-1 on SS, k+1k+1 off SS
ξm=Maj^([m])\xi_m=\widehat{\mathrm{Maj}}([m])
majority coefficient; zero for even mm, ∣ξk+1∣/∣ξk−1∣=(k−1)/(n−k)|\xi_{k+1}|/|\xi_{k-1}|=(k-1)/(n-k)
Majority gap
∣ξk−1∣−∣ξk+1∣≥0.03(n−1)−(k−1)/2|\xi_{k-1}|-|\xi_{k+1}|\ge0.03(n-1)^{-(k-1)/2}
Disjoint-PolyNet
∏i⟨wi,xPi⟩\prod_i\langle w_i,x_{P_i}\rangle on kk blocks; relevant weights solve v˙i=∏j≠ivj\dot v_i=\prod_{j\ne i}v_j
Plateau fraction
T(1/2−γ)/T(0)=1−O~((n′)1−k/2γ2/k−1)T(1/2-\gamma)/T(0)=1-\tilde O((n')^{1-k/2}\gamma^{2/k-1})
Kernel bound
DR2<ε2(nk)DR^2\lt\varepsilon^2\binom nk leaves some parity with hinge loss above 1−ε1-\varepsilon
Progress measure
∥wt−w0∥∞\|w_t-w_0\|_\infty: drift on SS beats t\sqrt t noise before the loss moves

Quiz

  1. Why can the population gradient at a random initialization carry information about SS even though every partial guess has zero correlation with χS\chi_S?
  2. Why does the first step need a batch of order nkn^k rather than nk−1n^{k-1}?
  3. Why does adding width not give an rr-fold speedup in the experiments?
  4. What does the kernel lower bound DR2<ε2(nk)DR^2\lt\varepsilon^2\binom nk imply for the networks studied?

Sources