Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
6d205516
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
6d205516
编写于
3月 16, 2022
作者:
X
xiongkun
提交者:
GitHub
3月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tranfer cumprod and kldiv_loss infershape to phi (#40575)
上级
c7637700
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
64 addition
and
48 deletion
+64
-48
paddle/fluid/operators/cumprod_op.cc
paddle/fluid/operators/cumprod_op.cc
+6
-9
paddle/fluid/operators/kldiv_loss_op.cc
paddle/fluid/operators/kldiv_loss_op.cc
+7
-39
paddle/phi/infermeta/binary.cc
paddle/phi/infermeta/binary.cc
+45
-0
paddle/phi/infermeta/binary.h
paddle/phi/infermeta/binary.h
+6
-0
未找到文件。
paddle/fluid/operators/cumprod_op.cc
浏览文件 @
6d205516
...
...
@@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -21,14 +23,6 @@ namespace operators {
class
CumprodOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"Cumprod"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"Cumprod"
);
ctx
->
ShareDim
(
"X"
,
"Out"
);
ctx
->
ShareLoD
(
"X"
,
"Out"
);
}
};
class
CumprodOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
...
...
@@ -82,9 +76,12 @@ class CumprodGradOp : public framework::OperatorWithKernel {
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
cumprod
,
CumprodInferShapeFunctor
,
PD_INFER_META
(
phi
::
UnchangedInferMeta
));
REGISTER_OPERATOR
(
cumprod
,
ops
::
CumprodOp
,
ops
::
CumprodOpMaker
,
ops
::
CumprodGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
CumprodGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
ops
::
CumprodGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
CumprodInferShapeFunctor
);
REGISTER_OPERATOR
(
cumprod_grad
,
ops
::
CumprodGradOp
);
paddle/fluid/operators/kldiv_loss_op.cc
浏览文件 @
6d205516
...
...
@@ -11,7 +11,9 @@
#include <memory>
#include <string>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/infermeta/binary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -21,44 +23,6 @@ using framework::Tensor;
class
KLDivLossOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"KLDivLoss"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"Target"
),
"Input"
,
"Target"
,
"KLDivLoss"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Loss"
),
"Output"
,
"Loss"
,
"KLDivLoss"
);
auto
dim_x
=
ctx
->
GetInputDim
(
"X"
);
auto
dim_target
=
ctx
->
GetInputDim
(
"Target"
);
PADDLE_ENFORCE_EQ
(
dim_x
.
size
(),
dim_target
.
size
(),
platform
::
errors
::
InvalidArgument
(
"Input(X) rank and Input(Target) rank should be "
"same, but received X rank(%d) != Target rank(%d)"
,
dim_x
.
size
(),
dim_target
.
size
()));
for
(
int
i
=
0
;
i
<
dim_x
.
size
();
i
++
)
{
if
(
ctx
->
IsRuntime
()
||
(
dim_x
[
i
]
>
0
&&
dim_target
[
i
]
>
0
))
{
PADDLE_ENFORCE_EQ
(
dim_x
[
i
],
dim_target
[
i
],
platform
::
errors
::
InvalidArgument
(
"Input(X) and Input(Target) should in same shape. but received "
"X dimension[%d](%d) != Target dimension[%d](%d)"
,
i
,
dim_x
[
i
],
i
,
dim_target
[
i
]));
}
}
auto
reduction
=
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"reduction"
);
auto
reduction_valid
=
"mean"
==
reduction
||
"sum"
==
reduction
||
"batchmean"
==
reduction
||
"none"
==
reduction
;
PADDLE_ENFORCE_EQ
(
reduction_valid
,
true
,
platform
::
errors
::
InvalidArgument
(
"Attr(reduction) can only be 'none'|'batchmean'|'sum'|'mean'."
));
if
(
"none"
==
reduction
)
{
ctx
->
SetOutputDim
(
"Loss"
,
dim_x
);
}
else
{
ctx
->
SetOutputDim
(
"Loss"
,
{
1
});
}
}
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
...
...
@@ -171,8 +135,12 @@ DECLARE_NO_NEED_BUFFER_VARS_INFERER(KLDivLossGradNoNeedBufferVarInferer, "X");
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
kldiv_loss
,
KLDivInferShapeFunctor
,
PD_INFER_META
(
phi
::
KLDivInferMeta
));
REGISTER_OPERATOR
(
kldiv_loss
,
ops
::
KLDivLossOp
,
ops
::
KLDivLossOpMaker
,
ops
::
KLDivLossOpGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
KLDivLossOpGradMaker
<
paddle
::
imperative
::
OpBase
>
);
ops
::
KLDivLossOpGradMaker
<
paddle
::
imperative
::
OpBase
>
,
KLDivInferShapeFunctor
);
REGISTER_OPERATOR
(
kldiv_loss_grad
,
ops
::
KLDivLossOpGrad
,
ops
::
KLDivLossGradNoNeedBufferVarInferer
);
paddle/phi/infermeta/binary.cc
浏览文件 @
6d205516
...
...
@@ -73,6 +73,51 @@ void AllValueCompareInferMeta(const MetaTensor& x,
out
->
set_dtype
(
DataType
::
BOOL
);
}
void
KLDivInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
label
,
const
std
::
string
&
reduction
,
MetaTensor
*
out
,
MetaConfig
config
)
{
auto
dim_x
=
x
.
dims
();
auto
dim_target
=
label
.
dims
();
PADDLE_ENFORCE_EQ
(
dim_x
.
size
(),
dim_target
.
size
(),
phi
::
errors
::
InvalidArgument
(
"Input(X) rank and Input(Target) rank should be "
"same, but received X rank(%d) != Target rank(%d)"
,
dim_x
.
size
(),
dim_target
.
size
()));
for
(
int
i
=
0
;
i
<
dim_x
.
size
();
i
++
)
{
if
(
config
.
is_runtime
||
(
dim_x
[
i
]
>
0
&&
dim_target
[
i
]
>
0
))
{
PADDLE_ENFORCE_EQ
(
dim_x
[
i
],
dim_target
[
i
],
phi
::
errors
::
InvalidArgument
(
"Input(X) and Input(Target) should in same shape. but received "
"X dimension[%d](%d) != Target dimension[%d](%d)"
,
i
,
dim_x
[
i
],
i
,
dim_target
[
i
]));
}
}
auto
reduction_valid
=
"mean"
==
reduction
||
"sum"
==
reduction
||
"batchmean"
==
reduction
||
"none"
==
reduction
;
PADDLE_ENFORCE_EQ
(
reduction_valid
,
true
,
phi
::
errors
::
InvalidArgument
(
"Attr(reduction) can only be 'none'|'batchmean'|'sum'|'mean'."
));
if
(
"none"
==
reduction
)
{
out
->
set_dims
(
dim_x
);
}
else
{
out
->
set_dims
({
1
});
}
out
->
set_dtype
(
x
.
dtype
());
}
void
Atan2InferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
y
,
MetaTensor
*
out
)
{
out
->
share_meta
(
x
);
}
...
...
paddle/phi/infermeta/binary.h
浏览文件 @
6d205516
...
...
@@ -35,6 +35,12 @@ void AllValueCompareInferMeta(const MetaTensor& x,
MetaTensor
*
out
,
MetaConfig
config
=
MetaConfig
());
void
KLDivInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
label
,
const
std
::
string
&
reduction
,
MetaTensor
*
out
,
MetaConfig
config
=
MetaConfig
());
void
Atan2InferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
y
,
MetaTensor
*
out
);
void
BCELossInferMeta
(
const
MetaTensor
&
input
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录