Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions emerging_optimizers/orthogonalized_optimizers/muon_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ def newton_schulz_step(
"""
A = X @ X.mT
if tp_group is not None:
A = A.to(torch.float32)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Precision fix lacks regression coverage

The new FP32 all-reduce path has no numerical test for BF16 tensor-parallel shards. The distributed step tests use FP32 inputs, where these casts are no-ops, while the medium-precision test checks only argument forwarding. A test with values sensitive to reduction rounding would help catch regressions in the behavior this change fixes.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

torch.distributed.all_reduce(A, op=torch.distributed.ReduceOp.SUM, group=tp_group)
A = A.to(X.dtype)
if c != 0.0:
B = torch.addmm(A, A, A, alpha=c, beta=b)
X = torch.addmm(X, B, X, alpha=1.0, beta=a)
Expand Down Expand Up @@ -402,7 +404,9 @@ def batched_newton_schulz_step(
"""
A = X @ X.mT
if tp_group is not None:
A = A.to(torch.float32)
torch.distributed.all_reduce(A, op=torch.distributed.ReduceOp.SUM, group=tp_group)
A = A.to(X.dtype)
if c != 0.0:
B = torch.baddbmm(A, A, A, alpha=c, beta=b)
X = torch.baddbmm(X, B, X, alpha=1.0, beta=a)
Expand Down Expand Up @@ -433,7 +437,9 @@ def newton_schulz_step_tsyrk(
)
A = triton_kernels.tsyrk_ex(X) # type: ignore[attr-defined]
if tp_group is not None:
A = A.to(torch.float32)
torch.distributed.all_reduce(A, op=torch.distributed.ReduceOp.SUM, group=tp_group)
A = A.to(X.dtype)
if c != 0.0:
B = triton_kernels.tsyrk_ex(A, A, alpha=c, beta=b) # type: ignore[attr-defined]
X = torch.addmm(X, B, X, alpha=1.0, beta=a)
Expand Down Expand Up @@ -467,7 +473,9 @@ def batched_newton_schulz_step_tsyrk(
)
A = triton_kernels.batched_tsyrk_ex(X) # type: ignore[attr-defined]
if tp_group is not None:
A = A.to(torch.float32)
torch.distributed.all_reduce(A, op=torch.distributed.ReduceOp.SUM, group=tp_group)
A = A.to(X.dtype)
if c != 0.0:
B = triton_kernels.batched_tsyrk_ex(A, A, alpha=c, beta=b) # type: ignore[attr-defined]
X = torch.baddbmm(X, B, X, alpha=1.0, beta=a)
Expand Down
Loading