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

Metrics that call NLTK.download cause lightning to hang in offline environments #1455

Closed
JohnGiorgi opened this issue Jan 23, 2023 · 1 comment · Fixed by #1456
Closed

Metrics that call NLTK.download cause lightning to hang in offline environments #1455

JohnGiorgi opened this issue Jan 23, 2023 · 1 comment · Fixed by #1456
Assignees
Labels
bug / fix Something isn't working help wanted Extra attention is needed Priority Critical task/issue

Comments

@JohnGiorgi
Copy link

JohnGiorgi commented Jan 23, 2023

🐛 Bug

Any metric that calls nltk.download is going to cause an issue in an offline environment, as the command will just hang. Examples include:

https://github.com/Lightning-AI/metrics/blob/6ae08a807fbd36976574bbffcf94140fce5564d6/src/torchmetrics/functional/text/rouge.py#L48

This actually extends to other Lightning packages as well, like Flash:

https://github.com/Lightning-AI/lightning-flash/blob/48a25006cad455672063dc5dc9141c43fcf6607d/flash_examples/question_answering.py#L23

I realized this when trying to run a Lightning Flash script on one of my clusters (offline) compute nodes, and my code simply hung before training.

To Reproduce

Just call nlkt.download in any offline environment, e.g.

Code sample

import nltk
# This will hang even if you have already downloaded the punkt data while online...
nltk.download("punkt")

Expected behavior

Ideally, if the required nltk data is already downloaded, nltk.download would not be called so that lightning will not hang.

Environment

  • TorchMetrics version: torchmetrics==0.10.3 from pip
  • Python & PyTorch Version (e.g., 1.0): Python 3.10, Torch 1.13.1
  • Any other relevant information such as OS (e.g., Linux): Linux

Additional context

I think the simplest fix would be to replace the nltk.download commands with a try/except, e.g.

try:
    nltk.word_tokenize("Check if punkt data is available")
except LookupError:
    nltk.download("punkt", quiet=True, force=False)

at the very least, this would allow someone to call nltk.download first in an online environment (e.g. on a login node) before running some lightning code in an offline environment (e.g. a compute node).

I think even better would be to log a message here, warning a user that a download is being attempted and that if they are offline they will need to download the data manually while online using nltk.download(...).

Would be happy to PR this if maintainers agree.

@JohnGiorgi JohnGiorgi added bug / fix Something isn't working help wanted Extra attention is needed labels Jan 23, 2023
@JohnGiorgi JohnGiorgi changed the title Metrics that call NLTK.download cause issues in offline environments Metrics that call NLTK.download cause lightning to hang in offline environments Jan 23, 2023
@github-actions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed Priority Critical task/issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants