-
Notifications
You must be signed in to change notification settings - Fork 3k
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
hawkoli1987
wants to merge
13
commits into
NVIDIA:main
Choose a base branch
from
hawkoli1987:feature/wsd_scheduler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/wsd scheduler #12611
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
78700d7
initial test of WSD scheduler pass
hawkoli1987 ec5a4d2
add pytest for wsd scheduler
hawkoli1987 973b7ab
Merge branch 'main' into feature/wsd_scheduler
marcromeyn e218694
initial test of WSD scheduler pass
hawkoli1987 41238a0
add pytest for wsd scheduler
hawkoli1987 2ca2d12
add docstring
hawkoli1987 ad70dfe
add reference to original WSD
hawkoli1987 d900f84
resolve conflict with earlier commit in wsd_scheduler branch
hawkoli1987 d39b302
Apply isort and black reformatting
hawkoli1987 8e1a493
Apply isort and black reformatting
artbataev 883fe73
resolve merge conflicts with main
hawkoli1987 72d7459
Apply isort and black reformatting
hawkoli1987 2de453f
Merge branch 'NVIDIA:main' into feature/wsd_scheduler
hawkoli1987 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Optional | ||
from typing import Literal, Optional | ||
|
||
from nemo.core.optim.lr_scheduler import ( | ||
InverseSquareRootAnnealing, | ||
|
@@ -24,6 +24,8 @@ | |
SquareRootAnnealing, | ||
T5InverseSquareRootAnnealing, | ||
WarmupAnnealing, | ||
WarmupHoldAnnealLinear, | ||
WarmupHoldAnnealOneMinusSquareRoot, | ||
WarmupHoldPolicy, | ||
WarmupPolicy, | ||
) | ||
|
@@ -484,3 +486,55 @@ def scheduler(self, model, optimizer): | |
# Metric to to monitor for schedulers like `ReduceLROnPlateau` | ||
"monitor": self.monitor, | ||
} | ||
|
||
|
||
class WarmupHoldAnnealScheduler(LRSchedulerModule): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc string missing here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
def __init__( | ||
self, | ||
warmup_ratio: Optional[float] = None, | ||
hold_ratio: Optional[float] = None, | ||
max_steps: int = 10, | ||
decay_schedule: Literal["one_minus_square_root", "linear"] = "linear", | ||
min_lr: float = 0.0, | ||
interval: str = "step", | ||
frequency: int = 1, | ||
monitor: str = "val_loss", | ||
): | ||
super().__init__() | ||
self.warmup_ratio = warmup_ratio | ||
self.hold_ratio = hold_ratio | ||
self.max_steps = max_steps | ||
self.decay_schedule = decay_schedule | ||
self.min_lr = min_lr | ||
self.interval = interval | ||
self.frequency = frequency | ||
self.monitor = monitor | ||
|
||
def scheduler(self, model, optimizer): | ||
if self.decay_schedule == "one_minus_square_root": | ||
lr_scheduler = WarmupHoldAnnealOneMinusSquareRoot( | ||
optimizer, | ||
warmup_ratio=self.warmup_ratio, | ||
hold_ratio=self.hold_ratio, | ||
max_steps=self.max_steps, | ||
min_lr=self.min_lr, | ||
) | ||
elif self.decay_schedule == "linear": | ||
lr_scheduler = WarmupHoldAnnealLinear( | ||
optimizer, | ||
warmup_ratio=self.warmup_ratio, | ||
hold_ratio=self.hold_ratio, | ||
max_steps=self.max_steps, | ||
min_lr=self.min_lr, | ||
) | ||
else: | ||
raise ValueError(f"Unknown decay schedule: {self.decay_schedule}") | ||
return { | ||
"optimizer": optimizer, | ||
"lr_scheduler": { | ||
"scheduler": lr_scheduler, | ||
"interval": self.interval, | ||
"frequency": self.frequency, | ||
}, | ||
"monitor": self.monitor, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.