Skip to content

Feature/wsd scheduler #12611

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

hawkoli1987
Copy link

Important

The Update branch button must only be pressed in very rare occassions.
An outdated branch is never blocking the merge of a PR.
Please reach out to the automation team before pressing that button.

What does this PR do ?

Implements the Weight Stable Decay (WSD) scheduler with both linear (https://arxiv.org/pdf/2404.06395) and one-minus-square-root decay options (https://arxiv.org/html/2408.11029) as described in recent research papers. This scheduler introduces a three-phase learning rate schedule: warmup, hold, and decay, which has been shown to improve training stability and performance for large language models.

Collection: [Note which collection this PR will affect]
Core

Changelog

  • Added WarmupHoldAnnealOneMinusSquareRoot scheduler that implements the 1-sqrt(t) decay pattern
  • Added WarmupHoldAnnealLinear scheduler that implements the linear decay pattern
  • Added WarmupHoldAnnealScheduler Lightning wrapper class that supports both decay schedules
  • Added unit tests for both scheduler implementations
  • Updated scheduler registry to include the new schedulers

Usage

  • You can potentially add a usage example below
# Using the Lightning wrapper
from nemo.core.optim.lr_scheduler import WarmupHoldAnneal

# One-minus-square-root decay (recommended in the paper)
scheduler = WarmupHoldAnneal(
    warmup_ratio=0.01,    # 1% of steps for warmup
    hold_ratio=0.19,      # 19% of steps for hold phase
    max_steps=10000,      # Total training steps
    decay_schedule="one_minus_square_root",  # Use 1-sqrt(t) decay
    min_lr=1e-6           # Minimum learning rate
)

# Linear decay option
scheduler = WarmupHoldAnneal(
    warmup_ratio=0.01,
    hold_ratio=0.19,
    max_steps=10000,
    decay_schedule="linear",  # Use linear decay
    min_lr=1e-6
)

# Direct usage with PyTorch optimizer
from nemo.core.optim.lr_scheduler import WarmupHoldAnnealOneMinusSquareRoot

optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
scheduler = WarmupHoldAnnealOneMinusSquareRoot(
    optimizer,
    warmup_ratio=0.01,
    hold_ratio=0.19,
    max_steps=10000,
    min_lr=1e-6
)

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
  • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

@github-actions github-actions bot added the core Changes to NeMo Core label Mar 14, 2025
@jojennin jojennin requested review from titu1994 and marcromeyn March 17, 2025 19:15
titu1994
titu1994 previously approved these changes Mar 17, 2025
Copy link
Collaborator

@titu1994 titu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution ! The PR looks correct and has tests that pass so it's good to merge from my end

@ericharper
Copy link
Collaborator

@hawkoli1987 , thanks for the contribution! Could you respond to the reviewer comments so we can merge this?

@hawkoli1987
Copy link
Author

@hawkoli1987 , thanks for the contribution! Could you respond to the reviewer comments so we can merge this?

Thanks @ericharper for your review! Sorry for the delay, I have updated the docstring and updated the PR. First time making PR to NeMo, please guide me along!

Copy link
Contributor

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Apr 16, 2025
Copy link
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this Apr 23, 2025
@ashors1 ashors1 removed the stale label May 14, 2025
@ashors1 ashors1 reopened this May 14, 2025
@ashors1
Copy link
Collaborator

ashors1 commented May 14, 2025

@marcromeyn Could you give this PR a final review? @hawkoli1987 It also looks like there's a merge conflict. Could you please help to resolve that so we can get this PR in? Thank you both!

@@ -484,3 +486,55 @@ def scheduler(self, model, optimizer):
# Metric to to monitor for schedulers like `ReduceLROnPlateau`
"monitor": self.monitor,
}


class WarmupHoldAnnealScheduler(LRSchedulerModule):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc string missing here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hawkoli1987 are you able to add a docstring here to address this comment?

Copy link
Contributor

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label May 30, 2025
@hawkoli1987
Copy link
Author

will try to resolve the conflicts asap, sorry for the delay!

@github-actions github-actions bot removed the stale label May 31, 2025
@hawkoli1987
Copy link
Author

conflict resolved, thanks!

Copy link
Contributor

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Jun 17, 2025
Copy link
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this Jun 24, 2025
@snowmanwwg snowmanwwg reopened this Jul 2, 2025
@github-actions github-actions bot removed the stale label Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Changes to NeMo Core Run CICD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants