mindformers.wrapper.MFPipelineWithLossScaleCell

class mindformers.wrapper.MFPipelineWithLossScaleCell(network, optimizer, use_clip_grad=True, max_grad_norm=1.0, scale_sense=1.0, micro_batch_num=1, **kwargs)[源代码]

Append an train one step cell with loss scale of pipeline parallel for MindFormers.

参数
  • network (Cell) – The training network. Note that loss function should have been added.

  • optimizer (Optimizer) – Optimizer for updating the weights.

  • use_clip_grad (bool) – Whether to use gradient clipping. Default: True.

  • max_grad_norm (float) – Maximum gradient constraint value. Default: 1.0.

  • scale_sense (Cell) – Cell to do the loss scale. Default: 1.0.

  • micro_batch_num (int) – Micro batch number of pipeline parallel. Default: 1.

Inputs:
  • (*inputs) (Tuple(Tensor)) - Tuple of input tensors with shape \((N, \ldots)\).

Outputs:

Tuple of 3 Tensor, the loss, overflow flag and current loss scale value.

  • loss (Tensor) - A scalar, the loss value.

  • overflow (Tensor) - A scalar, whether overflow occur or not, the type is bool.

  • loss scale (Tensor) - The loss scale value, the shape is \(()\) or \((1,)\).

引发
  • TypeError – If scale_sense is neither Cell nor Tensor.

  • ValueError – If shape of scale_sense is neither (1,) nor ().