Skip to content

Example: PyTorch Lightning integration #17

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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

LeoRoccoBreedt
Copy link
Contributor

@LeoRoccoBreedt LeoRoccoBreedt commented May 28, 2025

Description

Include a summary of the changes and the related issue.

Related to: <ClickUp/JIRA task name>

Any expected test failures?
Python 3.13 not supported for PyTorch (yet).


Add a [X] to relevant checklist items

❔ This change

  • adds a new feature
  • fixes breaking code
  • is cosmetic (refactoring/reformatting)

✔️ Pre-merge checklist

  • Refactored code (sourcery)
  • Tested code locally
  • Precommit installed and run before pushing changes
  • Added code to GitHub tests (notebooks, scripts)
  • Updated GitHub README
  • Updated the projects overview page on Notion

🧪 Test Configuration

  • OS: Windows
  • Python version: 3.12
  • Neptune version: 0.13.0
  • Affected libraries with version: torch, lightning

Summary by Sourcery

Add a PyTorch Lightning integration example notebook for Neptune Scale and update the CI workflow to run tests on it.

New Features:

  • Add Neptune + PyTorch Lightning example notebook demonstrating integration usage

CI:

  • Include the new PyTorch Lightning notebook in the test-notebooks CI workflow

Summary by Sourcery

Provide a Neptune Scale integration example for PyTorch Lightning by adding a Jupyter notebook, a Python script with supporting requirements and run script, and update CI workflows to test the new integration.

New Features:

  • Add Neptune + PyTorch Lightning example notebook, script, requirements, and run_examples.sh for demonstration

CI:

  • Include the PyTorch Lightning example notebook in the test-notebooks workflow
  • Include the PyTorch Lightning scripts directory in the test-scripts workflow

Copy link
Contributor

sourcery-ai bot commented May 28, 2025

Reviewer's Guide

This PR integrates a new PyTorch Lightning example into the repository by adding a detailed example notebook and script (with supporting requirements and run script) that demonstrate NeptuneScaleLogger usage, and updates the CI workflows to include these assets in automated tests.

Class Diagram for LitModel (PyTorch Lightning Module)

Loading
classDiagram
    class LightningModule {
        <<PyTorch Lightning>>
        +log()
        +log_dict()
    }
    class LitModel {
        +List training_step_outputs
        +List validation_step_outputs
        +List test_step_outputs
        +int linear
        +float learning_rate
        +float decay_factor
        +torch.nn.Linear layer_1
        +torch.nn.Linear layer_2
        +torch.nn.Linear layer_3
        +NeptuneScaleLogger logger
        +__init__(linear, learning_rate, decay_factor)
        +forward(x) Tensor
        +configure_optimizers() List
        +training_step(batch) Dict
        +on_train_epoch_end()
        +validation_step(batch, batch_idx) Dict
        +on_validation_epoch_end()
        +test_step(batch) Dict
        +on_test_epoch_end()
    }
    LightningModule <|-- LitModel

Class Diagram for MNISTDataModule (PyTorch Lightning DataModule)

Loading
classDiagram
    class LightningDataModule {
        <<PyTorch Lightning>>
    }
    class MNISTDataModule {
        +int batch_size
        +tuple normalization_vector
        +Dataset mnist_train
        +Dataset mnist_val
        +Dataset mnist_test
        +__init__(batch_size, normalization_vector)
        +prepare_data()
        +setup(stage)
        +train_dataloader() DataLoader
        +val_dataloader() DataLoader
        +test_dataloader() DataLoader
    }
    LightningDataModule <|-- MNISTDataModule

File-Level Changes

Change Details Files
Add PyTorch Lightning integration example notebook demonstrating NeptuneScaleLogger usage
  • Created a notebook with setup instructions, model and DataModule definitions, and logging steps
  • Included sections for hyperparameter logging, model summary, and run closure
  • Documented installation options and live metadata exploration
integrations-and-supported-tools/pytorch-lightning/notebooks/Neptune_PyTorch_Lightning.ipynb
Add PyTorch Lightning integration script for automated example execution
  • Implemented a script defining LitModel and MNISTDataModule with NeptuneScaleLogger
  • Configured the trainer, logging calls, and a main() entry point
  • Structured training and testing flow with live Neptune logging
integrations-and-supported-tools/pytorch-lightning/scripts/Neptune_Pytorch_Lightning.py
Add support files for example script execution
  • Created requirements.txt listing dependencies (Lightning, Neptune, torch, etc.)
  • Added run_examples.sh to install requirements and execute the example script
integrations-and-supported-tools/pytorch-lightning/scripts/requirements.txt
integrations-and-supported-tools/pytorch-lightning/scripts/run_examples.sh
Include new PyTorch Lightning example in CI testing workflows
  • Appended the new notebook path to the test-notebooks CI workflow
  • Appended the new scripts directory to the test-scripts CI workflow
.github/workflows/test-notebooks.yml
.github/workflows/test-scripts.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@LeoRoccoBreedt LeoRoccoBreedt changed the title feat: PyTorch Lightning Example Example: PyTorch Lightning integration Jun 2, 2025
@LeoRoccoBreedt LeoRoccoBreedt marked this pull request as ready for review June 2, 2025 15:06
@LeoRoccoBreedt LeoRoccoBreedt requested a review from a team as a code owner June 2, 2025 15:06
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @LeoRoccoBreedt - I've reviewed your changes - here's some feedback:

  • Consider refactoring the Lightning model and DataModule definitions into a shared utility module to avoid duplicating the same code in both the notebook and script.
  • The installation instructions rely on a custom PyTorch Lightning fork; please clarify version compatibility or plan to switch to the official release once supported to reduce long-term maintenance overhead.
Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@LeoRoccoBreedt LeoRoccoBreedt self-assigned this Jun 6, 2025
"source": [
"## Define Lightning model\n",
"\n",
"To log metrics to Neptune, define a Lightning model with both inbuilt logging (`self.log()` or `self.log_dict()`) and custom logging (`neptune_logger.run`).\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we split this info into bullets? Something like:
To log metrics to Neptune, define a Lightning model. You can use:

  • inbuilt logging methods, such as self.log() or self.log_dict()
  • neptune_logger.run, a reference to the Neptune run object created by the NeptuneScaleLogger() instance. + the rest of the info on it

Plus maybe a link to all Run methods? https://docs.neptune.ai/run/#methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szaganek I updated based on comments. Let me know if all good now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested just a tiny change in another comment.

LeoRoccoBreedt and others added 4 commits June 30, 2025 16:50
Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com>
Signed-off-by: Leo Breedt <101509998+LeoRoccoBreedt@users.noreply.github.com>
LeoRoccoBreedt and others added 2 commits July 4, 2025 11:35
Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com>
Signed-off-by: Leo Breedt <101509998+LeoRoccoBreedt@users.noreply.github.com>
" <img alt=\"Open in GitHub\" src=\"https://img.shields.io/badge/Open_in_GitHub-blue?logo=github&labelColor=black\">\n",
"</a><a target=\"_blank\" href=\"https://scale.neptune.ai/o/examples/org/pytorch-lightning/runs/table?viewId=9ea6121c-42a7-4ece-83b2-c591044837e7&detailsTab=charts&dash=table&type=experiment\"> \n",
" <img alt=\"Explore in Neptune\" src=\"https://neptune.ai/wp-content/uploads/2024/01/neptune-badge.svg\">\n",
"</a><!<a target=\"_blank\" href=\"https://docs.neptune.ai/integrations/pytorch_lightning\">\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"</a><!<a target=\"_blank\" href=\"https://docs.neptune.ai/integrations/pytorch_lightning\">\n",
"</a><a target=\"_blank\" href=\"https://docs.neptune.ai/integrations/pytorch_lightning\">\n",

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