MCPcopy Create free account
hub / github.com/pytorch/pytorch / persistent_id

Function persistent_id

torch/_deploy.py:21–45  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

19 importers = sys_importer
20
21 def persistent_id(obj):
22 if torch.is_storage(obj) or isinstance(obj, torch.storage.TypedStorage):
23 if isinstance(obj, torch.storage.TypedStorage):
24 # TODO: Once we decide to break serialization FC, we can
25 # remove this case
26 storage = obj._untyped_storage
27 dtype = obj.dtype
28 else:
29 storage = obj
30 dtype = torch.uint8
31
32 serialized_storages.append(obj)
33 serialized_dtypes.append(dtype)
34 return ("storage", len(serialized_storages) - 1)
35
36 if hasattr(obj, "__reduce_deploy__"):
37 if _serialized_reduces.get(id(obj)) is None:
38 _serialized_reduces[id(obj)] = (
39 "reduce_deploy",
40 id(obj),
41 *obj.__reduce_deploy__(importers),
42 )
43 return _serialized_reduces[id(obj)]
44
45 return None
46
47 # Write the pickle data for `obj`
48 data_buf = io.BytesIO()

Callers

nothing calls this directly

Calls 4

isinstanceFunction · 0.85
__reduce_deploy__Method · 0.80
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…