Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b9830634
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
b9830634
编写于
4月 17, 2023
作者:
L
LoneRanger
提交者:
GitHub
4月 17, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add autogen code support for uniform_inplace (#52955)
上级
337cc2ca
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
28 addition
and
185 deletion
+28
-185
paddle/fluid/operators/uniform_random_inplace_op.cc
paddle/fluid/operators/uniform_random_inplace_op.cc
+0
-120
paddle/phi/api/yaml/backward.yaml
paddle/phi/api/yaml/backward.yaml
+10
-0
paddle/phi/api/yaml/legacy_backward.yaml
paddle/phi/api/yaml/legacy_backward.yaml
+0
-10
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
+7
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+11
-0
paddle/phi/ops/compat/uniform_random_inplace_sig.cc
paddle/phi/ops/compat/uniform_random_inplace_sig.cc
+0
-44
未找到文件。
paddle/fluid/operators/uniform_random_inplace_op.cc
已删除
100644 → 0
浏览文件 @
337cc2ca
/* 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/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
class
UniformRandomInplaceOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddComment
(
R"DOC(
This operator fills self tensor with random values sampled from a
uniform distribution. The random result is in a range of [min, max).
)DOC"
);
AddInput
(
"X"
,
"The input tensor."
);
AddOutput
(
"Out"
,
"The output tensor of uniform random op"
);
AddAttr
<
float
>
(
"min"
,
"Minimum value of uniform random. [default -1.0]."
)
.
SetDefault
(
-
1.0
f
);
AddAttr
<
float
>
(
"max"
,
"Maximun value of uniform random. [default 1.0]."
)
.
SetDefault
(
1.0
f
);
AddAttr
<
int
>
(
"seed"
,
"Random seed used for generating samples. "
"If seed is 0, it will use the seed of the global default "
"generator (which can be set by paddle.seed). "
"Note that if seed is not 0, this operator will always "
"generate the same random numbers every time. [default 0]."
)
.
SetDefault
(
0
);
AddAttr
<
int
>
(
"diag_num"
,
"The number of diag elements. Note that if "
"diag_num is 0, it means without diag init.[default 0]."
)
.
SetDefault
(
0
);
AddAttr
<
int
>
(
"diag_step"
,
"The step between two diag element.[default 0]."
)
.
SetDefault
(
0
);
AddAttr
<
float
>
(
"diag_val"
,
"The value of diag element. [default 1.0]."
)
.
SetDefault
(
1.0
f
);
}
};
class
UniformRandomInplaceOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"X"
),
ctx
.
GetPlace
());
}
};
class
UniformRandomInplaceGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
};
class
UniformRandomInplaceOpVarTypeInference
:
public
framework
::
VarTypeInference
{
public:
void
operator
()(
framework
::
InferVarTypeContext
*
ctx
)
const
override
{}
};
template
<
typename
T
>
class
UniformRandomInplaceGradOpMaker
:
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
());
}
};
}
// namespace operators
}
// namespace paddle
DECLARE_INPLACE_OP_INFERER
(
UniformRandomInplaceInferer
,
{
"X"
,
"Out"
});
DECLARE_INPLACE_OP_INFERER
(
UniformRandomInplaceGradInplaceInferer
,
{
paddle
::
framework
::
GradVarName
(
"Out"
),
paddle
::
framework
::
GradVarName
(
"X"
)});
DECLARE_INFER_SHAPE_FUNCTOR
(
uniform_random_inplace
,
UniformRandomInplaceInferShapeFunctor
,
PD_INFER_META
(
phi
::
UniformRandomInplaceInferMeta
));
DECLARE_INFER_SHAPE_FUNCTOR
(
uniform_random_inplace_grad
,
UniformRandomInplaceGradInferShapeFunctor
,
PD_INFER_META
(
phi
::
UniformRandomInplaceGradInferMeta
));
REGISTER_OPERATOR
(
uniform_random_inplace
,
paddle
::
operators
::
UniformRandomInplaceOp
,
paddle
::
operators
::
UniformRandomInplaceOpMaker
,
paddle
::
operators
::
UniformRandomInplaceGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
paddle
::
operators
::
UniformRandomInplaceGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
paddle
::
operators
::
UniformRandomInplaceOpVarTypeInference
,
UniformRandomInplaceInferer
,
UniformRandomInplaceInferShapeFunctor
);
REGISTER_OPERATOR
(
uniform_random_inplace_grad
,
paddle
::
operators
::
UniformRandomInplaceGradOp
,
UniformRandomInplaceGradInplaceInferer
,
UniformRandomInplaceGradInferShapeFunctor
);
paddle/phi/api/yaml/backward.yaml
浏览文件 @
b9830634
...
...
@@ -1952,6 +1952,16 @@
data_type
:
out_grad
no_need_buffer
:
x
-
backward_op
:
uniform_inplace_grad
forward
:
uniform_inplace(Tensor x, float min = -1.0, float max = 1.0, int seed = 0, int diag_num = 0, int diag_step = 0, float diag_val = 1.0) -> Tensor(out)
args
:
(Tensor out_grad, float min = -1.0, float max = 1.0, int seed = 0, int diag_num = 0, int diag_step = 0, float diag_val = 1.0)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UniformRandomInplaceGradInferMeta
kernel
:
func
:
uniform_inplace_grad
inplace
:
(out_grad -> x_grad)
-
backward_op
:
unsqueeze_double_grad
forward
:
unsqueeze_grad(Tensor xshape, Tensor grad_out, IntArray axes) -> Tensor(grad_x)
args
:
(Tensor grad_x_grad, IntArray axes)
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
b9830634
...
...
@@ -1097,16 +1097,6 @@
kernel
:
func
:
triu_grad
-
backward_op
:
uniform_inplace_grad
forward
:
uniform_inplace(Tensor x, float min, float max, int seed, int diag_num, int diag_step, float diag_val) -> Tensor(out)
args
:
(Tensor out_grad, float min, float max, int seed, int diag_num, int diag_step, float diag_val)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UniformRandomInplaceGradInferMeta
kernel
:
func
:
uniform_inplace_grad
inplace
:
(out_grad -> x_grad)
-
backward_op
:
yolo_loss_grad
forward
:
yolo_loss(Tensor x, Tensor gt_box, Tensor gt_label, Tensor gt_score, int[] anchors, int[] anchor_mask, int class_num, float ignore_thresh, int downsample_ratio, bool use_label_smooth=true, float scale_x_y=1.0) -> Tensor(loss), Tensor(objectness_mask), Tensor(gt_match_mask)
args
:
(Tensor x, Tensor gt_box, Tensor gt_label, Tensor gt_score, Tensor objectness_mask, Tensor gt_match_mask, Tensor loss_grad, int[] anchors, int[] anchor_mask, int class_num, float ignore_thresh, int downsample_ratio, bool use_label_smooth=true, float scale_x_y=1.0)
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
b9830634
...
...
@@ -1312,17 +1312,6 @@
data_type
:
dtype
backend
:
place
-
op
:
uniform_inplace
args
:
(Tensor x, float min, float max, int seed, int diag_num, int diag_step, float diag_val)
output
:
Tensor(out)
infer_meta
:
func
:
UniformRandomInplaceInferMeta
kernel
:
func
:
uniform_inplace
data_type
:
x
inplace
:
(x -> out)
backward
:
uniform_inplace_grad
# The `axis` argument of Python API paddle.unique is not vector
-
op
:
unique
args
:
(Tensor x, bool return_index, bool return_inverse, bool return_counts, int[] axis, DataType dtype=DataType::INT64)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
b9830634
...
...
@@ -2264,6 +2264,13 @@
support_tensor
:
true
manual_signature
:
[
uniform
]
-
op
:
uniform_inplace (uniform_random_inplace)
backward
:
uniform_inplace_grad(uniform_random_inplace_grad)
inputs
:
x
:
X
outputs
:
out
:
Out
-
op
:
unique
inputs
:
{
x
:
X
}
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
b9830634
...
...
@@ -1980,6 +1980,17 @@
func
:
unfold
backward
:
unfold_grad
-
op
:
uniform_inplace
args
:
(Tensor x, float min = -1.0, float max = 1.0, int seed = 0, int diag_num = 0, int diag_step = 0, float diag_val = 1.0)
output
:
Tensor(out)
infer_meta
:
func
:
UniformRandomInplaceInferMeta
kernel
:
func
:
uniform_inplace
data_type
:
x
inplace
:
(x -> out)
backward
:
uniform_inplace_grad
-
op
:
unique_consecutive
args
:
(Tensor x, bool return_inverse =
false
, bool return_counts =
false
, int[] axis = {}, int dtype = 5)
output
:
Tensor(out), Tensor(index), Tensor(counts)
...
...
paddle/phi/ops/compat/uniform_random_inplace_sig.cc
已删除
100644 → 0
浏览文件 @
337cc2ca
/* 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
UniformRandomInplaceOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"uniform_inplace"
,
{
"X"
},
{
"min"
,
"max"
,
"seed"
,
"diag_num"
,
"diag_step"
,
"diag_val"
},
{
"Out"
});
}
KernelSignature
UniformRandomInplaceGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"uniform_inplace_grad"
,
{
"Out@GRAD"
},
{
"min"
,
"max"
,
"seed"
,
"diag_num"
,
"diag_step"
,
"diag_val"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_BASE_KERNEL_NAME
(
uniform_random_inplace
,
uniform_inplace
);
PD_REGISTER_ARG_MAPPING_FN
(
uniform_random_inplace
,
phi
::
UniformRandomInplaceOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
uniform_random_inplace_grad
,
phi
::
UniformRandomInplaceGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录