Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
93404a61
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
93404a61
编写于
4月 10, 2023
作者:
C
cyberslack_lee
提交者:
GitHub
4月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support auto generate for eigvalsh (#52687)
上级
0e776965
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
38 addition
and
171 deletion
+38
-171
paddle/fluid/operators/eigvalsh_op.cc
paddle/fluid/operators/eigvalsh_op.cc
+0
-113
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
-12
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+0
-9
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+9
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+10
-0
paddle/phi/kernels/cpu/eigvalsh_grad_kernel.cc
paddle/phi/kernels/cpu/eigvalsh_grad_kernel.cc
+3
-1
paddle/phi/kernels/gpu/eigvalsh_grad_kernel.cu
paddle/phi/kernels/gpu/eigvalsh_grad_kernel.cu
+3
-1
paddle/phi/kernels/gpu/eigvalsh_kernel.cu
paddle/phi/kernels/gpu/eigvalsh_kernel.cu
+3
-1
paddle/phi/ops/compat/eigvalsh_sig.cc
paddle/phi/ops/compat/eigvalsh_sig.cc
+0
-34
未找到文件。
paddle/fluid/operators/eigvalsh_op.cc
已删除
100644 → 0
浏览文件 @
0e776965
/* 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
EigvalshOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
};
class
EigvalshOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"(Tensor), Hermitian or real symmetric matrices."
"Its shape should be [*, N, N] where * is zero or"
"more batch dimensions. The data type is float32 ,"
"float64, complex64, complex128."
);
AddOutput
(
"Eigenvalues"
,
"(Tensor), The eigenvalues in ascending order."
"The data type is float32 or float64."
);
AddOutput
(
"Eigenvectors"
,
"(Tensor), The column is the normalized eigenvector "
"corresponding to the eigenvalue. The data type is the same as ``X``."
"Eigenvectors are required to calculate gradient when backward."
);
AddAttr
<
std
::
string
>
(
"UPLO"
,
"(string, default 'L'), 'L' represents the lower triangular matrix,"
"'U' represents the upper triangular matrix."
)
.
SetDefault
(
"L"
);
AddAttr
<
bool
>
(
"is_test"
,
"(bool, default false) Set to true for inference only, false "
"for training."
)
.
SetDefault
(
false
);
AddComment
(
R"DOC(
Eigvalsh Operator.
Computes the eigenvalues of a complex Hermitian
(conjugate symmetric) or a real symmetric matrix.
)DOC"
);
}
};
class
EigvalshGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"Eigenvectors"
),
ctx
.
device_context
().
GetPlace
());
}
};
template
<
typename
T
>
class
EigvalshGradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
void
Apply
(
GradOpPtr
<
T
>
op
)
const
override
{
op
->
SetType
(
this
->
ForwardOpType
()
+
"_grad"
);
op
->
SetInput
(
"Eigenvectors"
,
this
->
Output
(
"Eigenvectors"
));
op
->
SetInput
(
framework
::
GradVarName
(
"Eigenvalues"
),
this
->
OutputGrad
(
"Eigenvalues"
));
op
->
SetAttrMap
(
this
->
Attrs
());
op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
eigvalsh
,
EigvalshInferShapeFunctor
,
PD_INFER_META
(
phi
::
EigvalshInferMeta
));
DECLARE_INFER_SHAPE_FUNCTOR
(
eigvalsh_grad
,
EigvalshGradInferShapeFunctor
,
PD_INFER_META
(
phi
::
EigvalshGradInferMeta
));
REGISTER_OPERATOR
(
eigvalsh
,
ops
::
EigvalshOp
,
ops
::
EigvalshOpMaker
,
ops
::
EigvalshGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
EigvalshGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
EigvalshInferShapeFunctor
);
REGISTER_OPERATOR
(
eigvalsh_grad
,
ops
::
EigvalshGradOp
,
EigvalshGradInferShapeFunctor
);
paddle/phi/api/yaml/backward.yaml
浏览文件 @
93404a61
...
@@ -456,6 +456,16 @@
...
@@ -456,6 +456,16 @@
func
:
eigh_grad
func
:
eigh_grad
data_type
:
out_v
data_type
:
out_v
-
backward_op
:
eigvalsh_grad
forward
:
eigvalsh (Tensor x, str uplo = "L", bool is_test =
false
) -> Tensor(eigenvalues), Tensor(eigenvectors)
args
:
(Tensor eigenvectors, Tensor eigenvalues_grad, str uplo, bool is_test)
output
:
Tensor(x_grad)
infer_meta
:
func
:
EigvalshGradInferMeta
kernel
:
func
:
eigvalsh_grad
data_type
:
eigenvectors
-
backward_op
:
elu_double_grad
-
backward_op
:
elu_double_grad
forward
:
elu_grad (Tensor x, Tensor out, Tensor grad_out, float alpha)-> Tensor(grad_x)
forward
:
elu_grad (Tensor x, Tensor out, Tensor grad_out, float alpha)-> Tensor(grad_x)
args
:
(Tensor x, Tensor grad_out, Tensor grad_x_grad, float alpha)
args
:
(Tensor x, Tensor grad_out, Tensor grad_x_grad, float alpha)
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
93404a61
...
@@ -340,18 +340,6 @@
...
@@ -340,18 +340,6 @@
kernel
:
kernel
:
func
:
dropout_grad
func
:
dropout_grad
-
backward_op
:
eigvalsh_grad
forward
:
eigvalsh (Tensor x, str uplo, bool is_test) -> Tensor(eigenvalues), Tensor(eigenvectors)
args
:
(Tensor eigenvectors, Tensor eigenvalues_grad, str uplo, bool is_test)
output
:
Tensor(x_grad)
infer_meta
:
func
:
EigvalshGradInferMeta
kernel
:
func
:
eigvalsh_grad
data_type
:
eigenvectors
data_transform
:
skip_transform
:
eigenvalues_grad
-
backward_op
:
einsum_grad
-
backward_op
:
einsum_grad
forward
:
einsum (Tensor[] x, str equation) -> Tensor(out), Tensor[](inner_cache), Tensor[](x_shape)
forward
:
einsum (Tensor[] x, str equation) -> Tensor(out), Tensor[](inner_cache), Tensor[](x_shape)
args
:
(Tensor[] x_shape, Tensor[] inner_cache, Tensor out_grad, str equation)
args
:
(Tensor[] x_shape, Tensor[] inner_cache, Tensor out_grad, str equation)
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
93404a61
...
@@ -424,15 +424,6 @@
...
@@ -424,15 +424,6 @@
data_type
:
DataType::FLOAT32
data_type
:
DataType::FLOAT32
optional
:
hypslength, refslength
optional
:
hypslength, refslength
-
op
:
eigvalsh
args
:
(Tensor x, str uplo, bool is_test)
output
:
Tensor(eigenvalues), Tensor(eigenvectors)
infer_meta
:
func
:
EigvalshInferMeta
kernel
:
func
:
eigvalsh
backward
:
eigvalsh_grad
-
op
:
einsum
-
op
:
einsum
args
:
(Tensor[] x, str equation)
args
:
(Tensor[] x, str equation)
output
:
Tensor, Tensor[]{x.size()}, Tensor[]{x.size()}
output
:
Tensor, Tensor[]{x.size()}, Tensor[]{x.size()}
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
93404a61
...
@@ -614,6 +614,15 @@
...
@@ -614,6 +614,15 @@
outputs
:
outputs
:
out
:
Out
out
:
Out
-
op
:
eigvalsh
backward
:
eigvalsh_grad
inputs
:
{
x
:
X
}
outputs
:
{
eigenvalues
:
Eigenvalues
,
eigenvectors
:
Eigenvectors
}
attrs
:
uplo
:
UPLO
-
op
:
elementwise_pow
-
op
:
elementwise_pow
backward
:
elementwise_pow_grad
backward
:
elementwise_pow_grad
extra
:
extra
:
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
93404a61
...
@@ -486,6 +486,16 @@
...
@@ -486,6 +486,16 @@
kernel
:
kernel
:
func
:
eigvals
func
:
eigvals
-
op
:
eigvalsh
args
:
(Tensor x, str uplo = "L", bool is_test =
false
)
output
:
Tensor(eigenvalues), Tensor(eigenvectors)
infer_meta
:
func
:
EigvalshInferMeta
kernel
:
func
:
eigvalsh
data_type
:
x
backward
:
eigvalsh_grad
-
op
:
elu
-
op
:
elu
args
:
(Tensor x, float alpha = 1.0f)
args
:
(Tensor x, float alpha = 1.0f)
output
:
Tensor(out)
output
:
Tensor(out)
...
...
paddle/phi/kernels/cpu/eigvalsh_grad_kernel.cc
浏览文件 @
93404a61
...
@@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh_grad,
...
@@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh_grad,
float
,
float
,
double
,
double
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
phi
::
dtype
::
complex
<
double
>
)
{
kernel
->
InputAt
(
1
).
SetDataType
(
phi
::
dtype
::
ToReal
(
kernel_key
.
dtype
()));
}
paddle/phi/kernels/gpu/eigvalsh_grad_kernel.cu
浏览文件 @
93404a61
...
@@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh_grad,
...
@@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh_grad,
float
,
float
,
double
,
double
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
phi
::
dtype
::
complex
<
double
>
)
{
kernel
->
InputAt
(
1
).
SetDataType
(
phi
::
dtype
::
ToReal
(
kernel_key
.
dtype
()));
}
paddle/phi/kernels/gpu/eigvalsh_kernel.cu
浏览文件 @
93404a61
...
@@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh, // cuda_only
...
@@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh, // cuda_only
float
,
float
,
double
,
double
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
phi
::
dtype
::
complex
<
double
>
)
{
kernel
->
InputAt
(
1
).
SetDataType
(
phi
::
dtype
::
ToReal
(
kernel_key
.
dtype
()));
}
paddle/phi/ops/compat/eigvalsh_sig.cc
已删除
100644 → 0
浏览文件 @
0e776965
/* 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
EigvalshOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"eigvalsh"
,
{
"X"
},
{
"UPLO"
,
"is_test"
},
{
"Eigenvalues"
,
"Eigenvectors"
});
}
KernelSignature
EigvalshGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"eigvalsh_grad"
,
{
"Eigenvectors"
,
"Eigenvalues@GRAD"
},
{
"UPLO"
,
"is_test"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
eigvalsh
,
phi
::
EigvalshOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
eigvalsh_grad
,
phi
::
EigvalshGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录