Validate warmup_type in WarmupCosineLR like WarmupLR#8151
Open
sohumt123 wants to merge 1 commit into
Open
Conversation
WarmupLR warns and falls back to the log warmup curve when given an unrecognized warmup_type, but WarmupCosineLR stored the value unvalidated. Since get_lr_ratio() only assigns ratio for the two known types, any other value (e.g. a typo like 'Linear') crashed with UnboundLocalError on the first step() instead of the documented warn-and-default behavior. Normalize warmup_type in WarmupCosineLR.__init__ exactly as WarmupLR.__init__ does, and add a unit test asserting the fallback matches the log warmup curve. Signed-off-by: Sohum Trivedi <trivsohum@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
WarmupLR.__init__validateswarmup_typeand falls back tologwith a warning for unknown values, andWarmupDecayLRinherits that behavior.WarmupCosineLRdocuments the same{'log', 'linear'}contract but storeswarmup_typeunvalidated, andget_lr_ratio()'s warmup branch only assignsratiofor the two known types. Any other value (e.g. a typo like'Linear'or'cosine') crashes on the firststep():a confusing crash deep inside the scheduler instead of the documented warn-and-default behavior its sibling classes give.
Fix
Normalize
warmup_typeinWarmupCosineLR.__init__exactly asWarmupLR.__init__already does (same warning text, same fallback tolog). Behavior for validlog/linearvalues is unchanged.Testing
Added
test_warmup_cosine_lr_unknown_warmup_type_falls_back_to_log, which fails with theUnboundLocalErrorabove on current master and passes with this change; it asserts an unknownwarmup_typeproduces the same lr-ratio trajectory as an explicitlogscheduler through warmup and into cosine decay.yapf/flake8 clean on both touched files. Follows up on the recent scheduler hardening in #8126 and #8142, which did not cover
warmup_type.