fix RestrictedUnpickler

it does no harm to remove the pytorch_lightening dependency

see also 735ac4cf81
This commit is contained in:
Won-Kyu Park 2024-10-22 05:17:16 +09:00
parent 5865da28d1
commit b5c5938853
No known key found for this signature in database
GPG Key ID: 53AA79C8C9535D15

View File

@ -37,6 +37,9 @@ class RestrictedUnpickler(pickle.Unpickler):
if res is not None: if res is not None:
return res return res
class Empty:
pass
if module == 'collections' and name == 'OrderedDict': if module == 'collections' and name == 'OrderedDict':
return getattr(collections, name) return getattr(collections, name)
if module == 'torch._utils' and name in ['_rebuild_tensor_v2', '_rebuild_parameter', '_rebuild_device_tensor_from_numpy']: if module == 'torch._utils' and name in ['_rebuild_tensor_v2', '_rebuild_parameter', '_rebuild_device_tensor_from_numpy']:
@ -51,12 +54,8 @@ class RestrictedUnpickler(pickle.Unpickler):
return getattr(numpy, name) return getattr(numpy, name)
if module == '_codecs' and name == 'encode': if module == '_codecs' and name == 'encode':
return encode return encode
if module == "pytorch_lightning.callbacks" and name == 'model_checkpoint': if module.startswith("pytorch_lightning"):
import pytorch_lightning.callbacks return Empty
return pytorch_lightning.callbacks.model_checkpoint
if module == "pytorch_lightning.callbacks.model_checkpoint" and name == 'ModelCheckpoint':
import pytorch_lightning.callbacks.model_checkpoint
return pytorch_lightning.callbacks.model_checkpoint.ModelCheckpoint
if module == "__builtin__" and name == 'set': if module == "__builtin__" and name == 'set':
return set return set