diff --git a/benchmark/ascend/bert/src/bert_for_pre_training.py b/benchmark/ascend/bert/src/bert_for_pre_training.py index ec27daeaf412602b8b4eecda5174c3a78072fc39..e94b32a4e11ed4f8e4e29db948098d9ec435dcda 100644 --- a/benchmark/ascend/bert/src/bert_for_pre_training.py +++ b/benchmark/ascend/bert/src/bert_for_pre_training.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -403,7 +403,7 @@ class BertTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell): @@ -474,7 +474,7 @@ class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell) if self.loss_scaling_manager is not None: overflow = self.loss_scaling_manager(scaling_sens, cond) self.optimizer(grads, overflow) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) cast = P.Cast() add_grads = C.MultitypeFuncGraph("add_grads") @@ -651,7 +651,7 @@ class BertTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) - return (mean_loss, overflow, scaling_sens) + return (mean_loss, overflow, scaling_sens.value()) class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): @@ -798,7 +798,7 @@ class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): accu_succ = self.hyper_map(reset_accu_grads, self.accu_grads) succ = F.depend(succ, accu_succ) - ret = (mean_loss, overflow, scaling_sens) + ret = (mean_loss, overflow, scaling_sens.value()) return F.depend(ret, succ) diff --git a/benchmark/ascend/bert/src/bert_model.py b/benchmark/ascend/bert/src/bert_model.py index ef6c219c7566a40d6959ab1c0b61d9a1124ff540..dc16018e2d3632ef770dd0682547b4400cab13dc 100644 --- a/benchmark/ascend/bert/src/bert_model.py +++ b/benchmark/ascend/bert/src/bert_model.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/official/audio/tacotron2/src/tacotron2.py b/official/audio/tacotron2/src/tacotron2.py index d9d13630ee5101a330320f42c6555b631f7f503d..010009eac8256c4d417db72826d471e7265c7852 100644 --- a/official/audio/tacotron2/src/tacotron2.py +++ b/official/audio/tacotron2/src/tacotron2.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -1194,5 +1194,5 @@ class TrainStepWrap(nn.Cell): else: succ = self.optimizer(grads) - ret = (loss, scale_sense) + ret = (loss, scale_sense.value()) return F.depend(ret, succ) diff --git a/official/nlp/bert/src/bert_for_pre_training.py b/official/nlp/bert/src/bert_for_pre_training.py index a483913524d67387d7388443d0ab1a6f57b0cab7..1129203186665aeb66a4d7ae65eed142afe560d2 100644 --- a/official/nlp/bert/src/bert_for_pre_training.py +++ b/official/nlp/bert/src/bert_for_pre_training.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ from mindspore.common.api import ms_function from mindspore.common import dtype as mstype from mindspore.nn.wrap.grad_reducer import DistributedGradReducer from mindspore.context import ParallelMode -import mindspore.common._monad as monad from mindspore.communication.management import get_group_size from mindspore import context from .bert_model import BertModel @@ -367,7 +366,6 @@ class BertTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): if scale_update_cell: self.loss_scale = Parameter(Tensor(scale_update_cell.get_loss_scale(), dtype=mstype.float32)) self.enable_tuple_broaden = True - self.load = P.Load() @ms_function def clip_grads(self, grads): @@ -418,7 +416,7 @@ class BertTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return loss, cond, self.load(scaling_sens, monad.U) + return loss, cond, scaling_sens.value() class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell): @@ -495,7 +493,7 @@ class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell) if self.loss_scaling_manager is not None: overflow = self.loss_scaling_manager(scaling_sens, cond) self.optimizer(grads, overflow) - return (loss, cond, scaling_sens) + return loss, cond, scaling_sens.value() cast = P.Cast() add_grads = C.MultitypeFuncGraph("add_grads") @@ -672,7 +670,7 @@ class BertTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) - return (mean_loss, overflow, scaling_sens) + return mean_loss, overflow, scaling_sens.value() class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): @@ -819,7 +817,7 @@ class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): accu_succ = self.hyper_map(reset_accu_grads, self.accu_grads) succ = F.depend(succ, accu_succ) - ret = (mean_loss, overflow, scaling_sens) + ret = (mean_loss, overflow, scaling_sens.value()) return F.depend(ret, succ) diff --git a/official/nlp/bert/src/bert_model.py b/official/nlp/bert/src/bert_model.py index ef6c219c7566a40d6959ab1c0b61d9a1124ff540..dc16018e2d3632ef770dd0682547b4400cab13dc 100644 --- a/official/nlp/bert/src/bert_model.py +++ b/official/nlp/bert/src/bert_model.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/official/nlp/bert_thor/src/bert_for_pre_training.py b/official/nlp/bert_thor/src/bert_for_pre_training.py index 6b845d28da5eb84513a7ad98cab378cfc8aa665b..238832ffacd4102e4e7a10788a832ebb7b64185a 100644 --- a/official/nlp/bert_thor/src/bert_for_pre_training.py +++ b/official/nlp/bert_thor/src/bert_for_pre_training.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -402,7 +402,7 @@ class BertTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell): @@ -473,7 +473,7 @@ class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell) if self.loss_scaling_manager is not None: overflow = self.loss_scaling_manager(scaling_sens, cond) self.optimizer(grads, overflow) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) cast = P.Cast() add_grads = C.MultitypeFuncGraph("add_grads") @@ -650,7 +650,7 @@ class BertTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) - return (mean_loss, overflow, scaling_sens) + return (mean_loss, overflow, scaling_sens.value()) class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): @@ -797,5 +797,5 @@ class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): accu_succ = self.hyper_map(reset_accu_grads, self.accu_grads) succ = F.depend(succ, accu_succ) - ret = (mean_loss, overflow, scaling_sens) + ret = (mean_loss, overflow, scaling_sens.value()) return F.depend(ret, succ) diff --git a/official/nlp/bert_thor/src/bert_model.py b/official/nlp/bert_thor/src/bert_model.py index 7fe4f8955d6ce0d8741eaf5c664dbaf757e349ec..f7211843d58c2db2c03679259c72db57a6944d60 100644 --- a/official/nlp/bert_thor/src/bert_model.py +++ b/official/nlp/bert_thor/src/bert_model.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/official/nlp/cpm/src/embedding.py b/official/nlp/cpm/src/embedding.py index 9d9bdd40c2b906bbd072d4c9bc2c575ada7d53d3..2411485a2a05b0e13a1cefa0edfba49589839d69 100644 --- a/official/nlp/cpm/src/embedding.py +++ b/official/nlp/cpm/src/embedding.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -111,7 +111,7 @@ class EmbeddingLookup(nn.Cell): zero_tiled = self.cast(zero_tiled, self.get_dtype(output)) output = self.select(self.cast(input_mask_tile, mstype.bool_), zero_tiled, output) output = self.cast(output, mstype.float32) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/official/nlp/dgu/src/bert_for_pre_training.py b/official/nlp/dgu/src/bert_for_pre_training.py index e75e928c97cc1e0b4fcf376027c4125d0a4c80c9..926c7fdeb1cd74ad2ab67d7da02bd296bcba5568 100644 --- a/official/nlp/dgu/src/bert_for_pre_training.py +++ b/official/nlp/dgu/src/bert_for_pre_training.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -399,7 +399,7 @@ class BertTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell): @@ -470,7 +470,7 @@ class BertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell) if self.loss_scaling_manager is not None: overflow = self.loss_scaling_manager(scaling_sens, cond) self.optimizer(grads, overflow) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) cast = P.Cast() add_grads = C.MultitypeFuncGraph("add_grads") @@ -647,7 +647,7 @@ class BertTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) - return (mean_loss, overflow, scaling_sens) + return (mean_loss, overflow, scaling_sens.value()) class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): @@ -794,5 +794,5 @@ class BertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): accu_succ = self.hyper_map(reset_accu_grads, self.accu_grads) succ = F.depend(succ, accu_succ) - ret = (mean_loss, overflow, scaling_sens) + ret = (mean_loss, overflow, scaling_sens.value()) return F.depend(ret, succ) diff --git a/official/nlp/dgu/src/bert_model.py b/official/nlp/dgu/src/bert_model.py index b5a29588547ad97258f1a8637d175c1f9c66ac5f..268a8782c68308c30e5f96da667b3732e84daa48 100644 --- a/official/nlp/dgu/src/bert_model.py +++ b/official/nlp/dgu/src/bert_model.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/official/nlp/emotect/src/ernie_model.py b/official/nlp/emotect/src/ernie_model.py index ee678abf751943725a04b848ab8ea9b5e41184b6..e654ad0578f3737770e9d88d6a850f7e0b62a372 100644 --- a/official/nlp/emotect/src/ernie_model.py +++ b/official/nlp/emotect/src/ernie_model.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -129,7 +129,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/official/nlp/ernie/src/ernie_for_pretraining.py b/official/nlp/ernie/src/ernie_for_pretraining.py index 9af031f7714366df8063cf9419767d85683aa6c7..119632ea1b31067ed89fab7f8d0be86fdcb87a3c 100644 --- a/official/nlp/ernie/src/ernie_for_pretraining.py +++ b/official/nlp/ernie/src/ernie_for_pretraining.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -404,7 +404,7 @@ class ErnieTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): succ = False else: succ = self.optimizer(grads) - ret = (loss, cond, scaling_sens) + ret = (loss, cond, scaling_sens.value()) return F.depend(ret, succ) @@ -476,7 +476,7 @@ class ErnieTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell if self.loss_scaling_manager is not None: overflow = self.loss_scaling_manager(scaling_sens, cond) succ = self.optimizer(grads, overflow) - ret = (loss, cond, scaling_sens) + ret = (loss, cond, scaling_sens.value()) return F.depend(ret, succ) cast = P.Cast() @@ -658,7 +658,7 @@ class ErnieTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): else: succ = self.optimizer(grads) - ret = (mean_loss, overflow, scaling_sens) + ret = (mean_loss, overflow, scaling_sens.value()) return F.depend(ret, succ) @@ -806,5 +806,5 @@ class ErnieTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): accu_succ = self.hyper_map(reset_accu_grads, self.accu_grads) succ = F.depend(succ, accu_succ) - ret = (mean_loss, overflow, scaling_sens) + ret = (mean_loss, overflow, scaling_sens.value()) return F.depend(ret, succ) diff --git a/official/nlp/ernie/src/ernie_model.py b/official/nlp/ernie/src/ernie_model.py index b3c6523552c6c9d925ab28dcb9522acd6e23680b..557965c91f22410ae95aedac26130ce17cf908f0 100644 --- a/official/nlp/ernie/src/ernie_model.py +++ b/official/nlp/ernie/src/ernie_model.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -129,7 +129,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/official/nlp/gnmt_v2/src/gnmt_model/gnmt_for_train.py b/official/nlp/gnmt_v2/src/gnmt_model/gnmt_for_train.py index 2ec0b80a03368ccc3da09a8a9ae8b718fece36d5..1519f2d1d402f5d7b9697ded5b8a377f9c38c4f0 100644 --- a/official/nlp/gnmt_v2/src/gnmt_model/gnmt_for_train.py +++ b/official/nlp/gnmt_v2/src/gnmt_model/gnmt_for_train.py @@ -286,4 +286,4 @@ class GNMTTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) diff --git a/official/nlp/gpt/src/gpt.py b/official/nlp/gpt/src/gpt.py index f3747ad21d103d033483025376c35ddb48b4a17b..edcc2c7f02a7af478889731ceecd9734b2806309 100644 --- a/official/nlp/gpt/src/gpt.py +++ b/official/nlp/gpt/src/gpt.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ class EmbeddingLookup(nn.Cell): self.shape = (-1, config.seq_length, config.embedding_size) def construct(self, input_ids): output = self.gather(self.embedding_table, input_ids, 0) - return output, self.embedding_table + return output, self.embedding_table.value() class GPT_Model(nn.Cell): diff --git a/official/nlp/gpt/src/gpt_wrapcell.py b/official/nlp/gpt/src/gpt_wrapcell.py index 399250e5f99e6002bead5e46bc266caa6c6a22bf..07c8e25add6dff594597917114a81fb652761db1 100644 --- a/official/nlp/gpt/src/gpt_wrapcell.py +++ b/official/nlp/gpt/src/gpt_wrapcell.py @@ -153,4 +153,4 @@ class GPTTrainOneStepWithLossScaleCell(nn.Cell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) diff --git a/official/nlp/gru/src/gru_for_train.py b/official/nlp/gru/src/gru_for_train.py index e65a7b48362d30adb85ace30bccc9bcba1a15f66..2f029d99f8e3a56863d2b8335f62a41e7c799d73 100644 --- a/official/nlp/gru/src/gru_for_train.py +++ b/official/nlp/gru/src/gru_for_train.py @@ -236,7 +236,7 @@ class GRUTrainOneStepWithLossScaleCell(nn.Cell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class GRUTrainOneStepCell(nn.TrainOneStepCell): """ diff --git a/official/nlp/mass/src/transformer/embedding.py b/official/nlp/mass/src/transformer/embedding.py index 0b878e455bbfac0268650de3123ac97326e7e43a..8dbaf005526450f7249bc06ab1d6ab9707109ebc 100644 --- a/official/nlp/mass/src/transformer/embedding.py +++ b/official/nlp/mass/src/transformer/embedding.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -77,4 +77,4 @@ class EmbeddingLookup(nn.Cell): output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, (_batch_size, _max_len, self.embedding_dim)) - return output, self.embedding_table + return output, self.embedding_table.value() diff --git a/official/nlp/mass/src/transformer/transformer_for_train.py b/official/nlp/mass/src/transformer/transformer_for_train.py index 21a130240498cc1951ca7ebe255d18cf56694e38..e54165c5a43d4c3ac1aacc481609d2390a8f64f0 100644 --- a/official/nlp/mass/src/transformer/transformer_for_train.py +++ b/official/nlp/mass/src/transformer/transformer_for_train.py @@ -298,4 +298,4 @@ class TransformerTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) diff --git a/official/nlp/tinybert/src/tinybert_for_gd_td.py b/official/nlp/tinybert/src/tinybert_for_gd_td.py index 076fd919f45bdf07259d729ea726bbd585585fb6..e60835f85bc41c0cc810fac94ae442051f268569 100644 --- a/official/nlp/tinybert/src/tinybert_for_gd_td.py +++ b/official/nlp/tinybert/src/tinybert_for_gd_td.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -246,7 +246,7 @@ class BertTrainWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.process_loss_scale(cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class BertTrainCell(nn.Cell): """ @@ -470,7 +470,7 @@ class BertEvaluationWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.process_loss_scale(cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class BertEvaluationCell(nn.Cell): diff --git a/official/nlp/transformer/src/transformer_for_train.py b/official/nlp/transformer/src/transformer_for_train.py index cbfccc881cb9907811f314529e5f98fc47174005..be6bba0dfc0b7585da1743320087e38e9367083a 100644 --- a/official/nlp/transformer/src/transformer_for_train.py +++ b/official/nlp/transformer/src/transformer_for_train.py @@ -294,7 +294,7 @@ class TransformerTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell) overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) cast = ops.Cast() @@ -496,4 +496,4 @@ class TransformerTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) - return (mean_loss, overflow, scaling_sens) + return (mean_loss, overflow, scaling_sens.value()) diff --git a/official/nlp/transformer/src/transformer_model.py b/official/nlp/transformer/src/transformer_model.py index 172447b586793f90792c7abeab16e78d15430d6e..920c27e4f3326808f0d7c10294a8fddbf2de2678 100644 --- a/official/nlp/transformer/src/transformer_model.py +++ b/official/nlp/transformer/src/transformer_model.py @@ -138,7 +138,7 @@ class EmbeddingLookup(nn.Cell): out_shape = input_shape + (self.embedding_size,) output = self.reshape(output_for_reshape, out_shape) - return output, self.embedding_table + return output, self.embedding_table.value() def position_encoding(length, diff --git a/official/recommend/deep_and_cross/src/deep_and_cross.py b/official/recommend/deep_and_cross/src/deep_and_cross.py index 45fa398e9634054727831787142b110c49113d11..3862ecc2931db16d82b81a6a332a596598270734 100644 --- a/official/recommend/deep_and_cross/src/deep_and_cross.py +++ b/official/recommend/deep_and_cross/src/deep_and_cross.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -185,7 +185,7 @@ class EmbeddingLookup(nn.Cell): out_shape = input_shape + (self.embedding_size,) output = self.reshape(output_for_reshape, out_shape) - return output, self.embedding_table + return output, self.embedding_table.value() class DeepCrossModel(nn.Cell): diff --git a/research/audio/speech_transformer/src/transformer_for_train.py b/research/audio/speech_transformer/src/transformer_for_train.py index a5437a919437447a683c6395a1a4cde6433760db..e6e0867fb0a34dc2935a9364f34e2432549aba4e 100644 --- a/research/audio/speech_transformer/src/transformer_for_train.py +++ b/research/audio/speech_transformer/src/transformer_for_train.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -285,7 +285,7 @@ class TransformerTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell) overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) cast = P.Cast() diff --git a/research/audio/speech_transformer/src/transformer_model.py b/research/audio/speech_transformer/src/transformer_model.py index 5bc9afbe148ec69a494206e5a870765cf66c322b..05c7a8b579ba4b3b805b891e44ec3486f20563b4 100644 --- a/research/audio/speech_transformer/src/transformer_model.py +++ b/research/audio/speech_transformer/src/transformer_model.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -144,7 +144,7 @@ class EmbeddingLookup(nn.Cell): out_shape = input_shape + (self.embedding_size,) output = self.reshape(output_for_reshape, out_shape) - return output, self.embedding_table + return output, self.embedding_table.value() def position_encoding(length, diff --git a/research/audio/wavenet/src/loss.py b/research/audio/wavenet/src/loss.py index ecbf78219297fd4b93aed322029bd281e7f64c93..6b164c151fcddbe3ac60fe1a4141dc447871a988 100644 --- a/research/audio/wavenet/src/loss.py +++ b/research/audio/wavenet/src/loss.py @@ -446,5 +446,5 @@ class WaveNetTrainOneStepWithLossScaleCell(nn.Cell): self.scalar_summary("training.loss", loss) - ret = (loss, scale_sense) + ret = (loss, scale_sense.value()) return F.depend(ret, succ) diff --git a/research/cv/FaceDetection/src/network_define.py b/research/cv/FaceDetection/src/network_define.py index c46449c5767cff498baa639453a9dbfc6b1d735d..acaa665e1490106c41ca9914f63140f17fe8223c 100644 --- a/research/cv/FaceDetection/src/network_define.py +++ b/research/cv/FaceDetection/src/network_define.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -139,7 +139,7 @@ class TrainOneStepWithLossScaleCell(nn.Cell): cond = self.less_equal(self.base, flag_sum) self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class BuildTrainNetworkV2(nn.Cell): diff --git a/research/cv/IPT/src/loss.py b/research/cv/IPT/src/loss.py index 4ff191b64fc2e9dc8cc66051f586868baf2745f3..b9b71753596d23fe88704e724ab7ef4f29506366 100644 --- a/research/cv/IPT/src/loss.py +++ b/research/cv/IPT/src/loss.py @@ -144,7 +144,7 @@ class IPTTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class SupConLoss(nn.Cell): diff --git a/research/cv/LearningToSeeInTheDark/src/myutils.py b/research/cv/LearningToSeeInTheDark/src/myutils.py index 428e7ae5819f94320ed5570f967fd2b9c3a1a8ea..a0c01b63a32cfba8fca7a57a976779fcdb2dafa2 100644 --- a/research/cv/LearningToSeeInTheDark/src/myutils.py +++ b/research/cv/LearningToSeeInTheDark/src/myutils.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -228,4 +228,4 @@ class GNMTTrainOneStepWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) self.loss_scalar("loss", loss) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) diff --git a/research/cv/centernet/src/centernet_pose.py b/research/cv/centernet/src/centernet_pose.py index a9a0322ee52ba38c3b1e4a47d635e771f2effde9..f5509935acd2b236b99c2212ad1b8f40e31fb44e 100644 --- a/research/cv/centernet/src/centernet_pose.py +++ b/research/cv/centernet/src/centernet_pose.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -309,7 +309,7 @@ class CenterNetWithLossScaleCell(nn.Cell): cond = self.less_equal(self.base, flag_sum) self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class CenterNetMultiPoseEval(nn.Cell): """ diff --git a/research/mm/opt/src/model_mindspore/parallel_transformer.py b/research/mm/opt/src/model_mindspore/parallel_transformer.py index a0ba8c95e6db051d9b70b5433be2650681403f77..6dce1396afaa173785380958d07adaa4185d3d27 100644 --- a/research/mm/opt/src/model_mindspore/parallel_transformer.py +++ b/research/mm/opt/src/model_mindspore/parallel_transformer.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -633,7 +633,7 @@ class VocabEmbedding(Cell): def construct(self, input_ids): output = self.gather(self.embedding_table, input_ids, 0) - return output, self.embedding_table + return output, self.embedding_table.value() class MultiHeadAttention(Cell): diff --git a/research/nlp/DYR/src/bert_model.py b/research/nlp/DYR/src/bert_model.py index 7fe4f8955d6ce0d8741eaf5c664dbaf757e349ec..f7211843d58c2db2c03679259c72db57a6944d60 100644 --- a/research/nlp/DYR/src/bert_model.py +++ b/research/nlp/DYR/src/bert_model.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/research/nlp/albert/src/albert_for_pre_training.py b/research/nlp/albert/src/albert_for_pre_training.py index d1c795b862b7977220ecd6641420af4028e1b489..51cd62a117f8170507734567c603861d1cec152f 100644 --- a/research/nlp/albert/src/albert_for_pre_training.py +++ b/research/nlp/albert/src/albert_for_pre_training.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -403,7 +403,7 @@ class AlbertTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class AlbertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCell): @@ -474,7 +474,7 @@ class AlbertTrainOneStepWithLossScaleCellForAdam(nn.TrainOneStepWithLossScaleCel if self.loss_scaling_manager is not None: overflow = self.loss_scaling_manager(scaling_sens, cond) self.optimizer(grads, overflow) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) cast = P.Cast() add_grads = C.MultitypeFuncGraph("add_grads") @@ -651,7 +651,7 @@ class AlbertTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) - return (mean_loss, overflow, scaling_sens) + return (mean_loss, overflow, scaling_sens.value()) class AlbertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): @@ -798,7 +798,7 @@ class AlbertTrainAccumulationAllReduceEachWithLossScaleCell(nn.Cell): accu_succ = self.hyper_map(reset_accu_grads, self.accu_grads) succ = F.depend(succ, accu_succ) - ret = (mean_loss, overflow, scaling_sens) + ret = (mean_loss, overflow, scaling_sens.value()) return F.depend(ret, succ) diff --git a/research/nlp/albert/src/albert_model.py b/research/nlp/albert/src/albert_model.py index 625d587d82c996b2f735004fdf001a1974f158cd..4f2720d5ef54172a9dc9dd335ca7e1f8068dd978 100644 --- a/research/nlp/albert/src/albert_model.py +++ b/research/nlp/albert/src/albert_model.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -145,7 +145,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/research/nlp/gpt2/src/GPT2_model.py b/research/nlp/gpt2/src/GPT2_model.py index c7baa4e3dfc0f7961135c66517dff57b6f6a996f..b862565d12bdcdff87388ae3a2d4e9d7a564124e 100644 --- a/research/nlp/gpt2/src/GPT2_model.py +++ b/research/nlp/gpt2/src/GPT2_model.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -152,7 +152,7 @@ class EmbeddingLookup(nn.Cell): out_shape = input_shape + (self.embedding_dim,) output = self.reshape(output_for_reshape, out_shape) # [batch_size, seq_length, embedidng_dim] - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/research/nlp/ktnet/src/bert.py b/research/nlp/ktnet/src/bert.py index c30728502bb7aba0fdcd618b92c4363995d6ec4a..f3d06a4bb38b980fc48b16a40724a332c22814b9 100644 --- a/research/nlp/ktnet/src/bert.py +++ b/research/nlp/ktnet/src/bert.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -134,7 +134,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/research/nlp/senta/src/bert_model.py b/research/nlp/senta/src/bert_model.py index 78bd83a07a61c0581e449673793ad40b1ac9c86c..eb0cba1802ceed860dcabdfa1818a4da6e622b69 100644 --- a/research/nlp/senta/src/bert_model.py +++ b/research/nlp/senta/src/bert_model.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/research/nlp/soft_masked_bert/src/bert_model.py b/research/nlp/soft_masked_bert/src/bert_model.py index b7a3e39bfe9bb209af131f303bdda6baecd08cfc..81602cf32c6b0451b7e2ab85da8c16d03f2a9033 100644 --- a/research/nlp/soft_masked_bert/src/bert_model.py +++ b/research/nlp/soft_masked_bert/src/bert_model.py @@ -187,7 +187,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): """ diff --git a/research/nlp/speech_transformer/src/transformer_for_train.py b/research/nlp/speech_transformer/src/transformer_for_train.py index d3e1ab91096474fc4de15afb92c5b1c93df05595..8342a899e14f50d786a764718ab5d231498e9f8c 100644 --- a/research/nlp/speech_transformer/src/transformer_for_train.py +++ b/research/nlp/speech_transformer/src/transformer_for_train.py @@ -329,7 +329,7 @@ class TransformerTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell) overflow = self.loss_scaling_manager(self.loss_scale, cond) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) cast = P.Cast() @@ -519,4 +519,4 @@ class TransformerTrainAccumulationAllReducePostWithLossScaleCell(nn.Cell): if not overflow: self.optimizer(grads) - return mean_loss, overflow, scaling_sens + return mean_loss, overflow, scaling_sens.value() diff --git a/research/nlp/speech_transformer/src/transformer_model.py b/research/nlp/speech_transformer/src/transformer_model.py index bc4c2da1545c9e9a12f06f235e33c20e85c3c3d8..790e3050e725fe77f9bb003632ef9eced800d84b 100644 --- a/research/nlp/speech_transformer/src/transformer_model.py +++ b/research/nlp/speech_transformer/src/transformer_model.py @@ -144,7 +144,7 @@ class EmbeddingLookup(nn.Cell): out_shape = input_shape + (self.embedding_size,) output = self.reshape(output_for_reshape, out_shape) - return output, self.embedding_table + return output, self.embedding_table.value() def position_encoding(length, diff --git a/research/nlp/ternarybert/src/cell_wrapper.py b/research/nlp/ternarybert/src/cell_wrapper.py index d350f5a6111901dc4d11d9eafb4c5c02fd4dd084..888358b19d9aab0cde1752b6242439aca23ebfeb 100644 --- a/research/nlp/ternarybert/src/cell_wrapper.py +++ b/research/nlp/ternarybert/src/cell_wrapper.py @@ -406,7 +406,7 @@ class BertTrainOneStepWithLossScaleCell(nn.TrainOneStepWithLossScaleCell): F.assign(weights[i], param) if not overflow: self.optimizer(grads) - return (loss, cond, scaling_sens) + return (loss, cond, scaling_sens.value()) class BertTrainCell(nn.Cell): diff --git a/research/nlp/ternarybert/src/tinybert_model.py b/research/nlp/ternarybert/src/tinybert_model.py index a12ae393146bf3d5247726611fdcc93df3f889b3..c335ef72b8ea20dfadbd1727b9d2a1a1a4296624 100644 --- a/research/nlp/ternarybert/src/tinybert_model.py +++ b/research/nlp/ternarybert/src/tinybert_model.py @@ -327,7 +327,7 @@ class EmbeddingLookup(nn.Cell): else: output_for_reshape = self.gather(self.embedding_table, flat_ids, 0) output = self.reshape(output_for_reshape, self.shape) - return output, self.embedding_table + return output, self.embedding_table.value() class EmbeddingPostprocessor(nn.Cell): diff --git a/research/recommend/mmoe/src/mmoe.py b/research/recommend/mmoe/src/mmoe.py index 6396032f73ac8435009a0c209262c7cd7248e05b..e2f070dc1b0711b3999caf0cc8822f1d0e1124d5 100644 --- a/research/recommend/mmoe/src/mmoe.py +++ b/research/recommend/mmoe/src/mmoe.py @@ -306,5 +306,5 @@ class TrainStepWrap(nn.Cell): else: succ = self.optimizer(grads) - ret = (loss, scale_sense) + ret = (loss, scale_sense.value()) return F.depend(ret, succ)