Skip to content
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

Use LRScheduler for torch >= 1.14 otherwise use _LRScheduler #15768

Merged
merged 15 commits into from
Dec 12, 2022

Conversation

qmaruf
Copy link
Contributor

@qmaruf qmaruf commented Nov 22, 2022

What does this PR do?

Fixes #15587

Does your PR introduce any breaking changes? If yes, please list them.

No breaking changes.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

…refactoring will keep lightining sync with pytorch issue#61232.
@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Nov 22, 2022
@mergify mergify bot removed the has conflicts label Nov 22, 2022
@akihironitta akihironitta added the community This PR is from the community label Nov 23, 2022
@mergify mergify bot added the ready PRs ready to be merged label Nov 23, 2022
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

In general. If it was using torch.optim.lr_scheduler._LRScheduler, replace it with _TORCH_LRSCHEDULER

src/lightning_lite/strategies/deepspeed.py Outdated Show resolved Hide resolved
src/lightning_lite/utilities/types.py Outdated Show resolved Hide resolved
src/lightning_lite/utilities/types.py Outdated Show resolved Hide resolved
src/pytorch_lightning/cli.py Outdated Show resolved Hide resolved
src/pytorch_lightning/tuner/lr_finder.py Outdated Show resolved Hide resolved
src/pytorch_lightning/tuner/lr_finder.py Outdated Show resolved Hide resolved
src/pytorch_lightning/utilities/cli.py Outdated Show resolved Hide resolved
src/pytorch_lightning/utilities/cli.py Outdated Show resolved Hide resolved
src/pytorch_lightning/utilities/types.py Outdated Show resolved Hide resolved
@qmaruf
Copy link
Contributor Author

qmaruf commented Nov 30, 2022

Getting this error after applying all suggested changes. @carmocca any suggestion?

ubuntu@ip-172-31-47-37:~/p/lightning{remote:feature-15587} $ python -m pytest tests/tests_pytorch/test_cli.py::test_lightning_cli_run                                       (lightning) 
================================================================================= test session starts ==================================================================================
platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/ubuntu/pytorch-lightning/lightning, configfile: setup.cfg
plugins: forked-1.4.0, requests-mock-1.10.0, anyio-3.6.2, doctestplus-0.12.1, asyncio-0.20.2, rerunfailures-10.2, timeout-2.1.0, cov-4.0.0, hydra-core-1.2.0
asyncio: mode=strict
collected 1 item                                                                                                                                                                       

tests/tests_pytorch/test_cli.py F                                                                                                                                                [100%]

======================================================================================= FAILURES =======================================================================================
________________________________________________________________________________ test_lightning_cli_run ________________________________________________________________________________

cleandir = None

    def test_lightning_cli_run(cleandir):
        with mock.patch("sys.argv", ["any.py"]):
>           cli = LightningCLI(BoringModel, run=False)

/home/ubuntu/pytorch-lightning/lightning/tests/tests_pytorch/test_cli.py:817: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/home/ubuntu/pytorch-lightning/lightning/src/pytorch_lightning/cli.py:345: in __init__
    _populate_registries(auto_registry)
/home/ubuntu/pytorch-lightning/lightning/src/pytorch_lightning/utilities/cli.py:128: in _populate_registries
    LR_SCHEDULER_REGISTRY.register_classes(torch.optim.lr_scheduler, LRScheduler, show_deprecation=False)
/home/ubuntu/pytorch-lightning/lightning/src/pytorch_lightning/utilities/cli.py:69: in register_classes
    for cls in self.get_members(module, base_cls):
/home/ubuntu/pytorch-lightning/lightning/src/pytorch_lightning/utilities/cli.py:77: in <genexpr>
    if issubclass(cls, base_cls) and cls != base_cls
/home/ubuntu/miniconda3/envs/lightning/lib/python3.8/abc.py:102: in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

other = <class 'torch.optim.lr_scheduler.ChainedScheduler'>

    def _proto_hook(other):
        if not cls.__dict__.get('_is_protocol', False):
            return NotImplemented
    
        # First, perform various sanity checks.
        if not getattr(cls, '_is_runtime_protocol', False):
            if _allow_reckless_class_cheks():
                return NotImplemented
            raise TypeError("Instance and class checks can only be used with"
                            " @runtime_checkable protocols")
        if not _is_callable_members_only(cls):
            if _allow_reckless_class_cheks():
                return NotImplemented
>           raise TypeError("Protocols with non-method members"
                            " don't support issubclass()")
E           TypeError: Protocols with non-method members don't support issubclass()

/home/ubuntu/miniconda3/envs/lightning/lib/python3.8/typing.py:1081: TypeError
=============================================================================== short test summary info ================================================================================
FAILED tests/tests_pytorch/test_cli.py::test_lightning_cli_run - TypeError: Protocols with non-method members don't support issubclass()
============================================================================= 1 failed, 1 warning in 0.52s =============================================================================

@Borda Borda requested review from carmocca and mauvilsa December 6, 2022 03:19
@mergify mergify bot added the has conflicts label Dec 7, 2022
@mergify mergify bot removed the ready PRs ready to be merged label Dec 7, 2022
@Borda
Copy link
Member

Borda commented Dec 8, 2022

@qmaruf could you pls check the conflicts? :)

@Borda Borda requested review from lantiga and removed request for mauvilsa December 9, 2022 11:07
@Borda
Copy link
Member

Borda commented Dec 9, 2022

@lantiga mind checking out this PR? 🐰

@mergify mergify bot added ready PRs ready to be merged and removed has conflicts ready PRs ready to be merged labels Dec 9, 2022
@carmocca carmocca self-assigned this Dec 12, 2022
@carmocca carmocca added this to the v1.9 milestone Dec 12, 2022
@carmocca carmocca enabled auto-merge (squash) December 12, 2022 13:09
@carmocca carmocca merged commit 2577285 into Lightning-AI:master Dec 12, 2022
Borda pushed a commit that referenced this pull request Dec 14, 2022
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>

(cherry picked from commit 2577285)
EricCousineau-TRI added a commit to EricCousineau-TRI/pytorch-lightning that referenced this pull request Mar 30, 2023
…ng-AI#15768)

Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>
# Conflicts:
#	docs/source-pytorch/cli/lightning_cli_intermediate_2.rst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community This PR is from the community pl Generic label for PyTorch Lightning package ready PRs ready to be merged refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use the non-protected LRScheduler import
6 participants