Compile spectral descent Newton-Schulz with foreach_map - #274
Draft
mlazos wants to merge 1 commit into
Draft
Conversation
Express the BF16 Newton-Schulz spectral descent update as a foreach_map so PT2 can compile compatible matrices together. Compile the preconditioner callable independently because the surrounding optimizer preconditioning path intentionally disables compilation. Other dtypes and SVD orthogonalization continue to use the existing scalar implementation. Test Plan: ``` ruff check distributed_shampoo/distributed_shampoo.py distributed_shampoo/preconditioner/spectral_descent_preconditioner_list.py distributed_shampoo/preconditioner/tests/spectral_descent_preconditioner_list_test.py ruff format --check distributed_shampoo/distributed_shampoo.py distributed_shampoo/preconditioner/spectral_descent_preconditioner_list.py distributed_shampoo/preconditioner/tests/spectral_descent_preconditioner_list_test.py python -m pytest distributed_shampoo/preconditioner/tests/spectral_descent_preconditioner_list_test.py -q -k 'bfloat16_uses_foreach_map or empty_list' ``` Authored with an AI assistant.
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
foreach_mapThe separate compiled callable is needed because the surrounding optimizer preconditioning path intentionally disables compilation. It lets compatible matrix updates reach PT2 as one operation and enables grouped symmetric GEMM lowering when used with the corresponding PyTorch Inductor changes.
This draft currently depends on PyTorch Inductor symmetric/grouped GEMM changes that are not yet upstream.
Test plan
The two focused tests pass. Running the entire test file gives 11 passes and two unrelated SVD failures because the locally built PyTorch does not include LAPACK.
Local performance measurements with the dependent PyTorch changes:
1536 x 5120BF16 matrices: 2.043 ms to 1.396 ms for the isolated preconditioner (1.46x)The distributed result is included to avoid implying an end-to-end speedup; communication dominates this configuration. An NCCL-enabled measurement is still needed.