MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / get_mapping_to_flat_buffer

Function get_mapping_to_flat_buffer

deepspeed/runtime/zero/utils.py:202–212  ·  view source on GitHub ↗
(tensors: List[torch.Tensor])

Source from the content-addressed store, hash-verified

200
201
202def get_mapping_to_flat_buffer(tensors: List[torch.Tensor]) -> List[Tuple[torch.Tensor, int, int]]:
203 tensor_infos: List[Tuple[torch.Tensor, int, int]] = []
204
205 offset = 0
206 for tensor in tensors:
207 tensor_numel = tensor.numel()
208 # record some data so we can restore the device tensor later
209 tensor_infos.append((tensor, offset, tensor_numel))
210 offset += tensor_numel
211
212 return tensor_infos
213
214
215def defragment(tensors: List[torch.Tensor]) -> torch.Tensor:

Callers 3

offload_statesMethod · 0.90
reload_statesMethod · 0.90
defragmentFunction · 0.85

Calls 2

appendMethod · 0.80
numelMethod · 0.45

Tested by

no test coverage detected