-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Lightning Logging without Trainer #8509
Comments
I don't quite understand the motivation. Are you saying that new users would:
So you want to be able to Another challenge associated is that the following prog_bar: bool = False, # callbacks are managed by the trainer
logger: bool = True, # loggers are managed by the trainer
sync_dist: bool = False, # would require the user to handle the training type setup
sync_dist_group: Optional[Any] = None,
add_dataloader_idx: bool = True, # not necessary without a trainer that would add it automatically
rank_zero_only: Optional[bool] = None, Also, the user would need to update their training loop with all the logic we currently encode in the |
@carmocca - one idea is that the LightningModule directly owns the results as a buffer. We could offer an abstract interface for this. Some requirements:
For example, ResultsCollection could be considered one implementation of this interface, and perhaps its the default one the trainer uses in case the user doesn't provide their own. Then calling self.log(...) in the LightningModule simply populates this buffer. Log carries forward much of the assumptions around the prior Results struct, which itself was introduced in Lightning 0.7 or 0.8, before torchmetrics even existed. Since then, I think torchmetrics encapsulates the metric updates, syncing, and compute much much better! And it'll get even better after Lightning-AI/torchmetrics#344 Given all of the nice utilities of torchmetrics, the metric updates and syncing ideally should be handled as part of these metric classes and not as part of the logging. For example, if people are logging arbitrary float values, I think users ought to wrap these in utilities like https://github.com/PyTorchLightning/metrics/blob/master/torchmetrics/average.py What I think self.log in the lightning module ought to be responsible for is determining which destinations the value should be made available to (e.g. loggers, prog bar, callbacks, etc) Because the Trainer is the entity calling all the hooks in the LightningModule, it can inspect this buffer after every hook is called and make the log data available to its components. E.g. publish to logger connector The logger connector can then inspect the destinations for the log entry, and populate the corresponding metrics entries (e.g. progress_bar_metrics, callback_metrics, logged_metrics). https://github.com/PyTorchLightning/pytorch-lightning/blob/e1442d247e0e4967dd2772bdcf5166226c974f89/pytorch_lightning/trainer/properties.py#L631-L646 (separately, since progress bar is a callback, do we really need both progress bar and callback metrics?) @edward-io and I are interested in pursuing a POC for this. we'll write up a doc to discuss this proposal in more detail |
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team! |
I have another use-case for this: unit-testing an existing LightningModule. In our code, we have some
In Lightning 1.4, this fails because the module isn't attached to a trainer. |
I guess for that case in particular, we could convert to a warning + early return |
Hello, replying to #9716 (comment) That was a just mwe. My use case is to write unit tests for different methods of the model ( Another use case I am having problems with is benchmarking the def module_step_approximation(_):
module.zero_grad()
loss = module.training_step(batch, 0)
loss.backward() |
Dear @lucmos, One could patch the log function from the LightningModule to prevent the logging computation to be accounted for speed benchmarking. Best, |
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team! |
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team! |
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team! |
🚀 Feature
Motivation
To ease conversion from pure PyTorch to Lightning, users might start by creating their LightningModule.
However, their code would break if they try to log as the trainer isn't available.
Currently, we have 2 options:
self.log
in the absence of a TrainerHere is a pseudo code to explain how we could support it.
The
ResultCollection
object is pretty self contained and is used to store logged values.Drawback, every LightningModule hooks used for logging should be wrapped to set the
_current_fx
function.Pitch
Alternatives
Additional context
If you enjoy PL, check out our other projects:
cc @Borda @tchaton @justusschock @awaelchli @rohitgr7 @akihironitta @carmocca @edward-io @ananthsub @kamil-kaczmarek @Raalsky @Blaizzy
The text was updated successfully, but these errors were encountered: