Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

LightningCLI: limit the output of known subclasses for better readability #20591

Open
adosar opened this issue Feb 15, 2025 · 1 comment
Open
Labels
feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers

Comments

@adosar
Copy link
Contributor

adosar commented Feb 15, 2025

Description & Motivation

The output of <subcommand> --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).

# 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: <class 'Module'>, 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

@adosar adosar added feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers labels Feb 15, 2025
adosar added a commit to adosar/aidsorb that referenced this issue Feb 15, 2025
Previously was set to `Callable` for clarity in terminal (see 045c227).
For sake of consistency, it is now set to `Module`.

See also: Lightning-AI/pytorch-lightning#20591
@AmanSCoder
Copy link

I can work on this. Can anyone please assign this issue to me?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants