Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4277f61f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
4277f61f
编写于
6月 14, 2023
作者:
H
huangjiyi
提交者:
GitHub
6月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support code generation for op fill_any (#54378)
* update * update
上级
ded7d190
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
37 addition
and
157 deletion
+37
-157
paddle/fluid/operators/fill_any_op.cc
paddle/fluid/operators/fill_any_op.cc
+0
-88
paddle/phi/api/yaml/backward.yaml
paddle/phi/api/yaml/backward.yaml
+11
-0
paddle/phi/api/yaml/legacy_backward.yaml
paddle/phi/api/yaml/legacy_backward.yaml
+0
-11
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+0
-11
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+11
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+11
-0
paddle/phi/ops/compat/fill_sig.cc
paddle/phi/ops/compat/fill_sig.cc
+0
-35
test/legacy_test/test_fill_any_op.py
test/legacy_test/test_fill_any_op.py
+3
-8
test/xpu/test_fill_any_op_xpu.py
test/xpu/test_fill_any_op_xpu.py
+1
-4
未找到文件。
paddle/fluid/operators/fill_any_op.cc
已删除
100644 → 0
浏览文件 @
ded7d190
/* Copyright (c) 2021 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/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/backward.h"
#include "paddle/phi/kernels/funcs/math_function.h"
namespace
paddle
{
namespace
operators
{
class
FillAnyOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"(Tensor) The input tensor."
);
AddOutput
(
"Out"
,
"Tensor, the tensor filled with input value "
);
AddAttr
<
float
>
(
"value_float"
,
"The float var to fill in Tensor"
)
.
SetDefault
(
0
);
AddAttr
<
int
>
(
"value_int"
,
"The int var to fill in Tensor"
).
SetDefault
(
0
);
AddComment
(
R"DOC(Fill operator with backward;
Fill an tensor with `value`.
)DOC"
);
};
};
class
FillAnyOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
};
class
FillAnyGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
};
template
<
typename
T
>
class
FillAnyGradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
void
Apply
(
GradOpPtr
<
T
>
retv
)
const
override
{
retv
->
SetType
(
this
->
ForwardOpType
()
+
"_grad"
);
retv
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
this
->
OutputGrad
(
"Out"
));
retv
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
retv
->
SetAttrMap
(
this
->
Attrs
());
}
};
DECLARE_INPLACE_OP_INFERER
(
FillAnyOpInplaceInferer
,
{
"X"
,
"Out"
});
DECLARE_INPLACE_OP_INFERER
(
FillAnyGradInplaceInferer
,
{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)});
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
fill_any
,
FillAnyInferShapeFunctor
,
PD_INFER_META
(
phi
::
UnchangedInferMeta
));
DECLARE_INFER_SHAPE_FUNCTOR
(
fill_any_grad
,
FillAnyGradInferShapeFunctor
,
PD_INFER_META
(
phi
::
UnchangedInferMeta
));
REGISTER_OPERATOR
(
fill_any
,
ops
::
FillAnyOp
,
ops
::
FillAnyOpMaker
,
ops
::
FillAnyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
FillAnyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
FillAnyOpInplaceInferer
,
FillAnyInferShapeFunctor
);
REGISTER_OPERATOR
(
fill_any_grad
,
ops
::
FillAnyGradOp
,
ops
::
FillAnyGradInplaceInferer
,
FillAnyGradInferShapeFunctor
);
paddle/phi/api/yaml/backward.yaml
浏览文件 @
4277f61f
...
...
@@ -744,6 +744,17 @@
func
:
fill_diagonal_tensor_grad
inplace
:
(out_grad -> x_grad)
-
backward_op
:
fill_grad
forward
:
fill (Tensor x, Scalar value=0) -> Tensor(out)
args
:
(Tensor out_grad, Scalar value)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
out_grad
]
kernel
:
func
:
fill_grad
inplace
:
(out_grad -> x_grad)
-
backward_op
:
flash_attn_grad
forward
:
flash_attn (Tensor q, Tensor k, Tensor v, Tensor fixed_seed_offset, float dropout = 0.0, bool causal =
false
, bool return_softmax =
false
, bool is_test =
false
, str rng_name = "") -> Tensor(out), Tensor(softmax), Tensor(softmax_lse), Tensor(seed_offset)
args
:
(Tensor q, Tensor k, Tensor v, Tensor out, Tensor softmax_lse, Tensor seed_offset, Tensor out_grad, float dropout = 0.0, bool causal =
false
)
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
4277f61f
...
...
@@ -282,17 +282,6 @@
func
:
UnchangedInferMeta
invoke
:
zeros_like(out_grad)
-
backward_op
:
fill_grad
forward
:
fill (Tensor x, Scalar value) -> Tensor(out)
args
:
(Tensor out_grad, Scalar value)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
out_grad
]
kernel
:
func
:
fill_grad
inplace
:
(out_grad -> x_grad)
-
backward_op
:
fmin_grad
forward
:
fmin(Tensor x, Tensor y) -> Tensor(out)
args
:
(Tensor x, Tensor y, Tensor out_grad)
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
4277f61f
...
...
@@ -342,17 +342,6 @@
data_type
:
dtype
backend
:
place
-
op
:
fill
args
:
(Tensor x, Scalar value)
output
:
Tensor(out)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
fill
inplace
:
(x -> out)
backward
:
fill_grad
-
op
:
floor_divide
args
:
(Tensor x, Tensor y)
output
:
Tensor(out)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
4277f61f
...
...
@@ -981,6 +981,17 @@
inputs
:
{
x
:
X
}
outputs
:
{
out
:
Out
}
-
op
:
fill (fill_any)
backward
:
fill_grad (fill_any_grad)
inputs
:
x
:
X
outputs
:
out
:
Out
scalar
:
value
:
data_type
:
float
support_tensor
:
true
-
op
:
fill_diagonal
backward
:
fill_diagonal_grad
inputs
:
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
4277f61f
...
...
@@ -801,6 +801,17 @@
func
:
fft_r2c
backward
:
fft_r2c_grad
-
op
:
fill
args
:
(Tensor x, Scalar value=0)
output
:
Tensor(out)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
fill
inplace
:
(x -> out)
backward
:
fill_grad
-
op
:
fill_diagonal
args
:
(Tensor x, float value=0, int offset=0, bool wrap=false)
output
:
Tensor(out)
...
...
paddle/phi/ops/compat/fill_sig.cc
已删除
100644 → 0
浏览文件 @
ded7d190
// 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
FillOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"fill"
,
{
"X"
},
{
"value_float"
},
{
"Out"
});
}
KernelSignature
FillGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"fill_grad"
,
{
"Out@GRAD"
},
{
"value_float"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_BASE_KERNEL_NAME
(
fill_any
,
fill
);
PD_REGISTER_BASE_KERNEL_NAME
(
fill_any_grad
,
fill_grad
);
PD_REGISTER_ARG_MAPPING_FN
(
fill_any
,
phi
::
FillOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
fill_any_grad
,
phi
::
FillGradOpArgumentMapping
);
test/legacy_test/test_fill_any_op.py
浏览文件 @
4277f61f
...
...
@@ -20,10 +20,8 @@ from eager_op_test import OpTest
import
paddle
def
fill_any_wrapper
(
x
,
value_float
=
0
,
value_int
=
0
):
return
paddle
.
_legacy_C_ops
.
fill_any
(
x
,
"value_float"
,
value_float
,
"value_int"
,
value_int
)
def
fill_any_wrapper
(
x
,
value
=
0
):
return
paddle
.
_legacy_C_ops
.
fill_any
(
x
,
"value"
,
value
)
class
TestFillAnyOp
(
OpTest
):
...
...
@@ -34,10 +32,7 @@ class TestFillAnyOp(OpTest):
self
.
value
=
0.0
self
.
init
()
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
20
,
30
)).
astype
(
self
.
dtype
)}
self
.
attrs
=
{
'value_float'
:
float
(
self
.
value
),
'value_int'
:
int
(
self
.
value
),
}
self
.
attrs
=
{
'value'
:
float
(
self
.
value
)}
self
.
outputs
=
{
'Out'
:
self
.
value
*
np
.
ones_like
(
self
.
inputs
[
"X"
]).
astype
(
self
.
dtype
)
...
...
test/xpu/test_fill_any_op_xpu.py
浏览文件 @
4277f61f
...
...
@@ -39,10 +39,7 @@ class XPUTestFillAnyOp(XPUOpTestWrapper):
self
.
value
=
0.0
self
.
init
()
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
20
,
30
)).
astype
(
self
.
dtype
)}
self
.
attrs
=
{
'value_float'
:
float
(
self
.
value
),
'value_int'
:
int
(
self
.
value
),
}
self
.
attrs
=
{
'value'
:
float
(
self
.
value
)}
self
.
outputs
=
{
'Out'
:
self
.
value
*
np
.
ones_like
(
self
.
inputs
[
"X"
]).
astype
(
self
.
dtype
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录