climart/utils/utils.py
def log_hyperparameters(
        config,
        model: pl.LightningModule,
        data_module: pl.LightningDataModule,
        trainer: pl.Trainer,
        callbacks: List[pl.Callback],
) -> None:
    """This method controls which parameters from Hydra config are saved by Lightning loggers.
    Credits go to: https://github.com/ashleve/lightning-hydra-template

    Additionally saves:
        - number of {total, trainable, non-trainable} model parameters
    """

    def copy_and_ignore_keys(dictionary, *keys_to_ignore):
        new_dict = dict()
        for k in dictionary.keys():
            if k not in keys_to_ignore:
                new_dict[k] = dictionary[k]
        return new_dict

    params = dict()
    if 'seed' in config:
        params['seed'] = config['seed']
    if 'model' in config:
        params['model'] = config['model']

    # Remove redundant keys or those that are not important to know after training -- feel free to edit this!
    params["datamodule"] = copy_and_ignore_keys(config["datamodule"], 'pin_memory', 'num_workers')
    params['model'] = config['model']
    params["trainer"] = copy_and_ignore_keys(config["trainer"])
    # encoder, optims, and scheduler as separate top-level key
    params['optim'] = config['model']['optim']
    params['scheduler'] = config['model']['scheduler'] if 'scheduler' in config['model'] else None

    if "callbacks" in config:
        if 'model_checkpoint' in config['callbacks']:
            params["model_checkpoint"] = copy_and_ignore_keys(
                config["callbacks"]['model_checkpoint'], 'save_top_k'
            )

    # save number of model parameters
    params["model/params_total"] = sum(p.numel() for p in model.parameters())
    params["model/params_trainable"] = sum(
        p.numel() for p in model.parameters() if p.requires_grad
    )
    params["model/params_not_trainable"] = sum(
        p.numel() for p in model.parameters() if not p.requires_grad
    )

    # send hparams to all loggers
    trainer.logger.log_hyperparams(params)

    # disable logging any more hyperparameters for all loggers
    # this is just a trick to prevent trainer from logging hparams of model,
    # since we already did that above
    trainer.logger.log_hyperparams = no_op
This method controls which parameters from Hydra config are saved by Lightning loggers.
    Credits go to: https://github.com/ashleve/lightning-hydra-template

    Additionally saves:
        - number of {total, trainable, non-trainable} model parameters
    
This method controls which parameters from Hydra config are saved by Lightning loggers.

Additionally saves:
number of {total, trainable, non-trainable} model parameters
This method controls which parameters from Hydra config are saved by Lightning loggers . Additionally saves : number of { total trainable non - trainable } model parameters
def log_hyperparameters(
        config,
        model: pl.LightningModule,
        data_module: pl.LightningDataModule,
        trainer: pl.Trainer,
        callbacks: List[pl.Callback],
) -> None:
    def copy_and_ignore_keys(dictionary, *keys_to_ignore):
        new_dict = dict()
        for k in dictionary.keys():
            if k not in keys_to_ignore:
                new_dict[k] = dictionary[k]
        return new_dict
    params = dict()
    if 'seed' in config:
        params['seed'] = config['seed']
    if 'model' in config:
        params['model'] = config['model']
    params["datamodule"] = copy_and_ignore_keys(config["datamodule"], 'pin_memory', 'num_workers')
    params['model'] = config['model']
    params["trainer"] = copy_and_ignore_keys(config["trainer"])
    params['optim'] = config['model']['optim']
    params['scheduler'] = config['model']['scheduler'] if 'scheduler' in config['model'] else None
    if "callbacks" in config:
        if 'model_checkpoint' in config['callbacks']:
            params["model_checkpoint"] = copy_and_ignore_keys(
                config["callbacks"]['model_checkpoint'], 'save_top_k'
            )
    params["model/params_total"] = sum(p.numel() for p in model.parameters())
    params["model/params_trainable"] = sum(
        p.numel() for p in model.parameters() if p.requires_grad
    )
    params["model/params_not_trainable"] = sum(
        p.numel() for p in model.parameters() if not p.requires_grad
    )
    trainer.logger.log_hyperparams(params)
    trainer.logger.log_hyperparams = no_op
def log_hyperparameters ( config , model : pl . LightningModule , data_module : pl . LightningDataModule , trainer : pl . Trainer , callbacks : List [ pl . Callback ] , ) -> None : def copy_and_ignore_keys ( dictionary , * keys_to_ignore ) : new_dict = dict ( ) for k in dictionary . keys ( ) : if k not in keys_to_ignore : new_dict [ k ] = dictionary [ k ] return new_dict params = dict ( ) if 'seed' in config : params [ 'seed' ] = config [ 'seed' ] if 'model' in config : params [ 'model' ] = config [ 'model' ] params [ "datamodule" ] = copy_and_ignore_keys ( config [ "datamodule" ] , 'pin_memory' , 'num_workers' ) params [ 'model' ] = config [ 'model' ] params [ "trainer" ] = copy_and_ignore_keys ( config [ "trainer" ] ) params [ 'optim' ] = config [ 'model' ] [ 'optim' ] params [ 'scheduler' ] = config [ 'model' ] [ 'scheduler' ] if 'scheduler' in config [ 'model' ] else None if "callbacks" in config : if 'model_checkpoint' in config [ 'callbacks' ] : params [ "model_checkpoint" ] = copy_and_ignore_keys ( config [ "callbacks" ] [ 'model_checkpoint' ] , 'save_top_k' ) params [ "model/params_total" ] = sum ( p . numel ( ) for p in model . parameters ( ) ) params [ "model/params_trainable" ] = sum ( p . numel ( ) for p in model . parameters ( ) if p . requires_grad ) params [ "model/params_not_trainable" ] = sum ( p . numel ( ) for p in model . parameters ( ) if not p . requires_grad ) trainer . logger . log_hyperparams ( params ) trainer . logger . log_hyperparams = no_op
This method controls which parameters from Hydra config are saved by Lightning loggers.
This method controls which parameters from Hydra config are saved by Lightning loggers .
"""This method controls which parameters from Hydra config are saved by Lightning loggers.
    Credits go to: https://github.com/ashleve/lightning-hydra-template

    Additionally saves:
        - number of {total, trainable, non-trainable} model parameters
    """ # Remove redundant keys or those that are not important to know after training -- feel free to edit this! # encoder, optims, and scheduler as separate top-level key # save number of model parameters # send hparams to all loggers # disable logging any more hyperparameters for all loggers # this is just a trick to prevent trainer from logging hparams of model, # since we already did that above
config
model
pl.LightningModule
data_module
pl.LightningDataModule
trainer
pl.Trainer
callbacks
List[pl.Callback]