Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
4ac18762
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看板
提交
4ac18762
编写于
4月 14, 2020
作者:
Z
zhangz0911gm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adapting AccumulateNV2
上级
0327d7e7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
120 addition
and
1 deletion
+120
-1
mindspore/ccsrc/parallel/auto_parallel/rec_core/rec_parse_graph.h
...e/ccsrc/parallel/auto_parallel/rec_core/rec_parse_graph.h
+1
-0
mindspore/ops/_grad/grad_math_ops.py
mindspore/ops/_grad/grad_math_ops.py
+12
-0
mindspore/ops/_op_impl/tbe/__init__.py
mindspore/ops/_op_impl/tbe/__init__.py
+1
-0
mindspore/ops/_op_impl/tbe/accumulate_n_v2.py
mindspore/ops/_op_impl/tbe/accumulate_n_v2.py
+41
-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
+58
-0
tests/ut/python/ops/test_ops.py
tests/ut/python/ops/test_ops.py
+5
-0
未找到文件。
mindspore/ccsrc/parallel/auto_parallel/rec_core/rec_parse_graph.h
浏览文件 @
4ac18762
...
@@ -82,6 +82,7 @@ const std::map<std::string, OperatorType> DictOpType{
...
@@ -82,6 +82,7 @@ const std::map<std::string, OperatorType> DictOpType{
{
"Abs"
,
OperatorType
::
kRecElmWiseOp
},
{
"Abs"
,
OperatorType
::
kRecElmWiseOp
},
{
"Acosh"
,
OperatorType
::
kRecElmWiseOp
},
{
"Acosh"
,
OperatorType
::
kRecElmWiseOp
},
{
"AddN"
,
OperatorType
::
kRecElmWiseOp
},
{
"AddN"
,
OperatorType
::
kRecElmWiseOp
},
{
"AccumulateNV2"
,
OperatorType
::
kRecElmWiseOp
},
{
"Atan2"
,
OperatorType
::
kRecElmWiseOp
},
{
"Atan2"
,
OperatorType
::
kRecElmWiseOp
},
{
"Erf"
,
OperatorType
::
kRecElmWiseOp
},
{
"Erf"
,
OperatorType
::
kRecElmWiseOp
},
{
"Floor"
,
OperatorType
::
kRecElmWiseOp
},
{
"Floor"
,
OperatorType
::
kRecElmWiseOp
},
...
...
mindspore/ops/_grad/grad_math_ops.py
浏览文件 @
4ac18762
...
@@ -931,6 +931,18 @@ def get_bprop_scalar_cast(self):
...
@@ -931,6 +931,18 @@ def get_bprop_scalar_cast(self):
return
bprop
return
bprop
@
bprop_getters
.
register
(
P
.
AccumulateNV2
)
def
get_bprop_scalar_accumulatenv2
(
self
):
"""Generate bprop for AccumulateNV2"""
def
bprop
(
x
,
out
,
dout
):
dx
=
()
for
_
in
range
(
len
(
x
)):
dx
=
dx
+
(
dout
,)
return
dx
return
bprop
@
bprop_getters
.
register
(
P
.
AddN
)
@
bprop_getters
.
register
(
P
.
AddN
)
def
get_bprop_scalar_addn
(
self
):
def
get_bprop_scalar_addn
(
self
):
"""Generate bprop for AddN"""
"""Generate bprop for AddN"""
...
...
mindspore/ops/_op_impl/tbe/__init__.py
浏览文件 @
4ac18762
...
@@ -26,6 +26,7 @@ from .adam_apply_one_with_decay import _adam_apply_one_with_decay_tbe
...
@@ -26,6 +26,7 @@ from .adam_apply_one_with_decay import _adam_apply_one_with_decay_tbe
from
.add
import
_add_tbe
from
.add
import
_add_tbe
from
.apply_centered_rms_prop
import
_apply_centered_rms_prop_tbe
from
.apply_centered_rms_prop
import
_apply_centered_rms_prop_tbe
from
.add_n
import
_add_n_tbe
from
.add_n
import
_add_n_tbe
from
.accumulate_n_v2
import
_accumulate_n_v2_tbe
from
.apply_ftrl
import
_apply_ftrl_tbe
from
.apply_ftrl
import
_apply_ftrl_tbe
from
.apply_momentum
import
_apply_momentum_tbe
from
.apply_momentum
import
_apply_momentum_tbe
from
.apply_adam
import
_apply_adam_tbe
from
.apply_adam
import
_apply_adam_tbe
...
...
mindspore/ops/_op_impl/tbe/accumulate_n_v2.py
0 → 100644
浏览文件 @
4ac18762
# 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.
# ============================================================================
"""AccumulateNV2 op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
accumulate_n_v2_op_info
=
TBERegOp
(
"AccumulateNV2"
)
\
.
fusion_type
(
"ELEMWISE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"accumulate_n_v2.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"accumulate_n_v2"
)
\
.
partial_flag
(
True
)
\
.
attr
(
"n"
,
"required"
,
"int"
,
"all"
)
\
.
input
(
0
,
"x"
,
False
,
"dynamic"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
op_pattern
(
"broadcast"
)
\
.
dtype_format
(
DataType
.
F16_Default
,
DataType
.
F16_Default
)
\
.
dtype_format
(
DataType
.
F32_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
I32_Default
)
\
.
dtype_format
(
DataType
.
I8_Default
,
DataType
.
I8_Default
)
\
.
dtype_format
(
DataType
.
U8_Default
,
DataType
.
U8_Default
)
\
.
get_op_info
()
@
op_info_register
(
accumulate_n_v2_op_info
)
def
_accumulate_n_v2_tbe
():
"""AccumulateNV2 TBE register"""
return
mindspore/ops/operations/__init__.py
浏览文件 @
4ac18762
...
@@ -41,7 +41,7 @@ from .debug_ops import (ImageSummary, InsertGradientOf, HookBackward, ScalarSumm
...
@@ -41,7 +41,7 @@ from .debug_ops import (ImageSummary, InsertGradientOf, HookBackward, ScalarSumm
from
.control_ops
import
ControlDepend
,
GeSwitch
,
Merge
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
,
A
ccumulateNV2
,
A
ssignAdd
,
AssignSub
,
Atan2
,
BatchMatMul
,
BitwiseAnd
,
BitwiseOr
,
BitwiseXor
,
Inv
,
Invert
,
ApproximateEqual
,
InplaceAdd
,
InplaceSub
,
BitwiseXor
,
Inv
,
Invert
,
ApproximateEqual
,
InplaceAdd
,
InplaceSub
,
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
,
...
@@ -88,6 +88,7 @@ __all__ = [
...
@@ -88,6 +88,7 @@ __all__ = [
'ArgMaxWithValue'
,
'ArgMaxWithValue'
,
'ArgMinWithValue'
,
'ArgMinWithValue'
,
'AddN'
,
'AddN'
,
'AccumulateNV2'
,
'Sub'
,
'Sub'
,
'CumSum'
,
'CumSum'
,
'MatMul'
,
'MatMul'
,
...
...
mindspore/ops/operations/math_ops.py
浏览文件 @
4ac18762
...
@@ -798,6 +798,64 @@ class AddN(PrimitiveWithInfer):
...
@@ -798,6 +798,64 @@ class AddN(PrimitiveWithInfer):
return
Tensor
(
out
)
return
Tensor
(
out
)
class
AccumulateNV2
(
PrimitiveWithInfer
):
"""
Computes accumulation of all input tensors element-wise.
AccumulateNV2 is like AddN with a significant difference: AccumulateNV2 won't
wait for all of its inputs to be ready before beginning to sum. That is to say,
AccumulateNV2 will be able to save memory when inputs are ready at different
times since minimum temporary storage is proportional to the output size rather
than the inputs size.
Inputs:
- **input_x** (Union(tuple[Tensor], list[Tensor])) - The input tuple or list
is made up of multiple tensors whose dtype is number to be added together.
Outputs:
Tensor, has the same shape and dtype as each entry of the `input_x`.
Examples:
>>> class NetAccumulateNV2(nn.Cell):
>>> def __init__(self):
>>> super(NetAccumulateNV2, self).__init__()
>>> self.accumulateNV2 = P.AccumulateNV2()
>>>
>>> def construct(self, *z):
>>> return self.accumulateNV2(z)
>>>
>>> net = NetAccumulateNV2()
>>> input_x = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> input_y = Tensor(np.array([4, 5, 6]), mindspore.float32)
>>> net(input_x, input_y, input_x, input_y)
Tensor([10., 14., 18.], shape=(3,), dtype=mindspore.float32)
"""
@
prim_attr_register
def
__init__
(
self
):
self
.
__setattr_flag__
=
True
self
.
init_prim_io_names
(
inputs
=
[
"inputs"
],
outputs
=
[
"sum"
])
def
infer_shape
(
self
,
inputs
):
cls_name
=
self
.
name
validator
.
check_integer
(
"inputs"
,
len
(
inputs
),
1
,
Rel
.
GE
,
cls_name
)
self
.
add_prim_attr
(
'n'
,
len
(
inputs
))
shp0
=
inputs
[
0
]
for
i
,
shp
in
enumerate
(
inputs
):
validator
.
check
(
f
"shape of inputs[
{
i
}
]"
,
shp
,
'shape of inputs[0]'
,
shp0
,
Rel
.
EQ
,
cls_name
)
return
shp0
def
infer_dtype
(
self
,
inputs
):
cls_name
=
self
.
name
validator
.
check_value_type
(
"inputs"
,
inputs
,
[
tuple
,
list
],
cls_name
)
validator
.
check_integer
(
"inputs"
,
len
(
inputs
),
1
,
Rel
.
GE
,
cls_name
)
args
=
{}
for
i
,
dtype
in
enumerate
(
inputs
):
args
[
f
"inputs[
{
i
}
]"
]
=
dtype
validator
.
check_tensor_type_same
(
args
,
mstype
.
number_type
+
(
mstype
.
bool_
,),
cls_name
)
return
inputs
[
0
]
class
Neg
(
PrimitiveWithInfer
):
class
Neg
(
PrimitiveWithInfer
):
"""
"""
Returns a tensor with negative values of the input tensor element-wise.
Returns a tensor with negative values of the input tensor element-wise.
...
...
tests/ut/python/ops/test_ops.py
浏览文件 @
4ac18762
...
@@ -1415,6 +1415,11 @@ test_case_array_ops = [
...
@@ -1415,6 +1415,11 @@ test_case_array_ops = [
'desc_inputs'
:
[[
2
,
3
,
3
,
5
],
[
2
,
3
,
3
,
5
]],
'desc_inputs'
:
[[
2
,
3
,
3
,
5
],
[
2
,
3
,
3
,
5
]],
'desc_bprop'
:
[[
2
,
3
,
3
,
5
]],
'desc_bprop'
:
[[
2
,
3
,
3
,
5
]],
'skip'
:
[
'backward'
]}),
'skip'
:
[
'backward'
]}),
(
'AccumulateNV2'
,
{
'block'
:
NetForTupleInput
(
P
.
AccumulateNV2
()),
'desc_inputs'
:
[[
2
,
3
,
3
,
5
],
[
2
,
3
,
3
,
5
]],
'desc_bprop'
:
[[
2
,
3
,
3
,
5
]],
'skip'
:
[
'backward'
]}),
(
'Shape'
,
{
(
'Shape'
,
{
'block'
:
P
.
Shape
(),
'block'
:
P
.
Shape
(),
'desc_inputs'
:
[[
3
,
3
,
2
,
2
]],
'desc_inputs'
:
[[
3
,
3
,
2
,
2
]],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录