Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
1c9b2483
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1c9b2483
编写于
2月 17, 2022
作者:
C
Chen Weihang
提交者:
GitHub
2月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move trace infer shape (#39517)
上级
5fb9cf60
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
53 deletion
+63
-53
paddle/fluid/operators/trace_op.cc
paddle/fluid/operators/trace_op.cc
+7
-52
paddle/pten/infermeta/unary.cc
paddle/pten/infermeta/unary.cc
+52
-1
paddle/pten/infermeta/unary.h
paddle/pten/infermeta/unary.h
+4
-0
未找到文件。
paddle/fluid/operators/trace_op.cc
浏览文件 @
1c9b2483
...
...
@@ -12,8 +12,11 @@
// 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/op_version_registry.h"
#include "paddle/pten/core/infermeta_utils.h"
#include "paddle/pten/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -21,57 +24,6 @@ namespace operators {
class
TraceOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Input"
),
true
,
platform
::
errors
::
NotFound
(
"Input of TraceOp is not found."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
NotFound
(
"Output of TraceOp is not found."
));
int
dim1
=
ctx
->
Attrs
().
Get
<
int
>
(
"axis1"
);
int
dim2
=
ctx
->
Attrs
().
Get
<
int
>
(
"axis2"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"Input"
);
int
dim1_
=
dim1
<
0
?
x_dims
.
size
()
+
dim1
:
dim1
;
int
dim2_
=
dim2
<
0
?
x_dims
.
size
()
+
dim2
:
dim2
;
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
platform
::
errors
::
OutOfRange
(
"Input's dim is out of range (expected at least 2, but got %ld)."
,
x_dims
.
size
()));
PADDLE_ENFORCE_LT
(
dim1_
,
x_dims
.
size
(),
platform
::
errors
::
OutOfRange
(
"Attr(dim1) is out of range (expected to be in range of [%ld, "
"%ld], but got %ld)."
,
-
(
x_dims
.
size
()),
(
x_dims
.
size
()
-
1
),
dim1
));
PADDLE_ENFORCE_LT
(
dim2_
,
x_dims
.
size
(),
platform
::
errors
::
OutOfRange
(
"Attr(dim2) is out of range (expected to be in range of [%ld, "
"%ld], but got %ld)."
,
-
(
x_dims
.
size
()),
(
x_dims
.
size
()
-
1
),
dim2
));
PADDLE_ENFORCE_NE
(
dim1_
,
dim2_
,
platform
::
errors
::
InvalidArgument
(
"The dimensions should not be identical "
"%ld vs %ld."
,
dim1
,
dim2
));
auto
sizes
=
vectorize
(
x_dims
);
if
(
x_dims
.
size
()
==
2
)
{
sizes
.
clear
();
sizes
.
push_back
(
1
);
}
else
{
sizes
.
erase
(
sizes
.
begin
()
+
std
::
max
(
dim1_
,
dim2_
));
sizes
.
erase
(
sizes
.
begin
()
+
std
::
min
(
dim1_
,
dim2_
));
}
ctx
->
SetOutputDim
(
"Out"
,
framework
::
make_ddim
(
sizes
));
}
};
class
TraceOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
...
...
@@ -155,9 +107,12 @@ DECLARE_NO_NEED_BUFFER_VARS_INFERER(TraceGradNoNeedBufferVarsInferer, "Input");
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DELCARE_INFER_SHAPE_FUNCTOR
(
trace
,
TraceInferShapeFunctor
,
PT_INFER_META
(
pten
::
TraceInferMeta
));
REGISTER_OPERATOR
(
trace
,
ops
::
TraceOp
,
ops
::
TraceOpMaker
,
ops
::
TraceGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
TraceGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
ops
::
TraceGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
TraceInferShapeFunctor
);
REGISTER_OPERATOR
(
trace_grad
,
ops
::
TraceOpGrad
,
ops
::
TraceGradNoNeedBufferVarsInferer
);
...
...
paddle/pten/infermeta/unary.cc
浏览文件 @
1c9b2483
...
...
@@ -444,8 +444,59 @@ void SplitInferMeta(const MetaTensor& x,
(
*
out
)[
i
].
share_lod
(
x
);
}
}
}
void
TraceInferMeta
(
const
MetaTensor
&
x
,
int
offset
,
int
axis1
,
int
axis2
,
MetaTensor
*
out
)
{
int
dim1
=
axis1
;
int
dim2
=
axis2
;
auto
x_dims
=
x
.
dims
();
return
;
int
dim1_
=
dim1
<
0
?
x_dims
.
size
()
+
dim1
:
dim1
;
int
dim2_
=
dim2
<
0
?
x_dims
.
size
()
+
dim2
:
dim2
;
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
pten
::
errors
::
OutOfRange
(
"Input's dim is out of range (expected at least 2, but got %ld)."
,
x_dims
.
size
()));
PADDLE_ENFORCE_LT
(
dim1_
,
x_dims
.
size
(),
pten
::
errors
::
OutOfRange
(
"Attr(dim1) is out of range (expected to be in range of [%ld, "
"%ld], but got %ld)."
,
-
(
x_dims
.
size
()),
(
x_dims
.
size
()
-
1
),
dim1
));
PADDLE_ENFORCE_LT
(
dim2_
,
x_dims
.
size
(),
pten
::
errors
::
OutOfRange
(
"Attr(dim2) is out of range (expected to be in range of [%ld, "
"%ld], but got %ld)."
,
-
(
x_dims
.
size
()),
(
x_dims
.
size
()
-
1
),
dim2
));
PADDLE_ENFORCE_NE
(
dim1_
,
dim2_
,
pten
::
errors
::
InvalidArgument
(
"The dimensions should not be identical "
"%ld vs %ld."
,
dim1
,
dim2
));
auto
sizes
=
vectorize
(
x_dims
);
if
(
x_dims
.
size
()
==
2
)
{
sizes
.
clear
();
sizes
.
push_back
(
1
);
}
else
{
sizes
.
erase
(
sizes
.
begin
()
+
std
::
max
(
dim1_
,
dim2_
));
sizes
.
erase
(
sizes
.
begin
()
+
std
::
min
(
dim1_
,
dim2_
));
}
out
->
set_dims
(
framework
::
make_ddim
(
sizes
));
}
}
// namespace pten
paddle/pten/infermeta/unary.h
浏览文件 @
1c9b2483
...
...
@@ -80,4 +80,8 @@ void SplitInferMeta(const MetaTensor& x_meta,
const
Scalar
&
axis
,
std
::
vector
<
MetaTensor
>*
out
,
MetaConfig
config
=
MetaConfig
());
void
TraceInferMeta
(
const
MetaTensor
&
x
,
int
offset
,
int
axis1
,
int
axis2
,
MetaTensor
*
out
);
}
// namespace pten
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录