Skip to content

Conversation

@mehmoodulhaq570
Copy link

Fix Adam Optimizer Betas Type Error

Overview

This update fixes a runtime error encountered during training when initializing the Adam optimizer.

Problem

Training fails with the following error:

ValueError: betas must be either both floats or both Tensors

This happens because the betas parameter is provided as a Python list instead of the required tuple format.

Root Cause

PyTorch’s torch.optim.Adam expects the betas argument in the following form:

betas=(float, float)

However, the existing configuration uses:

betas=[0, 0.99]

When the optimizer is created via:

dnnlib.util.construct_class_by_name(...)

this results in a runtime ValueError.

Fix

The optimizer configuration has been updated to pass betas as a tuple:

betas=(0.0, 0.99)

This fix has been applied to:

  • Generator optimizer configuration
  • Discriminator optimizer configuration

Impact

  • Resolves training crash during optimizer initialization
  • Ensures full compatibility with PyTorch Adam
  • No change to optimizer behavior or hyperparameter values
  • Improves training reliability

Testing

  • Confirmed that the Adam optimizer initializes without errors
  • Verified that training runs successfully after the fix

@mehmoodulhaq570
Copy link
Author

This pull request fixes a runtime error encountered during training when initializing the Adam optimizer.

The issue was caused by passing the betas parameter as a Python list ([0, 0.99]), whereas PyTorch’s torch.optim.Adam requires betas to be provided as a tuple of floats.

@mehmoodulhaq570 mehmoodulhaq570 changed the title Fix Adam optimizer betas type error by using tuple instead of list Fix Adam optimizer betas type error by using tuple instead of list in train.py Dec 19, 2025
@mehmoodulhaq570 mehmoodulhaq570 changed the title Fix Adam optimizer betas type error by using tuple instead of list in train.py Fix train.py for Adam optimizer betas type error by using tuple instead of list Dec 19, 2025
@mehmoodulhaq570 mehmoodulhaq570 changed the title Fix train.py for Adam optimizer betas type error by using tuple instead of list Fix train.py for Adam optimizer betas type error Dec 19, 2025
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

Successfully merging this pull request may close these issues.

1 participant