Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
0a897b0c
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0a897b0c
编写于
6月 08, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 08, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1865 add inv,invgrad&invert for vm
Merge pull request !1865 from JichenZhao/bnops_for_vm
上级
40b1c316
cdb7ec93
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
218 addition
and
1 deletion
+218
-1
mindspore/ccsrc/kernel/tbe/tbe_adapter.cc
mindspore/ccsrc/kernel/tbe/tbe_adapter.cc
+1
-0
mindspore/ops/_grad/grad_math_ops.py
mindspore/ops/_grad/grad_math_ops.py
+11
-0
mindspore/ops/_op_impl/tbe/__init__.py
mindspore/ops/_op_impl/tbe/__init__.py
+3
-0
mindspore/ops/_op_impl/tbe/inv.py
mindspore/ops/_op_impl/tbe/inv.py
+39
-0
mindspore/ops/_op_impl/tbe/inv_grad.py
mindspore/ops/_op_impl/tbe/inv_grad.py
+39
-0
mindspore/ops/_op_impl/tbe/invert.py
mindspore/ops/_op_impl/tbe/invert.py
+36
-0
mindspore/ops/operations/__init__.py
mindspore/ops/operations/__init__.py
+3
-1
mindspore/ops/operations/_grad_ops.py
mindspore/ops/operations/_grad_ops.py
+17
-0
mindspore/ops/operations/math_ops.py
mindspore/ops/operations/math_ops.py
+60
-0
tests/ut/python/ops/test_ops.py
tests/ut/python/ops/test_ops.py
+9
-0
未找到文件。
mindspore/ccsrc/kernel/tbe/tbe_adapter.cc
浏览文件 @
0a897b0c
...
@@ -98,6 +98,7 @@ static std::map<string, string> tbe_func_adapter_map = {
...
@@ -98,6 +98,7 @@ static std::map<string, string> tbe_func_adapter_map = {
{
"n_ms_with_mask"
,
"nms_with_mask"
},
{
"n_ms_with_mask"
,
"nms_with_mask"
},
{
"square_sum_all"
,
"square_sum_all"
},
{
"square_sum_all"
,
"square_sum_all"
},
{
"cum_sum"
,
"cumsum_d"
},
{
"cum_sum"
,
"cumsum_d"
},
{
"inv_grad"
,
"inv_grad"
},
{
"apply_rms_prop"
,
"apply_rms_prop_d"
},
{
"apply_rms_prop"
,
"apply_rms_prop_d"
},
{
"cum_prod"
,
"cumprod_d"
},
{
"cum_prod"
,
"cumprod_d"
},
{
"reduce_all"
,
"reduce_all_d"
},
{
"reduce_all"
,
"reduce_all_d"
},
...
...
mindspore/ops/_grad/grad_math_ops.py
浏览文件 @
0a897b0c
...
@@ -1025,3 +1025,14 @@ def get_bprop_atanh(self):
...
@@ -1025,3 +1025,14 @@ def get_bprop_atanh(self):
dx
=
div
(
1
,
tmp
)
*
dout
dx
=
div
(
1
,
tmp
)
*
dout
return
(
dx
,)
return
(
dx
,)
return
bprop
return
bprop
@
bprop_getters
.
register
(
P
.
Inv
)
def
get_bprop_inv
(
self
):
"""Grad definition for 'Inv' operation"""
inv_grad
=
G
.
InvGrad
()
def
bprop
(
x
,
out
,
dout
):
dx
=
inv_grad
(
x
,
dout
)
return
(
dx
,)
return
bprop
mindspore/ops/_op_impl/tbe/__init__.py
浏览文件 @
0a897b0c
...
@@ -233,6 +233,9 @@ from .atan_grad import _atan_grad_tbe
...
@@ -233,6 +233,9 @@ from .atan_grad import _atan_grad_tbe
from
.atanh
import
_atanh_tbe
from
.atanh
import
_atanh_tbe
from
.cosh
import
_cosh_tbe
from
.cosh
import
_cosh_tbe
from
.sinh
import
_sinh_tbe
from
.sinh
import
_sinh_tbe
from
.inv
import
_inv_tbe
from
.inv_grad
import
_inv_grad_tbe
from
.invert
import
_invert_tbe
from
.basic_lstm_cell
import
_basic_lstm_cell_tbe
from
.basic_lstm_cell
import
_basic_lstm_cell_tbe
from
.basic_lstm_cell_c_state_grad
import
_basic_lstm_cell_c_state_grad_tbe
from
.basic_lstm_cell_c_state_grad
import
_basic_lstm_cell_c_state_grad_tbe
from
.basic_lstm_cell_weight_grad
import
_basic_lstm_cell_weight_grad_tbe
from
.basic_lstm_cell_weight_grad
import
_basic_lstm_cell_weight_grad_tbe
...
...
mindspore/ops/_op_impl/tbe/inv.py
0 → 100644
浏览文件 @
0a897b0c
# 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.
# ============================================================================
"""Inv op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
inv_op_info
=
TBERegOp
(
"Inv"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"inv.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"inv"
)
\
.
partial_flag
(
True
)
\
.
input
(
0
,
"x"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
F32_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
F16_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
I8_Default
)
\
.
dtype_format
(
DataType
.
U8_Default
,
DataType
.
U8_Default
)
\
.
get_op_info
()
@
op_info_register
(
inv_op_info
)
def
_inv_tbe
():
"""Inv TBE register"""
return
mindspore/ops/_op_impl/tbe/inv_grad.py
0 → 100644
浏览文件 @
0a897b0c
# 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.
# ============================================================================
"""InvGrad op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
inv_grad_op_info
=
TBERegOp
(
"InvGrad"
)
\
.
fusion_type
(
"ELEMWISE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"inv_grad.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"inv_grad"
)
\
.
partial_flag
(
True
)
\
.
input
(
0
,
"x"
,
False
,
"required"
,
"all"
)
\
.
input
(
1
,
"grad"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
dtype_format
(
DataType
.
F16_Default
,
DataType
.
F16_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
F32_Default
,
DataType
.
F32_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
I32_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
I8_Default
,
DataType
.
I8_Default
)
\
.
get_op_info
()
@
op_info_register
(
inv_grad_op_info
)
def
_inv_grad_tbe
():
"""InvGrad TBE register"""
return
mindspore/ops/_op_impl/tbe/invert.py
0 → 100644
浏览文件 @
0a897b0c
# 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.
# ============================================================================
"""Invert op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
invert_op_info
=
TBERegOp
(
"Invert"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"invert.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"invert"
)
\
.
partial_flag
(
True
)
\
.
input
(
0
,
"x"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
dtype_format
(
DataType
.
I16_Default
,
DataType
.
I16_Default
)
\
.
dtype_format
(
DataType
.
U16_Default
,
DataType
.
U16_Default
)
\
.
get_op_info
()
@
op_info_register
(
invert_op_info
)
def
_invert_tbe
():
"""Invert TBE register"""
return
mindspore/ops/operations/__init__.py
浏览文件 @
0a897b0c
...
@@ -41,7 +41,7 @@ from .control_ops import ControlDepend, GeSwitch, Merge
...
@@ -41,7 +41,7 @@ from .control_ops import ControlDepend, GeSwitch, Merge
from
.inner_ops
import
ScalarCast
from
.inner_ops
import
ScalarCast
from
.math_ops
import
(
Abs
,
ACos
,
Asin
,
Asinh
,
AddN
,
AssignAdd
,
AssignSub
,
Atan2
,
BatchMatMul
,
BitwiseAnd
,
BitwiseOr
,
from
.math_ops
import
(
Abs
,
ACos
,
Asin
,
Asinh
,
AddN
,
AssignAdd
,
AssignSub
,
Atan2
,
BatchMatMul
,
BitwiseAnd
,
BitwiseOr
,
BitwiseXor
,
BitwiseXor
,
Inv
,
Invert
,
ReduceMax
,
ReduceMin
,
ReduceMean
,
ReduceSum
,
ReduceAll
,
ReduceProd
,
CumProd
,
ReduceMax
,
ReduceMin
,
ReduceMean
,
ReduceSum
,
ReduceAll
,
ReduceProd
,
CumProd
,
Cos
,
Div
,
DivNoNan
,
Equal
,
EqualCount
,
Exp
,
Expm1
,
Erf
,
Erfc
,
Floor
,
FloorDiv
,
FloorMod
,
Ceil
,
Cos
,
Div
,
DivNoNan
,
Equal
,
EqualCount
,
Exp
,
Expm1
,
Erf
,
Erfc
,
Floor
,
FloorDiv
,
FloorMod
,
Ceil
,
Acosh
,
Greater
,
GreaterEqual
,
Less
,
LessEqual
,
Log
,
Log1p
,
LogicalAnd
,
Acosh
,
Greater
,
GreaterEqual
,
Less
,
LessEqual
,
Log
,
Log1p
,
LogicalAnd
,
...
@@ -141,6 +141,8 @@ __all__ = [
...
@@ -141,6 +141,8 @@ __all__ = [
'RealDiv'
,
'RealDiv'
,
'Div'
,
'Div'
,
'DivNoNan'
,
'DivNoNan'
,
'Inv'
,
'Invert'
,
'TruncatedNormal'
,
'TruncatedNormal'
,
'Fill'
,
'Fill'
,
'OnesLike'
,
'OnesLike'
,
...
...
mindspore/ops/operations/_grad_ops.py
浏览文件 @
0a897b0c
...
@@ -1308,3 +1308,20 @@ class BasicLSTMCellInputGrad(PrimitiveWithInfer):
...
@@ -1308,3 +1308,20 @@ class BasicLSTMCellInputGrad(PrimitiveWithInfer):
validator
.
check_type_name
(
"dgate"
,
dgate_dtype
,
[
mstype
.
float16
,
mstype
.
float32
],
self
.
name
)
validator
.
check_type_name
(
"dgate"
,
dgate_dtype
,
[
mstype
.
float16
,
mstype
.
float32
],
self
.
name
)
validator
.
check_type_name
(
"w"
,
w_dtype
,
[
mstype
.
float16
,
mstype
.
float32
],
self
.
name
)
validator
.
check_type_name
(
"w"
,
w_dtype
,
[
mstype
.
float16
,
mstype
.
float32
],
self
.
name
)
return
(
dgate_dtype
,
dgate_dtype
)
return
(
dgate_dtype
,
dgate_dtype
)
class
InvGrad
(
PrimitiveWithInfer
):
"""Computes gradients for inv operation."""
@
prim_attr_register
def
__init__
(
self
):
pass
def
infer_shape
(
self
,
x
,
grad
):
validator
.
check
(
"x_shape"
,
x
,
"grad_shape"
,
grad
,
Rel
.
EQ
,
self
.
name
)
return
x
def
infer_dtype
(
self
,
x
,
grad
):
validator
.
check_type_name
(
"dgate"
,
x
,
[
mstype
.
float16
,
mstype
.
float32
,
mstype
.
int32
,
mstype
.
int8
],
self
.
name
)
validator
.
check_type_name
(
"grad"
,
grad
,
[
mstype
.
float16
,
mstype
.
float32
,
mstype
.
int32
,
mstype
.
int8
],
self
.
name
)
return
x
mindspore/ops/operations/math_ops.py
浏览文件 @
0a897b0c
...
@@ -2597,3 +2597,63 @@ class BesselI1e(PrimitiveWithInfer):
...
@@ -2597,3 +2597,63 @@ class BesselI1e(PrimitiveWithInfer):
def
infer_dtype
(
self
,
x
):
def
infer_dtype
(
self
,
x
):
validator
.
check_tensor_type_same
({
'x'
:
x
},
mstype
.
number_type
,
self
.
name
)
validator
.
check_tensor_type_same
({
'x'
:
x
},
mstype
.
number_type
,
self
.
name
)
return
x
return
x
class
Inv
(
PrimitiveWithInfer
):
"""
Computes Inv(Reciprocal) of input tensor element-wise.
Inputs:
- **input_x** (Tensor) - The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
Outputs:
Tensor, has the same shape as `input_x`.
Examples:
>>> inv = P.Inv()
>>> input_x = Tensor(np.array([0.25, 0.4, 0.31, 0.52]), mindspore.float32)
>>> output = inv(input_x)
[4., 2.5, 3.2258065, 1.923077]
"""
@
prim_attr_register
def
__init__
(
self
):
pass
def
infer_shape
(
self
,
x_shape
):
return
x_shape
def
infer_dtype
(
self
,
x_dtype
):
validator
.
check_tensor_type_same
({
'x_dtype'
:
x_dtype
},
[
mstype
.
float16
,
mstype
.
float32
,
mstype
.
int32
,
mstype
.
int8
,
mstype
.
uint8
],
self
.
name
)
return
x_dtype
class
Invert
(
PrimitiveWithInfer
):
"""
Flips all bits of input tensor element-wise.
Inputs:
- **input_x** (Tensor[int16], Tensor[uint16]) - The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
Outputs:
Tensor, has the same shape as `input_x`.
Examples:
>>> invert = P.Invert()
>>> input_x = Tensor(np.array([25, 4, 13, 9]), mindspore.int16)
>>> output = invert(input_x)
[-26, -5, -14, -10]
"""
@
prim_attr_register
def
__init__
(
self
):
pass
def
infer_shape
(
self
,
x_shape
):
return
x_shape
def
infer_dtype
(
self
,
x_dtype
):
validator
.
check_tensor_type_same
({
'x_dtype'
:
x_dtype
},
[
mstype
.
int16
,
mstype
.
uint16
],
self
.
name
)
return
x_dtype
tests/ut/python/ops/test_ops.py
浏览文件 @
0a897b0c
...
@@ -750,6 +750,15 @@ test_case_math_ops = [
...
@@ -750,6 +750,15 @@ test_case_math_ops = [
'block'
:
P
.
Sinh
(),
'block'
:
P
.
Sinh
(),
'desc_inputs'
:
[[
3
,
4
,
5
]],
'desc_inputs'
:
[[
3
,
4
,
5
]],
'desc_bprop'
:
[[
3
,
4
,
5
]]}),
'desc_bprop'
:
[[
3
,
4
,
5
]]}),
(
'Inv'
,
{
'block'
:
P
.
Inv
(),
'desc_inputs'
:
[[
21
,
9
,
12
,
5
]],
'desc_bprop'
:
[[
21
,
9
,
12
,
5
]]}),
(
'Invert'
,
{
'block'
:
P
.
Invert
(),
'desc_inputs'
:
[
Tensor
(
np
.
array
([[
24
,
4
,
13
,
9
],
[
1
,
5
,
10
,
8
]]).
astype
(
np
.
int16
))],
'desc_bprop'
:
[],
'skip'
:
[
'backward'
]}),
]
]
test_case_nn_ops
=
[
test_case_nn_ops
=
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录