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

Method __init__

deepspeed/module_inject/layers.py:397–428  ·  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

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.

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