Skip to content

Conversation

@SiddhantSadangi
Copy link
Member

@SiddhantSadangi SiddhantSadangi commented May 20, 2025

Summary by Sourcery

Add checkpointing and model summary support to NeptuneScaleLogger, improve finalize status handling, and refresh documentation links for NeptuneLogger and NeptuneScaleLogger.

New Features:

  • Implement log_model_summary in NeptuneScaleLogger to upload layer summaries as text files
  • Add optional log_model_checkpoints flag to NeptuneScaleLogger to automatically log checkpoint paths

Enhancements:

  • Update documentation URLs in NeptuneLogger to use legacy Neptune site and in NeptuneScaleLogger to use current non-beta Neptune site
  • Change finalize behavior in NeptuneScaleLogger to record status via run.log_configs

Documentation:

  • Add NeptuneScaleLogger example under “neptune 3.x” in README

Tests:

  • Update tests to assert status logging via log_configs, verify File usage in log_model_summary, and cover after_save_checkpoint checkpoint logging

@sourcery-ai
Copy link

sourcery-ai bot commented May 20, 2025

Reviewer's Guide

This PR extends NeptuneScaleLogger with automatic model checkpoint and summary logging, updates documentation links and examples, refactors status logging in finalize, and adds tests covering these new features.

Sequence Diagram: Model Checkpoint Logging in NeptuneScaleLogger

sequenceDiagram
    participant T as Trainer
    participant NSL as NeptuneScaleLogger
    participant MCC as ModelCheckpoint
    participant NR as NeptuneRun

    T ->> NSL: after_save_checkpoint(checkpoint_callback: ModelCheckpoint)
    NSL ->> NSL: if not self._log_model_checkpoints: return

    NSL ->> MCC: Access last_model_path
    opt Has last_model_path
        NSL ->> NSL: model_last_name = _get_full_model_name(MCC.last_model_path, MCC)
        NSL ->> NR: run.log_configs({f"{NSL._prefix}/model/checkpoints/{model_last_name}": MCC.last_model_path})
    end

    NSL ->> MCC: Access best_k_models
    loop For each path_key in MCC.best_k_models
        NSL ->> NSL: model_name = _get_full_model_name(path_key, MCC)
        NSL ->> NR: run.log_configs({f"{NSL._prefix}/model/checkpoints/{model_name}": path_key})
    end

    NSL ->> MCC: Access best_model_path
    opt Has best_model_path
        NSL ->> NR: run.log_configs({f"{NSL._prefix}/model/best_model_path": MCC.best_model_path})
        NSL ->> NSL: model_name = _get_full_model_name(MCC.best_model_path, MCC)
        NSL ->> NR: run.log_configs({f"{NSL._prefix}/model/checkpoints/{model_name}": MCC.best_model_path})
    end

    NSL ->> MCC: Access best_model_score
    opt Has best_model_score
        NSL ->> NR: run.log_configs({f"{NSL._prefix}/model/best_model_score": float(MCC.best_model_score)})
    end
Loading

Sequence Diagram: Model Summary Logging in NeptuneScaleLogger

sequenceDiagram
    participant Caller
    participant NSL as NeptuneScaleLogger
    participant MS as ModelSummary
    participant NR as NeptuneRun

    Caller ->> NSL: log_model_summary(model, max_depth)
    NSL ->> MS: Create ModelSummary(model, max_depth)
    MS -->> NSL: model_summary_instance
    NSL ->> NSL: model_str = str(model_summary_instance)
    NSL ->> NR: run.assign_files({f"{NSL._prefix}/model/summary": File(source=model_str.encode("utf-8"))})
Loading

Sequence Diagram: Updated Status Finalization in NeptuneScaleLogger

sequenceDiagram
    participant T as Trainer
    participant NSL as NeptuneScaleLogger
    participant NR as NeptuneRun

    T ->> NSL: finalize(status: str)
    NSL ->> NR: run.log_configs({f"{NSL._prefix}/status": status})
Loading

File-Level Changes

Change Details Files
Added checkpoint and model summary logging in NeptuneScaleLogger
  • Introduce log_model_checkpoints flag in init to enable/disable checkpoint logging
  • Implement log_model_summary to upload model summaries via run.assign_files
  • Implement after_save_checkpoint to log last, best_k, and best_model paths using run.log_configs
  • Enhance internal helpers to generate and parse checkpoint names for logging
src/lightning/pytorch/loggers/neptune.py
Refactored finalize to use run.log_configs for status
  • Replace direct self.run._status assignment with self.run.log_configs call
src/lightning/pytorch/loggers/neptune.py
Updated documentation links and examples
  • Point NeptuneLogger and NeptuneScaleLogger URLs to current Neptune and Neptune Scale docs
  • Remove unsupported parameters and unused imports in examples
  • List NeptuneScaleLogger under 3.x in README
src/lightning/pytorch/loggers/neptune.py
src/pytorch_lightning/README.md
Extended tests for new logging capabilities
  • Modify finalize test to assert log_configs usage
  • Add tests for log_model_summary to verify File assignment
  • Add tests for after_save_checkpoint covering last, best_k, and best_model scenarios
tests/tests_pytorch/loggers/test_neptune.py

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

@SiddhantSadangi SiddhantSadangi requested a review from Copilot May 20, 2025 16:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds checkpointing and model summary support to NeptuneScaleLogger, updates status handling, and refreshes documentation links.

  • Implements log_model_summary to log model summaries as text files instead of issuing a warning.
  • Adds functionality in after_save_checkpoint to automatically log model checkpoints.
  • Updates documentation links and test cases to reflect Neptune Scale support.

Reviewed Changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated no comments.

File Description
tests/tests_pytorch/loggers/test_neptune.py Revised tests for log_model_summary and after_save_checkpoint to validate new assignment calls (though the tests still assert setitem, which may need updating).
src/pytorch_lightning/README.md Updated documentation sections to distinguish between Neptune 2.x and 3.x.
src/lightning/pytorch/loggers/neptune.py Reworked NeptuneScaleLogger implementation to support checkpointing and model summary logging along with refreshed docs and improved API calls.
Files not reviewed (3)
  • docs/source-pytorch/extensions/logging.rst: Language not supported
  • docs/source-pytorch/visualize/supported_exp_managers.rst: Language not supported
  • requirements/pytorch/loggers.info: Language not supported
Comments suppressed due to low confidence (2)

src/lightning/pytorch/loggers/neptune.py:1127

  • The return type annotation 'set[None]' appears to be incorrect; consider using 'set[str]' to accurately reflect the expected return values from this function.
def _get_full_model_names_from_exp_structure(cls, exp_structure: dict[str, Any], namespace: str) -> set[None]:

tests/tests_pytorch/loggers/test_neptune.py:492

  • The test assertion still checks for a setitem call, but the new implementation of log_model_summary uses 'assign_files'. Update the test to verify that 'assign_files' is called with the expected arguments.
run_instance_mock.__setitem__.assert_called_once_with(model_summary_key, File)

@github-actions
Copy link

github-actions bot commented May 20, 2025

⛈️ Required checks status: Has failure 🔴

Warning
This job will need to be re-run to merge your PR. If you do not have write access to the repository, you can ask Lightning-AI/lai-frameworks to re-run it. If you push a new commit, all of CI will re-trigger.

Groups summary

🟡 pytorch_lightning: Tests workflow
Check ID Status
pl-cpu-guardian no_status

These checks are required after the changes to requirements/pytorch/loggers.info, src/lightning/pytorch/loggers/neptune.py, tests/tests_pytorch/loggers/test_neptune.py.

🟡 pytorch_lightning: Azure GPU
Check ID Status
pytorch-lightning (GPUs) (testing Lightning latest) no_status
pytorch-lightning (GPUs) (testing PyTorch latest) no_status

These checks are required after the changes to requirements/pytorch/loggers.info, src/lightning/pytorch/loggers/neptune.py, tests/tests_pytorch/loggers/test_neptune.py.

🟡 pytorch_lightning: Benchmarks
Check ID Status
lightning.Benchmarks no_status

These checks are required after the changes to requirements/pytorch/loggers.info, src/lightning/pytorch/loggers/neptune.py.

🔴 pytorch_lightning: Docs
Check ID Status
docs-make (pytorch, doctest) failure
docs-make (pytorch, html) failure

These checks are required after the changes to src/lightning/pytorch/loggers/neptune.py, docs/source-pytorch/extensions/logging.rst, docs/source-pytorch/visualize/supported_exp_managers.rst, requirements/pytorch/loggers.info.

🔴 pytorch_lightning: Docker
Check ID Status
build-cuda (3.10, 2.1.2, 12.1.1) failure
build-cuda (3.11, 2.2.2, 12.1.1) failure
build-cuda (3.11, 2.3.1, 12.1.1) failure
build-cuda (3.11, 2.4.1, 12.1.1) failure
build-cuda (3.12, 2.5.1, 12.1.1) failure
build-cuda (3.12, 2.6.0, 12.4.1) failure
build-pl (3.10, 2.1, 12.1.1) success
build-pl (3.11, 2.2, 12.1.1) success
build-pl (3.11, 2.3, 12.1.1) failure
build-pl (3.11, 2.4, 12.1.1) success
build-pl (3.12, 2.5, 12.1.1) failure
build-pl (3.12, 2.6, 12.4.1) success
build-pl (3.12, 2.7, 12.6.3, true) failure

These checks are required after the changes to requirements/pytorch/loggers.info.

🔴 mypy
Check ID Status
mypy failure

These checks are required after the changes to requirements/pytorch/loggers.info, src/lightning/pytorch/loggers/neptune.py.

🟡 install
Check ID Status
install-pkg-guardian no_status

These checks are required after the changes to src/lightning/pytorch/loggers/neptune.py, requirements/pytorch/loggers.info.


Thank you for your contribution! 💜

Note
This comment is automatically generated and updates for 60 minutes every 180 seconds. If you have any other questions, contact carmocca for help.

Copy link

@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 @SiddhantSadangi - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 5 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@SiddhantSadangi
Copy link
Member Author

@sourcery-ai review

Copy link

@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 @SiddhantSadangi - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

Copy link

@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 @SiddhantSadangi - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Project placeholder should be a string literal. (link)

  • Update the tests for log_model_summary and after_save_checkpoint to assert run.assign_files and run.log_configs calls (instead of setitem/getitem or upload) since the implementation now uses those APIs.

  • Verify that neptune_scale.types.File(source=bytes, mime_type) is the correct way to upload text summaries—consider using a File.from_content utility if raw bytes aren’t supported by the File constructor.

  • Either remove or implement the commented‐out del logic in after_save_checkpoint once del support is available, to avoid accumulating dead code.

Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 1 other issue
  • 🟢 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.

@SiddhantSadangi SiddhantSadangi requested a review from Copilot May 26, 2025 09:51
@SiddhantSadangi
Copy link
Member Author

@sourcery-ai review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds checkpointing support and model summary logging to the Neptune Scale Logger while updating documentation links and extending tests. Key changes include updating tests for model summary and checkpoint logging, modifying documentation references for Neptune/Neptune Scale, and refactoring logger methods to support the new features.

Reviewed Changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 1 comment.

File Description
tests/tests_pytorch/loggers/test_neptune.py Updated tests to assert proper logging in model summary and checkpointing.
src/pytorch_lightning/README.md Updated documentation links and labels to differentiate Neptune versions.
src/lightning/pytorch/loggers/neptune.py Implemented log_model_summary, improved checkpoint logging, and updated docstrings and API behavior.
Files not reviewed (3)
  • docs/source-pytorch/extensions/logging.rst: Language not supported
  • docs/source-pytorch/visualize/supported_exp_managers.rst: Language not supported
  • requirements/pytorch/loggers.info: Language not supported
Comments suppressed due to low confidence (1)

src/lightning/pytorch/loggers/neptune.py:1043

  • ModelSummary is used without an explicit import, which could raise a NameError. Please add the appropriate import for ModelSummary.
model_str = str(ModelSummary(model=model, max_depth=max_depth))

Copy link

@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 @SiddhantSadangi - I've reviewed your changes - here's some feedback:

  • Update the docstring note in the Log model checkpoint paths section to reflect that save_last and save_top_k are now supported, or clearly specify which options remain unsupported.
  • Ensure import os is present at the top of the file since _get_full_model_name uses os.path and os.sep.
  • Add a test for log_model_checkpoints=False to verify that after_save_checkpoint does not log checkpoint paths when the flag is disabled.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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.

@SiddhantSadangi SiddhantSadangi added the enhancement New feature or request label May 26, 2025
@SiddhantSadangi SiddhantSadangi merged commit 9f4e139 into master May 26, 2025
40 of 60 checks passed
@SiddhantSadangi SiddhantSadangi deleted the ss/add_file_support branch May 26, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants