Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
c4af71e2
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看板
提交
c4af71e2
编写于
5月 18, 2020
作者:
H
huanghui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add LarsV2 fission pass
上级
a3e29e61
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
233 addition
and
0 deletion
+233
-0
mindspore/ccsrc/pre_activate/ascend/ir_fission/lars_v2_fission.cc
...e/ccsrc/pre_activate/ascend/ir_fission/lars_v2_fission.cc
+91
-0
mindspore/ccsrc/pre_activate/ascend/ir_fission/lars_v2_fission.h
...re/ccsrc/pre_activate/ascend/ir_fission/lars_v2_fission.h
+32
-0
mindspore/ccsrc/pre_activate/common/helper.h
mindspore/ccsrc/pre_activate/common/helper.h
+1
-0
mindspore/ccsrc/utils/utils.h
mindspore/ccsrc/utils/utils.h
+3
-0
tests/ut/cpp/pre_activate/ascend/ir_fission/lars_v2_fission_test.cc
...pp/pre_activate/ascend/ir_fission/lars_v2_fission_test.cc
+56
-0
tests/ut/cpp/python_input/gtest_input/pre_activate/lars_v2_fission_test.py
...on_input/gtest_input/pre_activate/lars_v2_fission_test.py
+50
-0
未找到文件。
mindspore/ccsrc/pre_activate/ascend/ir_fission/lars_v2_fission.cc
0 → 100644
浏览文件 @
c4af71e2
/**
* 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.
*/
#include "pre_activate/ascend/ir_fission/lars_v2_fission.h"
#include <memory>
#include <vector>
#include "session/anf_runtime_algorithm.h"
#include "pre_activate/common/helper.h"
#include "utils/utils.h"
namespace
mindspore
{
namespace
opt
{
namespace
{
void
CreateOutputsOfSquareSumAll
(
const
FuncGraphPtr
&
graph
,
const
CNodePtr
&
lars_v2
,
std
::
vector
<
AnfNodePtr
>
*
square_sum_all_outputs
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
MS_EXCEPTION_IF_NULL
(
lars_v2
);
if
(
lars_v2
->
size
()
!=
kLarsV2InputNum
)
{
MS_LOG
(
EXCEPTION
)
<<
"Op lars_v2's input not equal "
<<
kLarsV2InputNum
;
}
std
::
vector
<
AnfNodePtr
>
inputs
=
{
NewValueNode
(
std
::
make_shared
<
Primitive
>
(
kSquareSumAllOpName
))};
inputs
.
push_back
(
lars_v2
->
input
(
1
));
inputs
.
push_back
(
lars_v2
->
input
(
2
));
auto
square_sum_all
=
graph
->
NewCNode
(
inputs
);
MS_EXCEPTION_IF_NULL
(
square_sum_all
);
square_sum_all
->
set_scope
(
lars_v2
->
scope
());
auto
types
=
{
kNumberTypeFloat32
,
kNumberTypeFloat32
};
std
::
vector
<
size_t
>
shape
;
auto
shapes
=
{
shape
,
shape
};
AnfAlgo
::
SetOutputInferTypeAndShape
(
types
,
shapes
,
square_sum_all
.
get
());
CreateMultipleOutputsOfAnfNode
(
graph
,
square_sum_all
,
2
,
square_sum_all_outputs
);
}
CNodePtr
CreateLarsV2Update
(
const
FuncGraphPtr
&
graph
,
const
CNodePtr
&
lars_v2
,
const
std
::
vector
<
AnfNodePtr
>
&
square_sum_all_outputs
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
MS_EXCEPTION_IF_NULL
(
lars_v2
);
if
(
square_sum_all_outputs
.
size
()
!=
2
)
{
MS_LOG
(
EXCEPTION
)
<<
"square_sum_all_outputs' size not equal 2"
;
}
if
(
lars_v2
->
size
()
!=
kLarsV2InputNum
)
{
MS_LOG
(
EXCEPTION
)
<<
"Op lars_v2's input not equal "
<<
kLarsV2InputNum
;
}
std
::
vector
<
AnfNodePtr
>
inputs
=
{
NewValueNode
(
std
::
make_shared
<
Primitive
>
(
kLarsV2UpdateOpName
))};
inputs
.
push_back
(
lars_v2
->
input
(
1
));
inputs
.
push_back
(
lars_v2
->
input
(
2
));
inputs
.
push_back
(
square_sum_all_outputs
[
0
]);
inputs
.
push_back
(
square_sum_all_outputs
[
1
]);
inputs
.
push_back
(
lars_v2
->
input
(
3
));
inputs
.
push_back
(
lars_v2
->
input
(
4
));
auto
lars_v2_update
=
graph
->
NewCNode
(
inputs
);
MS_EXCEPTION_IF_NULL
(
lars_v2_update
);
lars_v2_update
->
set_scope
(
lars_v2
->
scope
());
lars_v2_update
->
set_abstract
(
lars_v2
->
abstract
());
return
lars_v2_update
;
}
}
// namespace
const
BaseRef
LarsV2Fission
::
DefinePattern
()
const
{
VarPtr
Xs
=
std
::
make_shared
<
SeqVar
>
();
auto
lars_v2_prim
=
std
::
make_shared
<
Primitive
>
(
kLarsV2OpName
);
return
VectorRef
({
lars_v2_prim
,
Xs
});
}
const
AnfNodePtr
LarsV2Fission
::
Process
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
,
const
EquivPtr
&
)
const
{
MS_EXCEPTION_IF_NULL
(
graph
);
MS_EXCEPTION_IF_NULL
(
node
);
auto
lars_v2
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
lars_v2
);
std
::
vector
<
AnfNodePtr
>
square_sum_all_outputs
;
CreateOutputsOfSquareSumAll
(
graph
,
lars_v2
,
&
square_sum_all_outputs
);
return
CreateLarsV2Update
(
graph
,
lars_v2
,
square_sum_all_outputs
);
}
}
// namespace opt
}
// namespace mindspore
mindspore/ccsrc/pre_activate/ascend/ir_fission/lars_v2_fission.h
0 → 100644
浏览文件 @
c4af71e2
/**
* 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.
*/
#ifndef MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_IR_FISSION_LARS_V2_FISSION_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_IR_FISSION_LARS_V2_FISSION_H_
#include "pre_activate/common/optimizer.h"
namespace
mindspore
{
namespace
opt
{
class
LarsV2Fission
:
public
PatternProcessPass
{
public:
explicit
LarsV2Fission
(
bool
multigraph
=
true
)
:
PatternProcessPass
(
"lars_v2_fission"
,
multigraph
)
{}
~
LarsV2Fission
()
override
=
default
;
const
BaseRef
DefinePattern
()
const
override
;
const
AnfNodePtr
Process
(
const
FuncGraphPtr
&
,
const
AnfNodePtr
&
,
const
EquivPtr
&
)
const
override
;
};
}
// namespace opt
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_IR_FISSION_LARS_V2_FISSION_H_
mindspore/ccsrc/pre_activate/common/helper.h
浏览文件 @
c4af71e2
...
...
@@ -91,6 +91,7 @@ constexpr size_t kBackendTransDataInputNum = 2;
constexpr
size_t
kApplyMomentumInputNum
=
6
;
constexpr
size_t
kBiasAddInputNum
=
3
;
constexpr
size_t
kTopkInputNum
=
3
;
constexpr
size_t
kLarsV2InputNum
=
5
;
enum
FusedBatchNormInput
{
kX
=
1
,
...
...
mindspore/ccsrc/utils/utils.h
浏览文件 @
c4af71e2
...
...
@@ -144,6 +144,9 @@ constexpr auto kBNInferGradOpName = "BNInferGrad";
constexpr
auto
kCallOpName
=
"call"
;
constexpr
auto
kPartialOpName
=
"partial"
;
constexpr
auto
kSwitchOpName
=
"switch"
;
constexpr
auto
kLarsV2OpName
=
"LarsV2"
;
constexpr
auto
kLarsV2UpdateOpName
=
"LarsV2Update"
;
constexpr
auto
kSquareSumAllOpName
=
"SquareSumAll"
;
// attr key name
constexpr
auto
kAttrInputNames
=
"input_names"
;
...
...
tests/ut/cpp/pre_activate/ascend/ir_fission/lars_v2_fission_test.cc
0 → 100644
浏览文件 @
c4af71e2
/**
* 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.
*/
#include "common/backend_common_test.h"
#include "common/py_func_graph_fetcher.h"
#include "pre_activate/ascend/ir_fission/lars_v2_fission.h"
namespace
mindspore
{
namespace
opt
{
class
TestHWLarsV2Fission
:
public
BackendCommon
{
public:
TestHWLarsV2Fission
()
:
get_py_fun_
(
"gtest_input.pre_activate.lars_v2_fission_test"
,
true
)
{}
~
TestHWLarsV2Fission
()
override
=
default
;
UT
::
PyFuncGraphFetcher
get_py_fun_
;
};
TEST_F
(
TestHWLarsV2Fission
,
test_fission
)
{
FuncGraphPtr
g
=
get_py_fun_
.
CallAndParseRet
(
"test_lars_v2_fission"
,
"before"
);
EXPECT_NE
(
g
,
nullptr
);
// set abstract for all nodes in g
std
::
vector
<
int
>
shp
{
2
,
32
,
224
,
224
};
auto
x_abstract
=
std
::
make_shared
<
abstract
::
AbstractTensor
>
(
kFloat32
,
shp
);
g
->
get_return
()
->
input
(
1
)
->
set_abstract
(
x_abstract
);
for
(
auto
&
p
:
g
->
parameters
()){
p
->
set_abstract
(
x_abstract
);
}
AbstractBasePtrList
args_spec_list
;
auto
kg
=
GetKernelGraph
(
g
,
args_spec_list
,
false
);
auto
optimizer
=
std
::
make_shared
<
opt
::
GraphOptimizer
>
();
auto
pm
=
std
::
make_shared
<
opt
::
PassManager
>
();
pm
->
AddPass
(
std
::
make_shared
<
opt
::
LarsV2Fission
>
());
optimizer
->
AddPassManager
(
pm
);
FuncGraphPtr
new_graph
=
optimizer
->
Optimize
(
kg
);
FuncGraphPtr
g_after
=
get_py_fun_
.
CallAndParseRet
(
"test_lars_v2_fission"
,
"after"
);
EXPECT_NE
(
g_after
,
nullptr
);
EXPECT_TRUE
(
CheckEqualGraph
(
g_after
,
new_graph
));
}
}
// namespace opt
}
// namespace mindspore
tests/ut/cpp/python_input/gtest_input/pre_activate/lars_v2_fission_test.py
0 → 100644
浏览文件 @
c4af71e2
# 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.
# ============================================================================
from
mindspore.ops
import
Primitive
lars_v2
=
Primitive
(
'LarsV2'
)
square_sum_all
=
Primitive
(
'SquareSumAll'
)
lars_v2_update
=
Primitive
(
'LarsV2Update'
)
make_tuple
=
Primitive
(
'make_tuple'
)
tuple_getitem
=
Primitive
(
'tuple_getitem'
)
class
FnDict
:
def
__init__
(
self
):
self
.
fnDict
=
{}
def
__call__
(
self
,
fn
):
self
.
fnDict
[
fn
.
__name__
]
=
fn
def
__getitem__
(
self
,
name
):
return
self
.
fnDict
[
name
]
def
test_lars_v2_fission
(
tag
):
fns
=
FnDict
()
@
fns
def
before
(
input0
,
input1
,
input2
,
input3
):
res
=
lars_v2
(
input0
,
input1
,
input2
,
input3
)
return
res
@
fns
def
after
(
input0
,
input1
,
input2
,
input3
):
res
=
square_sum_all
(
input0
,
input1
)
item0
=
tuple_getitem
(
res
,
0
)
item1
=
tuple_getitem
(
res
,
1
)
res
=
lars_v2_update
(
input0
,
input1
,
item0
,
item1
,
input2
,
input3
)
return
make_tuple
(
res
)
return
fns
[
tag
]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录