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

Method _partition_layers

deepspeed/runtime/pipe/module.py:353–404  ·  view source on GitHub ↗
(self, method='uniform')

Source from the content-addressed store, hash-verified

351 return x
352
353 def _partition_layers(self, method='uniform'):
354 num_stages = self._topo.get_dim('pipe')
355 stage_id = self._topo.get_coord(self.global_rank).pipe
356
357 if self.global_rank == 0:
358 logger.info(f'Partitioning pipeline stages with method {method}')
359
360 method = method.lower()
361
362 # Each stage gets a simple uniform number of layers.
363 if method == 'uniform':
364 num_layers = len(self._layer_specs)
365 self.parts = ds_utils.partition_uniform(num_items=num_layers, num_parts=num_stages)
366 elif method == 'parameters':
367 param_counts = self._count_layer_params()
368 self.parts = ds_utils.partition_balanced(weights=param_counts, num_parts=num_stages)
369 elif method.startswith('type:'):
370 layertype = method.split(':')[1]
371 binary_weights = [0] * len(self._layer_specs)
372 for idx in self._find_layer_type(layertype):
373 binary_weights[idx] = 1
374 self.parts = ds_utils.partition_balanced(weights=binary_weights, num_parts=num_stages)
375 elif method == 'profile':
376 raise NotImplementedError(f'Partitioning method {method} not implemented.')
377 else:
378 raise NotImplementedError(f'Partitioning method {method} not implemented.')
379
380 # Print some information on the partitioning.
381 if self.global_rank == 0:
382 for stage in range(num_stages):
383 start = self.parts[stage]
384 stop = self.parts[stage + 1]
385 print(f'stage={stage} layers={stop - start}')
386 for idx, layer in enumerate(self._layer_specs[start:stop]):
387 name = str(layer)
388 if isinstance(layer, LayerSpec):
389 name = layer.typename.__name__
390 if isinstance(layer, nn.Module):
391 name = layer.__class__.__name__
392 else:
393 try:
394 name = layer.__name__
395 except AttributeError:
396 pass
397 print(f' {idx+start:2d}: {name}')
398 if self.loss_fn:
399 try:
400 print(f' loss: {self.loss_fn.__name__}')
401 except AttributeError:
402 print(f' loss: {self.loss_fn.__class__.__name__}')
403
404 self._set_bounds(start=self.parts[stage_id], stop=self.parts[stage_id + 1])
405
406 def allreduce_tied_weight_gradients(self):
407 '''All reduce the gradients of the tied weights between tied stages'''

Callers 1

__init__Method · 0.95

Calls 5

_count_layer_paramsMethod · 0.95
_find_layer_typeMethod · 0.95
_set_boundsMethod · 0.95
get_dimMethod · 0.80
get_coordMethod · 0.80

Tested by

no test coverage detected