Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
53df6497
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看板
提交
53df6497
编写于
6月 05, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 05, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1863 add op broadcast_to
Merge pull request !1863 from zhaozhenlong/op/broadcast-to-d-vm
上级
41d195b5
1f342fb9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
108 addition
and
9 deletion
+108
-9
mindspore/ccsrc/kernel/tbe/tbe_adapter.cc
mindspore/ccsrc/kernel/tbe/tbe_adapter.cc
+3
-2
mindspore/nn/layer/quant.py
mindspore/nn/layer/quant.py
+2
-2
mindspore/ops/_grad/grad_array_ops.py
mindspore/ops/_grad/grad_array_ops.py
+15
-0
mindspore/ops/_op_impl/tbe/__init__.py
mindspore/ops/_op_impl/tbe/__init__.py
+4
-3
mindspore/ops/_op_impl/tbe/broadcast_to.py
mindspore/ops/_op_impl/tbe/broadcast_to.py
+40
-0
mindspore/ops/operations/__init__.py
mindspore/ops/operations/__init__.py
+3
-2
mindspore/ops/operations/array_ops.py
mindspore/ops/operations/array_ops.py
+37
-0
tests/ut/python/ops/test_ops.py
tests/ut/python/ops/test_ops.py
+4
-0
未找到文件。
mindspore/ccsrc/kernel/tbe/tbe_adapter.cc
浏览文件 @
53df6497
...
...
@@ -105,7 +105,8 @@ static std::map<string, string> tbe_func_adapter_map = {
{
"unsorted_segment_min"
,
"unsorted_segment_min_d"
},
{
"reduce_prod"
,
"reduce_prod_d"
},
{
"a_cos"
,
"acos"
},
{
"a_cos_grad"
,
"acos_grad"
}};
{
"a_cos_grad"
,
"acos_grad"
},
{
"broadcast_to"
,
"broadcast_to_d"
}};
void
TbeAdapter
::
NormalizeFuncName
(
std
::
string
*
func_name
)
{
if
(
func_name
==
nullptr
)
{
...
...
@@ -139,7 +140,7 @@ void TbeAdapter::NormalizeFuncName(std::string *func_name) {
*
func_name
=
name_tmp
;
auto
iter
=
tbe_func_adapter_map
.
find
(
*
func_name
);
if
(
iter
!=
tbe_func_adapter_map
.
end
())
{
MS_LOG
(
INFO
)
<<
"map actual op from me "
<<
func_name
<<
"
to tbe op"
<<
iter
->
second
;
MS_LOG
(
INFO
)
<<
"map actual op from me "
<<
*
func_name
<<
"
to tbe op"
<<
iter
->
second
;
*
func_name
=
iter
->
second
;
}
}
...
...
mindspore/nn/layer/quant.py
浏览文件 @
53df6497
...
...
@@ -175,7 +175,7 @@ class FakeQuantWithMinMaxAscend(Cell):
else
:
quant_fun
=
P
.
FakeQuantPerLayer
ema_fun
=
P
.
FakeQuantMinMaxPerLayerUpdate
self
.
fake_quant
=
quant_fun
(
num_bits
=
self
.
num_bits
,
ema
=
self
.
ema
,
ema_decay
=
self
.
ema_decay
,
...
...
@@ -272,7 +272,7 @@ class FakeQuantWithMinMaxGPU(Cell):
0
,
self
.
out_channels
)]).
astype
(
np
.
float32
)
self
.
minq
=
Parameter
(
Tensor
(
min_array
),
name
=
'quant_min'
,
requires_grad
=
False
)
self
.
maxq
=
Parameter
(
Tensor
(
max_array
),
name
=
'quant_max'
,
requires_grad
=
False
)
if
per_channel
:
quant_fun
=
partial
(
P
.
FakeQuantPerChannel
,
channel_axis
=
self
.
channel_axis
)
else
:
...
...
mindspore/ops/_grad/grad_array_ops.py
浏览文件 @
53df6497
...
...
@@ -18,6 +18,7 @@
from
..
import
operations
as
P
from
..operations
import
_grad_ops
as
G
from
..composite.multitype_ops.zeros_like_impl
import
zeros_like
from
..functional
import
broadcast_gradient_args
from
..
import
functional
as
F
from
.grad_base
import
bprop_getters
from
..primitive
import
constexpr
...
...
@@ -580,3 +581,17 @@ def get_bprop_batch_to_space_nd(self):
dx
=
batch_to_space_nd_grad
(
dout
)
return
(
dx
,)
return
bprop
@
bprop_getters
.
register
(
P
.
BroadcastTo
)
def
get_bprop_broadcast_to
(
self
):
"""Generate bprop for BroadcastTo"""
reduce_keep_dim
=
P
.
ReduceSum
(
keep_dims
=
True
)
broadcast_shape
=
self
.
shape
def
bprop
(
x
,
out
,
dout
):
x_shape
=
shape_op
(
x
)
_
,
reduction_axes
=
broadcast_gradient_args
(
broadcast_shape
,
x_shape
)
reduced_grad
=
reduce_keep_dim
(
dout
,
reduction_axes
)
dx
=
reshape
(
reduced_grad
,
x_shape
)
return
(
dx
,)
return
bprop
mindspore/ops/_op_impl/tbe/__init__.py
浏览文件 @
53df6497
...
...
@@ -217,9 +217,9 @@ from .bessel_i0e import _bessel_i0e_tbe
from
.bessel_i1e
import
_bessel_i1e_tbe
from
.batch_to_space_nd
import
_batch_to_space_nd_tbe
from
.space_to_batch_nd
import
_space_to_batch_nd_tbe
from
.bitwise_and
import
bitwise_and_op_info
from
.bitwise_or
import
bitwise_or_op_info
from
.bitwise_xor
import
bitwise_xor_op_info
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
.sparse_apply_adagrad
import
_sparse_apply_adagrad_tbe
from
.unsorted_segment_min
import
_unsorted_segment_min_tbe
...
...
@@ -238,3 +238,4 @@ 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_input_grad
import
_basic_lstm_cell_input_grad_tbe
from
.confusion_matrix
import
_confusion_matrix_tbe
from
.broadcast_to
import
_broadcast_to_tbe
mindspore/ops/_op_impl/tbe/broadcast_to.py
0 → 100644
浏览文件 @
53df6497
# 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.
# ============================================================================
"""BroadcastTo op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
TBERegOp
,
DataType
broadcast_to_op_info
=
TBERegOp
(
"BroadcastTo"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
async_flag
(
False
)
\
.
binfile_name
(
"broadcast_to_d.so"
)
\
.
compute_cost
(
10
)
\
.
kernel_name
(
"broadcast_to_d"
)
\
.
partial_flag
(
True
)
\
.
attr
(
"shape"
,
"required"
,
"listInt"
,
"all"
)
\
.
input
(
0
,
"x"
,
False
,
"required"
,
"all"
)
\
.
output
(
0
,
"y"
,
False
,
"required"
,
"all"
)
\
.
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
.
U16_Default
)
\
.
get_op_info
()
@
op_info_register
(
broadcast_to_op_info
)
def
_broadcast_to_tbe
():
"""BroadcastTo TBE register"""
return
mindspore/ops/operations/__init__.py
浏览文件 @
53df6497
...
...
@@ -30,7 +30,7 @@ from .array_ops import (Argmax, Argmin, Cast, Concat, Pack, Unpack,
Squeeze
,
StridedSlice
,
Tile
,
Transpose
,
TruncatedNormal
,
TupleToArray
,
UnsortedSegmentMin
,
UnsortedSegmentSum
,
SpaceToDepth
,
DepthToSpace
,
SpaceToBatch
,
BatchToSpace
,
SpaceToBatchND
,
BatchToSpaceND
)
SpaceToBatchND
,
BatchToSpaceND
,
BroadcastTo
)
from
.comm_ops
import
(
AllGather
,
AllReduce
,
_AlltoAll
,
ReduceScatter
,
Broadcast
,
_MirrorOperator
,
ReduceOp
,
_VirtualDataset
,
_VirtualDiv
,
_GetTensorSlice
,
...
...
@@ -289,7 +289,8 @@ __all__ = [
"Atan"
,
"Atanh"
,
"BasicLSTMCell"
,
"ConfusionMatrix"
"ConfusionMatrix"
,
"BroadcastTo"
]
__all__
.
extend
(
_quant_ops
.
__all__
)
...
...
mindspore/ops/operations/array_ops.py
浏览文件 @
53df6497
...
...
@@ -2738,3 +2738,40 @@ class BatchToSpaceND(PrimitiveWithInfer):
f
'block_shape_prod
{
block_shape_prod
}
'
)
out_shape
[
0
]
=
out_shape
[
0
]
//
block_shape_prod
return
out_shape
class
BroadcastTo
(
PrimitiveWithInfer
):
"""
Broadcasts input tensor to a given shape.
Args:
shape (tuple): The target shape to broadcast.
Inputs:
- **input_x** (Tensor) - The input tensor.
Outputs:
Tensor, with the given `shape` and the same data type as `input_x`.
Examples:
>>> shape = (2, 3)
>>> input_x = Tensor(np.array([1, 2, 3]).astype(np.float32))
>>> broadcast_to = P.BroadcastTo(shape)
>>> broadcast_to(input_x)
[[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]
"""
@
prim_attr_register
def
__init__
(
self
,
shape
):
"""Init BroadcastTo"""
validator
.
check_value_type
(
"shape"
,
shape
,
(
tuple
),
self
.
name
)
for
i
in
shape
:
validator
.
check_integer
(
"shape element"
,
i
,
0
,
Rel
.
GT
,
self
.
name
)
self
.
shape
=
shape
def
infer_shape
(
self
,
x_shape
):
return
self
.
shape
def
infer_dtype
(
self
,
x_dtype
):
validator
.
check_subclass
(
"input_x"
,
x_dtype
,
mstype
.
tensor
,
self
.
name
)
return
x_dtype
tests/ut/python/ops/test_ops.py
浏览文件 @
53df6497
...
...
@@ -1396,6 +1396,10 @@ test_case_array_ops = [
'desc_inputs'
:
[
Tensor
(
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
],
[
4
,
2
,
1
]]).
astype
(
np
.
float32
)),
Tensor
(
np
.
array
([
0
,
1
,
1
]).
astype
(
np
.
int32
))],
'desc_bprop'
:
[
Tensor
(
np
.
array
([[
1
,
2
,
3
],
[
4
,
2
,
1
]]).
astype
(
np
.
float32
))]}),
(
'BroadcastTo'
,
{
'block'
:
P
.
BroadcastTo
((
2
,
3
)),
'desc_inputs'
:
[
Tensor
(
np
.
array
([
1
,
2
,
3
]).
astype
(
np
.
float32
))],
'desc_bprop'
:
[
Tensor
(
np
.
array
([[
1
,
2
,
3
],
[
1
,
2
,
3
]]).
astype
(
np
.
float32
))]}),
]
test_case_other_ops
=
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录