Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
4be5448b
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4be5448b
编写于
3月 05, 2022
作者:
F
furnace
提交者:
GitHub
3月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Phi] move infershape for mv (#39954)
* [Phi] move infershape for mv * [Phi] delete extra codes for mv
上级
94f03dc2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
33 deletion
+41
-33
paddle/fluid/operators/mv_op.cc
paddle/fluid/operators/mv_op.cc
+8
-28
paddle/phi/infermeta/binary.cc
paddle/phi/infermeta/binary.cc
+30
-0
paddle/phi/infermeta/binary.h
paddle/phi/infermeta/binary.h
+3
-0
paddle/phi/ops/compat/mv_sig.cc
paddle/phi/ops/compat/mv_sig.cc
+0
-5
未找到文件。
paddle/fluid/operators/mv_op.cc
浏览文件 @
4be5448b
...
...
@@ -16,8 +16,11 @@ limitations under the License. */
#include <utility>
#include <vector>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/binary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -42,33 +45,6 @@ class MVOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
*
context
)
const
override
{
OP_INOUT_CHECK
(
context
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"mv"
);
OP_INOUT_CHECK
(
context
->
HasInput
(
"Vec"
),
"Input"
,
"Vec"
,
"mv"
);
OP_INOUT_CHECK
(
context
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"mv"
);
auto
dim_x
=
context
->
GetInputDim
(
"X"
);
auto
dim_vec
=
context
->
GetInputDim
(
"Vec"
);
PADDLE_ENFORCE_EQ
(
dim_x
.
size
(),
2
,
platform
::
errors
::
InvalidArgument
(
"The rank of input X should be 2, but is %d"
,
dim_x
.
size
()));
PADDLE_ENFORCE_EQ
(
dim_vec
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"The rank of input Vec should be 1, but is %d"
,
dim_vec
.
size
()));
PADDLE_ENFORCE_EQ
(
dim_x
[
1
],
dim_vec
[
0
],
platform
::
errors
::
InvalidArgument
(
"X's second dimension is expected to be equal to "
"Vec's first dimension"
"but recieved X'shape = [%s], Vec's shape = [%s]"
,
dim_x
,
dim_vec
));
framework
::
DDim
dim_out
=
phi
::
make_ddim
({
dim_x
[
0
]});
context
->
SetOutputDim
(
"Out"
,
dim_out
);
context
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
};
template
<
typename
T
>
...
...
@@ -118,7 +94,11 @@ class MVOpGrad : public framework::OperatorWithKernel {
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
DELCARE_INFER_SHAPE_FUNCTOR
(
mv
,
MvInferShapeFunctor
,
PT_INFER_META
(
phi
::
MvInferMeta
));
REGISTER_OPERATOR
(
mv
,
ops
::
MVOp
,
ops
::
MVOpMaker
,
ops
::
MVOpGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
MVOpGradMaker
<
paddle
::
imperative
::
OpBase
>
);
ops
::
MVOpGradMaker
<
paddle
::
imperative
::
OpBase
>
,
MvInferShapeFunctor
);
REGISTER_OPERATOR
(
mv_grad
,
ops
::
MVOpGrad
);
paddle/phi/infermeta/binary.cc
浏览文件 @
4be5448b
...
...
@@ -443,4 +443,34 @@ void GatherTreeMeta(const MetaTensor& ids,
out
->
set_dims
(
ids_dims
);
}
void
MvInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
vec
,
MetaTensor
*
out
)
{
auto
dim_x
=
x
.
dims
();
auto
dim_vec
=
vec
.
dims
();
PADDLE_ENFORCE_EQ
(
dim_x
.
size
(),
2
,
phi
::
errors
::
InvalidArgument
(
"The rank of input X should be 2, but is %d"
,
dim_x
.
size
()));
PADDLE_ENFORCE_EQ
(
dim_vec
.
size
(),
1
,
phi
::
errors
::
InvalidArgument
(
"The rank of input Vec should be 1, but is %d"
,
dim_vec
.
size
()));
PADDLE_ENFORCE_EQ
(
dim_x
[
1
],
dim_vec
[
0
],
phi
::
errors
::
InvalidArgument
(
"X's second dimension is expected to be equal to "
"Vec's first dimension"
"but recieved X'shape = [%s], Vec's shape = [%s]"
,
dim_x
,
dim_vec
));
auto
dim_out
=
phi
::
make_ddim
({
dim_x
[
0
]});
out
->
set_dims
(
dim_out
);
out
->
set_dtype
(
x
.
dtype
());
out
->
set_layout
(
x
.
layout
());
out
->
share_lod
(
x
);
}
}
// namespace phi
paddle/phi/infermeta/binary.h
浏览文件 @
4be5448b
...
...
@@ -85,4 +85,7 @@ void GatherNdInferMeta(const MetaTensor& x,
void
GatherTreeMeta
(
const
MetaTensor
&
ids
,
const
MetaTensor
&
parents
,
MetaTensor
*
out
);
void
MvInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
vec
,
MetaTensor
*
out
);
}
// namespace phi
paddle/phi/ops/compat/mv_sig.cc
浏览文件 @
4be5448b
...
...
@@ -16,10 +16,6 @@
namespace
phi
{
KernelSignature
MvOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"mv"
,
{
"X"
,
"Vec"
},
{},
{
"Out"
});
}
KernelSignature
MvGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"mv_grad"
,
{
"X"
,
"Vec"
,
GradVarName
(
"Out"
)},
...
...
@@ -29,5 +25,4 @@ KernelSignature MvGradOpArgumentMapping(const ArgumentMappingContext& ctx) {
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
mv
,
phi
::
MvOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
mv_grad
,
phi
::
MvGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录