feat: Log key prefix controls for Trainer, WandbLogger, and CometLogger #21783
feat: Log key prefix controls for Trainer, WandbLogger, and CometLogger #21783pupeno wants to merge 1 commit into
Conversation
Adds three independent parameters that let users control the metric keys generated by Lightning's own components, without touching user-provided metric names: - `Trainer(log_key_prefix=...)`: prefixes Trainer-generated metric keys. Currently the only such key is the automatic `epoch` metric injected into every logging step. Default `None`/`""` preserves current behavior. - `WandbLogger(log_key_prefix=...)`: controls the W&B-generated step key used in `define_metric` and `experiment.log`. Previously hardcoded to `"trainer/global_step"`; now configurable, defaulting to `"global_step"`. The existing `prefix=` argument is unchanged and continues to apply only to incoming/pass-through metric keys. - `CometLogger(epoch_key=...)`: controls which incoming metric key is popped and forwarded to Comet's dedicated `epoch=` argument. Previously hardcoded to `"epoch"`. `None` disables epoch extraction entirely. The design principle is: each `log_key_prefix` (or `epoch_key`) applies only to keys *generated by that component*, never to keys the user logged via `self.log(...)` or `logger.log_metrics(...)`. This makes it straightforward to align all Lightning-generated keys under a shared namespace. For example: ```python Trainer(log_key_prefix="trainer/") WandbLogger(log_key_prefix="trainer/") CometLogger(epoch_key="trainer/epoch") ```
|
Thanks for the thorough proposal and PR, the namespace inconsistency you're describing is real, and the Trainer-side piece is clean. Would you be open to splitting this into two PRs? I think it'll move faster: PR 1: Trainer only. The PR 2: per-logger keys. Each logger's handling of the keys it injects itself. Those touch logger files and need the respective codeowners, so keeping them separate avoids blocking the Trainer change on that review. If you split it, the Trainer PR should be straightforward to land. Thanks again. |
|
Ah, yes, that makes sense. I'll have it in a moment. Do you want me to create separate github issues or only separate PRs? |
|
Here are the PRs. I can also create the github issues if you want: |
|
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #21783 +/- ##
=========================================
- Coverage 87% 79% -8%
=========================================
Files 270 267 -3
Lines 24005 23950 -55
=========================================
- Hits 20776 18825 -1951
- Misses 3229 5125 +1896 |
What does this PR do?
Fixes #21782
Adds three independent parameters that let users control the metric keys generated by Lightning's
own components, without touching user-provided metric names:
Trainer(log_key_prefix=...): prefixes Trainer-generated metric keys. Currently the only suchkey is the automatic
epochmetric injected into every logging step. DefaultNone/""preserves previous behaviour.
WandbLogger(log_key_prefix=...): controls the W&B-generated step key used indefine_metricand
experiment.log. Previously hardcoded to"trainer/global_step"; now configurable,defaulting to
"global_step". The existingprefix=argument is unchanged and continues toapply only to pass-through metric keys.
CometLogger(epoch_key=...): controls which incoming metric key is extracted and forwarded toComet's dedicated
epoch=argument. Previously hardcoded to"epoch".Nonedisables epochextraction entirely. Default
"epoch"preserves previous behaviour.The design principle: each
log_key_prefix(orepoch_key) applies only to keys generated bythat component, never to keys the user logged via
self.log(...)orlogger.log_metrics(...).This makes it straightforward to align all Lightning-generated keys under a shared namespace:
Breaking change:
WandbLoggerpreviously hardcoded"trainer/global_step"as the step axiskey. With this PR, the default is bare
"global_step". Passlog_key_prefix="trainer/"torestore the previous behaviour.
Before submitting
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