Skip to content

update to use torch.optim.lr_scheduler.LRScheduler#4709

Closed
wat3rBro wants to merge 2 commits intofacebookresearch:mainfrom
wat3rBro:export-D42111273
Closed

update to use torch.optim.lr_scheduler.LRScheduler#4709
wat3rBro wants to merge 2 commits intofacebookresearch:mainfrom
wat3rBro:export-D42111273

Conversation

@wat3rBro
Copy link
Copy Markdown
Contributor

@wat3rBro wat3rBro commented Dec 16, 2022

Summary:
pytorch/pytorch#88503 introduces the public version LRScheduler, however isinstance(self.scheduler, torch.optim.lr_scheduler._LRScheduler) doesn't work anymore because of https://github.com/pytorch/pytorch/blob/1ea11ecb2eea99eb552603b7cf5fbfc59659832d/torch/optim/lr_scheduler.py#L166-L169, if the schedule is inherited from the public version.

It's a bit tricky to make it BC compatible for torch version <= 1.13. V1 of this diff uses try catch block to import the LRScheduler and make it available in detectron2.solver, then the whole D2 uses this version of LRScheduler. There're two drawbacks though:

  • it adds a little mental burden to figure out what's D2 (11528ce083dc9ff83ee3a8f9086a1ef54d2a402f)'s LRScheduler, previously it's clear that the LRScheduler/_LRScheduler is from torch.
  • it has a name collision with hooks.LRScheduler, eg. in the hooks.py I have to do LRScheduler as _LRScheduler.

But I couldn't found a better solution, maybe use try catch block in every file?

Differential Revision: D42111273

Yanghan Wang and others added 2 commits December 16, 2022 15:07
Summary:
X-link: facebookresearch/fvcore#118

Pull Request resolved: facebookresearch#4650

D35519683 (facebookresearch@0ad20f1) changed the default `matching_heuristics` from `False` to `True`, it may cause some issues:
- potential bug report: https://fb.workplace.com/groups/2240361332735959/posts/5264606250311437/?comment_id=5265167493588646
- bloated logging: facebookresearch#4364

This diff reverts the default value back to `False`, and introduce a way to specify this option via filename url.

Differential Revision: https://internalfb.com/D41145857

fbshipit-source-id: 1daa202d9cf48dddaee6d00d84306ef9dbc7e2a9
Summary:
pytorch/pytorch#88503 introduces the public version `LRScheduler`, however `isinstance(self.scheduler, torch.optim.lr_scheduler._LRScheduler)` doesn't work anymore because of https://github.com/pytorch/pytorch/blob/1ea11ecb2eea99eb552603b7cf5fbfc59659832d/torch/optim/lr_scheduler.py#L166-L169.

It's a bit tricky to make it BC compatible for torch version <= 1.13. V1 of this diff uses try catch block to import the `LRScheduler` and make it available in `detectron2.solver`, then the whole D2 (facebookresearch@11528ce) uses this version of `LRScheduler`. There're two drawbacks though:
- it adds a little mental burden to figure out what's D2 (facebookresearch@11528ce083dc9ff83ee3a8f9086a1ef54d2a402f)'s `LRScheduler`, previously it's clear that the `LRScheduler`/`_LRScheduler` is from `torch`.
- it has a name collision with `hooks.LRScheduler`, eg. in the `hooks.py` I have to do `LRScheduler as _LRScheduler`.

But I couldn't found a better solution, maybe use try catch block in every file?

Differential Revision: D42111273

fbshipit-source-id: 613cd35a1e0bdb9b8edd852042df047aba021d87
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Dec 16, 2022
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D42111273

Comment on lines 137 to -135
# MultiStepLR with WarmupLR but the current LRScheduler design doesn't allow it.


class WarmupMultiStepLR(torch.optim.lr_scheduler._LRScheduler):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

now it should be fine to remove everything below this line. Looks like they are not used any more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ppwwyyxx There're actually many usage internally (including _get_warmup_factor_at_iter), it's a bit hard to remove them.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 2108097.

wat3rBro pushed a commit to wat3rBro/d2go that referenced this pull request Jan 4, 2023
Summary:
Pull Request resolved: facebookresearch#453

Previous diffs updated the LRScheduler to public version (eg. facebookresearch/detectron2#4709), this also requires newer version of pytorch-lightning. This diff upgrades the lightning version to 1.8.6, also fixes some deprecated call sites of old lightning versions.
- `deepcopy` seems to be supported now, remove `_deepcopy` (there's now not allowed to access `trainer` attributed when it is `None`)
- `dataloader_idx` is removed from `on_train_batch_start`.
- stop using `_accelerator_connector` (the AcceleratorConnector doesn't have those attributes anymore).
- deprecated `on_pretrain_routine_end` -> `on_fit_start`

Differential Revision: D42319019

fbshipit-source-id: 3e5da0601e5f3a3fb482c84bb34bdc9f67b0ddfc
facebook-github-bot pushed a commit to facebookresearch/d2go that referenced this pull request Jan 4, 2023
Summary:
Pull Request resolved: #453

Previous diffs updated the LRScheduler to public version (eg. facebookresearch/detectron2#4709), this also requires newer version of pytorch-lightning. This diff upgrades the lightning version to 1.8.6, also fixes some deprecated call sites of old lightning versions.
- `deepcopy` seems to be supported now, remove `_deepcopy` (there's now not allowed to access `trainer` attributed when it is `None`)
- `dataloader_idx` is removed from `on_train_batch_start`.
- stop using `_accelerator_connector` (the AcceleratorConnector doesn't have those attributes anymore).
- deprecated `on_pretrain_routine_end` -> `on_fit_start`

Reviewed By: YanjunChen329

Differential Revision: D42319019

fbshipit-source-id: ba46abbd98da96783e15d187a361fda47dc7d4d6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants