mindspore.nn.FixedLossScaleUpdateCell
- class mindspore.nn.FixedLossScaleUpdateCell(loss_scale_value)[source]
Static scale update cell, the loss scaling value will not be updated.
For usage, refer to DynamicLossScaleUpdateCell.
- Parameters
loss_scale_value (float) – Initializes loss scale.
- Inputs:
loss_scale (Tensor) - The loss scale value during training with shape \(()\), that will be ignored.
overflow (bool) - Whether the overflow occurs or not.
- Outputs:
bool, the input overflow.
- Supported Platforms:
Ascend
GPU
Examples
>>> import numpy as np >>> from mindspore import Tensor, Parameter, nn, ops >>> >>> class Net(nn.Cell): ... def __init__(self, in_features, out_features): ... super(Net, self).__init__() ... self.weight = Parameter(Tensor(np.ones([in_features, out_features]).astype(np.float32)), ... name='weight') ... self.matmul = ops.MatMul() ... ... def construct(self, x): ... output = self.matmul(x, self.weight) ... return output ... >>> in_features, out_features = 16, 10 >>> net = Net(in_features, out_features) >>> loss = nn.MSELoss() >>> optimizer = nn.Momentum(net.trainable_params(), learning_rate=0.1, momentum=0.9) >>> net_with_loss = nn.WithLossCell(net, loss) >>> manager = nn.FixedLossScaleUpdateCell(loss_scale_value=2**12) >>> train_network = nn.TrainOneStepWithLossScaleCell(net_with_loss, optimizer, scale_sense=manager) >>> input = Tensor(np.ones([out_features, in_features]), mindspore.float32) >>> labels = Tensor(np.ones([out_features,]), mindspore.float32) >>> output = train_network(input, labels)