refactor(scheduler): add type hints to CosineLRScheduler #2640
+12
−12
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.
Description
This PR adds explicit type hints to the
__init__arguments ofCosineLRScheduler.Motivation and Context
Currently, the
warmup_lr_initargument defaults to0(integer). As a result, static analysis tools like Pylance (based on Pyright) and linters like Ruff infer the type asint.When a user passes a
floatvalue (e.g.,1e-6) towarmup_lr_init, it triggers a type mismatch error/warning, even though the code handles floats correctly at runtime.Example error in Pylance:
Changes
Tuple,List, andUnionfromtyping.__init__arguments intimm/scheduler/cosine_lr.py.warmup_lr_initis now typed asfloat(defaulting to0), which resolves the linting error.Notes
I noticed similar issues in other schedulers, but I am addressing
CosineLRSchedulerin this PR as a first step.