MCPcopy Create free account
hub / github.com/tdrussell/diffusion-pipe / StorageWeakRef

Class StorageWeakRef

utils/reduction.py:27–61  ·  view source on GitHub ↗

r"""A weak reference to a Storage. The cdata member is a Python number containing the integer representation of the Storage pointer.

Source from the content-addressed store, hash-verified

25
26
27class StorageWeakRef:
28 r"""A weak reference to a Storage.
29
30 The cdata member is a Python number containing the integer representation of
31 the Storage pointer.
32 """
33
34 __slots__ = ["cdata", "_free_weak_ref"]
35
36 def __init__(self, storage):
37 self.cdata = storage._weak_ref()
38 # Save a direct reference to _free_weak_ref because the `torch` module
39 # might be cleared during Python shutdown before this module is cleared.
40 self._free_weak_ref = torch.Storage._free_weak_ref # type: ignore[attr-defined]
41
42 @classmethod
43 def from_weakref(cls, cdata):
44 instance = cls.__new__(cls)
45 instance.cdata = cdata
46 instance._free_weak_ref = torch.Storage._free_weak_ref # type: ignore[attr-defined]
47 return instance
48
49 def expired(self):
50 return torch.Storage._expired(self.cdata) # type: ignore[attr-defined]
51
52 def __del__(self):
53 self._free_weak_ref(self.cdata)
54
55 def __hash__(self):
56 return self.cdata
57
58 def __eq__(self, other):
59 if id(self) == id(other):
60 return True
61 return self.cdata == other.cdata
62
63
64class SharedCache(dict):

Callers 5

rebuild_cuda_tensorFunction · 0.85
reduce_tensorFunction · 0.85
rebuild_storage_fdFunction · 0.85
rebuild_storage_filenameFunction · 0.85
reduce_storageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected