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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

lr_find doesn't return the correct suggestion if some losses are nan #1850

Closed
binshengliu opened this issue May 16, 2020 · 3 comments 路 Fixed by #1862
Closed

lr_find doesn't return the correct suggestion if some losses are nan #1850

binshengliu opened this issue May 16, 2020 · 3 comments 路 Fixed by #1862
Labels
bug Something isn't working help wanted Open to be worked on

Comments

@binshengliu
Copy link

馃悰 Bug

lr_finder doesn't return the correct suggestion if some losses are nan. The returned loss is the one corresponding to the nan value, which is very big in my case.

image

To Reproduce

This depends on the dataset. Please see the code sample.

Code sample

I believe this is caused by numpy. The related code should be https://github.com/PyTorchLightning/pytorch-lightning/blob/b84b02400a312240a6429c186cc63514eeb45a82/pytorch_lightning/trainer/lr_finder.py#L325

example_losses = [0.90, 0.89, 0.87, 0.86, 0.85, 0.84]
print(np.gradient(example_losses).argmin())
example_losses = [0.90, 0.89, 0.87, 0.86, 0.85, 0.84, float('nan')]
print(np.gradient(example_losses).argmin())

Output:

1
5

Expected behavior

Return the correct suggested loss.

Environment

  • CUDA:
    • GPU:
    • available: False
    • version: 10.2
  • Packages:
    • numpy: 1.18.4
    • pyTorch_debug: False
    • pyTorch_version: 1.5.0
    • pytorch-lightning: 0.7.6
    • tensorboard: 2.2.0
    • tqdm: 4.45.0
  • System:
    • OS: Linux
    • architecture:
      • 64bit
    • processor:
    • python: 3.7.6
    • version: Proposal for help聽#1 SMP Debian 4.19.118-2 (2020-04-29)

Additional context

NA

@binshengliu binshengliu added bug Something isn't working help wanted Open to be worked on labels May 16, 2020
@github-actions
Copy link
Contributor

Hi! thanks for your contribution!, great first issue!

@SkafteNicki
Copy link
Member

Good catch. I guess that we can not do much about how np.gradient behave but we can filter Nan values before doing the calculation. @binshengliu are you up for doing a PR?

@binshengliu
Copy link
Author

Filtering out nan would be a reasonable approach. Locally I just reset nan to inf also to avoid dealing with indexes.

Sorry I'm quite inundated with my own projects recently and may not have enough time to shape a proper PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Open to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants