Skip to content

Commit cccf74c

Browse files
leng-yueawaelchli
authored andcommitted
Make the is_picklable function more robust (#17270)
1 parent a0bcacd commit cccf74c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/lightning/pytorch/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

7+
## [2.0.2] - 2023-04-12
8+
9+
### Fixed
10+
11+
- Make the `is_picklable` function more robust ([#17270](https://github.com/Lightning-AI/lightning/pull/17270))
12+
13+
714
## [2.0.1] - 2023-03-30
815

916
### Changed
@@ -12,6 +19,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1219
- Generalized `Optimizer` validation to accommodate both FSDP 1.x and 2.x ([#16733](https://github.com/Lightning-AI/lightning/pull/16733))
1320
- Disable `torch.inference_mode` with `torch.compile` in PyTorch 2.0 ([#17215](https://github.com/Lightning-AI/lightning/pull/17215))
1421

22+
1523
### Fixed
1624

1725
- Fixed issue where pickling the module instance would fail with a DataLoader error ([#17130](https://github.com/Lightning-AI/lightning/pull/17130))

src/lightning/pytorch/utilities/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def is_picklable(obj: object) -> bool:
3232
try:
3333
pickle.dumps(obj)
3434
return True
35-
except (pickle.PickleError, AttributeError, RuntimeError):
35+
except (pickle.PickleError, AttributeError, RuntimeError, TypeError):
3636
return False
3737

3838

tests/tests_pytorch/utilities/test_parsing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import inspect
15+
import threading
1516

1617
import pytest
1718
from torch.jit import ScriptModule
@@ -169,7 +170,7 @@ class UnpicklableClass:
169170
pass
170171

171172
true_cases = [None, True, 123, "str", (123, "str"), max]
172-
false_cases = [unpicklable_function, UnpicklableClass, ScriptModule()]
173+
false_cases = [unpicklable_function, UnpicklableClass, ScriptModule(), threading.Lock()]
173174

174175
for case in true_cases:
175176
assert is_picklable(case) is True

0 commit comments

Comments
 (0)