MCPcopy Create free account
hub / github.com/ace-step/ACE-Step / configure_optimizers

Method configure_optimizers

trainer.py:413–443  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

411 )
412
413 def configure_optimizers(self):
414 trainable_params = [
415 p for name, p in self.transformers.named_parameters() if p.requires_grad
416 ]
417 optimizer = torch.optim.AdamW(
418 params=[
419 {"params": trainable_params},
420 ],
421 lr=self.hparams.learning_rate,
422 weight_decay=self.hparams.weight_decay,
423 betas=(0.8, 0.9),
424 )
425 max_steps = self.hparams.max_steps
426 warmup_steps = self.hparams.warmup_steps # New hyperparameter for warmup steps
427
428 # Create a scheduler that first warms up linearly, then decays linearly
429 def lr_lambda(current_step):
430 if current_step < warmup_steps:
431 # Linear warmup from 0 to learning_rate
432 return float(current_step) / float(max(1, warmup_steps))
433 else:
434 # Linear decay from learning_rate to 0
435 progress = float(current_step - warmup_steps) / float(
436 max(1, max_steps - warmup_steps)
437 )
438 return max(0.0, 1.0 - progress)
439
440 lr_scheduler = torch.optim.lr_scheduler.LambdaLR(
441 optimizer, lr_lambda, last_epoch=-1
442 )
443 return [optimizer], [{"scheduler": lr_scheduler, "interval": "step"}]
444
445 def train_dataloader(self):
446 self.train_dataset = Text2MusicDataset(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected