diff --git a/.actions/assistant.py b/.actions/assistant.py index 41002ee5f5e45..47a0543f228ad 100644 --- a/.actions/assistant.py +++ b/.actions/assistant.py @@ -502,21 +502,6 @@ def generate_docker_tags( if __name__ == "__main__": - import sys - import jsonargparse - from jsonargparse import ArgumentParser - - def patch_jsonargparse_python_3_12_8(): - if sys.version_info < (3, 12, 8): - return - - def _parse_known_args_patch(self: ArgumentParser, args: Any = None, namespace: Any = None) -> tuple[Any, Any]: - namespace, args = super(ArgumentParser, self)._parse_known_args(args, namespace, intermixed=False) # type: ignore - return namespace, args - - setattr(ArgumentParser, "_parse_known_args", _parse_known_args_patch) - - patch_jsonargparse_python_3_12_8() # Required until fix https://github.com/omni-us/jsonargparse/issues/641 jsonargparse.CLI(AssistantCLI, as_positional=False) diff --git a/.actions/requirements.txt b/.actions/requirements.txt index 4b5cc8d568c02..44548c1e0a370 100644 --- a/.actions/requirements.txt +++ b/.actions/requirements.txt @@ -1,3 +1,3 @@ -jsonargparse >=4.16.0, <4.28.0 +jsonargparse >=4.16.0, <=4.35.0 requests packaging diff --git a/.azure/gpu-benchmarks.yml b/.azure/gpu-benchmarks.yml index 6825850ae01bd..82ee475d53d31 100644 --- a/.azure/gpu-benchmarks.yml +++ b/.azure/gpu-benchmarks.yml @@ -77,7 +77,7 @@ jobs: - bash: | pip install -e .[dev] --find-links ${TORCH_URL} - pip install setuptools==75.6.0 + pip install setuptools==75.6.0 jsonargparse==4.35.0 env: FREEZE_REQUIREMENTS: "1" displayName: "Install package" diff --git a/.azure/gpu-tests-fabric.yml b/.azure/gpu-tests-fabric.yml index 9d7514f285bda..0d970a552cecc 100644 --- a/.azure/gpu-tests-fabric.yml +++ b/.azure/gpu-tests-fabric.yml @@ -107,7 +107,7 @@ jobs: - bash: | extra=$(python -c "print({'lightning': 'fabric-'}.get('$(PACKAGE_NAME)', ''))") pip install -e ".[${extra}dev]" pytest-timeout -U --find-links="${TORCH_URL}" --find-links="${TORCHVISION_URL}" - pip install setuptools==75.6.0 + pip install setuptools==75.6.0 jsonargparse==4.35.0 displayName: "Install package & dependencies" - bash: | diff --git a/.azure/gpu-tests-pytorch.yml b/.azure/gpu-tests-pytorch.yml index b48961c7f3a26..e09ad011908cb 100644 --- a/.azure/gpu-tests-pytorch.yml +++ b/.azure/gpu-tests-pytorch.yml @@ -111,7 +111,7 @@ jobs: - bash: | extra=$(python -c "print({'lightning': 'pytorch-'}.get('$(PACKAGE_NAME)', ''))") pip install -e ".[${extra}dev]" pytest-timeout -U --find-links="${TORCH_URL}" --find-links="${TORCHVISION_URL}" - pip install setuptools==75.6.0 + pip install setuptools==75.6.0 jsonargparse==4.35.0 displayName: "Install package & dependencies" - bash: pip uninstall -y lightning diff --git a/.github/workflows/ci-tests-fabric.yml b/.github/workflows/ci-tests-fabric.yml index c2fda73dcf1f4..c6d1dbf5b5ff2 100644 --- a/.github/workflows/ci-tests-fabric.yml +++ b/.github/workflows/ci-tests-fabric.yml @@ -49,16 +49,16 @@ jobs: - { os: "macOS-14", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" } - { os: "ubuntu-20.04", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" } - { os: "windows-2022", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" } - - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" } - - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" } - - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" } - - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" } + - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" } + - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" } + - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" } + - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" } # only run PyTorch latest with Python latest, use Fabric scope to limit dependency issues - - { os: "macOS-14", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "ubuntu-22.04", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "windows-2022", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" } + - { os: "macOS-14", pkg-name: "fabric", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "ubuntu-22.04", pkg-name: "fabric", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "windows-2022", pkg-name: "fabric", python-version: "3.12.7", pytorch-version: "2.5.1" } # "oldest" versions tests, only on minimum Python - { os: "macOS-14", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" } - { diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index ba8519ea8ed8a..0112d21d33a5c 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -53,16 +53,16 @@ jobs: - { os: "macOS-14", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" } - { os: "ubuntu-20.04", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" } - { os: "windows-2022", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" } - - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" } - - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" } - - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" } - - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" } + - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" } + - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" } + - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" } + - { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" } # only run PyTorch latest with Python latest, use PyTorch scope to limit dependency issues - - { os: "macOS-14", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" } - - { os: "windows-2022", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" } + - { os: "macOS-14", pkg-name: "pytorch", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.12.7", pytorch-version: "2.5.1" } + - { os: "windows-2022", pkg-name: "pytorch", python-version: "3.12.7", pytorch-version: "2.5.1" } # "oldest" versions tests, only on minimum Python - { os: "macOS-14", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" } - { diff --git a/requirements/pytorch/extra.txt b/requirements/pytorch/extra.txt index 12bbdf5a70ab0..70c6548817b4a 100644 --- a/requirements/pytorch/extra.txt +++ b/requirements/pytorch/extra.txt @@ -5,7 +5,7 @@ matplotlib>3.1, <3.9.0 omegaconf >=2.2.3, <2.4.0 hydra-core >=1.2.0, <1.4.0 -jsonargparse[signatures] >=4.27.7, <4.28.0 +jsonargparse[signatures] >=4.27.7, <=4.35.0 rich >=12.3.0, <13.6.0 tensorboardX >=2.2, <2.7.0 # min version is set by torch.onnx missing attribute bitsandbytes >=0.44.0,<0.44.2; sys_platform == 'linux' or sys_platform == 'win32' diff --git a/src/lightning/pytorch/cli.py b/src/lightning/pytorch/cli.py index 5e70a9bdd8b9e..c79f2481c8af4 100644 --- a/src/lightning/pytorch/cli.py +++ b/src/lightning/pytorch/cli.py @@ -37,18 +37,6 @@ _JSONARGPARSE_SIGNATURES_AVAILABLE = RequirementCache("jsonargparse[signatures]>=4.27.7") - -def patch_jsonargparse_python_3_12_8() -> None: - if sys.version_info < (3, 12, 8): - return - - def _parse_known_args_patch(self: ArgumentParser, args: Any = None, namespace: Any = None) -> tuple[Any, Any]: - namespace, args = super(ArgumentParser, self)._parse_known_args(args, namespace, intermixed=False) # type: ignore - return namespace, args - - setattr(ArgumentParser, "_parse_known_args", _parse_known_args_patch) - - if _JSONARGPARSE_SIGNATURES_AVAILABLE: import docstring_parser from jsonargparse import ( @@ -60,8 +48,6 @@ def _parse_known_args_patch(self: ArgumentParser, args: Any = None, namespace: A set_config_read_mode, ) - patch_jsonargparse_python_3_12_8() # Required until fix https://github.com/omni-us/jsonargparse/issues/641 - register_unresolvable_import_paths(torch) # Required until fix https://github.com/pytorch/pytorch/issues/74483 set_config_read_mode(fsspec_enabled=True) else: diff --git a/tests/parity_fabric/test_parity_ddp.py b/tests/parity_fabric/test_parity_ddp.py index aebd9064b31fd..217d401ad6fba 100644 --- a/tests/parity_fabric/test_parity_ddp.py +++ b/tests/parity_fabric/test_parity_ddp.py @@ -162,8 +162,5 @@ def run_parity_test(accelerator: str = "cpu", devices: int = 2, tolerance: float if __name__ == "__main__": from jsonargparse import CLI - from lightning.pytorch.cli import patch_jsonargparse_python_3_12_8 - - patch_jsonargparse_python_3_12_8() # Required until fix https://github.com/omni-us/jsonargparse/issues/641 CLI(run_parity_test) diff --git a/tests/tests_pytorch/checkpointing/test_model_checkpoint.py b/tests/tests_pytorch/checkpointing/test_model_checkpoint.py index ef0abc7c463a8..d43f07179e7bb 100644 --- a/tests/tests_pytorch/checkpointing/test_model_checkpoint.py +++ b/tests/tests_pytorch/checkpointing/test_model_checkpoint.py @@ -29,10 +29,10 @@ import pytest import torch import yaml +from jsonargparse import ArgumentParser from lightning.fabric.utilities.cloud_io import _load as pl_load from lightning.pytorch import Trainer, seed_everything from lightning.pytorch.callbacks import ModelCheckpoint -from lightning.pytorch.cli import LightningArgumentParser as ArgumentParser from lightning.pytorch.demos.boring_classes import BoringModel from lightning.pytorch.loggers import CSVLogger, TensorBoardLogger from lightning.pytorch.utilities.exceptions import MisconfigurationException diff --git a/tests/tests_pytorch/test_cli.py b/tests/tests_pytorch/test_cli.py index f60eadbf38898..de89d094cdfcf 100644 --- a/tests/tests_pytorch/test_cli.py +++ b/tests/tests_pytorch/test_cli.py @@ -754,6 +754,7 @@ def add_arguments_to_parser(self, parser): @_xfail_python_ge_3_11_9 +@RunIf(min_torch="2.2") @pytest.mark.parametrize("use_generic_base_class", [False, True]) def test_lightning_cli_optimizers_and_lr_scheduler_with_link_to(use_generic_base_class): class MyLightningCLI(LightningCLI): @@ -801,6 +802,7 @@ def __init__(self, optim1: dict, optim2: dict, scheduler: dict): @_xfail_python_ge_3_11_9 +@RunIf(min_torch="2.2") def test_lightning_cli_optimizers_and_lr_scheduler_with_callable_type(): class TestModel(BoringModel): def __init__(