Skip to content

[Feat]: Stochastic rounding of AdamW momentums #1005

Description

@kohya-ss

Describe your use-case.

With Adam/AdamW, gradients and optimizer state appear to stay in bf16, which can lead to a loss of precision during the accumulation of gradients over many steps, potentially impacting training stability and final model quality. Adafactor already does the math/state in fp32 and only stochastic rounding on copy-back.

This proposal aims to align the Adam optimizer with this best practice, which should improve its performance in bfloat16 training scenarios.

What would you like to see as a solution?

I suggest modifying step_adam_parameter in modules/util/optimizer/adam_extensions.py (and adamw_extensions.py) to ensure internal calculations are performed in float32.

A simple way to achieve this would be to cast the gradient to float32 before it is used for state updates, similar to how it is handled in the Adafactor implementation.

Have you considered alternatives? List them here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions