-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEAT / Trainer: LOMO optimizer support #30178
Changes from all commits
e7d7bbe
8cdc21e
029a9c9
62b5e0e
629413c
4907531
51c8e9e
d9499c5
afaabfc
a57dd5e
beb7edc
5184057
ac007ee
741a1a4
80105e1
49ce45e
8d008a5
40db2fa
5a536bf
c1ac8bf
9d547be
efe04a5
6cadb75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
require_deepspeed, | ||
require_galore_torch, | ||
require_intel_extension_for_pytorch, | ||
require_lomo, | ||
require_optuna, | ||
require_peft, | ||
require_ray, | ||
|
@@ -1229,6 +1230,49 @@ def test_dataloader_without_dataset(self): | |
trainer.train() | ||
trainer.evaluate() | ||
|
||
@require_lomo | ||
@require_torch_gpu | ||
def test_lomo(self): | ||
config = LlamaConfig(vocab_size=100, hidden_size=32, num_hidden_layers=3, num_attention_heads=4) | ||
tiny_llama = LlamaForCausalLM(config) | ||
|
||
previous_params = {n: p.clone() for n, p in tiny_llama.named_parameters()} | ||
|
||
x = torch.randint(0, 100, (128,)) | ||
train_dataset = RepeatDataset(x) | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
# Trainer without inf/nan filter | ||
args = TrainingArguments(tmpdir, learning_rate=1e-2, logging_steps=5, optim="lomo", max_steps=20) | ||
trainer = Trainer(tiny_llama, args, train_dataset=train_dataset) | ||
|
||
# Check this works | ||
_ = trainer.train() | ||
|
||
for name, param in tiny_llama.named_parameters(): | ||
self.assertFalse(torch.allclose(param, previous_params[name].to(param.device), rtol=1e-12, atol=1e-12)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tolerance is super small, do we expect optimizers to make changes on this order? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is ok to put it higher, I decided to put it low so that even small changes would be captured by the test (sometimes higher tolerances would fail even though the weights are properly updated + with a high learning rate, so just to be on the safe zone) |
||
|
||
@require_lomo | ||
@require_torch_gpu | ||
def test_adalomo(self): | ||
config = LlamaConfig(vocab_size=100, hidden_size=32, num_hidden_layers=3, num_attention_heads=4) | ||
tiny_llama = LlamaForCausalLM(config) | ||
x = torch.randint(0, 100, (128,)) | ||
train_dataset = RepeatDataset(x) | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
# Trainer without inf/nan filter | ||
args = TrainingArguments( | ||
tmpdir, | ||
learning_rate=1e-9, | ||
logging_steps=5, | ||
optim="adalomo", | ||
) | ||
trainer = Trainer(tiny_llama, args, train_dataset=train_dataset) | ||
|
||
# Check this works | ||
_ = trainer.train() | ||
|
||
def test_galore_matched_modules(self): | ||
regex_patterns = [r".*.attn.*", r".*.mlp.*"] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we pass the learning rate through when lomo isn't being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will break .. 😢 but we:
1- raise an error if users do not have the correct accelerate version with init-ing the trainer with lomo
2- pass
learning_rate
only if the optimizer is a lomo optimizer3- removed
kwargs
in training stepSo hopefully this should be safe enough 🙏