Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8947488c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
8947488c
编写于
6月 19, 2023
作者:
W
Wang Xin
提交者:
GitHub
6月 19, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
static graph autogen code support for full_like op (#54698)
* static graph autogen code support for full_like op * fix * fix bug
上级
93f7a02a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
30 addition
and
130 deletion
+30
-130
paddle/fluid/operators/fill_any_like_op.cc
paddle/fluid/operators/fill_any_like_op.cc
+0
-98
paddle/fluid/operators/generator/templates/operator_utils.c.j2
...e/fluid/operators/generator/templates/operator_utils.c.j2
+2
-2
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+4
-2
paddle/phi/api/yaml/static_ops.yaml
paddle/phi/api/yaml/static_ops.yaml
+10
-0
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+9
-0
paddle/phi/infermeta/unary.h
paddle/phi/infermeta/unary.h
+5
-0
paddle/phi/ops/compat/fill_any_like_sig.cc
paddle/phi/ops/compat/fill_any_like_sig.cc
+0
-28
未找到文件。
paddle/fluid/operators/fill_any_like_op.cc
已删除
100644 → 0
浏览文件 @
93f7a02a
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
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 <string>
#include "paddle/fluid/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
class
FillAnyLikeOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"fill_any_like"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"fill_any_like"
);
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
phi
::
KernelKey
kt
=
OperatorWithKernel
::
GetExpectedKernelType
(
ctx
);
const
auto
&
data_type
=
ctx
.
Attr
<
int
>
(
"dtype"
);
if
(
data_type
>=
0
)
{
kt
.
set_dtype
(
phi
::
TransToPhiDataType
(
static_cast
<
framework
::
proto
::
VarType
::
Type
>
(
data_type
)));
}
return
kt
;
}
phi
::
KernelKey
GetKernelTypeForVar
(
const
std
::
string
&
var_name
,
const
phi
::
DenseTensor
&
tensor
,
const
phi
::
KernelKey
&
expected_kernel_type
)
const
override
{
return
phi
::
KernelKey
(
phi
::
Backend
::
ALL_BACKEND
,
tensor
.
layout
(),
expected_kernel_type
.
dtype
());
}
};
class
FillAnyLikeOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"The input of fill-zeros-like op."
);
AddOutput
(
"Out"
,
"The variable will be filled up with specified value."
);
AddAttr
<
float
>
(
"value"
,
"The filled value"
).
SetDefault
(
0.0
);
AddAttr
<
int
>
(
"dtype"
,
"Output tensor data type. default value is -1,"
"according to the input dtype."
)
.
SetDefault
(
-
1
);
AddComment
(
R"DOC(
FillAnyLike Operator.
Fill up a variable with Attr(value).
The output will have the same shape and dtype as the input.
)DOC"
);
}
};
class
FillAnyLikeVarTypeInference
:
public
framework
::
VarTypeInference
{
public:
void
operator
()(
framework
::
InferVarTypeContext
*
ctx
)
const
override
{
auto
var_data_type
=
static_cast
<
framework
::
proto
::
VarType
::
Type
>
(
PADDLE_GET_CONST
(
int
,
ctx
->
GetAttr
(
"dtype"
)));
if
(
var_data_type
<
0
)
{
ctx
->
SetOutputDataType
(
"Out"
,
ctx
->
GetInputDataType
(
"X"
));
}
else
{
ctx
->
SetOutputDataType
(
"Out"
,
var_data_type
);
}
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
fill_any_like
,
ops
::
FillAnyLikeOp
,
ops
::
FillAnyLikeOpMaker
,
::
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
::
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
FillAnyLikeVarTypeInference
)
paddle/fluid/operators/generator/templates/operator_utils.c.j2
浏览文件 @
8947488c
...
@@ -335,8 +335,8 @@ phi::KernelKey GetExpectedKernelType(
...
@@ -335,8 +335,8 @@ phi::KernelKey GetExpectedKernelType(
{% endif %}
{% endif %}
{% elif kernel["data_type"]["candidates"] | length == 2 %}
{% elif kernel["data_type"]["candidates"] | length == 2 %}
{% set data_type_args = kernel["data_type"]["candidates"] %}
{% set data_type_args = kernel["data_type"]["candidates"] %}
auto data_type = framework::proto::VarType::Type(ctx.Attr<int>("{{data_type_args[0]}}");
auto data_type = framework::proto::VarType::Type(ctx.Attr<int>("{{data_type_args[0]}}")
)
;
if (data_type == static_cast<proto::VarType::Type>(-1)) {
if (data_type == static_cast<
framework::
proto::VarType::Type>(-1)) {
data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, {{data_type_args[1] | to_opmaker_name}});
data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, {{data_type_args[1] | to_opmaker_name}});
}
}
{% endif %}
{% endif %}
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
8947488c
...
@@ -1095,8 +1095,10 @@
...
@@ -1095,8 +1095,10 @@
x
:
X
x
:
X
outputs
:
outputs
:
out
:
Out
out
:
Out
attrs
:
scalar
:
{
value
:
value
,
dtype
:
dtype
}
value
:
data_type
:
float
support_tensor
:
true
-
op
:
fused_conv2d
-
op
:
fused_conv2d
extra
:
extra
:
...
...
paddle/phi/api/yaml/static_ops.yaml
浏览文件 @
8947488c
...
@@ -203,6 +203,16 @@
...
@@ -203,6 +203,16 @@
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
backward
:
frobenius_norm_grad
backward
:
frobenius_norm_grad
-
op
:
full_like
args
:
(Tensor x, Scalar value = 0.0, DataType dtype = DataType::UNDEFINED)
output
:
Tensor(out)
infer_meta
:
func
:
FillAnyLikeInferMeta
kernel
:
func
:
full_like
param
:
[
x
,
value
,
dtype
]
data_type
:
dtype > x
-
op
:
gaussian
-
op
:
gaussian
args
:
(IntArray shape = {}, float mean = .0f, float std = 1.0f, int seed = 0, DataType dtype = DataType::FLOAT32)
args
:
(IntArray shape = {}, float mean = .0f, float std = 1.0f, int seed = 0, DataType dtype = DataType::FLOAT32)
output
:
Tensor(out)
output
:
Tensor(out)
...
...
paddle/phi/infermeta/unary.cc
浏览文件 @
8947488c
...
@@ -1111,6 +1111,15 @@ void ExpandInferMeta(const MetaTensor& x,
...
@@ -1111,6 +1111,15 @@ void ExpandInferMeta(const MetaTensor& x,
}
}
}
}
void
FillAnyLikeInferMeta
(
const
MetaTensor
&
x
,
const
Scalar
&
value
,
DataType
dtype
,
MetaTensor
*
out
)
{
out
->
set_dims
(
x
.
dims
());
out
->
set_dtype
(
dtype
==
DataType
::
UNDEFINED
?
x
.
dtype
()
:
dtype
);
out
->
share_lod
(
x
);
}
void
FillDiagonalInferMeta
(
void
FillDiagonalInferMeta
(
const
MetaTensor
&
x
,
float
value
,
int
offset
,
bool
wrap
,
MetaTensor
*
out
)
{
const
MetaTensor
&
x
,
float
value
,
int
offset
,
bool
wrap
,
MetaTensor
*
out
)
{
PADDLE_ENFORCE_NE
(
PADDLE_ENFORCE_NE
(
...
...
paddle/phi/infermeta/unary.h
浏览文件 @
8947488c
...
@@ -178,6 +178,11 @@ void ExpandInferMeta(const MetaTensor& x,
...
@@ -178,6 +178,11 @@ void ExpandInferMeta(const MetaTensor& x,
const
IntArray
&
shape
,
const
IntArray
&
shape
,
MetaTensor
*
out
);
MetaTensor
*
out
);
void
FillAnyLikeInferMeta
(
const
MetaTensor
&
x
,
const
Scalar
&
value
,
DataType
dtype
,
MetaTensor
*
out
);
void
FillDiagonalInferMeta
(
void
FillDiagonalInferMeta
(
const
MetaTensor
&
x
,
float
value
,
int
offset
,
bool
wrap
,
MetaTensor
*
out
);
const
MetaTensor
&
x
,
float
value
,
int
offset
,
bool
wrap
,
MetaTensor
*
out
);
...
...
paddle/phi/ops/compat/fill_any_like_sig.cc
已删除
100644 → 0
浏览文件 @
93f7a02a
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
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 "paddle/phi/core/compat/op_utils.h"
namespace
phi
{
KernelSignature
FillAnyLikeOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"full_like"
,
{
"X"
},
{
"value"
,
"dtype"
},
{
"Out"
});
}
}
// namespace phi
PD_REGISTER_BASE_KERNEL_NAME
(
fill_any_like
,
full_like
);
PD_REGISTER_ARG_MAPPING_FN
(
fill_any_like
,
phi
::
FillAnyLikeOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录