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