Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
6f174704
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,发现更多精彩内容 >>
提交
6f174704
编写于
3月 31, 2020
作者:
Z
zhangz0911gm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add FloorMod, Acosh in ME
上级
d8b460c7
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
112 addition
and
3 deletion
+112
-3
mindspore/ccsrc/transform/convert.cc
mindspore/ccsrc/transform/convert.cc
+4
-0
mindspore/ccsrc/transform/op_declare.cc
mindspore/ccsrc/transform/op_declare.cc
+10
-0
mindspore/ccsrc/transform/op_declare.h
mindspore/ccsrc/transform/op_declare.h
+4
-1
mindspore/ops/_grad/grad_math_ops.py
mindspore/ops/_grad/grad_math_ops.py
+25
-0
mindspore/ops/operations/__init__.py
mindspore/ops/operations/__init__.py
+3
-1
mindspore/ops/operations/math_ops.py
mindspore/ops/operations/math_ops.py
+56
-0
mindspore/ops/operations/nn_ops.py
mindspore/ops/operations/nn_ops.py
+1
-1
tests/ut/python/ops/test_ops.py
tests/ut/python/ops/test_ops.py
+9
-0
未找到文件。
mindspore/ccsrc/transform/convert.cc
浏览文件 @
6f174704
...
...
@@ -171,6 +171,8 @@ const char kNameAbsGrad[] = "AbsGrad";
const
char
kNameBinaryCrossEntropy
[]
=
"BinaryCrossEntropy"
;
const
char
kNameBinaryCrossEntropyGrad
[]
=
"BinaryCrossEntropyGrad"
;
const
char
kNameSparseApplyAdagrad
[]
=
"SparseApplyAdagrad"
;
const
char
kNameAcosh
[]
=
"Acosh"
;
const
char
kNameFloorMod
[]
=
"FloorMod"
;
const
char
kNameSpaceToDepth
[]
=
"SpaceToDepth"
;
const
char
kNameDepthToSpace
[]
=
"DepthToSpace"
;
const
char
kNameSign
[]
=
"Sign"
;
...
...
@@ -360,6 +362,8 @@ std::unordered_map<std::string, OpAdapterDescPtr> &DfGraphConvertor::get_adpt_ma
{
string
(
kNameBinaryCrossEntropy
),
ADPT_DESC
(
BinaryCrossEntropy
)},
{
string
(
kNameBinaryCrossEntropyGrad
),
ADPT_DESC
(
BinaryCrossEntropyGrad
)},
{
string
(
kNameSparseApplyAdagrad
),
ADPT_DESC
(
SparseApplyAdagradD
)},
{
string
(
kNameAcosh
),
ADPT_DESC
(
Acosh
)},
{
string
(
kNameFloorMod
),
ADPT_DESC
(
FloorMod
)},
{
string
(
kNameSpaceToDepth
),
ADPT_DESC
(
SpaceToDepth
)},
{
string
(
kNameDepthToSpace
),
ADPT_DESC
(
DepthToSpace
)},
{
string
(
kNameSign
),
ADPT_DESC
(
Sign
)},
...
...
mindspore/ccsrc/transform/op_declare.cc
浏览文件 @
6f174704
...
...
@@ -357,6 +357,11 @@ INPUT_MAP(AcosGrad) = {{1, INPUT_DESC(y)}, {2, INPUT_DESC(dy)}};
ATTR_MAP
(
AcosGrad
)
=
EMPTY_ATTR_MAP
;
OUTPUT_MAP
(
AcosGrad
)
=
{{
0
,
OUTPUT_DESC
(
z
)}};
// Acosh
INPUT_MAP
(
Acosh
)
=
{{
1
,
INPUT_DESC
(
x
)}};
ATTR_MAP
(
Acosh
)
=
EMPTY_ATTR_MAP
;
OUTPUT_MAP
(
Acosh
)
=
{{
0
,
OUTPUT_DESC
(
y
)}};
// Floor
INPUT_MAP
(
Floor
)
=
{{
1
,
INPUT_DESC
(
x
)}};
ATTR_MAP
(
Floor
)
=
EMPTY_ATTR_MAP
;
...
...
@@ -367,6 +372,11 @@ INPUT_MAP(FloorDiv) = {{1, INPUT_DESC(x1)}, {2, INPUT_DESC(x2)}};
ATTR_MAP
(
FloorDiv
)
=
EMPTY_ATTR_MAP
;
OUTPUT_MAP
(
FloorDiv
)
=
{{
0
,
OUTPUT_DESC
(
y
)}};
// FloorMod
INPUT_MAP
(
FloorMod
)
=
{{
1
,
INPUT_DESC
(
x1
)},
{
2
,
INPUT_DESC
(
x2
)}};
ATTR_MAP
(
FloorMod
)
=
EMPTY_ATTR_MAP
;
OUTPUT_MAP
(
FloorMod
)
=
{{
0
,
OUTPUT_DESC
(
y
)}};
// Sin
INPUT_MAP
(
Sin
)
=
{{
1
,
INPUT_DESC
(
x
)}};
ATTR_MAP
(
Sin
)
=
EMPTY_ATTR_MAP
;
...
...
mindspore/ccsrc/transform/op_declare.h
浏览文件 @
6f174704
...
...
@@ -324,11 +324,15 @@ DECLARE_OP_USE_OUTPUT(Acos)
DECLARE_OP_ADAPTER
(
AcosGrad
)
DECLARE_OP_USE_OUTPUT
(
AcosGrad
)
DECLARE_OP_ADAPTER
(
Acosh
)
DECLARE_OP_USE_OUTPUT
(
Acosh
)
DECLARE_OP_ADAPTER
(
Floor
)
DECLARE_OP_USE_OUTPUT
(
Floor
)
DECLARE_OP_ADAPTER
(
FloorDiv
)
DECLARE_OP_USE_OUTPUT
(
FloorDiv
)
DECLARE_OP_ADAPTER
(
FloorMod
)
DECLARE_OP_USE_OUTPUT
(
FloorMod
)
DECLARE_OP_ADAPTER
(
Sin
)
DECLARE_OP_USE_OUTPUT
(
Sin
)
DECLARE_OP_ADAPTER
(
Exp
)
...
...
@@ -450,7 +454,6 @@ DECLARE_OP_USE_INPUT_ATTR(ApplyRMSPropD)
DECLARE_OP_USE_OUTPUT
(
ApplyRMSPropD
)
DECLARE_OP_ADAPTER
(
ApplyCenteredRMSProp
)
DECLARE_OP_USE_OUTPUT
(
ApplyCenteredRMSProp
)
#ifdef ENABLE_GE
DECLARE_OP_ADAPTER
(
Print
)
DECLARE_OP_USE_DYN_INPUT
(
Print
)
...
...
mindspore/ops/_grad/grad_math_ops.py
浏览文件 @
6f174704
...
...
@@ -251,6 +251,20 @@ def get_bprop_floordiv(self):
return
bprop
@
bprop_getters
.
register
(
P
.
FloorMod
)
def
get_bprop_floormod
(
self
):
"""Grad definition for `FloorMod` operation."""
div_op
=
P
.
FloorMod
()
neg
=
P
.
Neg
()
mul_op
=
P
.
Mul
()
def
bprop
(
x
,
y
,
out
,
dout
):
bc_x
=
div_op
(
dout
,
y
)
bc_y
=
neg
(
mul_op
(
bc_x
,
out
))
return
binop_grad_common
(
x
,
y
,
bc_x
,
bc_y
)
return
bprop
@
bprop_getters
.
register
(
P
.
Square
)
def
get_bprop_square
(
self
):
"""Grad definition for `Square` operation."""
...
...
@@ -690,6 +704,17 @@ def get_bprop_acos(self):
return
bprop
@
bprop_getters
.
register
(
P
.
Acosh
)
def
get_bprop_acosh
(
self
):
"""Grad definition for `Acosh` operation."""
input_grad
=
G
.
AcoshGrad
()
def
bprop
(
x
,
out
,
dout
):
dx
=
input_grad
(
x
,
dout
)
return
(
dx
,)
return
bprop
@
bprop_getters
.
register
(
P
.
Abs
)
def
get_bprop_abs
(
self
):
"""Grad definition for `Abs` operation."""
...
...
mindspore/ops/operations/__init__.py
浏览文件 @
6f174704
...
...
@@ -39,7 +39,7 @@ from .control_ops import ControlDepend, GeSwitch, Merge
from
.inner_ops
import
ScalarCast
from
.math_ops
import
(
Abs
,
ACos
,
AddN
,
AssignAdd
,
AssignSub
,
Atan2
,
BatchMatMul
,
ReduceMax
,
ReduceMin
,
ReduceMean
,
ReduceSum
,
ReduceAll
,
ReduceProd
,
CumProd
,
Cos
,
Div
,
Equal
,
EqualCount
,
Exp
,
Floor
,
FloorDiv
,
Cos
,
Div
,
Equal
,
EqualCount
,
Exp
,
Floor
,
FloorDiv
,
FloorMod
,
Acosh
,
Greater
,
GreaterEqual
,
Less
,
LessEqual
,
Log
,
LogicalAnd
,
LogicalNot
,
LogicalOr
,
MatMul
,
Maximum
,
Minimum
,
Mul
,
Neg
,
NMSWithMask
,
NotEqual
,
...
...
@@ -205,6 +205,8 @@ __all__ = [
'Log'
,
'SigmoidCrossEntropyWithLogits'
,
'FloorDiv'
,
'FloorMod'
,
'Acosh'
,
"PReLU"
,
"Cos"
,
"ACos"
,
...
...
mindspore/ops/operations/math_ops.py
浏览文件 @
6f174704
...
...
@@ -1183,6 +1183,62 @@ class Floor(PrimitiveWithInfer):
return
x_dtype
class
FloorMod
(
_MathBinaryOp
):
"""
Compute element-wise remainder of division.
The inputs must be two tensors or one tensor and one scalar.
When the inputs are two tensors, the shapes of them could be broadcast,
and the data types of them should be same.
When the inputs are one tensor and one scalar, the scalar cannot be a parameter, only can be a constant,
and the type of the scalar is the same as the data type of the tensor.
Inputs:
- **input_x** (Union[Tensor, Number]) - The first input is a tensor whose data type is number or a number.
- **input_y** (Union[Tensor, Number]) - The second input is a tensor whose data type is same as 'input_x' or
a number.
Outputs:
Tensor, the shape is same as the shape after broadcasting, and the data type is same as 'input_x'.
Examples:
>>> input_x = Tensor(np.array([2, 4, -1]), mindspore.int32)
>>> input_y = Tensor(np.array([3, 3, 3]), mindspore.int32)
>>> floor_mod = FloorMod()
>>> floor_mod(input_x, input_y)
[2, 1, 2]
"""
class
Acosh
(
PrimitiveWithInfer
):
"""
Compute inverse hyperbolic cosine of x 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:
>>> acosh = Acosh()
>>> X = Tensor(np.array([1.0, 1.5, 3.0, 100.0]), ms.float32)
>>> output = acosh(X)
"""
@
prim_attr_register
def
__init__
(
self
):
"""init Acosh"""
def
infer_shape
(
self
,
x
):
return
x
def
infer_dtype
(
self
,
x
):
validator
.
check_subclass
(
"x_dtype"
,
x
,
mstype
.
tensor
)
validator
.
check_typename
(
'x_dtype'
,
x
,
mstype
.
number_type
)
return
x
class
_LogicBinaryOp
(
_BinaryOp
):
"""
Define logic binary operators.
...
...
mindspore/ops/operations/nn_ops.py
浏览文件 @
6f174704
...
...
@@ -2395,4 +2395,4 @@ class ApplyFtrl(PrimitiveWithInfer):
validator
.
check_typename
(
"l1"
,
l1_type
,[
mstype
.
float16
,
mstype
.
float32
])
validator
.
check_typename
(
"l2"
,
l2_type
,[
mstype
.
float16
,
mstype
.
float32
])
validator
.
check_typename
(
"lr_power"
,
lr_power_type
,[
mstype
.
float16
,
mstype
.
float32
])
return
var_type
\ No newline at end of file
return
var_type
tests/ut/python/ops/test_ops.py
浏览文件 @
6f174704
...
...
@@ -219,6 +219,10 @@ test_case_math_ops = [
'block'
:
P
.
ACos
(),
'desc_inputs'
:
[[
2
,
3
]],
'desc_bprop'
:
[[
2
,
3
]]}),
(
'Acosh'
,
{
'block'
:
P
.
Acosh
(),
'desc_inputs'
:
[
Tensor
(
np
.
random
.
rand
(
4
).
astype
(
np
.
float16
))],
'skip'
:
[
'backward'
]}),
(
'Sin'
,
{
'block'
:
P
.
Sin
(),
'desc_inputs'
:
[[
2
,
3
]],
...
...
@@ -301,6 +305,11 @@ test_case_math_ops = [
'desc_inputs'
:
[
Tensor
(
np
.
random
.
rand
(
4
).
astype
(
np
.
float16
)),
Tensor
(
np
.
random
.
rand
(
4
).
astype
(
np
.
float16
))],
'skip'
:
[
'backward'
]}),
(
'FloorMod'
,
{
'block'
:
P
.
FloorMod
(),
'desc_inputs'
:
[
Tensor
(
np
.
random
.
rand
(
4
).
astype
(
np
.
float16
)),
Tensor
(
np
.
random
.
rand
(
4
).
astype
(
np
.
float16
))],
'skip'
:
[
'backward'
]}),
(
'identity'
,
{
'block'
:
ops
.
functional
.
identity
,
'desc_inputs'
:
[[
2
,
2
]],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录