!1094 Complete vm ops for L2Normalize and L2NormalizeGrad

Merge pull request !1094 from zhouneng/add_vm_support_l2normalize
This commit is contained in:
mindspore-ci-bot 2020-05-13 21:52:45 +08:00 committed by Gitee
commit 7e3ec651dc
5 changed files with 105 additions and 0 deletions

View File

@ -125,6 +125,8 @@ from .layer_norm import _layer_norm_tbe
from .layer_norm_grad import _layer_norm_grad_tbe
from .layer_norm_x_backprop import _layer_norm_x_backprop_tbe
from .l2_loss import _l2_loss_tbe
from .l2_normalize import _l2_normalize_tbe
from .l2_normalize_grad import _l2_normalize_grad_tbe
from .square_sum_v1 import _square_sum_v1_tbe
from .square_sum_v2 import _square_sum_v2_tbe
from .confusion_transpose_d import _confusion_transpose_d_tbe

View File

@ -0,0 +1,38 @@
# Copyright 2020 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""L2Normalize op"""
from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType
l2_normalize_op_info = TBERegOp("L2Normalize") \
.fusion_type("OPAQUE") \
.async_flag(False) \
.binfile_name("l2_normalize.so") \
.compute_cost(10) \
.kernel_name("l2_normalize") \
.partial_flag(True) \
.attr("axis", "required", "listInt", "all") \
.attr("epsilon", "required", "float", "all") \
.input(0, "x", False, "required", "all") \
.output(0, "y", True, "required", "all") \
.dtype_format(DataType.F16_Default, DataType.F16_Default) \
.dtype_format(DataType.F32_Default, DataType.F32_Default) \
.get_op_info()
@op_info_register(l2_normalize_op_info)
def _l2_normalize_tbe():
"""L2Normalize TBE register"""
return

View File

@ -0,0 +1,40 @@
# Copyright 2020 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""L2NormalizeGrad op"""
from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType
l2_normalize_grad_op_info = TBERegOp("L2NormalizeGrad") \
.fusion_type("OPAQUE") \
.async_flag(False) \
.binfile_name("l2_normalize_grad.so") \
.compute_cost(10) \
.kernel_name("l2_normalize_grad") \
.partial_flag(True) \
.attr("axis", "required", "listInt", "all") \
.attr("epsilon", "required", "float", "all") \
.input(0, "x", False, "required", "all") \
.input(1, "y", False, "required", "all") \
.input(2, "dy", False, "requried", "all") \
.output(0, "dx", True, "required", "all") \
.dtype_format(DataType.F16_Default, DataType.F16_Default, DataType.F16_Default, DataType.F16_Default) \
.dtype_format(DataType.F32_Default, DataType.F32_Default, DataType.F32_Default, DataType.F32_Default) \
.get_op_info()
@op_info_register(l2_normalize_grad_op_info)
def _l2_normalize_grad_tbe():
"""L2NormalizeGrad TBE register"""
return

View File

@ -198,6 +198,18 @@ class ScalarSummaryNet(nn.Cell):
return out
class L2NormalizeNet(nn.Cell):
""" L2NormalizeNet definition """
def __init__(self):
super(L2NormalizeNet, self).__init__()
self.l2_normalize = P.L2Normalize()
def construct(self, x):
out = self.l2_normalize(x)
return out
class HistogramSummaryNet(nn.Cell):
"""HistogramSummaryNet definition"""
@ -450,6 +462,10 @@ test_cases = [
'block': ScalarSummaryNet(),
'desc_inputs': [2.2],
}),
('L2Normalize', {
'block': L2NormalizeNet(),
'desc_inputs': [Tensor(np.array([[1.0, 2, 3], [4.0, 5, 6], [7.0, 8, 9]]), mindspore.float32)],
}),
('HistogramSummary', {
'block': HistogramSummaryNet(),
'desc_inputs': [[1,2,3]],

View File

@ -681,6 +681,15 @@ test_case_nn_ops = [
'desc_inputs': [[16, 1234], [16, 1234]],
'desc_bprop': [[64, 2]],
'skip': ['backward']}),
('L2Normalize', {
'block': P.L2Normalize(),
'desc_inputs': [[2, 2]],
'desc_bprop': [[2, 2]]}),
('L2NormalizeGrad', {
'block': G.L2NormalizeGrad(),
'desc_inputs': [[2, 2], [2, 2], [2, 2]],
'desc_bprop': [[2, 2]],
'skip': ['backward']}),
('LayerNorm', {
'block': P.LayerNorm(),
'desc_inputs': [[2, 16], [16], [16]],