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

Function load_tensor

torch/serialization.py:1367–1389  ·  view source on GitHub ↗
(dtype, numel, key, location)

Source from the content-addressed store, hash-verified

1365 UserWarning)
1366
1367 def load_tensor(dtype, numel, key, location):
1368 name = f'data/{key}'
1369 if overall_storage is not None:
1370 storage_offset = zip_file.get_record_offset(name)
1371 storage = overall_storage[storage_offset:storage_offset + numel]
1372 else:
1373 storage = zip_file.get_storage_from_record(name, numel, torch.UntypedStorage)._typed_storage()._untyped_storage
1374 # swap here if byteswapping is needed
1375 if byteorderdata is not None:
1376 if byteorderdata.decode() != sys.byteorder:
1377 storage.byteswap(dtype)
1378
1379 # TODO: Once we decide to break serialization FC, we can
1380 # stop wrapping with TypedStorage
1381 typed_storage = torch.storage.TypedStorage(
1382 wrap_storage=restore_location(storage, location),
1383 dtype=dtype,
1384 _internal=True)
1385
1386 if typed_storage._data_ptr() != 0:
1387 loaded_storages[key] = typed_storage
1388
1389 return typed_storage
1390
1391 def persistent_load(saved_id):
1392 assert isinstance(saved_id, tuple)

Callers 1

persistent_loadFunction · 0.70

Calls 6

_data_ptrMethod · 0.95
restore_locationFunction · 0.85
_typed_storageMethod · 0.80
byteswapMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…