Lightning-AI / Lightning-AI/pytorch-lightning
Automated metric logging in Lightning Trainer
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
### Description & Motivation
As described in [the docs](https://torchmetrics.readthedocs.io/en/stable/pages/lightning.html), you need to define log statements for each of your metrics in your LightningModule to collect this data during training. Personally I have never created any custom logging metric, and always log fairly standard metrics (accuracy, F1, etc.) for training and validation (on an epoch-level or step-interval-leval basis). This introduces the following repetitive code in my model module for both training and validation:
- Definition of the metrics
- Logging to the metrics on step
- Logging to the metrics on epoch
### Pitch
From my perspective, there could be merit in a `metrics` argument of type `Optional[Union[Metric, Iterable[Metric]]]` that is passed to the `Trainer` object and collects these metrics on a per-epoch or per-step-interval basis for both training and validation. This would give the user the possibility to abstract away the the logging of metrics for the most common usecases to inside the trainer class and not left to the user.
### Alternatives
_No response_
### Additional context
_No response_
cc @borda
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Trainer and LightningModule entry points, along with the linked TorchMetrics Lightning documentation. Define the expected metrics argument and its training and validation logging behavior, including epoch and step intervals, then add tests showing that the requested metrics are collected automatically.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100