Skip to content

Commit

Permalink
Add version header to CLI config files (#12532)
Browse files Browse the repository at this point in the history
  • Loading branch information
carmocca authored Apr 7, 2022
1 parent 868c94c commit 124b529
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
-


-
- Include the `pytorch_lightning` version as a header in the CLI config files ([#12532](https://github.com/PyTorchLightning/pytorch-lightning/pull/12532))


-
Expand Down
1 change: 1 addition & 0 deletions pytorch_lightning/utilities/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ def _setup_parser_kwargs(

def init_parser(self, **kwargs: Any) -> LightningArgumentParser:
"""Method that instantiates the argument parser."""
kwargs.setdefault("dump_header", [f"pytorch_lightning=={pl.__version__}"])
return LightningArgumentParser(**kwargs)

def setup_parser(
Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/utilities/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _compare_version(package: str, op: Callable, version: str, use_base_version:
_HOROVOD_AVAILABLE = _module_available("horovod.torch")
_HYDRA_AVAILABLE = _package_available("hydra")
_HYDRA_EXPERIMENTAL_AVAILABLE = _module_available("hydra.experimental")
_JSONARGPARSE_AVAILABLE = _package_available("jsonargparse") and _compare_version("jsonargparse", operator.ge, "4.3.0")
_JSONARGPARSE_AVAILABLE = _package_available("jsonargparse") and _compare_version("jsonargparse", operator.ge, "4.5.0")
_KINETO_AVAILABLE = _TORCH_GREATER_EQUAL_1_8_1 and torch.profiler.kineto_available()
_NEPTUNE_AVAILABLE = _package_available("neptune")
_NEPTUNE_GREATER_EQUAL_0_9 = _NEPTUNE_AVAILABLE and _compare_version("neptune", operator.ge, "0.9.0")
Expand Down
2 changes: 1 addition & 1 deletion requirements/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ horovod>=0.21.2,!=0.24.0 # no need to install with [pytorch] as pytorch is alre
torchtext>=0.9.*
omegaconf>=2.0.5
hydra-core>=1.0.5
jsonargparse[signatures]>=4.3.0
jsonargparse[signatures]>=4.5.0
gcsfs>=2021.5.0
rich>=10.2.2,!=10.15.*
8 changes: 6 additions & 2 deletions tests/utilities/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from torch.optim import SGD
from torch.optim.lr_scheduler import ReduceLROnPlateau, StepLR

from pytorch_lightning import Callback, LightningDataModule, LightningModule, Trainer
from pytorch_lightning import __version__, Callback, LightningDataModule, LightningModule, Trainer
from pytorch_lightning.callbacks import LearningRateMonitor, ModelCheckpoint
from pytorch_lightning.loggers import LightningLoggerBase, TensorBoardLogger
from pytorch_lightning.plugins.environments import SLURMEnvironment
Expand Down Expand Up @@ -458,7 +458,11 @@ def test_lightning_cli_print_config():
with mock.patch("sys.argv", cli_args), redirect_stdout(out), pytest.raises(SystemExit):
any_model_any_data_cli()

outval = yaml.safe_load(out.getvalue())
text = out.getvalue()
# test dump_header
assert text.startswith(f"# pytorch_lightning=={__version__}")

outval = yaml.safe_load(text)
assert outval["seed_everything"] == 1234
assert outval["model"]["class_path"] == "tests.helpers.BoringModel"
assert outval["data"]["class_path"] == "tests.helpers.BoringDataModule"
Expand Down

0 comments on commit 124b529

Please sign in to comment.