From e48ac22122c00e190742958a02f42eaeeb7d7bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Musil?= <23387713+vejtek@users.noreply.github.com> Date: Tue, 20 Oct 2026 16:47:16 +0200 Subject: [PATCH 1/2] refactor(lightning): take MultiloaderLifecycle from ratiopath The callback moved to ratiopath 1.5.0 (ratiopath[lightning]). mlkit keeps the old import paths as a re-export, so projects that import it from mlkit keep working and get the same class. --- pyproject.toml | 2 +- .../callbacks/multiloader_lifecycle.py | 118 +----------------- uv.lock | 15 ++- 3 files changed, 14 insertions(+), 121 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b1570be..a4dd65e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "numpy>=2.0", "openslide-python>=1.4.2", "pyarrow>=23.0.1", - "ratiopath>=1.4.2", + "ratiopath[lightning]>=1.5.0", "torch>=2.9.1", ] diff --git a/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py b/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py index e06c88e..b00d22a 100644 --- a/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py +++ b/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py @@ -1,118 +1,6 @@ -from abc import ABC -from typing import Any +"""`MultiloaderLifecycle` now lives in ratiopath; this module keeps the old import path.""" -from lightning import LightningModule, Trainer -from lightning.pytorch.callbacks import Callback +from ratiopath.lightning.callbacks import MultiloaderLifecycle -class MultiloaderLifecycle(Callback, ABC): - """An abstract callback class that adds new methods: `on_{stage}_dataloader_start` and `on_{stage}_dataloader_end`. - - `stage` is one of "validation", "test", or "predict". - - The callback monitors the dataloader index and calls the - `on_{stage}_dataloader_start` and `on_{stage}_dataloader_end` methods when the - dataloader index changes. - - Note: - If subclasses override either `on_{stage}_batch_start` or `on_{stage}_epoch_end`, - they must also call the corresponding parent methods to ensure proper - functionality. - """ - - def __init__(self) -> None: - self._dataloader_idxs = {"validation": -1, "test": -1, "predict": -1} - - def on_validation_dataloader_start( - self, trainer: Trainer, pl_module: LightningModule, dataloader_idx: int - ) -> None: ... - - def on_validation_dataloader_end( - self, trainer: Trainer, pl_module: LightningModule, dataloader_idx: int - ) -> None: ... - - def on_test_dataloader_start( - self, trainer: Trainer, pl_module: LightningModule, dataloader_idx: int - ) -> None: ... - - def on_test_dataloader_end( - self, trainer: Trainer, pl_module: LightningModule, dataloader_idx: int - ) -> None: ... - - def on_predict_dataloader_start( - self, trainer: Trainer, pl_module: LightningModule, dataloader_idx: int - ) -> None: ... - - def on_predict_dataloader_end( - self, trainer: Trainer, pl_module: LightningModule, dataloader_idx: int - ) -> None: ... - - def on_batch_start( - self, - stage: str, - trainer: Trainer, - pl_module: LightningModule, - dataloader_idx: int, - ) -> None: - if dataloader_idx != self._dataloader_idxs[stage]: - if self._dataloader_idxs[stage] != -1: - getattr(self, f"on_{stage}_dataloader_end")( - trainer, pl_module, self._dataloader_idxs[stage] - ) - - self._dataloader_idxs[stage] = dataloader_idx - getattr(self, f"on_{stage}_dataloader_start")( - trainer, pl_module, dataloader_idx - ) - - def on_epoch_end( - self, stage: str, trainer: Trainer, pl_module: LightningModule - ) -> None: - if self._dataloader_idxs[stage] != -1: - getattr(self, f"on_{stage}_dataloader_end")( - trainer, pl_module, self._dataloader_idxs[stage] - ) - self._dataloader_idxs[stage] = -1 - - def on_validation_batch_start( - self, - trainer: Trainer, - pl_module: LightningModule, - batch: Any, - batch_idx: int, - dataloader_idx: int = 0, - ) -> None: - self.on_batch_start("validation", trainer, pl_module, dataloader_idx) - - def on_validation_epoch_end( - self, trainer: Trainer, pl_module: LightningModule - ) -> None: - self.on_epoch_end("validation", trainer, pl_module) - - def on_test_batch_start( - self, - trainer: Trainer, - pl_module: LightningModule, - batch: Any, - batch_idx: int, - dataloader_idx: int = 0, - ) -> None: - self.on_batch_start("test", trainer, pl_module, dataloader_idx) - - def on_test_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None: - self.on_epoch_end("test", trainer, pl_module) - - def on_predict_batch_start( - self, - trainer: Trainer, - pl_module: LightningModule, - batch: Any, - batch_idx: int, - dataloader_idx: int = 0, - ) -> None: - self.on_batch_start("predict", trainer, pl_module, dataloader_idx) - - def on_predict_epoch_end( - self, trainer: Trainer, pl_module: LightningModule - ) -> None: - self.on_epoch_end("predict", trainer, pl_module) +__all__ = ["MultiloaderLifecycle"] diff --git a/uv.lock b/uv.lock index d8b81af..131837d 100644 --- a/uv.lock +++ b/uv.lock @@ -2305,7 +2305,7 @@ dependencies = [ { name = "numpy" }, { name = "openslide-python" }, { name = "pyarrow" }, - { name = "ratiopath" }, + { name = "ratiopath", extra = ["lightning"] }, { name = "torch" }, ] @@ -2326,7 +2326,7 @@ requires-dist = [ { name = "numpy", specifier = ">=2.0" }, { name = "openslide-python", specifier = ">=1.4.2" }, { name = "pyarrow", specifier = ">=23.0.1" }, - { name = "ratiopath", specifier = ">=1.4.2" }, + { name = "ratiopath", extras = ["lightning"], specifier = ">=1.5.0" }, { name = "torch", specifier = ">=2.9.1" }, ] @@ -2338,7 +2338,7 @@ dev = [ [[package]] name = "ratiopath" -version = "1.4.2" +version = "1.5.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "albumentationsx" }, @@ -2358,9 +2358,14 @@ dependencies = [ { name = "torch" }, { name = "zarr" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/38/a9/afbe608b0cc33dc3093bd3afc1e7b995dc1bc2b9a298c171fe43c78c0027/ratiopath-1.4.2.tar.gz", hash = "sha256:880885a2c7a24ded3d0eb9522be60315289a6fe074018555a130dd3479afad25", size = 45043, upload-time = "2026-07-11T18:28:28.82Z" } +sdist = { url = "https://files.pythonhosted.org/packages/97/0e/40f651495cf057428d91363ba0ebfa80eaa615ca65f63fb7e59267ffaee7/ratiopath-1.5.0.tar.gz", hash = "sha256:ac1d5cc082776f207f2ba96068ee421ddd9b8357a851235ab7cc0e25a68ebd28", size = 47974, upload-time = "2026-10-20T12:59:50.802Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/b8/50/9cec2cca4083323fa850bb343590fe0c414fab1ee33480adaeeac514d280/ratiopath-1.4.2-py3-none-any.whl", hash = "sha256:01ef5c1d61803a5197e318a7295e2ece6edd85314ba7273fc50d7c2c38e41279", size = 51181, upload-time = "2026-07-11T18:28:27.85Z" }, + { url = "https://files.pythonhosted.org/packages/a9/bf/0c64567922ad1e44c6bea930e899aa2fb820ca4c182f0549ec7e5545f6e4/ratiopath-1.5.0-py3-none-any.whl", hash = "sha256:b7ea74cdc6594ea487c1d2ad962d4f37c9d04c9af01e5a3931f1662fed744f97", size = 53848, upload-time = "2026-10-20T12:59:49.803Z" }, +] + +[package.optional-dependencies] +lightning = [ + { name = "lightning" }, ] [[package]] From 418a5e4a2b16777306a150bcc7c7f19bf1c306fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Musil?= <23387713+vejtek@users.noreply.github.com> Date: Tue, 20 Oct 2026 22:44:37 +0200 Subject: [PATCH 2/2] refactor(lightning)!: remove MultiloaderLifecycle, it lives in ratiopath The callback moved to ratiopath 1.5.0 (ratiopath.lightning.callbacks). mlkit no longer defines or re-exports it; the rationai.mlkit.lightning.callbacks package is removed. mlkit requires ratiopath>=1.5.0, so every mlkit environment already has the class under its new import path. BREAKING CHANGE: import MultiloaderLifecycle from ratiopath.lightning.callbacks. --- pyproject.toml | 2 +- rationai/mlkit/lightning/callbacks/__init__.py | 6 ------ .../mlkit/lightning/callbacks/multiloader_lifecycle.py | 6 ------ uv.lock | 9 ++------- 4 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 rationai/mlkit/lightning/callbacks/__init__.py delete mode 100644 rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py diff --git a/pyproject.toml b/pyproject.toml index a4dd65e..5614c85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "numpy>=2.0", "openslide-python>=1.4.2", "pyarrow>=23.0.1", - "ratiopath[lightning]>=1.5.0", + "ratiopath>=1.5.0", "torch>=2.9.1", ] diff --git a/rationai/mlkit/lightning/callbacks/__init__.py b/rationai/mlkit/lightning/callbacks/__init__.py deleted file mode 100644 index 914d283..0000000 --- a/rationai/mlkit/lightning/callbacks/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from rationai.mlkit.lightning.callbacks.multiloader_lifecycle import ( - MultiloaderLifecycle, -) - - -__all__ = ["MultiloaderLifecycle"] diff --git a/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py b/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py deleted file mode 100644 index b00d22a..0000000 --- a/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py +++ /dev/null @@ -1,6 +0,0 @@ -"""`MultiloaderLifecycle` now lives in ratiopath; this module keeps the old import path.""" - -from ratiopath.lightning.callbacks import MultiloaderLifecycle - - -__all__ = ["MultiloaderLifecycle"] diff --git a/uv.lock b/uv.lock index 131837d..2d60dc8 100644 --- a/uv.lock +++ b/uv.lock @@ -2305,7 +2305,7 @@ dependencies = [ { name = "numpy" }, { name = "openslide-python" }, { name = "pyarrow" }, - { name = "ratiopath", extra = ["lightning"] }, + { name = "ratiopath" }, { name = "torch" }, ] @@ -2326,7 +2326,7 @@ requires-dist = [ { name = "numpy", specifier = ">=2.0" }, { name = "openslide-python", specifier = ">=1.4.2" }, { name = "pyarrow", specifier = ">=23.0.1" }, - { name = "ratiopath", extras = ["lightning"], specifier = ">=1.5.0" }, + { name = "ratiopath", specifier = ">=1.5.0" }, { name = "torch", specifier = ">=2.9.1" }, ] @@ -2363,11 +2363,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/a9/bf/0c64567922ad1e44c6bea930e899aa2fb820ca4c182f0549ec7e5545f6e4/ratiopath-1.5.0-py3-none-any.whl", hash = "sha256:b7ea74cdc6594ea487c1d2ad962d4f37c9d04c9af01e5a3931f1662fed744f97", size = 53848, upload-time = "2026-10-20T12:59:49.803Z" }, ] -[package.optional-dependencies] -lightning = [ - { name = "lightning" }, -] - [[package]] name = "ray" version = "2.52.0"