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

Method _get_zero_param_shapes

deepspeed/runtime/engine.py:5647–5683  ·  view source on GitHub ↗

Returns a dict of name to shape mapping, only for the flattened fp32 weights saved by the optimizer. the names are exactly as in state_dict. The order is absolutely important, since the saved data is just flattened data with no identifiers and requires reconstruction in the s

(self)

Source from the content-addressed store, hash-verified

5645 return frozen_param_fragments
5646
5647 def _get_zero_param_shapes(self):
5648 """Returns a dict of name to shape mapping, only for the flattened fp32 weights saved by the
5649 optimizer. the names are exactly as in state_dict. The order is absolutely important, since
5650 the saved data is just flattened data with no identifiers and requires reconstruction in the
5651 same order it was saved.
5652 We can't rely on self.module.named_parameters() to get the saved tensors, as some params
5653 will be missing and others unsaved and then it'd be impossible to reconstruct state_dict
5654 from the flattened weights.
5655 optimizer.bit16_groups seems to be the easiest to use as it's in all zeroX versions.
5656 """
5657 param_group_shapes = []
5658 cnt = 0
5659 numel = 0
5660
5661 # zero2 started using a round_robin_bit16_groups which is a shuffled version of bit16_groups -
5662 # if we don't use it, we get parameters ordered incorrectly
5663 if hasattr(self.optimizer, "round_robin_bit16_groups"):
5664 bit16_groups = self.optimizer.round_robin_bit16_groups
5665 elif self.bfloat16_enabled() and hasattr(self.optimizer, "bf16_groups"):
5666 bit16_groups = self.optimizer.bf16_groups
5667 else:
5668 bit16_groups = self.optimizer.bit16_groups if self.zero_optimization_stage(
5669 ) == 2 else self.optimizer.fp16_groups
5670
5671 for bit16_group in bit16_groups:
5672 param_shapes = OrderedDict()
5673 for param in bit16_group:
5674 cnt += 1
5675 numel += param.ds_numel if hasattr(param, "ds_numel") else param.numel()
5676 shape = param.ds_shape if hasattr(param, "ds_shape") else param.shape
5677 if param not in self.param_names:
5678 raise ValueError("failed to find optimizer param in named params")
5679 name = self.param_names[param]
5680 param_shapes[name] = shape
5681 param_group_shapes.append(param_shapes)
5682
5683 return param_group_shapes
5684
5685 def _get_shared_params(self):
5686 """

Callers 6

_load_zero_checkpointMethod · 0.95
_save_moe_checkpointMethod · 0.95
train_save_convertFunction · 0.80
_run_testMethod · 0.80

Calls 4

bfloat16_enabledMethod · 0.95
numelMethod · 0.45
appendMethod · 0.45

Tested by 2

train_save_convertFunction · 0.64
_run_testMethod · 0.64