-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent unexpected unpacking error when calling
lr_finder.plot()
wi…
…th `suggest_lr=True` (#98) * MAINT: always return 2 values when `suggest_lr` is True As it's mentioned in #88, suggested lr would not be returned along with `ax` (`matplotlib.Axes`) if there is no sufficient data points to calculate gradient of lr-loss curve. Though it would warn user about this problem [1], but users might be confused by another error caused by unpacking returned value. This is because users would usually expect it works as below: ```python ax, lr = lr_finder.plot(..., suggest_lr=True) ``` But the second returned value `lr` might not exist when it failed to find a suggested lr, then the returned value would be a single value instead. Therefore, the unpacking syntax `ax, lr = ...` would fail and result in the error reported in #88. So we fix it by always returning both `ax` and `suggested_lr` when the flag `suggest_lr` is True to meet the expectation, and leave the responsibility of "check whether `lr` is null" back to user. [1]: https://github.com/davidtvs/pytorch-lr-finder/blob/fd9e949/torch_lr_finder/lr_finder.py#L539-L542 * MAINT: raise error earlier if there is no sufficient data points to suggest LR Now LR finder will raise a RuntimeError if there is no sufficient data points to calculate gradient for suggested LR when `lr_finder.plot(..., suggest_lr=True)` is called. The error message will clarify the details of failure, so users can fix the issue earlier as well.
- Loading branch information
1 parent
fd9e949
commit 5b9d92c
Showing
2 changed files
with
85 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters