Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
兔爷不爱我
mindspore
提交
228a959c
M
mindspore
项目概览
兔爷不爱我
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
228a959c
编写于
7月 22, 2020
作者:
F
fangzehua
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add reduce any op for vm
上级
de14b851
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
95 addition
and
1 deletion
+95
-1
mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_adapter.cc
mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_adapter.cc
+1
-0
mindspore/ccsrc/backend/optimizer/pass/const_input_to_attr_registry.cc
...rc/backend/optimizer/pass/const_input_to_attr_registry.cc
+1
-0
mindspore/core/base/core_ops.h
mindspore/core/base/core_ops.h
+1
-0
mindspore/ops/_grad/grad_math_ops.py
mindspore/ops/_grad/grad_math_ops.py
+10
-0
mindspore/ops/_op_impl/tbe/__init__.py
mindspore/ops/_op_impl/tbe/__init__.py
+1
-0
mindspore/ops/_op_impl/tbe/reduce_any.py
mindspore/ops/_op_impl/tbe/reduce_any.py
+38
-0
mindspore/ops/operations/__init__.py
mindspore/ops/operations/__init__.py
+2
-1
mindspore/ops/operations/math_ops.py
mindspore/ops/operations/math_ops.py
+36
-0
tests/ut/python/ops/test_ops.py
tests/ut/python/ops/test_ops.py
+5
-0
未找到文件。
mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_adapter.cc
浏览文件 @
228a959c
...
...
@@ -126,6 +126,7 @@ static std::map<string, string> tbe_func_adapter_map = {
{
"apply_rms_prop"
,
"apply_rms_prop_d"
},
{
"cum_prod"
,
"cumprod_d"
},
{
"reduce_all"
,
"reduce_all_d"
},
{
"reduce_any"
,
"reduce_any_d"
},
{
"sparse_apply_adagrad"
,
"sparse_apply_adagrad_d"
},
{
"unsorted_segment_min"
,
"unsorted_segment_min_d"
},
{
"reduce_prod"
,
"reduce_prod_d"
},
...
...
mindspore/ccsrc/backend/optimizer/pass/const_input_to_attr_registry.cc
浏览文件 @
228a959c
...
...
@@ -46,6 +46,7 @@ ConstInputToAttrInfoRegistry::ConstInputToAttrInfoRegistry() {
Register
(
prim
::
kPrimCumSum
->
name
(),
{
1
});
Register
(
prim
::
kPrimCumProd
->
name
(),
{
1
});
Register
(
prim
::
kPrimReduceAll
->
name
(),
{
1
});
Register
(
prim
::
kPrimReduceAny
->
name
(),
{
1
});
Register
(
prim
::
kPrimUnsortedSegmentMin
->
name
(),
{
2
});
Register
(
kSparseGatherV2
,
{
2
});
Register
(
kUnsortedSegmentProdOpName
,
{
2
});
...
...
mindspore/core/base/core_ops.h
浏览文件 @
228a959c
...
...
@@ -34,6 +34,7 @@ inline const PrimitivePtr kPrimMinimumGrad = std::make_shared<Primitive>("Minimu
inline
const
PrimitivePtr
kPrimReduceMean
=
std
::
make_shared
<
Primitive
>
(
"ReduceMean"
);
inline
const
PrimitivePtr
kPrimReduceSum
=
std
::
make_shared
<
Primitive
>
(
"ReduceSum"
);
inline
const
PrimitivePtr
kPrimReduceAll
=
std
::
make_shared
<
Primitive
>
(
"ReduceAll"
);
inline
const
PrimitivePtr
kPrimReduceAny
=
std
::
make_shared
<
Primitive
>
(
"ReduceAny"
);
inline
const
PrimitivePtr
kPrimReduceMax
=
std
::
make_shared
<
Primitive
>
(
"ReduceMax"
);
inline
const
PrimitivePtr
kPrimReduceMin
=
std
::
make_shared
<
Primitive
>
(
"ReduceMin"
);
inline
const
PrimitivePtr
kPrimNeg
=
std
::
make_shared
<
Primitive
>
(
"Neg"
);
...
...
mindspore/ops/_grad/grad_math_ops.py
浏览文件 @
228a959c
...
...
@@ -641,6 +641,16 @@ def get_bprop_reduceall(self):
return
bprop
@
bprop_getters
.
register
(
P
.
ReduceAny
)
def
get_bprop_reduceany
(
self
):
"""Grad definition for `ReduceAny` operation."""
def
bprop
(
x
,
axis
,
out
,
dout
):
return
zeros_like
(
x
),
zeros_like
(
axis
)
return
bprop
@
bprop_getters
.
register
(
P
.
ReduceMax
)
def
get_bprop_reducemax
(
self
):
"""Grad definition for `Max` operation."""
...
...
mindspore/ops/_op_impl/tbe/__init__.py
浏览文件 @
228a959c
...
...
@@ -245,6 +245,7 @@ from .bitwise_and import _bitwise_and_tbe
from
.bitwise_or
import
_bitwise_or_tbe
from
.bitwise_xor
import
_bitwise_xor_tbe
from
.reduce_all
import
_reduce_all_tbe
from
.reduce_any
import
_reduce_any_tbe
from
.sparse_apply_adagrad
import
_sparse_apply_adagrad_tbe
from
.unsorted_segment_min
import
_unsorted_segment_min_tbe
from
.asin
import
_asin_tbe
...
...
mindspore/ops/_op_impl/tbe/reduce_any.py
0 → 100644
浏览文件 @
228a959c
# 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.
# ============================================================================
"""ReduceAny op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
reduce_any_op_info
=
TBERegOp
(
"ReduceAny"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"reduce_any_d.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"reduce_any_d"
)
\
.
partial_flag
(
True
)
\
.
attr
(
"axis"
,
"required"
,
"listInt"
,
"all"
)
\
.
attr
(
"keep_dims"
,
"optional"
,
"bool"
,
"all"
)
\
.
input
(
0
,
"x"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
op_pattern
(
"reduce"
)
\
.
dtype_format
(
DataType
.
BOOL_None
,
DataType
.
BOOL_None
)
\
.
get_op_info
()
@
op_info_register
(
reduce_any_op_info
)
def
_reduce_any_tbe
():
"""ReduceAny TBE register"""
return
mindspore/ops/operations/__init__.py
浏览文件 @
228a959c
...
...
@@ -44,7 +44,7 @@ from .inner_ops import ScalarCast
from
.math_ops
import
(
Abs
,
ACos
,
Asin
,
Asinh
,
AddN
,
AccumulateNV2
,
AssignAdd
,
AssignSub
,
Atan2
,
BatchMatMul
,
BitwiseAnd
,
BitwiseOr
,
BitwiseXor
,
Inv
,
Invert
,
ApproximateEqual
,
InplaceAdd
,
InplaceSub
,
ReduceMax
,
ReduceMin
,
ReduceMean
,
ReduceSum
,
ReduceAll
,
ReduceProd
,
CumProd
,
ReduceMax
,
ReduceMin
,
ReduceMean
,
ReduceSum
,
ReduceAll
,
ReduceProd
,
CumProd
,
ReduceAny
,
Cos
,
Div
,
DivNoNan
,
Equal
,
EqualCount
,
Exp
,
Expm1
,
Erf
,
Erfc
,
Floor
,
FloorDiv
,
FloorMod
,
Ceil
,
Acosh
,
Greater
,
GreaterEqual
,
Less
,
LessEqual
,
Log
,
Log1p
,
LogicalAnd
,
Mod
,
LogicalNot
,
LogicalOr
,
MatMul
,
Maximum
,
...
...
@@ -215,6 +215,7 @@ __all__ = [
'CTCLoss'
,
'RNNTLoss'
,
'ReduceAll'
,
'ReduceAny'
,
'ScalarToArray'
,
'ScalarToTensor'
,
'TupleToArray'
,
...
...
mindspore/ops/operations/math_ops.py
浏览文件 @
228a959c
...
...
@@ -405,6 +405,42 @@ class ReduceAll(_Reduce):
return
self
.
do_infer
(
input_x
,
axis
,
(
mstype
.
bool_
,))
class
ReduceAny
(
_Reduce
):
"""
Reduce a dimension of a tensor by the "logical or" of all elements in the dimension.
The dtype of the tensor to be reduced is bool.
Args:
keep_dims (bool): If True, keep these reduced dimensions and the length is 1.
If False, don't keep these dimensions.
Default : False, don't keep these reduced dimensions.
Inputs:
- **input_x** (Tensor[bool]) - The input tensor.
- **axis** (Union[int, tuple(int), list(int)]) - The dimensions to reduce. Default: (), reduce all dimensions.
Only constant value is allowed.
Outputs:
Tensor, the dtype is bool.
- If axis is (), and keep_dims is false,
the output is a 0-D tensor representing the "logical or" of of all elements in the input tensor.
- If axis is int, set as 2, and keep_dims is false,
and keep_dims is false, the shape of output is :math:`(x_1, x_3, ..., x_R)`.
- If axis is tuple(int), set as (2, 3), and keep_dims is false,
the shape of output is :math:`(x_1, x_4, ..., x_R)`.
Examples:
>>> input_x = Tensor(np.array([[True, False], [True, True]]))
>>> op = P.ReduceAny(keep_dims=True)
>>> output = op(input_x, 1)
"""
def
__infer__
(
self
,
input_x
,
axis
):
return
self
.
do_infer
(
input_x
,
axis
,
(
mstype
.
bool_
,))
class
ReduceMax
(
_Reduce
):
"""
Reduce a dimension of a tensor by the maximum value in this dimension.
...
...
tests/ut/python/ops/test_ops.py
浏览文件 @
228a959c
...
...
@@ -1186,6 +1186,11 @@ test_case_math_ops = [
'desc_const'
:
[
1
],
'desc_inputs'
:
[
Tensor
(
np
.
array
([[
True
,
False
],
[
True
,
True
]]))],
'desc_bprop'
:
[]}),
(
'ReduceAny'
,
{
'block'
:
P
.
ReduceAny
(),
'desc_const'
:
[
1
],
'desc_inputs'
:
[
Tensor
(
np
.
array
([[
True
,
False
],
[
True
,
True
]]))],
'desc_bprop'
:
[]}),
(
'BesselI0e'
,
{
'block'
:
P
.
BesselI0e
(),
'desc_inputs'
:
[[
2
,
3
]],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录