Browse Source

!10034 modify Note

From: @Somnus2020
Reviewed-by: @zhunaipan,@kingxian,@zhoufeng54
Signed-off-by: @kingxian
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
e694161ce9
2 changed files with 10 additions and 6 deletions
  1. +1
    -1
      mindspore/nn/wrap/cell_wrapper.py
  2. +9
    -5
      mindspore/nn/wrap/loss_scale.py

+ 1
- 1
mindspore/nn/wrap/cell_wrapper.py View File

@@ -412,7 +412,7 @@ class ParameterUpdate(Cell):
>>> update = nn.ParameterUpdate(param)
>>> update.phase = "update_param"
>>> weight = Tensor(np.arange(12).reshape((4, 3)), mindspore.float32)
>>> network_updata = update(weight)
>>> output = update(weight)
"""

def __init__(self, param):


+ 9
- 5
mindspore/nn/wrap/loss_scale.py View File

@@ -102,7 +102,9 @@ class DynamicLossScaleUpdateCell(Cell):
>>> net_with_loss = WithLossCell(net, loss)
>>> manager = nn.DynamicLossScaleUpdateCell(loss_scale_value=2**12, scale_factor=2, scale_window=1000)
>>> train_network = nn.TrainOneStepWithLossScaleCell(net_with_loss, optimizer, scale_sense=manager)
>>> train_network.set_train()
>>> input = Tensor(np.ones([out_features, in_features]), mindspore.float32)
>>> labels = Tensor(np.ones([out_features,]), mindspore.float32)
>>> output = train_network(input, labels)
"""

def __init__(self,
@@ -185,7 +187,9 @@ class FixedLossScaleUpdateCell(Cell):
>>> net_with_loss = WithLossCell(net, loss)
>>> manager = nn.FixedLossScaleUpdateCell(loss_scale_value=2**12)
>>> train_network = nn.TrainOneStepWithLossScaleCell(net_with_loss, optimizer, scale_sense=manager)
>>> train_network.set_train()
>>> input = Tensor(np.ones([out_features, in_features]), mindspore.float32)
>>> labels = Tensor(np.ones([out_features,]), mindspore.float32)
>>> output = train_network(input, labels)
"""

def __init__(self, loss_scale_value):
@@ -255,7 +259,9 @@ class TrainOneStepWithLossScaleCell(TrainOneStepCell):
>>> net_with_loss = WithLossCell(net, loss)
>>> manager = nn.DynamicLossScaleUpdateCell(loss_scale_value=2**12, scale_factor=2, scale_window=1000)
>>> train_network = nn.TrainOneStepWithLossScaleCell(net_with_loss, optimizer, scale_sense=manager)
>>> train_network.set_train()
>>> input = Tensor(np.ones([out_features, in_features]), mindspore.float32)
>>> labels = Tensor(np.ones([out_features,]), mindspore.float32)
>>> output = train_network(input, labels)
>>>
>>> #2) when the type of scale_sense is Tensor:
>>> net = Net(in_features, out_features)
@@ -267,8 +273,6 @@ class TrainOneStepWithLossScaleCell(TrainOneStepCell):
>>> scaling_sens = Tensor(np.full((1), np.finfo(np.float32).max), dtype=mstype.float32)
>>> train_network = nn.TrainOneStepWithLossScaleCell(net_with_loss, optimizer, scale_sense=scaling_sens)
>>> output = train_network(inputs, label)
>>> print(output[0])
256.0
"""
def __init__(self, network, optimizer, scale_sense):
super(TrainOneStepWithLossScaleCell, self).__init__(network, optimizer, sens=None)


Loading…
Cancel
Save