Repository: Lightning-AI/pytorch-lightning
File: pytorch_lightning/core/lightning.py (Python)

Code before:
            else:
                raise ValueError(f"The 'method' parameter only supports 'script' or 'trace', but value given was:"
                                 f"{method}")
        self.train(mode)

        if file_path is not None:
            torch.jit.save(torchscript_module, file_path)

        return torchscript_module

    def add_datamodule_hparams(self, datamodule: LightningDataModule):
        """Add the hparams of a LightningDataModule to the hparams and hparams_initial of this module."""
        if not hasattr(datamodule, 'hparams'):
            return

        hparams = self._to_hparams_dict(datamodule.hparams)
        if not hasattr(self, '_hparams'):
            self._hparams = hparams
            self._hparams_initial = hparams
        else:
            colliding_keys = [key for key in hparams.keys() if key in self.hparams]
            colliding_keys += [key for key in hparams.keys() if key in self.hparams_initial]
            colliding_keys = set(colliding_keys)
            if colliding_keys:
                raise ValueError(f'Error while adding datamodule hparams: '
                                 f'the keys {colliding_keys} are already present in the model hparams.')
            self.hparams.update(hparams)
            self._hparams_initial.update(hparams)


Review comment (suggestion):
```suggestion
                raise ValueError(
                    f'Error while adding datamodule hparams: the keys {colliding_keys} are already present in the model hparams.'
                )
```

Code after:
                    f"Argument `mode` in `LightningModule.summarize` is deprecated in v1.4"
                    f" and will be removed in v1.6. Use `max_depth={max_depth}` to replicate `mode={mode}` behavior."
                )
                model_summary = ModelSummary(self, max_depth=max_depth)
            elif mode is not None:
                raise MisconfigurationException(f"`mode` can be None, {', '.join(ModelSummary.MODES)}, got {mode}")
        else:
            model_summary = ModelSummary(self, max_depth=max_depth)

        log.info("\n" + str(model_summary))
        return model_summary

    def freeze(self) -> None:
        r"""
        Freeze all params for inference.

        Example::

            model = MyLightningModule(...)
            model.freeze()

        """
        for param in self.parameters():
            param.requires_grad = False

        self.eval()

    def unfreeze(self) -> None:
        """
        Unfreeze all parameters for training.

        .. code-block:: python

            model = MyLightningModule(...)
            model.unfreeze()

        """
        for param in self.parameters():
            param.requires_grad = True

        self.train()

    def get_progress_bar_dict(self) -> Dict[str, Union[int, str]]:
        r"""
        Implement this to override the default items displayed in the progress bar.
        By default it includes the average loss value, split index of BPTT (if used)
        and the version of the experiment when using a logger.

        .. code-block::

            Epoch 1:   4%|▎         | 40/1095 [00:03<01:37, 10.84it/s, loss=4.501, v_num=10]