diff --git a/.all-contributorsrc b/.all-contributorsrc index 05d4ce9..87074f8 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -17,6 +17,13 @@ "avatar_url": "https://avatars.githubusercontent.com/u/123608862?v=4", "profile": "https://github.com/MoH-assan", "contributions": ["bug"] + }, + { + "login": "CedricLeon", + "name": "Cedric Leonard", + "avatar_url": "https://avatars.githubusercontent.com/u/51703091?v=4", + "profile": "https://github.com/CedricLeon", + "contributions": ["code", "bug"] } ], "contributorsPerLine": 7, diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6e113a2..bd2c8f4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -24,7 +24,7 @@ jobs: - name: Check products run: pipx run twine check dist/* - - uses: pypa/gh-action-pypi-publish@v1.8.12 + - uses: pypa/gh-action-pypi-publish@v1.8.14 if: github.event_name == 'release' && github.event.action == 'published' with: # Remember to generate this and set it in "GitHub Secrets" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 08b036a..846a8c0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,4 +26,4 @@ jobs: run: | pytest - name: Upload coverage report - uses: codecov/codecov-action@v4.1.0 + uses: codecov/codecov-action@v4.4.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2491d95..ca4ae3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,16 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.0 + rev: v0.4.7 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black - rev: 24.1.1 + rev: 24.4.2 hooks: - id: black - id: black-jupyter - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -20,11 +20,11 @@ repos: exclude: '.*\.ipynb' - id: trailing-whitespace - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.8.0" + rev: "v1.10.0" hooks: - id: mypy - repo: https://github.com/codespell-project/codespell - rev: "v2.2.6" + rev: "v2.3.0" hooks: - id: codespell args: ["-I", "codespell.txt"] diff --git a/CHANGELOG.md b/CHANGELOG.md index f261686..562d7ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.2.2 (21.03.2024) + +### Fixed + +- Switched to modern way of importing pytorch lightning (issue #96, PR #96, #97) + +### Changed + +- When installed with the `lightnign` optional dependency, `lightning` is installed + instead of `pytorch-lightning` + ## 1.2.1 (02.02.2024) ### Fixed diff --git a/README.md b/README.md index 0058497..5cfec32 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,7 @@ Bug reports and pull requests are credited with the help of the [allcontributors Barthelemy Meynard-Piganeau
Barthelemy Meynard-Piganeau

🐛 MoH-assan
MoH-assan

🐛 + Cedric Leonard
Cedric Leonard

💻 🐛 diff --git a/setup.cfg b/setup.cfg index 97c99b3..e6e90ba 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = wandb_osh -version = 1.2.1 +version = 1.2.2 description = Trigger wandb offline syncs from a compute node without internet long_description = file: README.md long_description_content_type = text/markdown @@ -46,7 +46,7 @@ console_scripts = [options.extras_require] lightning = - pytorch-lightning + lightning ray = ray[tune] testing = diff --git a/src/wandb_osh/lightning_hooks.py b/src/wandb_osh/lightning_hooks.py index b769a23..675df69 100644 --- a/src/wandb_osh/lightning_hooks.py +++ b/src/wandb_osh/lightning_hooks.py @@ -2,18 +2,30 @@ from os import PathLike -from pytorch_lightning import LightningModule, Trainer -from pytorch_lightning.callbacks import Callback - 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(Callback): +class TriggerWandbSyncLightningCallback(pl.Callback): def __init__( self, communication_dir: PathLike = _comm_default_dir, ): - """Hook to be used when interfacing wandb with pytorch lightning. + """Hook to be used when interfacing wandb with Lightning. Args: communication_dir: Directory used for communication with wandb-osh. @@ -32,8 +44,8 @@ def __init__( def on_validation_epoch_end( self, - trainer: Trainer, - pl_module: LightningModule, + trainer: pl.Trainer, + pl_module: pl.LightningModule, ) -> None: if trainer.sanity_checking: return diff --git a/tests/test_lightning_hooks.py b/tests/test_lightning_hooks.py index 90d9c06..dfae291 100644 --- a/tests/test_lightning_hooks.py +++ b/tests/test_lightning_hooks.py @@ -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