diff --git a/pyproject.toml b/pyproject.toml index b1570be..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>=1.4.2", + "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 e06c88e..0000000 --- a/rationai/mlkit/lightning/callbacks/multiloader_lifecycle.py +++ /dev/null @@ -1,118 +0,0 @@ -from abc import ABC -from typing import Any - -from lightning import LightningModule, Trainer -from lightning.pytorch.callbacks import Callback - - -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) diff --git a/uv.lock b/uv.lock index d8b81af..2d60dc8 100644 --- a/uv.lock +++ b/uv.lock @@ -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", 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,9 @@ 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]]