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

🐛 Support different ways of importing lightning #99

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ console_scripts =

[options.extras_require]
lightning =
pytorch-lightning
lightning
ray =
ray[tune]
testing =
Expand Down
17 changes: 15 additions & 2 deletions src/wandb_osh/lightning_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

from os import PathLike

import lightning.pytorch as pl

from wandb_osh.hooks import TriggerWandbSyncHook, _comm_default_dir
from wandb_osh.util.log import logger


# See #96
# Possible additional issues: If both imports are working, the wrong one might be used.
try:
# This is the modern way
import lightning.pytorch as pl
except ImportError:
import pytorch_lightning as pl

logger.warning(
"Imported lightning the legacy way (import pytorch_lightning as pl). "
"For more information see https://github.com/klieret/wandb-offline-sync-hook/issues/96"
)


class TriggerWandbSyncLightningCallback(pl.Callback):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lightning_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import wandb

_ray = pytest.importorskip("pytorch_lightning")
_ray = pytest.importorskip("lightning")

from wandb_osh.lightning_hooks import TriggerWandbSyncLightningCallback # noqa: E402

Expand Down
Loading