Skip to content

feat(lightning): add MultiloaderLifecycle callback - #56

Open
vejtek wants to merge 1 commit into
mainfrom
claude/multiloader-lifecycle
Open

vejtek wants to merge 1 commit into
mainfrom
claude/multiloader-lifecycle

Conversation

@vejtek

@vejtek vejtek commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Moves MultiloaderLifecycle from mlkit into ratiopath, as agreed at the 8 Oct repository meeting (DEV-161): extensions of third-party frameworks for digital pathology belong in ratiopath, the way train_test_split extends scikit-learn. Here it is PyTorch Lightning.

Changes

  • ratiopath/lightning/callbacks/multiloader_lifecycle.py: the callback adds on_{stage}_dataloader_start / _end hooks for validation, test and predict. The logic is copied from rationai.mlkit.lightning.callbacks unchanged (diffed). The empty hook stubs got docstrings, and the class got a Google-style docstring with an example.
  • Lightning is an optional extra: pip install ratiopath[lightning] (lightning>=2.4.0). The base install doesn't change. Lightning is also in the tests group, so the new tests run in CI.
  • Reference page in the docs under a new "Lightning" section.
  • tests/test_multiloader_lifecycle.py: hook order across dataloader changes for all three stages, state reset between epochs, and an epoch with no batches.

Checks (local)

  • pytest: 381 passed (5 new).
  • mypy .: clean.
  • ruff check / ruff format --check (0.17.0): clean.
  • mkdocs build --strict: passes.
  • uv.lock only adds lightning and its dependencies (torchmetrics, pytorch-lightning, aiohttp, …), nothing upgraded.

Follow-up and questions

  • Release: mlkit takes ratiopath from PyPI. Once this is merged and released (1.5.0?), I'll open a PR in mlkit that re-exports the callback from ratiopath, so existing imports keep working (carcinoma-binary-classification-methods and stain-normalization use it), and then drops the copy.
  • Is ratiopath.lightning.callbacks the namespace you want, or would you rather have something under ratiopath.torch?
  • Is an optional extra OK, or should Lightning be a regular dependency, given that torch already is one?

🤖 Generated with Claude Code

Moved from mlkit, as agreed for DEV-161: extensions of third-party
frameworks for digital pathology belong in ratiopath (like train_test_split
for scikit-learn). The callback adds on_{stage}_dataloader_start/end hooks
for validation, test and predict. Lightning is an optional extra
(ratiopath[lightning]); the logic is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vejtek
vejtek requested review from a team, Adames4 and matejpekar October 15, 2026 13:09
@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8c8d027d-6667-464b-b555-3328b90eba1a
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Documentation Preview

Preview URL: https://RationAI.github.io/ratiopath/claude-multiloader-lifecycle/

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants