MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / PipelineEngine

Class PipelineEngine

deepspeed/runtime/pipe/engine.py:42–1307  ·  view source on GitHub ↗

A training engine hybrid pipeline, data, and model parallel training. This engine is created by ``deepspeed.initialize()`` when a :class:`PipelineModule` is provided.

Source from the content-addressed store, hash-verified

40
41
42class PipelineEngine(DeepSpeedEngine):
43 """ A training engine hybrid pipeline, data, and model parallel training.
44
45 This engine is created by ``deepspeed.initialize()`` when a :class:`PipelineModule`
46 is provided.
47 """
48 ID_TO_DTYPE = [
49 torch.float32, torch.float64, torch.complex64, torch.complex128, torch.float16, torch.bfloat16, torch.uint8,
50 torch.int8, torch.int16, torch.int32, torch.int64, torch.bool
51 ]
52 DTYPE_TO_ID = {dtype: id_ for id_, dtype in enumerate(ID_TO_DTYPE)}
53
54 def __init__(self, has_bool_tensors=False, *super_args, **super_kwargs):
55 super().__init__(*super_args, **super_kwargs)
56 assert isinstance(self.module, PipelineModule), "model must base PipelineModule"
57
58 assert self.zero_optimization_stage() < 2, "ZeRO-2 and ZeRO-3 are incompatible with pipeline parallelism"
59
60 # We schedule the all-reduces, so disable it in super().backward()
61 self.enable_backward_allreduce = False
62 self.has_bool_tensors = has_bool_tensors
63 self.eval_return_logits = False
64 self.outputs = None
65
66 # used to disable the pipeline all-reduce when used with 1-bit Adam/1-bit LAMB
67 self.pipeline_enable_backward_allreduce = True
68
69 if self.elasticity_enabled():
70 if not self.is_elastic_model_parallel_supported():
71 assert not self.elasticity_enabled(), "Elasticity is not currently supported" \
72 " with pipeline parallelism."
73
74 # pipeline step for logging
75 self.log_batch_step_id = -1
76
77 self.micro_batch_size = self.train_micro_batch_size_per_gpu()
78 self.micro_batches = self.gradient_accumulation_steps()
79
80 # Set Grid and Communication Groups
81 self.grid = self.module._grid
82 if self.grid.get_global_rank() == 0:
83 logger.info(f'CONFIG: micro_batches={self.micro_batches} '
84 f'micro_batch_size={self.micro_batch_size}')
85
86 self.global_rank = self.grid.get_global_rank()
87
88 assert self.dp_world_size == self.grid.data_parallel_size
89 assert self.train_batch_size() == \
90 self.micro_batch_size * self.micro_batches * self.grid.data_parallel_size
91
92 # Set Stage Inf
93 self.num_stages = self.grid.pipe_parallel_size
94 self.stage_id = self.grid.get_stage_id()
95 self.prev_stage = self.stage_id - 1
96 self.next_stage = self.stage_id + 1
97
98 self.data_iterator = None
99 self.batch_fn = None

Callers 1

initializeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected