Skip to content

Commit 4567c49

Browse files
authored
Merge branch 'master' into chualan/fix-19658
2 parents 9e53990 + 6b88ddc commit 4567c49

File tree

11 files changed

+61
-12
lines changed

11 files changed

+61
-12
lines changed

.actions/assistant.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,21 @@ def convert_version2nightly(ver_file: str = "src/version.info") -> None:
483483

484484

485485
if __name__ == "__main__":
486+
import sys
487+
486488
import jsonargparse
489+
from jsonargparse import ArgumentParser
490+
491+
def patch_jsonargparse_python_3_12_8():
492+
if sys.version_info < (3, 12, 8):
493+
return
494+
495+
def _parse_known_args_patch(self: ArgumentParser, args: Any = None, namespace: Any = None) -> tuple[Any, Any]:
496+
namespace, args = super(ArgumentParser, self)._parse_known_args(args, namespace, intermixed=False) # type: ignore
497+
return namespace, args
498+
499+
setattr(ArgumentParser, "_parse_known_args", _parse_known_args_patch)
500+
501+
patch_jsonargparse_python_3_12_8() # Required until fix https://github.com/omni-us/jsonargparse/issues/641
487502

488503
jsonargparse.CLI(AssistantCLI, as_positional=False)

_notebooks

dockers/base-cuda/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ RUN \
5959
add-apt-repository ppa:deadsnakes/ppa && \
6060
apt-get install -y \
6161
python${PYTHON_VERSION} \
62-
python${PYTHON_VERSION}-distutils \
62+
python3-setuptools \
6363
python${PYTHON_VERSION}-dev \
6464
&& \
6565
update-alternatives --install /usr/bin/python${PYTHON_VERSION%%.*} python${PYTHON_VERSION%%.*} /usr/bin/python${PYTHON_VERSION} 1 && \

dockers/docs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ RUN \
4444
dvipng \
4545
texlive-pictures \
4646
python3 \
47-
python3-distutils \
47+
python3-setuptools \
4848
python3-dev \
4949
&& \
5050
update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \

examples/fabric/reinforcement_learning/rl/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import argparse
22
import math
33
import os
4-
from distutils.util import strtobool
54
from typing import TYPE_CHECKING, Optional, Union
65

76
import gymnasium as gym
@@ -12,6 +11,23 @@
1211
from rl.agent import PPOAgent, PPOLightningAgent
1312

1413

14+
def strtobool(val):
15+
"""Convert a string representation of truth to true (1) or false (0).
16+
17+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'.
18+
Raises ValueError if 'val' is anything else.
19+
20+
Note: taken from distutils after its deprecation.
21+
22+
"""
23+
val = val.lower()
24+
if val in ("y", "yes", "t", "true", "on", "1"):
25+
return 1
26+
if val in ("n", "no", "f", "false", "off", "0"):
27+
return 0
28+
raise ValueError(f"invalid truth value {val!r}")
29+
30+
1531
def parse_args():
1632
parser = argparse.ArgumentParser()
1733
parser.add_argument("--exp-name", type=str, default="default", help="the name of this experiment")

src/lightning/fabric/connector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
import os
1515
from collections import Counter
16+
from collections.abc import Iterable
1617
from typing import Any, Optional, Union, cast
1718

1819
import torch
@@ -102,7 +103,7 @@ def __init__(
102103
devices: Union[list[int], str, int] = "auto",
103104
num_nodes: int = 1,
104105
precision: Optional[_PRECISION_INPUT] = None,
105-
plugins: Optional[Union[_PLUGIN_INPUT, list[_PLUGIN_INPUT]]] = None,
106+
plugins: Optional[Union[_PLUGIN_INPUT, Iterable[_PLUGIN_INPUT]]] = None,
106107
) -> None:
107108
# These arguments can be set through environment variables set by the CLI
108109
accelerator = self._argument_from_env("accelerator", accelerator, default="auto")
@@ -165,7 +166,7 @@ def _check_config_and_set_final_flags(
165166
strategy: Union[str, Strategy],
166167
accelerator: Union[str, Accelerator],
167168
precision: Optional[_PRECISION_INPUT],
168-
plugins: Optional[Union[_PLUGIN_INPUT, list[_PLUGIN_INPUT]]],
169+
plugins: Optional[Union[_PLUGIN_INPUT, Iterable[_PLUGIN_INPUT]]],
169170
) -> None:
170171
"""This method checks:
171172
@@ -180,7 +181,7 @@ def _check_config_and_set_final_flags(
180181
181182
"""
182183
if plugins is not None:
183-
plugins = [plugins] if not isinstance(plugins, list) else plugins
184+
plugins = [plugins] if not isinstance(plugins, Iterable) else plugins
184185

185186
if isinstance(strategy, str):
186187
strategy = strategy.lower()

src/lightning/pytorch/cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
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+
4052
if _JSONARGPARSE_SIGNATURES_AVAILABLE:
4153
import docstring_parser
4254
from jsonargparse import (
@@ -48,6 +60,8 @@
4860
set_config_read_mode,
4961
)
5062

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

src/lightning/pytorch/trainer/connectors/accelerator_connector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616
import os
1717
from collections import Counter
18+
from collections.abc import Iterable
1819
from typing import Literal, Optional, Union
1920

2021
import torch
@@ -78,7 +79,7 @@ def __init__(
7879
num_nodes: int = 1,
7980
accelerator: Union[str, Accelerator] = "auto",
8081
strategy: Union[str, Strategy] = "auto",
81-
plugins: Optional[Union[_PLUGIN_INPUT, list[_PLUGIN_INPUT]]] = None,
82+
plugins: Optional[Union[_PLUGIN_INPUT, Iterable[_PLUGIN_INPUT]]] = None,
8283
precision: Optional[_PRECISION_INPUT] = None,
8384
sync_batchnorm: bool = False,
8485
benchmark: Optional[bool] = None,
@@ -166,7 +167,7 @@ def _check_config_and_set_final_flags(
166167
strategy: Union[str, Strategy],
167168
accelerator: Union[str, Accelerator],
168169
precision: Optional[_PRECISION_INPUT],
169-
plugins: Optional[Union[_PLUGIN_INPUT, list[_PLUGIN_INPUT]]],
170+
plugins: Optional[Union[_PLUGIN_INPUT, Iterable[_PLUGIN_INPUT]]],
170171
sync_batchnorm: bool,
171172
) -> None:
172173
"""This method checks:
@@ -182,7 +183,7 @@ def _check_config_and_set_final_flags(
182183
183184
"""
184185
if plugins is not None:
185-
plugins = [plugins] if not isinstance(plugins, list) else plugins
186+
plugins = [plugins] if not isinstance(plugins, Iterable) else plugins
186187

187188
if isinstance(strategy, str):
188189
strategy = strategy.lower()

src/pytorch_lightning/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Lightning is rigorously tested across multiple CPUs, GPUs and TPUs and against m
8080
| System / PyTorch ver. | 1.12 | 1.13 | 2.0 | 2.1 |
8181
| :--------------------------------: | :---------------------------------------------------------------------------------------------------------: | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
8282
| Linux py3.9 \[GPUs\] | | | | ![Build Status](https://dev.azure.com/Lightning-AI/lightning/_apis/build/status%2Fpytorch-lightning%20%28GPUs%29) |
83-
| Linux py3.9 \[TPUs\] | | | ![Test PyTorch - TPU](https://github.com/Lightning-AI/lightning/actions/workflows/tpu-tests.yml/badge.svg) | |
8483
| Linux (multiple Python versions) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) |
8584
| OSX (multiple Python versions) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) |
8685
| Windows (multiple Python versions) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) | ![Test PyTorch](https://github.com/Lightning-AI/lightning/actions/workflows/ci-tests-pytorch.yml/badge.svg) |

tests/parity_fabric/test_parity_ddp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,8 @@ 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
165168

166169
CLI(run_parity_test)

0 commit comments

Comments
 (0)