Skip to content

feat(adapter/nemo): add EventLoggingCallback for lifecycle monitoring#34

Merged
kkkapu merged 4 commits intomainfrom
step_callback
Feb 9, 2026
Merged

feat(adapter/nemo): add EventLoggingCallback for lifecycle monitoring#34
kkkapu merged 4 commits intomainfrom
step_callback

Conversation

@kkkapu
Copy link
Collaborator

@kkkapu kkkapu commented Feb 5, 2026

Change-Id: I1497831c8c1fdca614c053df39957eb6116840d7
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kkkapu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new PyTorch Lightning callback designed to provide comprehensive logging of the model training lifecycle. This callback records timestamps for critical events, enabling developers to monitor and analyze the execution flow of their training processes, which can be invaluable for debugging, performance profiling, and understanding model behavior.

Highlights

  • New Feature: StepTimerCallback: A new StepTimerCallback class has been introduced to provide comprehensive logging of PyTorch Lightning lifecycle events.
  • Detailed Event Logging: The callback overrides numerous on_... methods (e.g., on_train_start, on_train_batch_end, on_save_checkpoint, on_before_backward) to log the occurrence of these critical training, validation, testing, checkpointing, and optimization steps.
  • Execution Flow Monitoring: Each logged event records its hook name, allowing for detailed monitoring and analysis of the execution flow within a PyTorch Lightning training run.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/ml_flashpoint/adapter/nemo/step_timer_callback.py
    • Added a new StepTimerCallback class.
    • Implemented logging for various PyTorch Lightning lifecycle hooks, including training, validation, testing, checkpointing, and optimization steps.
Activity
  • No human activity (comments, reviews) has been recorded yet on this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a StepTimerCallback to log PyTorch Lightning lifecycle events, which is useful for monitoring and debugging training jobs. The implementation is straightforward. My review includes a few suggestions to improve code consistency and cleanliness. Specifically, I've pointed out an opportunity to refactor the logging helper method to remove an unused parameter and then apply it consistently across all hooks, including load_state_dict which currently has a redundant logging format. I've also noted a commented-out import that can be removed.

from lightning.pytorch import callbacks as pl_callbacks
from lightning.pytorch.utilities.types import STEP_OUTPUT

# from lightning.pytorch.utilities import types as pl_util_types
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This commented-out import appears to be unnecessary and can be removed to keep the code clean.

Comment on lines 37 to 43
def _log_event(self, trainer: "pl.Trainer", hook_name: str) -> None:
_LOGGER.info(f"{hook_name: <30}")

@override
def on_train_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
"""Called when the train begins."""
self._log_event(trainer, "on_train_start")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The _log_event method has an unused trainer parameter. It's good practice to remove it to simplify the method signature. This also enables _log_event to be used in hooks that don't receive a trainer object, like load_state_dict, ensuring consistent logging across the callback. All call sites will need to be updated as shown in the suggestion for on_train_start.

Suggested change
def _log_event(self, trainer: "pl.Trainer", hook_name: str) -> None:
_LOGGER.info(f"{hook_name: <30}")
@override
def on_train_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
"""Called when the train begins."""
self._log_event(trainer, "on_train_start")
def _log_event(self, hook_name: str) -> None:
_LOGGER.info(f"{hook_name: <30}")
@override
def on_train_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
"""Called when the train begins."""
self._log_event("on_train_start")

Comment on lines 125 to 128
def load_state_dict(self, state_dict: Dict[str, Any]) -> None:
"""Called when loading a checkpoint, implement to reload callback state."""
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
_LOGGER.info(f"[{timestamp}] Hook: load_state_dict")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logging implementation here is inconsistent with the other lifecycle hooks. It manually creates a timestamp, which is redundant because the logger is already configured to add one. This results in log entries with duplicate timestamps. To ensure consistent log formatting, this method should use the centralized _log_event helper, assuming it has been refactored to no longer require the trainer argument.

Suggested change
def load_state_dict(self, state_dict: Dict[str, Any]) -> None:
"""Called when loading a checkpoint, implement to reload callback state."""
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
_LOGGER.info(f"[{timestamp}] Hook: load_state_dict")
@override
def load_state_dict(self, state_dict: Dict[str, Any]) -> None:
"""Called when loading a checkpoint, implement to reload callback state."""
self._log_event("load_state_dict")

Change-Id: If6fe4e90ef0b576568dc38a08aaf63d8fcfb7ba0
@kkkapu kkkapu requested review from Leahlijuan and g-husam February 5, 2026 21:07
@override
def on_train_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
"""Called when the train begins."""
self._log_event("on_train_start")
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we generate some basic tests to validate some of the key events are logged, like on_train_*, on_train_batch_*

"""

def _log_event(self, hook_name: str) -> None:
_LOGGER.info(f"{hook_name: <30}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is <30 needed?

nit: maybe add event= to make it more unique of a log statement

Suggested change
_LOGGER.info(f"{hook_name: <30}")
_LOGGER.info(f"event={hook_name}")

Change-Id: Ifca5e8885cdf0a3ac0f10f925c5415e83bdda721

def test_is_subtype_of_pytorch_lightning_callback():
"""Verify inheritance to ensure compatibility with PyTorch Lightning."""
# assert issubclass(MLFlashpointCheckpointCallback, pl.callbacks.Callback)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can remove this commented out line

"""
Tests that every lifecycle hook in StepTimerCallback logs the correct event.
"""

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can add "# Given # When # Then" comments to highlight different parts of the test. setup, execution, assertions. makes it easier to see what is being asserted and which parts are just setup vs execution

@@ -0,0 +1,162 @@
# Copyright 2025 Google LLC
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can prob stay as 2026? same for the other file

_LOGGER = get_logger(__name__)


class StepTimerCallback(pl_callbacks.Callback):
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe renaming to EventLoggingCallback, since it isnt timing anything, and is just logging every event. should update test file/code accordingly

@g-husam g-husam changed the title feat: add StepTimerCallback for lifecycle monitoring feat(adapter/nemo): add StepTimerCallback for lifecycle monitoring Feb 9, 2026
@g-husam g-husam changed the title feat(adapter/nemo): add StepTimerCallback for lifecycle monitoring feat(adapter/nemo): add EventLoggerCallback for lifecycle monitoring Feb 9, 2026
@g-husam g-husam changed the title feat(adapter/nemo): add EventLoggerCallback for lifecycle monitoring feat(adapter/nemo): add EventLoggingCallback for lifecycle monitoring Feb 9, 2026
…omments

Change-Id: Ibaa19a73eeccd19f5ef46a5d620c862c7cfd0fe8
@kkkapu kkkapu merged commit 06ebcbf into main Feb 9, 2026
5 of 12 checks passed
@kkkapu kkkapu deleted the step_callback branch February 9, 2026 17:45
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.

2 participants