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

Update pytorch lightning import to work with Ray and other libraries. #2432

Closed
ru-ko opened this issue Jun 28, 2024 · 2 comments
Closed

Update pytorch lightning import to work with Ray and other libraries. #2432

ru-ko opened this issue Jun 28, 2024 · 2 comments
Labels
devops CI/CD, packaging, code maintenance, ... good first issue Good for newcomers improvement New feature or improvement

Comments

@ru-ko
Copy link

ru-ko commented Jun 28, 2024

Is your feature request related to a current problem? Please describe.
Importing and using lightning.pytorch and pytorch_lightning in the same program causes conflicts. Ray has migrated their tuning to ray.tune.Tuner and is deprecating ray.tune.run. Ray uses a conditional import, importing pytorch_lightning only if the other is not available. However, it will import lightning.pytorch first, where the darts pl_forecasting_module imports pytorch_lightning. This may also apply to other places.

Describe proposed solution
Darts should incorporate a conditional import that matches this priority in pl_forecasting_module, lr_finder, etc as follows:

#import pytorch_lightning as pl
def import_lightning():  # noqa: F402
    try:
        import lightning.pytorch as pl
    except ModuleNotFoundError:
        import pytorch_lightning as pl
    return pl

pl = import_lightning()

Note that files may import more than just pl - those other imports could also be wrapped under the conditional.

Describe potential alternatives
Change imports of pytorch_lightning to lightning.pytorch

Additional context
I noticed this issue when attempting to use ray.tune.Tuner and ray.train.torch.TorchTrainer in conjunction with RNNModel. I solved it by making the change in the proposed solution.

@ru-ko ru-ko added the triage Issue waiting for triaging label Jun 28, 2024
@madtoinou
Copy link
Collaborator

Hi @ru-ko,

We are aware of this problem, it's already tracked by #2198.

I like the approach you're proposing, would you be willing to open a PR to implement it and see if it solves the problem?

@madtoinou madtoinou added good first issue Good for newcomers devops CI/CD, packaging, code maintenance, ... improvement New feature or improvement and removed triage Issue waiting for triaging labels Jun 28, 2024
@ru-ko
Copy link
Author

ru-ko commented Jun 28, 2024

Ope, didn't realize it was tracked by that. I'll start a branch for it and make changes when I can, although it'll be slow going.

@ru-ko ru-ko closed this as completed Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devops CI/CD, packaging, code maintenance, ... good first issue Good for newcomers improvement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants