Skip to content

Add log_key_prefix parameter to LearningRateMonitor#21612

Merged
tchaton merged 4 commits intoLightning-AI:masterfrom
Krishnachaitanyakc:feature/21590_lr-monitor-log-key-prefix
Apr 1, 2026
Merged

Add log_key_prefix parameter to LearningRateMonitor#21612
tchaton merged 4 commits intoLightning-AI:masterfrom
Krishnachaitanyakc:feature/21590_lr-monitor-log-key-prefix

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor

@Krishnachaitanyakc Krishnachaitanyakc commented Mar 25, 2026

What does this PR do?

Adds a log_key_prefix parameter to the LearningRateMonitor callback, allowing users to prepend a configurable prefix to all logged metric names (learning rate, momentum, weight decay). This is useful for grouping learning rate metrics in loggers like TensorBoard.

Example:

lr_monitor = LearningRateMonitor(log_key_prefix="optim/")
# Logs "optim/lr-Adam" instead of "lr-Adam"

Fixes #21590

Changes

  • src/lightning/pytorch/callbacks/lr_monitor.py: Added log_key_prefix parameter to __init__ and applied the prefix in _check_duplicates_and_update_name so it flows consistently through all metric keys (self.lrs, self.last_momentum_values, self.last_weight_decay_values, and logged metrics)
  • tests/tests_pytorch/callbacks/test_lr_monitor.py: Added 4 test cases covering prefix with single optimizer, with momentum/weight_decay, with multiple optimizers, and with None (default behavior)
  • src/lightning/pytorch/CHANGELOG.md: Added entry under [unreleased]
Before submitting
  • Was this discussed/agreed via a GitHub issue? (prerfix for metric names the LearningRateMonitor #21590, maintainer @justusschock invited a PR)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (docstring updated)
  • Did you write any new necessary tests? (4 new tests)
  • Did you verify new and existing tests pass locally with your changes? (24 passed, 1 skipped)
  • Did you update the CHANGELOG?

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--21612.org.readthedocs.build/en/21612/

Allow users to prepend a configurable prefix to all metric names logged
by `LearningRateMonitor`. This is useful for grouping learning rate
metrics in loggers like TensorBoard (e.g., `optim/lr-Adam` instead of
`lr-Adam`).

Fixes Lightning-AI#21590
@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Mar 25, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79%. Comparing base (612ab08) to head (451716a).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

❗ There is a different number of reports uploaded between BASE (612ab08) and HEAD (451716a). Click for more details.

HEAD has 920 uploads less than BASE
Flag BASE (612ab08) HEAD (451716a)
cpu 251 42
lightning_fabric 80 0
pytest 125 0
python3.12 72 12
python 18 3
lightning 90 15
python3.11 36 6
python3.13 53 9
python3.12.7 54 9
python3.10 18 3
pytorch_lightning 81 27
pytorch2.7 9 3
pytest-full 126 42
pytorch2.1 18 6
pytorch2.4.1 9 3
pytorch2.5.1 9 3
pytorch2.2.2 9 3
pytorch2.9 18 6
pytorch2.10 18 6
pytorch2.8 18 6
pytorch2.3 9 3
pytorch2.6 9 3
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #21612     +/-   ##
=========================================
- Coverage      87%      79%     -8%     
=========================================
  Files         270      267      -3     
  Lines       23898    23843     -55     
=========================================
- Hits        20678    18769   -1909     
- Misses       3220     5074   +1854     

Comment thread src/lightning/pytorch/CHANGELOG.md Outdated
@tchaton tchaton merged commit d3b25f8 into Lightning-AI:master Apr 1, 2026
106 of 107 checks passed
bhimrazy pushed a commit to bhimrazy/pytorch-lightning that referenced this pull request Apr 13, 2026
…#21612)

* Add `log_key_prefix` parameter to `LearningRateMonitor` callback

Allow users to prepend a configurable prefix to all metric names logged
by `LearningRateMonitor`. This is useful for grouping learning rate
metrics in loggers like TensorBoard (e.g., `optim/lr-Adam` instead of
`lr-Adam`).

Fixes Lightning-AI#21590

* Update src/lightning/pytorch/CHANGELOG.md

---------

Co-authored-by: Deependu <deependujha21@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pl Generic label for PyTorch Lightning package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prerfix for metric names the LearningRateMonitor

3 participants