Skip to content

Commit 4337f7f

Browse files
authored
Revert "Patch jsonargparse for Python >= 3.12.8" (#20513)
* Revert "Patch jsonargparse for Python >= 3.12.8 (#20479)" This reverts commit 38971a0. * Update upper bound for jsonargparse * Ensure jsonargparse is up to date in containers * Skip pt 2.1 tests incompatible with new jsonargparse
1 parent 58a749a commit 4337f7f

File tree

12 files changed

+26
-56
lines changed

12 files changed

+26
-56
lines changed

.actions/assistant.py

-15
Original file line numberDiff line numberDiff line change
@@ -502,21 +502,6 @@ def generate_docker_tags(
502502

503503

504504
if __name__ == "__main__":
505-
import sys
506-
507505
import jsonargparse
508-
from jsonargparse import ArgumentParser
509-
510-
def patch_jsonargparse_python_3_12_8():
511-
if sys.version_info < (3, 12, 8):
512-
return
513-
514-
def _parse_known_args_patch(self: ArgumentParser, args: Any = None, namespace: Any = None) -> tuple[Any, Any]:
515-
namespace, args = super(ArgumentParser, self)._parse_known_args(args, namespace, intermixed=False) # type: ignore
516-
return namespace, args
517-
518-
setattr(ArgumentParser, "_parse_known_args", _parse_known_args_patch)
519-
520-
patch_jsonargparse_python_3_12_8() # Required until fix https://github.com/omni-us/jsonargparse/issues/641
521506

522507
jsonargparse.CLI(AssistantCLI, as_positional=False)

.actions/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
jsonargparse >=4.16.0, <4.28.0
1+
jsonargparse >=4.16.0, <=4.35.0
22
requests
33
packaging

.azure/gpu-benchmarks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
7878
- bash: |
7979
pip install -e .[dev] --find-links ${TORCH_URL}
80-
pip install setuptools==75.6.0
80+
pip install setuptools==75.6.0 jsonargparse==4.35.0
8181
env:
8282
FREEZE_REQUIREMENTS: "1"
8383
displayName: "Install package"

.azure/gpu-tests-fabric.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
- bash: |
108108
extra=$(python -c "print({'lightning': 'fabric-'}.get('$(PACKAGE_NAME)', ''))")
109109
pip install -e ".[${extra}dev]" pytest-timeout -U --find-links="${TORCH_URL}" --find-links="${TORCHVISION_URL}"
110-
pip install setuptools==75.6.0
110+
pip install setuptools==75.6.0 jsonargparse==4.35.0
111111
displayName: "Install package & dependencies"
112112
113113
- bash: |

.azure/gpu-tests-pytorch.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
- bash: |
112112
extra=$(python -c "print({'lightning': 'pytorch-'}.get('$(PACKAGE_NAME)', ''))")
113113
pip install -e ".[${extra}dev]" pytest-timeout -U --find-links="${TORCH_URL}" --find-links="${TORCHVISION_URL}"
114-
pip install setuptools==75.6.0
114+
pip install setuptools==75.6.0 jsonargparse==4.35.0
115115
displayName: "Install package & dependencies"
116116
117117
- bash: pip uninstall -y lightning

.github/workflows/ci-tests-fabric.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ jobs:
4949
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" }
5050
- { os: "ubuntu-20.04", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" }
5151
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" }
52-
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" }
53-
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" }
54-
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" }
55-
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
56-
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
57-
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
52+
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" }
53+
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" }
54+
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" }
55+
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" }
56+
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" }
57+
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" }
5858
# only run PyTorch latest with Python latest, use Fabric scope to limit dependency issues
59-
- { os: "macOS-14", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" }
60-
- { os: "ubuntu-22.04", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" }
61-
- { os: "windows-2022", pkg-name: "fabric", python-version: "3.12", pytorch-version: "2.5.1" }
59+
- { os: "macOS-14", pkg-name: "fabric", python-version: "3.12.7", pytorch-version: "2.5.1" }
60+
- { os: "ubuntu-22.04", pkg-name: "fabric", python-version: "3.12.7", pytorch-version: "2.5.1" }
61+
- { os: "windows-2022", pkg-name: "fabric", python-version: "3.12.7", pytorch-version: "2.5.1" }
6262
# "oldest" versions tests, only on minimum Python
6363
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" }
6464
- {

.github/workflows/ci-tests-pytorch.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ jobs:
5353
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" }
5454
- { os: "ubuntu-20.04", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" }
5555
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" }
56-
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" }
57-
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" }
58-
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.4.1" }
59-
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
60-
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
61-
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12", pytorch-version: "2.5.1" }
56+
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" }
57+
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" }
58+
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" }
59+
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" }
60+
- { os: "ubuntu-22.04", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" }
61+
- { os: "windows-2022", pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" }
6262
# only run PyTorch latest with Python latest, use PyTorch scope to limit dependency issues
63-
- { os: "macOS-14", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" }
64-
- { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" }
65-
- { os: "windows-2022", pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.5.1" }
63+
- { os: "macOS-14", pkg-name: "pytorch", python-version: "3.12.7", pytorch-version: "2.5.1" }
64+
- { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.12.7", pytorch-version: "2.5.1" }
65+
- { os: "windows-2022", pkg-name: "pytorch", python-version: "3.12.7", pytorch-version: "2.5.1" }
6666
# "oldest" versions tests, only on minimum Python
6767
- { os: "macOS-14", pkg-name: "lightning", python-version: "3.9", pytorch-version: "2.1", requires: "oldest" }
6868
- {

requirements/pytorch/extra.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
matplotlib>3.1, <3.9.0
66
omegaconf >=2.2.3, <2.4.0
77
hydra-core >=1.2.0, <1.4.0
8-
jsonargparse[signatures] >=4.27.7, <4.28.0
8+
jsonargparse[signatures] >=4.27.7, <=4.35.0
99
rich >=12.3.0, <13.6.0
1010
tensorboardX >=2.2, <2.7.0 # min version is set by torch.onnx missing attribute
1111
bitsandbytes >=0.44.0,<0.44.2; sys_platform == 'linux' or sys_platform == 'win32'

src/lightning/pytorch/cli.py

-14
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@
3737

3838
_JSONARGPARSE_SIGNATURES_AVAILABLE = RequirementCache("jsonargparse[signatures]>=4.27.7")
3939

40-
41-
def patch_jsonargparse_python_3_12_8() -> None:
42-
if sys.version_info < (3, 12, 8):
43-
return
44-
45-
def _parse_known_args_patch(self: ArgumentParser, args: Any = None, namespace: Any = None) -> tuple[Any, Any]:
46-
namespace, args = super(ArgumentParser, self)._parse_known_args(args, namespace, intermixed=False) # type: ignore
47-
return namespace, args
48-
49-
setattr(ArgumentParser, "_parse_known_args", _parse_known_args_patch)
50-
51-
5240
if _JSONARGPARSE_SIGNATURES_AVAILABLE:
5341
import docstring_parser
5442
from jsonargparse import (
@@ -60,8 +48,6 @@ def _parse_known_args_patch(self: ArgumentParser, args: Any = None, namespace: A
6048
set_config_read_mode,
6149
)
6250

63-
patch_jsonargparse_python_3_12_8() # Required until fix https://github.com/omni-us/jsonargparse/issues/641
64-
6551
register_unresolvable_import_paths(torch) # Required until fix https://github.com/pytorch/pytorch/issues/74483
6652
set_config_read_mode(fsspec_enabled=True)
6753
else:

tests/parity_fabric/test_parity_ddp.py

-3
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,5 @@ def run_parity_test(accelerator: str = "cpu", devices: int = 2, tolerance: float
162162

163163
if __name__ == "__main__":
164164
from jsonargparse import CLI
165-
from lightning.pytorch.cli import patch_jsonargparse_python_3_12_8
166-
167-
patch_jsonargparse_python_3_12_8() # Required until fix https://github.com/omni-us/jsonargparse/issues/641
168165

169166
CLI(run_parity_test)

tests/tests_pytorch/checkpointing/test_model_checkpoint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import pytest
3030
import torch
3131
import yaml
32+
from jsonargparse import ArgumentParser
3233
from lightning.fabric.utilities.cloud_io import _load as pl_load
3334
from lightning.pytorch import Trainer, seed_everything
3435
from lightning.pytorch.callbacks import ModelCheckpoint
35-
from lightning.pytorch.cli import LightningArgumentParser as ArgumentParser
3636
from lightning.pytorch.demos.boring_classes import BoringModel
3737
from lightning.pytorch.loggers import CSVLogger, TensorBoardLogger
3838
from lightning.pytorch.utilities.exceptions import MisconfigurationException

tests/tests_pytorch/test_cli.py

+2
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ def add_arguments_to_parser(self, parser):
754754

755755

756756
@_xfail_python_ge_3_11_9
757+
@RunIf(min_torch="2.2")
757758
@pytest.mark.parametrize("use_generic_base_class", [False, True])
758759
def test_lightning_cli_optimizers_and_lr_scheduler_with_link_to(use_generic_base_class):
759760
class MyLightningCLI(LightningCLI):
@@ -801,6 +802,7 @@ def __init__(self, optim1: dict, optim2: dict, scheduler: dict):
801802

802803

803804
@_xfail_python_ge_3_11_9
805+
@RunIf(min_torch="2.2")
804806
def test_lightning_cli_optimizers_and_lr_scheduler_with_callable_type():
805807
class TestModel(BoringModel):
806808
def __init__(

0 commit comments

Comments
 (0)