~/fba-lab/lab/speedrun/journey/trace-polar-lab

FBALab

Code · architecture · study mode

AboutRoadmapSpeedrun
FBALab

Study mode — no GPU required.

Interactive LLM training & inference lab.

Qwen CAboutContactTermsPrivacyCookiesCommunity

© 2026 FBA Lab

Contact · contact@bubblspace.com · +91 75061 55016

Speedrun›Profiler deep-dive›Polar Lab
Act 1Model Training FundamentalsAct 2AI Systems OptimizationAct 3World-Record Training Optimization
Step 12 of 28Skill: AI Systems Optimization
← 02 · Polar Express03 · Data Generator →
TRAINING SIMULATION

Polar Lab

running
◷train_gpt.py▸polar_express◎learner$no GPU
1/1
Blocks
Quick summary

5-iteration polynomial approximation of the polar decomposition. Input gradient G → orthogonal matrix U (from G =…

Full explanation below the code →

fba-lab — train_gpt.py · polar_expressexecuting
// block: polar_express · lines 151–174$ study train_gpt.py --block polar-express-fn5-iteration polynomial approximation of the polar decomposition. Input gradient G → orthogonal matri… ✓
Explanation

5-iteration polynomial approximation of the polar decomposition. Input gradient G → orthogonal matrix U (from G = U·Σ·V^T). dynamic=False required — Triton recompiles on shape change, killing speed.

Think about

What does it mean for the update matrix to be orthogonal, and why does Muon need this?

// architecture

Live diagram

100%
02 · train_gpt.py line 151
polar_express

Turning gradient matrices into orthogonal update directions

The NorMuon optimizer doesn't apply raw gradients. Before updating weights, it orthogonalizes the gradient — turns it into a matrix where every row is perpendicular to every other row. This is called the polar decomposition. polar_express computes it fast using 5 iterations of a polynomial approximation.

@torch.compile(dynamic=False, fullgraph=True) # dynamic=False required — re-tracing kills speed
def polar_express(G: torch.Tensor, split_baddbmm: bool = False):
X = G.bfloat16() # run in bf16 for speed
if G.size(-2) > G.size(-1): X = X.mT # algorithm needs tall/square matrix
X = X / (X.norm(dim=(-2,-1), keepdim=True) * 1.02 + 1e-6) # normalize spectral norm ≤ 1
for a, b, c in polar_express_coeffs:
A = XXT(X)
B = b*A + c*(A @ A)
X, C = a*X + B@X, X
return X # ≈ orthogonal: U from polar decomposition G = U·Σ·V^T
gradient G bf16, ‖G‖≤1 Iter 1 A = X·X^T X ← a·X + (b·A+c·A²)X (8.16, -22.48, 15.88) Iter 2 A = X·X^T X ← a·X + (b·A+c·A²)X (4.04, -2.81, 0.50) Iters 3–5 refine approximation coefficients shrink ≈ orthogonal U from G=UΣV^T
Where it fits in the optimizer
# NorMuonAndAdam._normuon_update()
grad = grad.float()
momentum_buf.lerp_(grad, 1 - momentum)
v = polar_express(momentum_buf) # ← orthogonalize
v = _apply_normuon_variance_reduction(v)
p_slice.add_(v, alpha=-lr)
Why orthogonalize at all?

Raw gradient updates can couple different feature directions — one dimension's update interferes with another's. Orthogonalizing the update matrix ensures each direction is updated independently. This is the core insight from Muon (MomentUm Orthogonalized by Newton-Schulz). polar_express uses precomputed polynomial coefficients for speed.