Repository navigation
Run Newton-Schulz in float32 on CPU - #68
Open
shaneraphel wants to merge 5 commits into
Open
shaneraphel wants to merge 5 commits into
shaneraphel wants to merge 5 commits into
Conversation
The quintic is unchanged. bfloat16 stays the path for every other device. On an Apple M4, a 256x256 matrix was about 32x faster in float32, with max absolute difference 0.0086 against the bfloat16 quintic.
shaneraphel
force-pushed
the
cpu-float32-newtonschulz
branch
from
September 22, 2026 15:53
751ae66 to
1cb9958
Compare
The quintic comparison already bounds the absolute error. This pins the dtype of the CPU path.
Apple M4, PyTorch 2.11, 10 threads. At n=1024 the MPS quintic is 0.0161 s in bfloat16 and 0.0196 s in float32. The CPU path stays float32, where the same size is 0.046 s against 10.5 s in bfloat16.
Apple M4, PyTorch 2.11, 10 threads. At n=1024 the MPS quintic is 0.0161 s in bfloat16 and 0.0196 s in float32. The CPU path stays float32, where the same size is 0.046 s against 10.5 s in bfloat16.
The CPU test pins float32. This runs the same function on CUDA or MPS when present and pins bfloat16 there, so the GPU path cannot silently change dtype. Each device is skipped when unavailable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
zeropower_via_newtonschulz5keeps the same quintic coefficients.SingleDeviceMuon.steppicks this up without an API change.Evidence
Apple M4, PyTorch 2.11.0, 10 CPU threads, 5 Newton-Schulz steps, median of 5 calls. MPS timed with Metal debug wrappers off.
Max absolute difference, CPU n=256, same seed:
0.008578. MPS n=1024 max abs difference:0.00412.python test_cpu_zeropower.pyprintsbranch ok mpsthenok 0.00857803225517273.Float32 is the CPU path only. On MPS, bfloat16 is the faster of the two at n=1024, so that device is unchanged.
Test plan
python test_cpu_zeropower.pyon CPU (dtype, finite, error bound, one optimizer step)