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

Function _layer_shape

deepspeed/__init__.py:345–354  ·  view source on GitHub ↗

The parameter's shape as a layer, rather than as a ZeRO-3 partition. Under ``deepspeed.zero.Init`` a partitioned parameter's data is a flat placeholder - ``torch.Size([0])`` on the ranks that do not hold it - and the shape it has as a layer is recorded as ``ds_shape``. Reading ``param.s

(param: torch.Tensor)

Source from the content-addressed store, hash-verified

343
344
345def _layer_shape(param: torch.Tensor):
346 """The parameter's shape as a layer, rather than as a ZeRO-3 partition.
347
348 Under ``deepspeed.zero.Init`` a partitioned parameter's data is a flat placeholder -
349 ``torch.Size([0])`` on the ranks that do not hold it - and the shape it has as a layer is
350 recorded as ``ds_shape``. Reading ``param.shape`` there sees a 1-D tensor for every
351 parameter in the model.
352 """
353 ds_shape = getattr(param, "ds_shape", None)
354 return tuple(param.shape) if ds_shape is None else tuple(ds_shape)
355
356
357def set_optimizer_flags(config_class: DeepSpeedConfig, model: torch.nn.Module) -> None:

Callers 3

_confirmFunction · 0.85
set_optimizer_flagsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected