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

Method __init__

deepspeed/module_inject/layers.py:393–424  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

AutoTPMetaClass · 0.90
get_world_sizeMethod · 0.80
__init__Method · 0.45
get_rankMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected