Skip to content

Conversation

@haru-256
Copy link
Contributor

Description

This PR adds explicit type hints to the __init__ arguments of CosineLRScheduler.

Motivation and Context

Currently, the warmup_lr_init argument defaults to 0 (integer). As a result, static analysis tools like Pylance (based on Pyright) and linters like Ruff infer the type as int.

When a user passes a float value (e.g., 1e-6) to warmup_lr_init, it triggers a type mismatch error/warning, even though the code handles floats correctly at runtime.

Example error in Pylance:

"Argument of type 'float' cannot be assigned to parameter 'warmup_lr_init' of type 'int'"

image

Changes

  • Imported Tuple, List, and Union from typing.
  • Added explicit type annotations to __init__ arguments in timm/scheduler/cosine_lr.py.
  • Specifically, warmup_lr_init is now typed as float (defaulting to 0), which resolves the linting error.

Notes

I noticed similar issues in other schedulers, but I am addressing CosineLRScheduler in this PR as a first step.

- Add type annotations to `__init__` arguments in `CosineLRScheduler`
- Import `Tuple` and `Union` from `typing`
- Fix missing newline at end of file
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@rwightman rwightman merged commit 9d62118 into huggingface:main Dec 30, 2025
22 checks passed
@haru-256 haru-256 deleted the feat/type-hint branch December 31, 2025 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants