Instructions to use Motif-Technologies/optimizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use Motif-Technologies/optimizer with Kernels:
# !pip install kernels from kernels import get_kernel # a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones kernel = get_kernel("Motif-Technologies/optimizer", version=1) - Notebooks
- Google Colab
- Kaggle
modify pre step (overlap step) can get from arsgs
Browse files- torch-ext/optimizer/muon.py +12 -5
torch-ext/optimizer/muon.py
CHANGED
|
@@ -516,6 +516,11 @@ class Muon(torch.optim.Optimizer):
|
|
| 516 |
"head_dim": 128,
|
| 517 |
"threshold": 100
|
| 518 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
"""
|
| 520 |
|
| 521 |
def __init__(self,
|
|
@@ -534,7 +539,8 @@ class Muon(torch.optim.Optimizer):
|
|
| 534 |
"k_indices": [],
|
| 535 |
"head_dim": 128,
|
| 536 |
"threshold": 100
|
| 537 |
-
}
|
|
|
|
| 538 |
defaults = dict(
|
| 539 |
lr=lr,
|
| 540 |
weight_decay=weight_decay,
|
|
@@ -564,6 +570,7 @@ class Muon(torch.optim.Optimizer):
|
|
| 564 |
self.compute_stream = torch.cuda.Stream()
|
| 565 |
self.debug = debug
|
| 566 |
self.clip_config = clip_config
|
|
|
|
| 567 |
|
| 568 |
def _calc_flops(self, G, steps):
|
| 569 |
assert len(G.shape) == 2
|
|
@@ -821,16 +828,16 @@ class Muon(torch.optim.Optimizer):
|
|
| 821 |
# Wait grad update
|
| 822 |
self.comm_stream.wait_stream(torch.cuda.current_stream())
|
| 823 |
|
| 824 |
-
|
| 825 |
-
for i in range(0,
|
| 826 |
enqueue_all2all_gather(i * chunk_size, chunk_size)
|
| 827 |
enqueue_computes(i * chunk_size, chunk_size)
|
| 828 |
|
| 829 |
for i in range(0, len(params) + chunk_size - 1, chunk_size):
|
| 830 |
enqueue_all2all_scatter(i, chunk_size)
|
| 831 |
-
enqueue_all2all_gather(i +
|
| 832 |
enqueue_update_param(i, chunk_size)
|
| 833 |
-
enqueue_computes(i +
|
| 834 |
|
| 835 |
# Wait the last update_param to finish
|
| 836 |
torch.cuda.current_stream().wait_stream(self.compute_stream)
|
|
|
|
| 516 |
"head_dim": 128,
|
| 517 |
"threshold": 100
|
| 518 |
}
|
| 519 |
+
overlap_step : How many all2all gather, compute operations are launched in advance
|
| 520 |
+
before the corresponding all2all scatter steps begin.
|
| 521 |
+
A higher overlap_step increases memory usage but can improve
|
| 522 |
+
performance by overlapping communication.
|
| 523 |
+
Parallel muon only.
|
| 524 |
"""
|
| 525 |
|
| 526 |
def __init__(self,
|
|
|
|
| 539 |
"k_indices": [],
|
| 540 |
"head_dim": 128,
|
| 541 |
"threshold": 100
|
| 542 |
+
},
|
| 543 |
+
overlap_step=5):
|
| 544 |
defaults = dict(
|
| 545 |
lr=lr,
|
| 546 |
weight_decay=weight_decay,
|
|
|
|
| 570 |
self.compute_stream = torch.cuda.Stream()
|
| 571 |
self.debug = debug
|
| 572 |
self.clip_config = clip_config
|
| 573 |
+
self.overlap_step = overlap_step
|
| 574 |
|
| 575 |
def _calc_flops(self, G, steps):
|
| 576 |
assert len(G.shape) == 2
|
|
|
|
| 828 |
# Wait grad update
|
| 829 |
self.comm_stream.wait_stream(torch.cuda.current_stream())
|
| 830 |
|
| 831 |
+
overlap_step = self.overlap_step
|
| 832 |
+
for i in range(0, overlap_step):
|
| 833 |
enqueue_all2all_gather(i * chunk_size, chunk_size)
|
| 834 |
enqueue_computes(i * chunk_size, chunk_size)
|
| 835 |
|
| 836 |
for i in range(0, len(params) + chunk_size - 1, chunk_size):
|
| 837 |
enqueue_all2all_scatter(i, chunk_size)
|
| 838 |
+
enqueue_all2all_gather(i + overlap_step * chunk_size, chunk_size)
|
| 839 |
enqueue_update_param(i, chunk_size)
|
| 840 |
+
enqueue_computes(i + overlap_step * chunk_size, chunk_size)
|
| 841 |
|
| 842 |
# Wait the last update_param to finish
|
| 843 |
torch.cuda.current_stream().wait_stream(self.compute_stream)
|