Lightning-AI / Lightning-AI/pytorch-lightning

Feature Request : Gradient Statistics Monitoring Callback

Open
#21,589 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

callback feature
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

Description & Motivation

While PyTorch Lightning provides useful callbacks for monitoring learning rates, device statistics, and throughput, there is currently no built-in utility for tracking gradient behavior.

Having access to gradient statistics (e.g., norm, mean, variance, sparsity) can significantly help in debugging training instability, tune hyperparameters, and better understand model behavior.

Pitch

I propose adding a GradientStatsMonitor callback that logs gradient-related statistics during training.

The callback could:

  • Compute global gradient norm across all parameters
  • Optionally compute per-layer gradient norms
  • Track basic statistics such as mean, standard deviation, and fraction of near-zero gradients
  • Log metrics through the existing Lightning logger interface
  • Optionally provide warnings for potential issues (e.g., exploding or vanishing gradients)
Alternatives

No response

Additional context

No response

cc @lantiga

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing callbacks for learning-rate, device-statistics, and throughput monitoring, then inspect the Lightning logger interface mentioned in the proposal. Define the scope for global and per-layer gradient statistics, optional warnings, and logging behavior before implementation; done means the callback supports the agreed metrics and integrates with the existing logger.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.