Repository: Lightning-AI/pytorch-lightning
Issue category: Feature Request

Issue:
Proposal(CLI): after_instantiate_classes hook
### Description & Motivation

Adds a `after_instantiate_classes` hook to the Lightning CLI, called after `self.instantiate_classes()` during the initalization of `LightningCLI`.

### Pitch

While having the Lightning CLI is great, it is not perfect for each use case out-of-the-box. Hence, you included hooks like `before_instantiate_classes` and describe in the docs how to extend the CLI. Problem is, you cannot extend this feature without hacks or substantial copy-pasta.

I think, to further improve the CLI, without adding any complexity, it makes sense to add a `after_instantiate_classes` hook, too.

### Alternatives

1. Hacks
 - Extend the Lightning CLI and run the `after_instantiate_classes` function before the `self._run_subcommand` function.
 - Problems: it's not intuitive that the function is called there, won't be called if `self.subcommand is None`
2. Copy-Pasta
 - Extend the Lightning CLI and replace the original `__init__` with the proposed one.
 - Problems: could break with any update, lots of code duplication


### Additional context

_No response_

cc @borda @tchaton @justusschock @awaelchli @mauvilsa


Hints:

Patch:
diff --git a/src/lightning/pytorch/cli.py b/src/lightning/pytorch/cli.py
index 26af335f7be93..e0de8a24b38f5 100644
--- a/src/lightning/pytorch/cli.py
+++ b/src/lightning/pytorch/cli.py
@@ -389,6 +389,7 @@ def __init__(
         self._add_instantiators()
         self.before_instantiate_classes()
         self.instantiate_classes()
+        self.after_instantiate_classes()
 
         if self.subcommand is not None:
             self._run_subcommand(self.subcommand)
@@ -560,6 +561,9 @@ def instantiate_classes(self) -> None:
         self._add_configure_optimizers_method_to_model(self.subcommand)
         self.trainer = self.instantiate_trainer()
 
+    def after_instantiate_classes(self) -> None:
+        """Implement to run some code after instantiating the classes."""
+
     def instantiate_trainer(self, **kwargs: Any) -> Trainer:
         """Instantiates the trainer.
 


Test patch: