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

Method _get_zero_param_shapes

deepspeed/runtime/engine.py:5551–5587  ·  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

5549 return frozen_param_fragments
5550
5551 def _get_zero_param_shapes(self):
5552 """Returns a dict of name to shape mapping, only for the flattened fp32 weights saved by the
5553 optimizer. the names are exactly as in state_dict. The order is absolutely important, since
5554 the saved data is just flattened data with no identifiers and requires reconstruction in the
5555 same order it was saved.
5556 We can't rely on self.module.named_parameters() to get the saved tensors, as some params
5557 will be missing and others unsaved and then it'd be impossible to reconstruct state_dict
5558 from the flattened weights.
5559 optimizer.bit16_groups seems to be the easiest to use as it's in all zeroX versions.
5560 """
5561 param_group_shapes = []
5562 cnt = 0
5563 numel = 0
5564
5565 # zero2 started using a round_robin_bit16_groups which is a shuffled version of bit16_groups -
5566 # if we don't use it, we get parameters ordered incorrectly
5567 if hasattr(self.optimizer, "round_robin_bit16_groups"):
5568 bit16_groups = self.optimizer.round_robin_bit16_groups
5569 elif self.bfloat16_enabled() and hasattr(self.optimizer, "bf16_groups"):
5570 bit16_groups = self.optimizer.bf16_groups
5571 else:
5572 bit16_groups = self.optimizer.bit16_groups if self.zero_optimization_stage(
5573 ) == 2 else self.optimizer.fp16_groups
5574
5575 for bit16_group in bit16_groups:
5576 param_shapes = OrderedDict()
5577 for param in bit16_group:
5578 cnt += 1
5579 numel += param.ds_numel if hasattr(param, "ds_numel") else param.numel()
5580 shape = param.ds_shape if hasattr(param, "ds_shape") else param.shape
5581 if param not in self.param_names:
5582 raise ValueError("failed to find optimizer param in named params")
5583 name = self.param_names[param]
5584 param_shapes[name] = shape
5585 param_group_shapes.append(param_shapes)
5586
5587 return param_group_shapes
5588
5589 def _get_shared_params(self):
5590 """

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
appendMethod · 0.80
numelMethod · 0.45

Tested by 2

train_save_convertFunction · 0.64
_run_testMethod · 0.64