Skip to content

Conversation

@donlapark
Copy link
Contributor

What does this PR do?

Fixes typing errors in pytorch_lightning/tuner/lr_finder.py in #13445.

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

None

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 🙃

* Refactor docker builds in CI
* Reduce duplicate and merge two workflows
* push: bool expression
* Extend timeout for ipu builds
* Update concurrency group
* Define env for push to hub
* Rename workflow
* Fix bool expressions
* Remove unnecessary trigger paths
* Remove unused env var
* Update job names
* Trim timeout
* rename

Co-authored-by: Jirka <[email protected]>
early_stop_threshold: float = 4.0,
update_attr: bool = False,
) -> Optional[_LRFinder]:
) -> Optional[Union[int, _LRFinder]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

this was correct no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the tune is expected to return Optional[Union[int, _LRFinder]].

https://github.com/Lightning-AI/lightning/blob/6f5193244993750de2707b55cfe89e315310cc33/src/pytorch_lightning/trainer/trainer.py#L1010-L1018

mypy detects this and returns an assignment error.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but lr_find returns result['lr_find'].

max_trials: int = 25,
batch_arg_name: str = "batch_size",
) -> Optional[int]:
) -> Optional[Union[int, _LRFinder]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

lr_find_kwargs = lr_find_kwargs or {}
# return a dict instead of a tuple so BC is not broken if a new tuning procedure is added
result = {}
result: Dict[str, Any] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
result: Dict[str, Any] = {}
result: Dict[str, Union[int, _LRFinder]] = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I think the Union has to be optional otherwise mypy will throw an error: Incompatible types in assignment (expression has type "Optional[int]", target has type "Union[int, _LRFinder]").
`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
result: Dict[str, Any] = {}
result: Dict[str, Optional[Union[int, _LRFinder]]] = {}

@rohitgr7 rohitgr7 added this to the pl:1.7 milestone Jul 12, 2022
@otaj otaj mentioned this pull request Jul 12, 2022
52 tasks
@rohitgr7 rohitgr7 added tuner code quality community This PR is from the community labels Jul 12, 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.

I would explore using a TypedDict instead:

from typing_extensions import TypedDict

class _TunerResult(TypedDict):
    lr_find: Optional[_LRFinder]
    scale_batch_size: Optional[int]

Which should clarify the ambiguity and improve the type checks

dependabot bot added 3 commits July 12, 2022 16:13
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v2...v3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 1 to 2.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](docker/setup-buildx-action@v1...v2)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
samz5320 and others added 4 commits July 13, 2022 00:53
…hSamplerWrapper.batch_indices` (#13565)

* Removed the deprecated   method

* Removed deprecated  IndexBatchSamplerWrapper.batch_indices

* Update src/pytorch_lightning/CHANGELOG.md

* Missed code

Co-authored-by: Akihiro Nitta <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>
@donlapark
Copy link
Contributor Author

Thanks. I'll close this PR and incorporate the suggestions in the next one.

@donlapark donlapark closed this Jul 13, 2022
@donlapark donlapark deleted the fix_typing_pl_tuner_tuning branch July 13, 2022 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality community This PR is from the community tuner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants