Lightning-AI / Lightning-AI/pytorch-lightning
LightningCLI: limit the output of known subclasses for better readability
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
The output of ` --help` is populated with all known subclasses based on the docstring's type hints. As it can be seen in the following MWE, this can span multiple lines/pages in a terminal which IMHO limits readability.
It would be great if this output for subclasses could somehow be suppressed (either partially or completely).
```python
# main.py
import lightning as L
import torch
from lightning.pytorch.cli import LightningCLI
class LitModel(L.LightningModule):
def __init__(self, model: torch.nn.Module):
super().__init__()
self.model = model
def forward(self, x):
return self.model(x)
def configure_optimizers(self):
return torch.optim.Adam(self.parameters())
def cli_main():
return LightningCLI(LitModel)
def cli_main():
cli = LightningCLI(LitModel)
# note: don't call fit!!
if __name__ == "__main__":
cli_main()
# note: it is good practice to implement the CLI in a function and call it in the main if block
```
```
python main.py fit --help
```
And the output is:
```
...
--model.model MODEL (required, type: , known subclasses: torch.nn.Module, torch.nn.Identity, torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear,
torch.nn.LazyLinear, torch.ao.nn.qat.Linear, torch.ao.nn.intrinsic.qat.LinearReLU, torch.ao.nn.qat.dynamic.Linear, torch.ao.nn.intrinsic.qat.LinearBn1d,
torch.ao.nn.quantized.reference.Linear, torch.nn.Bilinear, torch.nn.Threshold, torch.nn.ReLU, torch.ao.nn.quantized.ReLU6, torch.nn.RReLU, torch.nn.Hardtanh,
torch.nn.ReLU6, torch.nn.Sigmoid, torch.ao.nn.quantized.Sigmoid, torch.nn.Hardsigmoid, torch.nn.Tanh, torch.nn.SiLU, torch.nn.Mish, torch.nn.Hardswish,
torch.ao.nn.quantized.Hardswish, torch.nn.ELU, torch.ao.nn.quantized.ELU, torch.nn.CELU, torch.nn.SELU, torch.nn.GLU, torch.nn.GELU, torch.nn.Hardshrink,
torch.nn.LeakyReLU, torch.ao.nn.quantized.LeakyReLU, torch.nn.LogSigmoid, torch.nn.Softplus, torch.nn.Softshrink, torch.nn.MultiheadAttention,
(many more modules are shown here)
...
```
### Pitch
_No response_
### Alternatives
_No response_
### Additional context
_No response_
cc @lantiga @borda @mauvilsa
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
Reproduce the issue with main.py and `python main.py fit --help`, using the LightningCLI entry point shown in the report. Trace how help output is generated for the model type and known subclasses, then verify that the resulting help text limits or suppresses that list without removing the rest of the option information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100