(self, storage: torch.UntypedStorage)
| 152 | |
| 153 | # TODO: offer some sort of non-blocking API to speed things up |
| 154 | def write_storage(self, storage: torch.UntypedStorage) -> str: |
| 155 | h = hash_storage(storage, stable_hash=self.stable_hash) |
| 156 | if h in self.seen_storage_hashes: |
| 157 | return h |
| 158 | # TODO: consider not using torch.save for this; we don't actually |
| 159 | # need any metadata for the storage |
| 160 | subfolder = os.path.join(self.loc, "storages") |
| 161 | os.makedirs(subfolder, exist_ok=True) |
| 162 | target = os.path.join(subfolder, h) |
| 163 | if os.path.exists(target): |
| 164 | return h |
| 165 | torch.save(storage, target) |
| 166 | self.seen_storage_hashes.add(h) |
| 167 | return h |
| 168 | |
| 169 | def compute_tensor_metadata(self, t: torch.Tensor, h=None): |
| 170 | if h is None: |
no test coverage detected