Skip to content
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

Fixing the 'initial_lr' KeyError When Resuming Training from a Checkpoint #70

Open
omarrayyann opened this issue Dec 7, 2024 · 1 comment

Comments

@omarrayyann
Copy link

omarrayyann commented Dec 7, 2024

If you attempt to resume training from a checkpoint, you might encounter the following error:

KeyError: "param 'initial_lr' is not specified in param_groups[0] when resuming an optimizer"

it can be fixed by adjusting the initialization of param_groups in the train_diffusion_unet_image_workspace.py file (line ~ 70) to this:

param_groups = [
            {'params': self.model.model.parameters(), 'lr': cfg.optimizer.lr, 'initial_lr': cfg.optimizer.lr},
            {'params': obs_encorder_params, 'lr': obs_encorder_lr, 'initial_lr': obs_encorder_lr}
        ]
@WilliamBonilla62
Copy link

WilliamBonilla62 commented Dec 9, 2024

Hey @omarrayyann change this in the file train_diffusion_unet_image_workspace.py

lr_scheduler = get_scheduler(
    cfg.training.lr_scheduler,
    optimizer=self.optimizer,
    num_warmup_steps=cfg.training.lr_warmup_steps,
    num_training_steps=(
        len(train_dataloader) * cfg.training.num_epochs
    ) // cfg.training.gradient_accumulate_every,
    # pytorch assumes stepping LRScheduler every epoch
    # however huggingface diffusers steps it every batch
    last_epoch=self.global_step - 1
)

to

lr_scheduler = get_scheduler(
    cfg.training.lr_scheduler,
    optimizer=self.optimizer,
    num_warmup_steps=cfg.training.lr_warmup_steps,
    num_training_steps=(
        len(train_dataloader) * cfg.training.num_epochs
    ) // cfg.training.gradient_accumulate_every,
    # pytorch assumes stepping LRScheduler every epoch
    # however huggingface diffusers steps it every batch
    last_epoch=-1
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants