-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from jeongseok-meta/fix_pytorch_cpu_strings
Fix pytorch-cpu/gpu build only for single python version
- Loading branch information
Showing
2 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
diff --git a/torch/serialization.py b/torch/serialization.py | ||
index d936d31d6f5..d937680c031 100644 | ||
--- a/torch/serialization.py | ||
+++ b/torch/serialization.py | ||
@@ -1005,8 +1005,12 @@ def _legacy_save(obj, f, pickle_module, pickle_protocol) -> None: | ||
pickle_module.dump(MAGIC_NUMBER, f, protocol=pickle_protocol) | ||
pickle_module.dump(PROTOCOL_VERSION, f, protocol=pickle_protocol) | ||
pickle_module.dump(sys_info, f, protocol=pickle_protocol) | ||
- pickler = pickle_module.Pickler(f, protocol=pickle_protocol) | ||
- pickler.persistent_id = persistent_id | ||
+ | ||
+ class PyTorchLegacyPickler(pickle_module.Pickler): | ||
+ def persistent_id(self, obj): | ||
+ return persistent_id(obj) | ||
+ | ||
+ pickler = PyTorchLegacyPickler(f, protocol=pickle_protocol) | ||
pickler.dump(obj) | ||
|
||
serialized_storage_keys = sorted(serialized_storages.keys()) | ||
@@ -1083,8 +1087,12 @@ def _save( | ||
|
||
# Write the pickle data for `obj` | ||
data_buf = io.BytesIO() | ||
- pickler = pickle_module.Pickler(data_buf, protocol=pickle_protocol) | ||
- pickler.persistent_id = persistent_id | ||
+ | ||
+ class PyTorchPickler(pickle_module.Pickler): # type: ignore[name-defined] | ||
+ def persistent_id(self, obj): | ||
+ return persistent_id(obj) | ||
+ | ||
+ pickler = PyTorchPickler(data_buf, protocol=pickle_protocol) | ||
pickler.dump(obj) | ||
data_value = data_buf.getvalue() | ||
zip_file.write_record("data.pkl", data_value, len(data_value)) |