Initializes the TensorParallel_Layer with optional model parallelism group and layer name. Args: mp_group (Optional[dist.ProcessGroup]): The process group for model parallelism. If None, no model parallelism is set.
(self, mp_group: Optional[dist.ProcessGroup], **kwargs: Any)
| 395 | """ Whether to overlap communication with computation. Currently, only allreduce supports overlap. """ |
| 396 | |
| 397 | def __init__(self, mp_group: Optional[dist.ProcessGroup], **kwargs: Any): |
| 398 | """ |
| 399 | Initializes the TensorParallel_Layer with optional model parallelism group and layer name. |
| 400 | |
| 401 | Args: |
| 402 | mp_group (Optional[dist.ProcessGroup]): The process group for model parallelism. |
| 403 | If None, no model parallelism is set. |
| 404 | """ |
| 405 | super().__init__() |
| 406 | self.support_training: bool = False |
| 407 | self.defer_collectives_to_compiler: bool = False |
| 408 | self.mp_group = mp_group |
| 409 | if mp_group is not None: |
| 410 | self.tp_world_size: int = dist.get_world_size(self.mp_group) |
| 411 | self.tp_index: int = dist.get_rank(self.mp_group) |
| 412 | else: |
| 413 | self.tp_world_size: int = 1 |
| 414 | self.tp_index: int = 0 |
| 415 | # Cached once so hot and compiled paths need no process-group query per call. |
| 416 | self.is_tp_parallel: bool = pg_utils.is_parallel(mp_group) |
| 417 | |
| 418 | # backward compatibility |
| 419 | self.world_size = self.tp_world_size |
| 420 | self.rank = self.tp_index |
| 421 | |
| 422 | self.name = getattr(self, 'name', None) |
| 423 | if kwargs.get('name') is not None: |
| 424 | self.name = kwargs.get('name') # Set the layer name if provided. |
| 425 | |
| 426 | # Per-model TP metadata threaded from AutoTP; defaults for layers built outside it |
| 427 | # (e.g. the from_weights back-compat constructor). |
| 428 | self.tp_meta: AutoTPMeta = kwargs.get('tp_meta') or AutoTPMeta() |
| 429 | |
| 430 | def _assert_compiled_if_deferred(self): |
| 431 | """Fail loudly if a deferred layer is executed outside a compiled region. |
nothing calls this directly
no test coverage detected