| 1094 | """Column-parallel vocabulary projection that keeps rank-local logits.""" |
| 1095 | |
| 1096 | def __init__(self, module, mp_group=None, **kwargs): |
| 1097 | super().__init__(module, mp_group, gather_output=False, **kwargs) |
| 1098 | if min(self._partition_sizes) == 0: |
| 1099 | # The shard-size list is identical on every TP rank, so all ranks raise here |
| 1100 | # together instead of one rank failing into a collective hang at the loss. |
| 1101 | raise ValueError(f"vocab_parallel_lm_head requires a vocabulary of at least tp_size=" |
| 1102 | f"{self.tp_world_size} rows, but '{self.name}' has {self._orig_weight_shape[0]}") |
| 1103 | self.is_vocab_parallel_lm_head = True |
| 1104 | self.vocab_size = self._orig_weight_shape[0] |
| 1105 | self.vocab_start_index = sum(self._partition_sizes[:self.tp_index]) |
| 1106 | self.vocab_end_index = self.vocab_start_index + self._partition_sizes[self.tp_index] |
| 1107 | # Set by the fused linear cross-entropy loss, which defers this projection into the loss. |
| 1108 | self.fused_loss_capture = None |
| 1109 | |
| 1110 | def forward(self, input): |
| 1111 | capture = self.fused_loss_capture |