Skip to content

LightningCLI access DataModule methods in model constructor #13403

Discussion options

You must be logged in to vote

For this you use link_arguments which requires to subclass LightningCLI. Something like:

class MyLightningModule(LightningModule):
    def __init__(self, input_dim: int):
        ...

class MyCLI(LightningCLI):
    def add_arguments_to_parser(self, parser):
        parser.link_arguments('data.input_dim', 'model.input_dim', apply_on='instantiate')

It might also be possible like your second example linking the entire data object. Though this needs the latest version of jsonargparse:

class MyLightningModule(pl.LightningModule):
    def __init__(self, data: BigVulDatasetLineVDDataModule):
        self.data = data
        # instantiate model...

class MyCLI(LightningCLI):
    def add_arguments…

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
1 reply
@bstee615
Comment options

Answer selected by bstee615
Comment options

You must be logged in to vote
8 replies
@terbed
Comment options

@calvinshopify
Comment options

@calvinshopify
Comment options

@mauvilsa
Comment options

@calvinshopify
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lightningcli pl.cli.LightningCLI pl Generic label for PyTorch Lightning package
5 participants