!17406 fix the format and other warning problems.

From: @wangshuide2020
Reviewed-by: @liangchenghui,@wuxuejian
Signed-off-by: @liangchenghui
This commit is contained in:
mindspore-ci-bot 2021-06-01 09:25:39 +08:00 committed by Gitee
commit 417bd45e0f
15 changed files with 33 additions and 4 deletions

View File

@ -461,6 +461,7 @@ class MultiFieldEmbeddingLookup(EmbeddingLookup):
OPERATOR_SUM = 'SUM'
OPERATOR_MEAN = 'MEAN'
OPERATOR_MAX = 'MAX'
def __init__(self, vocab_size, embedding_size, field_size, param_init='normal', target='CPU',
slice_mode='batch_slice', feature_num_list=None, max_norm=None, sparse=True, operator='SUM'):
super(MultiFieldEmbeddingLookup, self).__init__(vocab_size, embedding_size, param_init, target,

View File

@ -113,6 +113,7 @@ def _get_dtype_max(dtype):
dtype_max = 1.0
return dtype_max
@constexpr
def _check_input_4d(input_shape, param_name, func_name):
if len(input_shape) != 4:
@ -471,6 +472,7 @@ def _raise_dims_rank_error(input_shape, param_name, func_name):
"""raise error if input is not 3d or 4d"""
raise ValueError(f"{func_name} {param_name} should be 3d or 4d, but got shape {input_shape}")
@constexpr
def _get_bbox(rank, shape, central_fraction):
"""get bbox start and size for slice"""

View File

@ -88,6 +88,7 @@ dout_cast = C.MultitypeFuncGraph("dout_cast")
@dout_cast.register("Tensor", "Tensor")
def dout_cast_tensor(dout, x):
"""Casts dout to the dtype of x for Tensor."""
cast = P.Cast()
get_dtype = P.DType()
dx = cast(dout, get_dtype(x))
@ -96,6 +97,7 @@ def dout_cast_tensor(dout, x):
@dout_cast.register("Number", "Number")
def dout_cast_number(dout, x):
"""Casts dout to the dtype of x for Number."""
cast = P.Cast()
get_dtype = P.DType()
dx = cast(dout, get_dtype(x))
@ -104,6 +106,7 @@ def dout_cast_number(dout, x):
@dout_cast.register("RowTensor", "Tensor")
def dout_cast_row_tensor(dout, x):
"""Casts dout values to the dtype of x for RowTensor."""
cast = P.Cast()
get_dtype = P.DType()
values = cast(dout.values, get_dtype(x))
@ -275,6 +278,7 @@ def get_bprop_embedding_lookup(self):
@constexpr
def make_begin(shp):
"""Creates a tuple with zero according to the shape."""
begin = tuple([0 for _ in shp])
return begin

View File

@ -87,6 +87,7 @@ def get_bprop_sync_batch_norm(self):
@bprop_getters.register(inner.GpuConvertToDynamicShape)
def get_bprop_gpu_convert_to_dynamic_shape(self):
"""Get backprop for GpuConvertToDynamicShape."""
def bprop(x, out, dout):
return (dout,)
return bprop

View File

@ -450,6 +450,7 @@ def _get_output_shape(batch_size, x1_ret, x2_ret):
output_shape = tuple([batch_size]) + x1_ret + x2_ret
return output_shape
def batch_dot(x1, x2, axes=None):
"""
Computation of batch dot product between samples in two tensors containing batch dims.

View File

@ -1,4 +1,4 @@
# Copyright 2020 Huawei Technologies Co., Ltd
# Copyright 2020-2021 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.

View File

@ -49,16 +49,19 @@ SET_ITEM_BY_NON_TENSOR = 2
@constexpr
def raise_value_error(msg):
"""Constexpr for raise_value_error."""
raise ValueError(msg)
@constexpr
def raise_index_error(msg):
"""Constexpr for raise_index_error."""
raise IndexError(msg)
@constexpr
def raise_type_error(msg):
"""Constexpr for raise_type_error."""
raise TypeError(msg)
@ -77,6 +80,7 @@ def check_equal(param1, param2, msg="{},{}"):
@constexpr
def make_empty_slice():
"""Creates a empty slice."""
return slice(None, None, None)
@ -179,6 +183,7 @@ tensor_operator_registry.register('make_tensor', make_tensor)
@constexpr
def judge_data_dim(data_dim, min_data_dim=0, max_data_dim=8):
"""Judges whether the data dim is valid."""
if data_dim < min_data_dim or data_dim > max_data_dim:
raise ValueError(f"The input data's dim should in the range of[{min_data_dim}, "
f"{max_data_dim}], bug actually is '{data_dim}'")
@ -244,12 +249,14 @@ def is_same_type(inst, type_):
@constexpr
def check_valid_dim(dim, name):
"""Checks whether the dim is valid."""
if dim not in (1, 2):
raise ValueError(f"For {name}, inputs dim must be 1d or 2d")
@constexpr
def judge_index_type(index_type, target_type):
"""Judges whether the index type is valid."""
if index_type == target_type or (isinstance(target_type, (list, tuple)) and index_type in target_type):
return True
return False
@ -270,6 +277,7 @@ def judge_indexes_types(dtypes, target_type):
@constexpr
def check_type_valid(dtype, target_type, op_name):
"""Checks whether the dtype is valid."""
if dtype != target_type and (isinstance(target_type, (list, tuple)) and dtype not in target_type):
if op_name in (TENSOR_GETITEM, TENSOR_SETITEM):
raise IndexError(
@ -476,6 +484,7 @@ def generate_updates_shape(data_shape, index_shape, op_type):
@constexpr
def transform_slice_to_ele_list(slice_index, dim_len):
"""Transforms slice to element list."""
slice_obj = slice(slice_index.start, slice_index.stop, slice_index.step)
start, stop, end = normalize_slice(slice_obj, dim_len)
slice_ele_list = list(range(start, stop, end))
@ -528,6 +537,7 @@ def scalar_in_sequence(x, y):
@constexpr
def get_np_eps(input_dtype):
"""Get numpy eps."""
nptype = mstype.dtype_to_nptype(input_dtype)
eps = np.finfo(nptype).eps
return float(eps)

View File

@ -135,6 +135,7 @@ stack = P.Stack()
def pack(x):
"""Call stack in this pack function."""
print("WARNING: 'pack' is deprecated from version 1.1 and will be removed in a future version, use 'stack' instead"
".")
return stack(x)

View File

@ -683,6 +683,7 @@ class ErrorOnDynamicShapeInput(PrimitiveWithInfer):
return input_shape
def infer_type(self, input_dtype):
"""Infer the dtype of input for ErrorOnDynamicShapeInput."""
validator.check_subclass("input_dtype", input_dtype, mstype.tensor, self.name)
return input_dtype

View File

@ -19,7 +19,6 @@ from ..primitive import prim_attr_register, PrimitiveWithInfer
from ...common import dtype as mstype
from ..._checkparam import Validator as validator
from ..operations.nn_ops import _check_positive_int_or_tuple
from ..._checkparam import Rel
__all__ = ["CusBatchMatMul",
"CusCholeskyTrsm",
@ -362,6 +361,7 @@ class CusTranspose02314(PrimitiveWithInfer):
from mindspore.ops._op_impl._custom_op.transpose02314_impl import cus_transpose02314
def get_bprop(self):
"""Get backprop for CusTranspose02314."""
def bprop(x, out, dout):
return (C.zeros_like(x),)

View File

@ -5293,6 +5293,7 @@ class Range(PrimitiveWithCheck):
validator.check_tensors_dtypes_same_and_valid(inputs, valid_dtypes, self.name)
def infer_value(self, start_value, limit_value, delat_value):
"""Infer the value of input for Range."""
if start_value is not None and limit_value is not None and delat_value is not None:
start = np.asscalar(start_value.asnumpy())
limit = np.asscalar(limit_value.asnumpy())

View File

@ -48,6 +48,7 @@ target_dtypes = (mstype.int8, mstype.int32, mstype.float16, mstype.float32)
def check_hcom_group_valid(group):
"""Check if hcom group is valid."""
if context.get_context("mode") == context.PYNATIVE_MODE and \
context.get_context("device_target") == "Ascend" and \
group != GlobalComm.WORLD_COMM_GROUP:

View File

@ -84,6 +84,7 @@ class _MathBinaryOp(_BinaryOp):
@staticmethod
def do_infer_dtype(x_dtype, y_dtype, valid_dtype=mstype.number_type, prim_name=None):
"""Staticmethod of infer dtype for _MathBinaryOp."""
args_type = {"x": x_dtype, "y": y_dtype}
validator.check_tensors_dtypes_same_and_valid(args_type, valid_dtype, prim_name)
return x_dtype
@ -808,6 +809,7 @@ class MatMul(PrimitiveWithCheck):
validator.check_value_type("transpose_b", transpose_b, [bool], cls_name)
def check_shape_size(self, x1, x2):
"""Check the shape size of inputs for MatMul."""
if len(x1) != 2 or len(x2) != 2:
raise ValueError('P.MatMul inputs x1, x2 should have the same dimension size and '
+ f'equal to 2, while x1 size is ({len(x1)}) and x2 size is ({len(x2)}).')
@ -1451,6 +1453,7 @@ class Square(PrimitiveWithCheck):
validator.check_tensor_dtype_valid("x", x_dtype, mstype.number_type, self.name)
def infer_value(self, x):
"""Infer the value of input for Square."""
if x is not None:
x = x.asnumpy()
out = x * x
@ -1538,6 +1541,7 @@ class Sqrt(PrimitiveWithCheck):
validator.check_tensor_dtype_valid("x", x_type, mstype.number_type, self.name)
def infer_value(self, x):
"""Infer the value of input for Sqrt."""
if x is not None:
x = x.asnumpy()
out = np.sqrt(x)
@ -2768,6 +2772,7 @@ class _LogicBinaryOp(_BinaryOp):
@staticmethod
def do_infer_dtype(x_dtype, y_dtype, valid_type=mstype.number_type, prim_name=None):
"""Staticmethod of infer dtype for _LogicBinaryOp."""
args_dtype = {"x": x_dtype, "y": y_dtype}
validator.check_tensors_dtypes_same_and_valid(args_dtype, valid_type, prim_name)
return mstype.tensor_type(mstype.bool_)

View File

@ -141,7 +141,7 @@ class Load(PrimitiveWithCheck):
def check_dtype(self, variable):
if variable != mstype.type_refkey:
validator.check_tensor_type_same({"variable": variable}, mstype.number_type, self.name)
validator.check_tensors_dtypes_same_and_valid({"variable": variable}, mstype.number_type, self.name)
class BoundingBoxEncode(PrimitiveWithInfer):

View File

@ -1,4 +1,4 @@
# Copyright 2020 Huawei Technologies Co., Ltd
# Copyright 2020-2021 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.
@ -538,6 +538,7 @@ def constexpr(fn=None, get_instance=True, name=None):
"""
def deco(fn):
"""Decorator for CompileOp."""
class CompileOp(PrimitiveWithInfer):
"""
CompileOp is a temporary operator used to execute the constexpr function.