Add Newton Schultz via Polar Express as a retraction for Iso optimizer - #294
Add Newton Schultz via Polar Express as a retraction for Iso optimizer#294kogolobo wants to merge 5 commits into
Conversation
Signed-off-by: Konstantin Golobokov <kogolobo@uw.edu>
Greptile SummaryThe PR adds a Newton–Schulz Stiefel retraction to the Iso optimizer and extracts the retraction implementations into a reusable module.
Confidence Score: 4/5The PR should not merge until the outstanding device-to-host synchronization in the benchmark workflow is resolved. The CPU SYRK failure has been fixed by selecting SYRK only for CUDA tensors, but the benchmark still converts stacked CUDA metrics to a Python list and synchronizes the host despite the repository rule prohibiting that operation outside tests. Files Needing Attention: benchmarks/benchmark_stiefel_retraction.py Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
G[Factor gradient and momentum] --> S[Finite factor step]
S --> N[Newton-Schulz retraction]
N --> U[Retracted U]
N --> V[Retracted V]
U --> R[Rebuild U Sigma V.T]
V --> R
F[Fixed singular values Sigma] --> R
R --> P[Updated isospectral parameter]
Reviews (6): Last reviewed commit: "Renmae the Stiefel retraction benchmark" | Re-trigger Greptile |
Signed-off-by: Konstantin Golobokov <kogolobo@uw.edu>
581648e to
12888d2
Compare
Signed-off-by: Konstantin Golobokov <kogolobo@uw.edu>
|
Thank you for contribution! It looks like the retractions are becoming big. Could you move this entire block into a RetractionT = Literal["qr", "polar", "cayley", "newton_schulz"] |
Signed-off-by: Konstantin Golobokov <kogolobo@uw.edu>
Done, thanks! |
Signed-off-by: Konstantin Golobokov <kogolobo@uw.edu>
| ("polar_wide", "polar", (5, 8)), | ||
| ("cayley_tall", "cayley", (8, 5)), | ||
| ("cayley_wide", "cayley", (5, 8)), | ||
| ("newton_shultz_tall", "newton_schulz", (8, 5)), |
There was a problem hiding this comment.
nit: typo in new schultz
There was a problem hiding this comment.
typo is not nit and should be fixed.
|
/claude review |
| ("polar_wide", "polar", (5, 8)), | ||
| ("cayley_tall", "cayley", (8, 5)), | ||
| ("cayley_wide", "cayley", (5, 8)), | ||
| ("newton_shultz_tall", "newton_schulz", (8, 5)), |
There was a problem hiding this comment.
typo is not nit and should be fixed.
Summary
Contributes to #28.
This PR adds a Newton-Schulz matrix-sign retraction (
retraction="newton_schulz") to theIso(isospectral) optimizer. This allows to approximate the polar retraction without usingtorch.linalg.svd. This is an incremental step toward #28, exploring iterative matrix polynomial retractions for Stiefel factors.Key Changes
_newton_schulz_retractionleveragingmuon_utils.newton_schulz(defaults tosteps=8withpolar_expresscoefficients).tests/riemannian_optimizers/test_isospectral.pywith parameterization fornewton_schulz, validating singular value preservation and Stiefel factor orthogonality (becnmarks/benchmark_isospectral_retraction.pywhich usestriton.testing.do_benchto measure combined retraction time for both Stiefel factorsBenchmark: Retraction Latency & Manifold Precision
Benchmarked on NVIDIA GeForce RTX 4090 using with TF32 enabled (
fp32_matmul_prec="high"):polar(SVD)qrcayleynewton_schulz(steps=8)Observations:
newton_schulz(polar_express) track the analytical SVD polar factor withinnewton_schulz(21.53 ms) is 2.66x faster than Cayley (57.25 ms) and faster than QR (26.81 ms), avoiding thenum_ns_steps=8as the necessary default for numerical stability.Testing
pre-commit run --all-filespasses cleanly.pytest tests/riemannian_optimizers/test_isospectral.pypasses on CPU and CUDA.