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

Method __init__

deepspeed/module_inject/layers.py:1139–1181  ·  view source on GitHub ↗
(self, module, mp_group=None, tied_vocab_parallel_linear=None, **kwargs)

Source from the content-addressed store, hash-verified

1137 f"{embedding_type.__name__}.")
1138
1139 def __init__(self, module, mp_group=None, tied_vocab_parallel_linear=None, **kwargs):
1140 super().__init__(mp_group, **kwargs)
1141 self.validate_embedding(module)
1142 self.weight = module.weight
1143 # nn.Embedding has no bias, but the base class's extra_repr() unconditionally reads
1144 # self.bias, same as every other TensorParallel_Layer subclass here.
1145 self.bias = None
1146 self.support_training = True
1147
1148 if tied_vocab_parallel_linear is not None:
1149 # The lm_head side already partitioned and materialized its shard; share that
1150 # Parameter verbatim so the tied weight has exactly one physical copy per rank.
1151 # Its gather_params/_tp_partition hooks are equivalent to ours (both split dim 0
1152 # the same way), so we deliberately leave them attached instead of re-configuring.
1153 self._orig_weight_shape = tied_vocab_parallel_linear._orig_weight_shape
1154 self._partition_sizes = tied_vocab_parallel_linear._partition_sizes
1155 self.vocab_start_index = tied_vocab_parallel_linear.vocab_start_index
1156 self.vocab_end_index = tied_vocab_parallel_linear.vocab_end_index
1157 self.weight = tied_vocab_parallel_linear.weight
1158 else:
1159 self._orig_weight_shape = self._shape_before_zero3_partition(module.weight)
1160 self._freeze_partition_sizes(self._orig_weight_shape[0])
1161 if self._should_materialize_tp_partition():
1162 self._tp_partition([self.weight])
1163 self.vocab_start_index = sum(self._partition_sizes[:self.tp_index])
1164 self.vocab_end_index = self.vocab_start_index + self._partition_sizes[self.tp_index]
1165 self.config_tp_params(self.weight)
1166
1167 self.vocab_size = self._orig_weight_shape[0]
1168 self.padding_idx = None
1169 if module.padding_idx is not None and self.vocab_start_index <= module.padding_idx < self.vocab_end_index:
1170 self.padding_idx = module.padding_idx - self.vocab_start_index
1171 embed_scale = None
1172 if type(module).forward is not nn.Embedding.forward:
1173 embed_scale = module.embed_scale.to(self.weight.device)
1174 self.register_buffer("embed_scale", embed_scale, persistent=False)
1175 # collect_autotp_universal_checkpoint_info() re-invokes _mark_uc_metadata() on every
1176 # module unconditionally, so whichever of the tied pair runs last determines the
1177 # metadata actually attached to the shared Parameter. Calling it here too keeps this
1178 # layer correctly self-described even when queried standalone, before that collection
1179 # runs; the affine map it derives is identical either way since both sides shard dim 0
1180 # with the same partition_sizes.
1181 self._mark_uc_metadata()
1182
1183 def forward(self, input):
1184 self._assert_compiled_if_deferred()

Callers

nothing calls this directly

Calls 9

validate_embeddingMethod · 0.95
_tp_partitionMethod · 0.95
_mark_uc_metadataMethod · 0.95
config_tp_paramsMethod · 0.80
__init__Method · 0.45
toMethod · 0.45

Tested by

no test coverage detected