Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion baseline/gpt2_small/muon_speedrun/optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ def make_stock_optimizers(model, rt, kind):
else:
role = 'other'
multiplier = SGD_OTHER_MULTIPLIER
# Keep matrix decay and bias/LayerNorm no-decay groups separate even
# when they share a blockwise LR multiplier.
decay = SGD_WEIGHT_DECAY if p.ndim >= 2 else 0.0
grouped[(role, multiplier, decay)].append(p)
decay_role = role + ('_matrices' if p.ndim >= 2 else '_bias_and_layernorm')
grouped[(decay_role, multiplier, decay)].append(p)
groups = []
for (role, multiplier, decay), params in grouped.items():
peak = SGD_PEAK_LR * multiplier
Expand Down
7 changes: 4 additions & 3 deletions baseline/gpt2_small/muon_speedrun/test_sgd_momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def test_tied_parameter_once_and_classical_momentum(self):
self.assertEqual(len(params), len(set(map(id, params))))
self.assertEqual(set(map(id, params)), set(map(id, model.parameters())))
groups = {g['role']:g for g in opt.param_groups}
self.assertAlmostEqual(groups['block_0']['lr_multiplier'], SGD_BLOCK_MULTIPLIERS[0])
self.assertEqual(groups['block_0']['weight_decay'], SGD_WEIGHT_DECAY)
self.assertEqual(groups['other']['weight_decay'], 0.0)
self.assertAlmostEqual(groups['block_0_matrices']['lr_multiplier'], SGD_BLOCK_MULTIPLIERS[0])
self.assertEqual(groups['block_0_matrices']['weight_decay'], SGD_WEIGHT_DECAY)
self.assertEqual(groups['block_0_bias_and_layernorm']['weight_decay'], 0.0)
self.assertEqual(groups['other_bias_and_layernorm']['weight_decay'], 0.0)
self.assertTrue(all(g["momentum"] == SGD_MOMENTUM for g in opt.param_groups))
self.assertTrue(all(not g["nesterov"] for g in opt.param_groups))
self.assertEqual(optimizer_metadata(opt)["class"], "torch.optim.SGD")
Expand Down
Loading