Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a862debf
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看板
未验证
提交
a862debf
编写于
5月 18, 2023
作者:
W
Wang Xin
提交者:
GitHub
5月 18, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move sequence_mask op InferShape func (#53782)
* move sequence_mask op InferShape func * add dtype infer
上级
2782b291
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
16 deletion
+34
-16
paddle/fluid/operators/sequence_ops/sequence_mask_op.cc
paddle/fluid/operators/sequence_ops/sequence_mask_op.cc
+9
-16
paddle/phi/infermeta/binary.cc
paddle/phi/infermeta/binary.cc
+19
-0
paddle/phi/infermeta/binary.h
paddle/phi/infermeta/binary.h
+6
-0
未找到文件。
paddle/fluid/operators/sequence_ops/sequence_mask_op.cc
浏览文件 @
a862debf
...
...
@@ -12,7 +12,10 @@
// 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/binary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -21,21 +24,6 @@ class SequenceMaskOp : public framework::OperatorWithKernel {
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"SequenceMask"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Y"
),
"Output"
,
"Y"
,
"SequenceMask"
);
int
maxlen
=
ctx
->
Attrs
().
Get
<
int
>
(
"maxlen"
);
auto
dim
=
phi
::
vectorize
<
int
>
(
ctx
->
GetInputDim
(
"X"
));
if
(
ctx
->
HasInputs
(
"MaxLenTensor"
))
{
dim
.
push_back
(
-
1
);
}
else
{
dim
.
push_back
(
maxlen
>
0
?
maxlen
:
-
1
);
}
ctx
->
SetOutputDim
(
"Y"
,
phi
::
make_ddim
(
dim
));
}
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
...
@@ -93,9 +81,14 @@ If maxlen < 0, maxlen = max(X)
}
// namespace operators
}
// namespace paddle
DECLARE_INFER_SHAPE_FUNCTOR
(
sequence_mask
,
SequenceMaskInferShapeFunctor
,
PD_INFER_META
(
phi
::
SequenceMaskInferMeta
));
REGISTER_OPERATOR
(
sequence_mask
,
paddle
::
operators
::
SequenceMaskOp
,
paddle
::
operators
::
SequenceMaskOpMaker
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
SequenceMaskInferShapeFunctor
);
paddle/phi/infermeta/binary.cc
浏览文件 @
a862debf
...
...
@@ -23,6 +23,7 @@ limitations under the License. */
#include "paddle/phi/common/type_traits.h"
#include "paddle/phi/core/ddim.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/core/utils/data_type.h"
#include "paddle/phi/infermeta/unary.h"
#include "paddle/phi/kernels/cpu/conv_util.h"
#include "paddle/phi/kernels/funcs/axis_utils.h"
...
...
@@ -2584,6 +2585,24 @@ void SearchsortedInferMeta(const MetaTensor& sorted_sequence,
}
}
void
SequenceMaskInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
max_len_tensor
,
int
maxlen
,
int
out_dtype
,
MetaTensor
*
y
)
{
auto
dim
=
phi
::
vectorize
<
int
>
(
x
.
dims
());
if
(
max_len_tensor
)
{
dim
.
push_back
(
-
1
);
}
else
{
dim
.
push_back
(
maxlen
>
0
?
maxlen
:
-
1
);
}
y
->
set_dims
(
phi
::
make_ddim
(
dim
));
auto
out_phi_dtype
=
phi
::
TransToPhiDataType
(
out_dtype
);
y
->
set_dtype
(
out_phi_dtype
);
}
void
SoftmaxMaskFuseInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
mask
,
MetaTensor
*
out
)
{
...
...
paddle/phi/infermeta/binary.h
浏览文件 @
a862debf
...
...
@@ -399,6 +399,12 @@ void SearchsortedInferMeta(const MetaTensor& sorted_sequence,
bool
right
,
MetaTensor
*
out
);
void
SequenceMaskInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
max_len_tensor
,
int
maxlen
,
int
out_dtype
,
MetaTensor
*
y
);
void
SoftmaxMaskFuseInferMeta
(
const
MetaTensor
&
x
,
const
MetaTensor
&
mask
,
MetaTensor
*
out
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录