(self)
| 215 | self.module.transformer._prepare_attn_mask = lambda attention_mask, *args, **kwargs: attention_mask |
| 216 | |
| 217 | def build_alibi_tensor(self): |
| 218 | if hasattr(self.module, 'transformer'): |
| 219 | if hasattr(self.module.transformer, 'build_alibi_tensor'): |
| 220 | # The heads must be sliced with the same tensor-parallel group that partitioned |
| 221 | # the attention weights, so bind it rather than letting the helper guess. |
| 222 | meta = self._autotp_meta(self.module.transformer) |
| 223 | shard_sizes = get_head_shard_sizes(meta, self.mp_group) |
| 224 | self.module.transformer.build_alibi_tensor = functools.partial( |
| 225 | build_bloom_alibi_tensor, |
| 226 | mp_group=self.mp_group, |
| 227 | head_shard_sizes=shard_sizes, |
| 228 | total_num_heads=meta.num_attention_heads) |
| 229 | if hasattr(self.module.transformer, 'build_mpt_alibi_tensor'): |
| 230 | meta = self._autotp_meta(self.module.transformer) |
| 231 | install_head_sharded_helper(self.module.transformer, 'build_mpt_alibi_tensor', build_mpt_alibi_tensor, |
| 232 | meta, self.mp_group) |
| 233 | if hasattr(self.module, 'model'): |
| 234 | if hasattr(self.module.model, 'get_alibi_mask'): |
| 235 | meta = self._autotp_meta(self.module.model) |
| 236 | install_head_sharded_helper(self.module.model, 'get_alibi_mask', get_alibi_mask, meta, self.mp_group) |
| 237 | |
| 238 | def build_attn_bias(self): |
| 239 | if hasattr(self.module, 'transformer'): |
no test coverage detected