Skip to content

Commit f4cd9df

Browse files
awaelchlitchaton
andauthored
Patch Release 2.2.3 (#19800)
Co-authored-by: thomas chaton <[email protected]>
1 parent fa4b3f7 commit f4cd9df

File tree

10 files changed

+72
-10
lines changed

10 files changed

+72
-10
lines changed

docs/source-pytorch/ecosystem/community_examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Community Examples
44
==================
55

66

7-
- `Lightning Bolts: Deep Learning components for extending PyTorch Lightning <https://lightning.ai/docs/pytorch/latest/ecosystem/bolts.html>`_.
7+
- `Lightning Bolts: Deep Learning components for extending PyTorch Lightning <https://lightning.ai/docs/pytorch/stable/ecosystem/bolts.html>`_.
88
- `Lightning Flash: Your PyTorch AI Factory - Flash enables you to easily configure and run complex AI recipes <https://github.com/Lightning-AI/lightning-flash>`_.
99
- `Contextual Emotion Detection (DoubleDistilBert) <https://github.com/juliusberner/emotion_transformer>`_
1010
- `Cotatron: Transcription-Guided Speech Encoder <https://github.com/mindslab-ai/cotatron>`_

examples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Examples
22

33
Our most robust examples showing all sorts of implementations
4-
can be found in our sister library [Lightning Bolts](https://lightning.ai/docs/pytorch/latest/ecosystem/bolts.html).
4+
can be found in our sister library [Lightning Bolts](https://lightning.ai/docs/pytorch/stable/ecosystem/bolts.html).
55

66
______________________________________________________________________
77

@@ -33,5 +33,5 @@ ______________________________________________________________________
3333
## Domain Examples
3434

3535
This folder contains older examples. You should instead use the examples
36-
in [Lightning Bolts](https://lightning.ai/docs/pytorch/latest/ecosystem/bolts.html)
36+
in [Lightning Bolts](https://lightning.ai/docs/pytorch/stable/ecosystem/bolts.html)
3737
for advanced use cases.

requirements/app/app.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
lightning-cloud == 0.5.65 # Must be pinned to ensure compatibility
1+
lightning-cloud == 0.5.67 # Must be pinned to ensure compatibility
22
packaging
33
typing-extensions >=4.4.0, <4.10.0
44
deepdiff >=5.7.0, <6.6.0

src/lightning/fabric/utilities/logger.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import json
1515
from argparse import Namespace
1616
from dataclasses import asdict, is_dataclass
1717
from typing import Any, Dict, Mapping, MutableMapping, Optional, Union
@@ -132,6 +132,23 @@ def _sanitize_params(params: Dict[str, Any]) -> Dict[str, Any]:
132132
return params
133133

134134

135+
def _convert_json_serializable(params: Dict[str, Any]) -> Dict[str, Any]:
136+
"""Convert non-serializable objects in params to string."""
137+
return {k: str(v) if not _is_json_serializable(v) else v for k, v in params.items()}
138+
139+
140+
def _is_json_serializable(value: Any) -> bool:
141+
"""Test whether a variable can be encoded as json."""
142+
if value is None or isinstance(value, (bool, int, float, str, list, dict)): # fast path
143+
return True
144+
try:
145+
json.dumps(value)
146+
return True
147+
except (TypeError, OverflowError):
148+
# OverflowError is raised if number is too large to encode
149+
return False
150+
151+
135152
def _add_prefix(
136153
metrics: Mapping[str, Union[Tensor, float]], prefix: str, separator: str
137154
) -> Mapping[str, Union[Tensor, float]]:

src/lightning/pytorch/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

77

8+
## [2.2.3] - 2024-04-23
9+
10+
### Fixed
11+
12+
- Fixed `WandbLogger.log_hyperparameters()` raising an error if hyperparameters are not JSON serializable ([#19769](https://github.com/Lightning-AI/pytorch-lightning/pull/19769))
13+
14+
815
## [2.2.2] - 2024-04-11
916

1017
### Fixed

src/lightning/pytorch/loggers/wandb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
from torch import Tensor
2727
from typing_extensions import override
2828

29-
from lightning.fabric.utilities.logger import _add_prefix, _convert_params, _sanitize_callable_params
29+
from lightning.fabric.utilities.logger import (
30+
_add_prefix,
31+
_convert_json_serializable,
32+
_convert_params,
33+
_sanitize_callable_params,
34+
)
3035
from lightning.fabric.utilities.types import _PATH
3136
from lightning.pytorch.callbacks.model_checkpoint import ModelCheckpoint
3237
from lightning.pytorch.loggers.logger import Logger, rank_zero_experiment
@@ -419,6 +424,7 @@ def watch(
419424
def log_hyperparams(self, params: Union[Dict[str, Any], Namespace]) -> None: # type: ignore[override]
420425
params = _convert_params(params)
421426
params = _sanitize_callable_params(params)
427+
params = _convert_json_serializable(params)
422428
self.experiment.config.update(params, allow_val_change=True)
423429

424430
@override

src/version.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.2
1+
2.2.3

tests/tests_app/cli/test_cmd_launch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from unittest import mock
88
from unittest.mock import ANY, MagicMock, Mock
99

10+
import pytest
1011
from click.testing import CliRunner
1112
from lightning.app.cli.lightning_cli_launch import run_flow, run_flow_and_servers, run_frontend, run_server
1213
from lightning.app.core.queues import QueuingSystem
@@ -189,6 +190,7 @@ def start_processes(**functions):
189190

190191

191192
@_RunIf(skip_windows=True)
193+
@pytest.mark.xfail(strict=False, reason="Flaky test")
192194
def test_manage_server_processes_one_process_gets_killed(capfd):
193195
functions = {"p1": run_forever_process, "p2": run_for_2_seconds_and_raise}
194196
p = Process(target=start_processes, kwargs=functions)
@@ -207,6 +209,7 @@ def test_manage_server_processes_one_process_gets_killed(capfd):
207209

208210

209211
@_RunIf(skip_windows=True)
212+
@pytest.mark.xfail(strict=False, reason="Flaky test")
210213
def test_manage_server_processes_all_processes_exits_with_zero_exitcode(capfd):
211214
functions = {
212215
"p1": exit_successfully_immediately,

tests/tests_fabric/utilities/test_logger.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
from argparse import Namespace
1615
from dataclasses import dataclass
16+
from pathlib import Path
1717

1818
import numpy as np
1919
import torch
2020
from lightning.fabric.utilities.logger import (
2121
_add_prefix,
22+
_convert_json_serializable,
2223
_convert_params,
2324
_flatten_dict,
2425
_sanitize_callable_params,
@@ -167,3 +168,29 @@ def test_add_prefix():
167168
assert "prefix-metric2" not in metrics
168169
assert metrics["prefix2_prefix-metric1"] == 1
169170
assert metrics["prefix2_prefix-metric2"] == 2
171+
172+
173+
def test_convert_json_serializable():
174+
data = {
175+
# JSON-serializable
176+
"none": None,
177+
"int": 1,
178+
"float": 1.1,
179+
"bool": True,
180+
"dict": {"a": 1},
181+
"list": [2, 3, 4],
182+
# not JSON-serializable
183+
"path": Path("path"),
184+
"tensor": torch.tensor(1),
185+
}
186+
expected = {
187+
"none": None,
188+
"int": 1,
189+
"float": 1.1,
190+
"bool": True,
191+
"dict": {"a": 1},
192+
"list": [2, 3, 4],
193+
"path": "path",
194+
"tensor": "tensor(1)",
195+
}
196+
assert _convert_json_serializable(data) == expected

tests/tests_pytorch/loggers/test_wandb.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
import os
1515
import pickle
16+
from pathlib import Path
1617
from unittest import mock
1718

1819
import pytest
@@ -113,9 +114,10 @@ def test_wandb_logger_init(wandb_mock):
113114
wandb_mock.init().log.assert_called_with({"acc": 1.0, "trainer/global_step": 6})
114115

115116
# log hyper parameters
116-
hparams = {"test": None, "nested": {"a": 1}, "b": [2, 3, 4]}
117+
hparams = {"none": None, "dict": {"a": 1}, "b": [2, 3, 4], "path": Path("path")}
118+
expected = {"none": None, "dict": {"a": 1}, "b": [2, 3, 4], "path": "path"}
117119
logger.log_hyperparams(hparams)
118-
wandb_mock.init().config.update.assert_called_once_with(hparams, allow_val_change=True)
120+
wandb_mock.init().config.update.assert_called_once_with(expected, allow_val_change=True)
119121

120122
# watch a model
121123
logger.watch("model", "log", 10, False)

0 commit comments

Comments
 (0)