From 219367975c2c592c5e4ce51ff4cf61bfa8be9ab8 Mon Sep 17 00:00:00 2001 From: guozhibin Date: Mon, 14 Jul 2025 10:39:43 +0800 Subject: [PATCH] adapte old dtype api --- benchmark/ascend/bert/src/bert_model.py | 4 ++-- community/nlp/Roberta_Seq2Seq/src/roberta_model.py | 2 +- official/nlp/Bert/src/bert_model.py | 2 +- official/nlp/Bert_thor/src/bert_model.py | 2 +- research/nlp/DYR/src/bert_model.py | 2 +- research/nlp/albert/src/albert_model.py | 2 +- research/nlp/cpm/src/model_cpm.py | 4 ++-- research/nlp/dgu/src/bert_model.py | 2 +- research/nlp/emotect/src/ernie_model.py | 2 +- research/nlp/ernie/src/ernie_model.py | 2 +- research/nlp/ktnet/src/bert.py | 2 +- research/nlp/senta/src/bert_model.py | 2 +- research/nlp/soft_masked_bert/src/bert_model.py | 2 +- research/nlp/ternarybert/src/tinybert_model.py | 2 +- research/nlp/tinybert/src/tinybert_model.py | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-) diff --git a/benchmark/ascend/bert/src/bert_model.py b/benchmark/ascend/bert/src/bert_model.py index 23e17f6d6..2923199fc 100644 --- a/benchmark/ascend/bert/src/bert_model.py +++ b/benchmark/ascend/bert/src/bert_model.py @@ -340,7 +340,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) @@ -451,7 +451,7 @@ class BertFlashAttention(nn.Cell): query_out = self.query_layer(from_tensor_2d) key_out = self.key_layer(to_tensor_2d) value_out = self.value_layer(to_tensor_2d) - #b, s, n, d + #b, s, n, d query_layer = self.reshape(query_out, (-1, shape_from, self.num_attention_heads, self.size_per_head)) query_layer = self.transpose(query_layer, self.trans_shape) key_layer = self.reshape(key_out, (-1, shape_from, self.num_attention_heads, self.size_per_head)) diff --git a/community/nlp/Roberta_Seq2Seq/src/roberta_model.py b/community/nlp/Roberta_Seq2Seq/src/roberta_model.py index d3f5b0a3f..e831ead2e 100644 --- a/community/nlp/Roberta_Seq2Seq/src/roberta_model.py +++ b/community/nlp/Roberta_Seq2Seq/src/roberta_model.py @@ -179,7 +179,7 @@ class SaturateCast(nn.Cell): def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/official/nlp/Bert/src/bert_model.py b/official/nlp/Bert/src/bert_model.py index ecc07b5b1..3d50b026b 100644 --- a/official/nlp/Bert/src/bert_model.py +++ b/official/nlp/Bert/src/bert_model.py @@ -339,7 +339,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/official/nlp/Bert_thor/src/bert_model.py b/official/nlp/Bert_thor/src/bert_model.py index 9a5605919..4390df458 100644 --- a/official/nlp/Bert_thor/src/bert_model.py +++ b/official/nlp/Bert_thor/src/bert_model.py @@ -341,7 +341,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/DYR/src/bert_model.py b/research/nlp/DYR/src/bert_model.py index ec9931881..b176000d3 100644 --- a/research/nlp/DYR/src/bert_model.py +++ b/research/nlp/DYR/src/bert_model.py @@ -341,7 +341,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/albert/src/albert_model.py b/research/nlp/albert/src/albert_model.py index d33284f41..e267ce473 100644 --- a/research/nlp/albert/src/albert_model.py +++ b/research/nlp/albert/src/albert_model.py @@ -371,7 +371,7 @@ class SaturateCast(nn.Cell): def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = Tensor(np.finfo(np_type).min, dtype=src_type) self.tensor_max_type = Tensor(np.finfo(np_type).max, dtype=src_type) diff --git a/research/nlp/cpm/src/model_cpm.py b/research/nlp/cpm/src/model_cpm.py index cccf1b991..be16acfea 100644 --- a/research/nlp/cpm/src/model_cpm.py +++ b/research/nlp/cpm/src/model_cpm.py @@ -19,7 +19,7 @@ from mindspore.train.callback import RunContext from mindspore import context from mindspore.context import ParallelMode from mindspore import Model, connect_network_with_dataset -from mindspore.common.dtype import pytype_to_dtype +from mindspore.common.dtype import _pytype_to_dtype from mindspore._c_expression import init_exec_dataset from mindspore.train.train_thor.dataset_helper import DatasetHelper @@ -36,7 +36,7 @@ def _convert_type(types): """ ms_types = [] for np_type in types: - ms_type = pytype_to_dtype(np_type) + ms_type = _pytype_to_dtype(np_type) ms_types.append(ms_type) return ms_types diff --git a/research/nlp/dgu/src/bert_model.py b/research/nlp/dgu/src/bert_model.py index 0210a719d..2c6a22946 100644 --- a/research/nlp/dgu/src/bert_model.py +++ b/research/nlp/dgu/src/bert_model.py @@ -349,7 +349,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/emotect/src/ernie_model.py b/research/nlp/emotect/src/ernie_model.py index 0946abd3c..864cfde96 100644 --- a/research/nlp/emotect/src/ernie_model.py +++ b/research/nlp/emotect/src/ernie_model.py @@ -334,7 +334,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/ernie/src/ernie_model.py b/research/nlp/ernie/src/ernie_model.py index b6c53200c..83c7cab06 100644 --- a/research/nlp/ernie/src/ernie_model.py +++ b/research/nlp/ernie/src/ernie_model.py @@ -333,7 +333,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/ktnet/src/bert.py b/research/nlp/ktnet/src/bert.py index de70995eb..2aae15818 100644 --- a/research/nlp/ktnet/src/bert.py +++ b/research/nlp/ktnet/src/bert.py @@ -356,7 +356,7 @@ class SaturateCast(nn.Cell): def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/senta/src/bert_model.py b/research/nlp/senta/src/bert_model.py index e28db53c8..f3366f83c 100644 --- a/research/nlp/senta/src/bert_model.py +++ b/research/nlp/senta/src/bert_model.py @@ -349,7 +349,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/soft_masked_bert/src/bert_model.py b/research/nlp/soft_masked_bert/src/bert_model.py index 1b2dbd531..d9e11ea49 100644 --- a/research/nlp/soft_masked_bert/src/bert_model.py +++ b/research/nlp/soft_masked_bert/src/bert_model.py @@ -400,7 +400,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access self.tensor_min_type = float(np.finfo(np_type).min) self.tensor_max_type = float(np.finfo(np_type).max) diff --git a/research/nlp/ternarybert/src/tinybert_model.py b/research/nlp/ternarybert/src/tinybert_model.py index cf8290bec..6f3bb21c0 100644 --- a/research/nlp/ternarybert/src/tinybert_model.py +++ b/research/nlp/ternarybert/src/tinybert_model.py @@ -564,7 +564,7 @@ class SaturateCast(nn.Cell): def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access min_type = np.finfo(np_type).min max_type = np.finfo(np_type).max self.tensor_min_type = Tensor([min_type], dtype=src_type) diff --git a/research/nlp/tinybert/src/tinybert_model.py b/research/nlp/tinybert/src/tinybert_model.py index 875cc6048..1b4cc2de9 100644 --- a/research/nlp/tinybert/src/tinybert_model.py +++ b/research/nlp/tinybert/src/tinybert_model.py @@ -298,7 +298,7 @@ class SaturateCast(nn.Cell): """ def __init__(self, src_type=mstype.float32, dst_type=mstype.float32): super(SaturateCast, self).__init__() - np_type = mstype.dtype_to_nptype(dst_type) + np_type = mstype._dtype_to_nptype(dst_type) # pylint: disable=protected-access min_type = np.finfo(np_type).min max_type = np.finfo(np_type).max self.tensor_min_type = Tensor([min_type], dtype=src_type) -- Gitee