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

Method forward

deepspeed/module_inject/layers.py:1187–1202  ·  view source on GitHub ↗
(self, input)

Source from the content-addressed store, hash-verified

1185 self._mark_uc_metadata()
1186
1187 def forward(self, input):
1188 self._assert_compiled_if_deferred()
1189 if not self.is_tp_parallel:
1190 output = F.embedding(input, self.weight, padding_idx=self.padding_idx)
1191 else:
1192 # Tokens outside this rank's vocab shard are remapped to index 0 so the local lookup
1193 # never runs out of bounds; their (wrong) contribution is then zeroed before the
1194 # cross-rank reduction assembles the correct embedding for every token.
1195 input_mask = (input < self.vocab_start_index) | (input >= self.vocab_end_index)
1196 local_input = (input - self.vocab_start_index).masked_fill(input_mask, 0)
1197 output = F.embedding(local_input, self.weight, padding_idx=self.padding_idx)
1198 output = output.masked_fill(input_mask.unsqueeze(-1), 0.0)
1199 output = RowParallel.apply(self.mp_group, output, not self.is_training_mode())
1200 if self.embed_scale is not None:
1201 output = output * self.embed_scale.to(self.weight.dtype)
1202 return output
1203
1204 @torch.no_grad()
1205 def gather_params(self, params_list):

Callers

nothing calls this directly

Calls 4

is_training_modeMethod · 0.80
applyMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected