Skip to content

Commit fd4697c

Browse files
authored
Make the is_picklable function more robust (Lightning-AI#17270)
1 parent fb775e0 commit fd4697c

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/lightning/pytorch/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2727

2828
- Disable `torch.inference_mode` with `torch.compile` in PyTorch 2.0 ([#17215](https://github.com/Lightning-AI/lightning/pull/17215))
2929

30+
- Changed the `is_picklable` util function to handle the edge case that throws a `TypeError` ([#17270](https://github.com/Lightning-AI/lightning/pull/17270))
31+
3032
### Depercated
3133

3234
-

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)