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

Method __init__

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

Source from the content-addressed store, hash-verified

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