Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fused_seqpool_cvm op #45

Merged
merged 76 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
aff3b0e
opt for train
hutuxian Jun 1, 2020
6e0a949
add paddlebox dual dataset and datafeed
Jun 3, 2020
f940e0c
opt for train
hutuxian Jun 1, 2020
e668c14
support fix_dayid gflag
hutuxian Jun 5, 2020
ee3be0b
修复wasq pv处理不正确的BUG, 添加绑核逻辑
Jun 6, 2020
e937c95
修复datafeed bug
Jun 6, 2020
434cedf
add paddlebox dual dataset and datafeed
Jun 3, 2020
a8d3fff
修复wasq pv处理不正确的BUG, 添加绑核逻辑
Jun 6, 2020
84770be
修复datafeed bug
Jun 6, 2020
337397a
merge hutuxian/Paddle
Jun 6, 2020
cc47cca
merge hutuxian/Paddle
Jun 6, 2020
5b38bee
release slots_shuffle_original_data_ for auc_runner
hutuxian Jun 8, 2020
517c75b
batch kernel
Jun 10, 2020
bb8e2cc
add support feed asq
Jun 10, 2020
b3ac26c
Opt for datafeed (Mingqing) (#18)
qingshui Jun 11, 2020
c6e1b00
fix resize memory address is nullptr bug
Jun 11, 2020
b7cf036
Merge branch 'paddlebox' into paddlebox
qingshui Jun 11, 2020
af81f6d
merge paddlebox
Jun 11, 2020
9462949
merge paddlebox
Jun 11, 2020
134f88c
join async release thread
hutuxian Jun 11, 2020
1917000
test=paddlebox
mingqinghu Jun 12, 2020
b04eab2
test=paddlebox
mingqinghu Jun 12, 2020
12d8e63
test=paddlebox
mingqinghu Jun 12, 2020
51f340e
test=paddlebox
mingqinghu Jun 12, 2020
5919a04
Merge branch 'paddlebox' into paddlebox
qingshui Jun 12, 2020
45c7677
test=paddlebox,merge master fix pre-commit
mingqinghu Jun 12, 2020
b346e17
Merge branch 'paddlebox' into paddlebox
hutuxian Jun 13, 2020
42795a9
add key filter
mingqinghu Jun 13, 2020
602f7b1
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
mingqinghu Jun 13, 2020
25e5ab2
Merge branch 'paddlebox' into paddlebox
qingshui Jun 13, 2020
5431fe4
Merge branch 'paddlebox' of https://github.com/hutuxian/Paddle into p…
mingqinghu Jun 13, 2020
c99c9fe
Merge branch 'paddlebox' of https://github.com/hutuxian/Paddle into p…
Jun 13, 2020
e352353
fix dualbox mpi coredump bug
mingqinghu Jun 20, 2020
17d61d5
Merge branch 'paddlebox' of https://github.com/hutuxian/Paddle into p…
mingqinghu Jun 20, 2020
e90049b
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
Jun 20, 2020
d324da7
fix dualbox calculate_bucket_error
mingqinghu Jun 20, 2020
221c337
Merge branch 'paddlebox' of https://github.com/hutuxian/Paddle into p…
mingqinghu Jun 20, 2020
aacd136
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
Jun 20, 2020
1b31042
Merge branch 'paddlebox' of https://github.com/hutuxian/Paddle into p…
Jun 20, 2020
0aa0cd6
add paddlebox slot gflags
mingqinghu Jun 20, 2020
7a90faa
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
Jun 20, 2020
311f81e
fix gflags bug and add so support pipe command
mingqinghu Jun 20, 2020
5b2b418
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
Jun 22, 2020
949b384
fix dualbox shuffle miss data
mingqinghu Jun 25, 2020
5c2c578
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
Jun 25, 2020
20a19b9
Set the gradient to 0 if embedx is empty
mingqinghu Jul 1, 2020
a7223e4
fix FLAGS_padbox_dataset_merge_thread_num tid not match datafeed id
mingqinghu Jul 7, 2020
86e5bbd
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
Jul 16, 2020
154fb64
Merge branch 'paddlebox' of https://github.com/hutuxian/Paddle into p…
Jul 16, 2020
6ea44bf
Optimize box_wrapper pull push performance, fix dualbox data shuffle bug
mingqinghu Jul 22, 2020
6602243
Optimize AucCalculator
mingqinghu Jul 23, 2020
483a36d
æ·OOptimize batch pack
mingqinghu Jul 24, 2020
2450731
optimize batch pack
mingqinghu Jul 24, 2020
ffb2764
fix paddlebox exit coredump
mingqinghu Jul 28, 2020
f030030
Optimize pack memory allocation
mingqinghu Aug 14, 2020
2241cf1
Optimize pack memory allocation
mingqinghu Aug 14, 2020
4cfe07b
fix no float slot
mingqinghu Aug 20, 2020
bd2c709
add read bad file log
mingqinghu Aug 24, 2020
9ca3e27
1. add fuse mixallgather op, 2. add sclice tensor op, 3. fix gcc82 error
mingqinghu Aug 27, 2020
e2a4152
1. add fuse mixallgather op, 2. add sclice tensor op, 3. fix gcc82 error
mingqinghu Aug 27, 2020
f07d092
Merge branch 'paddlebox' of https://github.com/hutuxian/Paddle into p…
mingqinghu Aug 28, 2020
da1cd20
pull paddlebox
mingqinghu Aug 28, 2020
f43a0ff
pull paddlebox
mingqinghu Aug 28, 2020
302e151
Merge pull request #1 from hutuxian/paddlebox
qingshui Sep 10, 2020
73ec32e
1. fix dump ins id, 2. add boxps dense update
mingqinghu Sep 15, 2020
74b51f7
Merge branch 'paddlebox' of https://github.com/qingshui/Paddle into p…
mingqinghu Sep 15, 2020
9e49ca6
1. fix dump ins id
mingqinghu Sep 15, 2020
c6c0690
add dense one ring update and multi ring part data update
mingqinghu Sep 16, 2020
1c3f00c
Merge pull request #2 from hutuxian/paddlebox
qingshui Sep 22, 2020
5e6f8bf
add fused_seqpool_cvm_op
Sep 22, 2020
8aaccfb
Merge pull request #3 from neuzxy/fuse_op
qingshui Sep 22, 2020
47d5c41
fix grid size
Sep 22, 2020
fe6ffca
put fused_seqpool_cvm_op layer in contrib
Sep 23, 2020
5fac7a4
Merge pull request #4 from neuzxy/fuse_op
qingshui Sep 23, 2020
1c5c059
add quant feature in fused_seqpool_cvm_op
Sep 25, 2020
ae11126
Merge pull request #5 from neuzxy/quant
qingshui Sep 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 214 additions & 0 deletions paddle/fluid/operators/fused/fused_seqpool_cvm_op.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/* Copyright (c) 2019 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/operators/fused/fused_seqpool_cvm_op.h"

namespace paddle {
namespace operators {

class FusedSeqpoolCVMOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;
void InferShape(framework::InferShapeContext* ctx) const override {
PADDLE_ENFORCE_GE(ctx->Inputs("X").size(), 1UL,
"Inputs(X) of FusedSeqpoolCVMOp should not be empty.");
PADDLE_ENFORCE_GE(ctx->Outputs("Out").size(), 1UL,
"Outputs(Out) of FusedSeqpoolCVMOp should not be empty.");

auto cvm_dims = ctx->GetInputDim("CVM");
PADDLE_ENFORCE_EQ(
cvm_dims.size(), 2UL,
platform::errors::InvalidArgument("Input(CVM)'s rank should be 2."));
PADDLE_ENFORCE_EQ(
cvm_dims[1], 2UL,
platform::errors::InvalidArgument("The 2nd dimension of "
"Input(CVM) should be 2."));

auto ins_dims = ctx->GetInputsDim("X");
const size_t num_inputs = ins_dims.size();
std::vector<framework::DDim> outs_dims;
outs_dims.resize(num_inputs);

PADDLE_ENFORCE_GT(num_inputs, 0UL,
platform::errors::InvalidArgument(
"Input tensors count should be greater than 0, "
"but received value is %d.",
num_inputs));

// The output height should be confirmed in Compute,
// since input lod is not accessible here.
PADDLE_ENFORCE_EQ(ins_dims[0].size(), 2,
platform::errors::InvalidArgument(
"The dims size of first input should be equal to 2, "
"but received value is %d.",
ins_dims[0].size()));

for (size_t i = 0; i < num_inputs; ++i) {
const auto dims = ins_dims[i];
int rank = dims.size();
if (ctx->Attrs().Get<bool>("use_cvm")) {
PADDLE_ENFORCE_GT(
dims[rank - 1], 2,
"Shape error in %lu id, the last dimension(embedding) of the "
"'X' tensor must be larger than 2.",
i);
}
// input lod is not accessible here
std::vector<int64_t> out_dim;
if (ctx->Attrs().Get<bool>("use_cvm")) {
out_dim = {-1, dims[rank - 1]};
} else {
out_dim = {-1, dims[rank - 1] - 2};
}
outs_dims[i] = framework::make_ddim(out_dim);
}
ctx->SetOutputsDim("Out", outs_dims);
}

protected:
framework::OpKernelType GetExpectedKernelType(
const framework::ExecutionContext& ctx) const override {
return framework::OpKernelType(framework::proto::VarType::FP32,
ctx.device_context());
}
};

class FusedSeqpoolCVMOpMaker : public framework::OpProtoAndCheckerMaker {
public:
void Make() override {
AddInput("X",
"(vector<LoDTensor>) The input tensors of"
" operator.")
.AsDuplicable();
AddInput("CVM",
"(Tensor), a 2-D Tensor with shape [N x 2], where N is the batch "
"size, 2 is show and click.");
AddOutput("Out",
"(vector<Tensor>) The output of Op does not contain LoD "
"information.")
.AsDuplicable();
AddAttr<std::string>("pooltype",
"(string, default 'SUM') the pooling pooltype of "
"SequencePoolOp, only support SUM now.")
.SetDefault("SUM")
.InEnum({"SUM"});
AddAttr<float>("pad_value",
"(float, default 0.0) The value to pad for empty sequence.")
.SetDefault(0.0);
AddAttr<bool>("use_cvm", "bool, use cvm or not").SetDefault(true);
AddAttr<bool>("need_filter", "(bool, default false)").SetDefault(false);
AddAttr<float>("show_coeff", "(float, default 0.2)").SetDefault(0.2);
AddAttr<float>("clk_coeff", "(float, default 1)").SetDefault(1);
AddAttr<float>("threshold", "(float, default 0.96)").SetDefault(0.96);

AddComment(R"DOC(
Fuse multiple pairs of Sequence Pool and CVM Operator.

)DOC");
}
};

class FusedSeqpoolCVMGradOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;

void InferShape(framework::InferShapeContext* ctx) const override {
auto og_dims = ctx->GetInputsDim(framework::GradVarName("Out"));
auto x_dims = ctx->GetInputsDim("X");
auto cvm_dims = ctx->GetInputDim("CVM");

PADDLE_ENFORCE_EQ(
cvm_dims.size(), 2,
platform::errors::InvalidArgument("Input(CVM)'s rank should be 2."));

for (size_t i = 0; i < og_dims.size(); i++) {
PADDLE_ENFORCE_EQ(
og_dims[i].size(), x_dims[i].size(),
platform::errors::InvalidArgument(
"The rank of output grad must equal to Input(X). But "
"received: input rank %u, input shape [%s].",
og_dims[i].size(), og_dims[i]));
if (ctx->Attrs().Get<bool>("use_cvm")) {
PADDLE_ENFORCE_EQ(
og_dims[i][og_dims[i].size() - 1], x_dims[i][og_dims[i].size() - 1],
platform::errors::InvalidArgument(
"The dimension mismatch between Input(OUT@GRAD) and "
"Input(X). Received Input(OUT@GRAD): input rank %u, "
"input shape [%s]; received Input(X): input rank %u, "
"input shape [%s].",
og_dims[i].size(), og_dims[i], x_dims[i].size(), x_dims[i]));
} else {
PADDLE_ENFORCE_EQ(
og_dims[i][og_dims[i].size() - 1],
x_dims[i][og_dims[i].size() - 1] - 2,
platform::errors::InvalidArgument(
"The dimension mismatch between Input(OUT@GRAD) and "
"Input(X). Received Input(OUT@GRAD): input rank %u, "
"input shape [%s]; received Input(X): input rank %u, "
"input shape [%s].",
og_dims[i].size(), og_dims[i], x_dims[i].size(), x_dims[i]));
}
}
for (size_t i = 0; i < x_dims.size(); ++i) {
ctx->ShareLoD("X", framework::GradVarName("X"), i, i);
ctx->ShareDim("X", framework::GradVarName("X"), i, i);
}
}

protected:
framework::OpKernelType GetExpectedKernelType(
const framework::ExecutionContext& ctx) const override {
return framework::OpKernelType(OperatorWithKernel::IndicateVarDataType(
ctx, framework::GradVarName("Out")),
ctx.device_context());
}
};

template <typename T>
class FusedSeqpoolCVMGradOpMaker : public framework::SingleGradOpMaker<T> {
public:
using framework::SingleGradOpMaker<T>::SingleGradOpMaker;

protected:
void Apply(GradOpPtr<T> op_desc_ptr) const override {
op_desc_ptr->SetType("fused_seqpool_cvm_grad");
op_desc_ptr->SetInput("X", this->Input("X"));
op_desc_ptr->SetInput("CVM", this->Input("CVM"));

op_desc_ptr->SetInput(framework::GradVarName("Out"),
this->OutputGrad("Out"));
op_desc_ptr->SetOutput(framework::GradVarName("X"),
this->InputGrad("X", false));
op_desc_ptr->SetOutput(framework::GradVarName("CVM"),
this->InputGrad("CVM"));
op_desc_ptr->SetAttrMap(this->Attrs());
}
};

} // namespace operators
} // namespace paddle

namespace ops = paddle::operators;
namespace plat = paddle::platform;

REGISTER_OPERATOR(fused_seqpool_cvm, ops::FusedSeqpoolCVMOp,
ops::FusedSeqpoolCVMOpMaker,
ops::FusedSeqpoolCVMGradOpMaker<paddle::framework::OpDesc>,
ops::FusedSeqpoolCVMGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(fused_seqpool_cvm_grad, ops::FusedSeqpoolCVMGradOp)

REGISTER_OP_CPU_KERNEL(fused_seqpool_cvm,
ops::FusedSeqpoolCVMOpCPUKernel<float>)
REGISTER_OP_CPU_KERNEL(fused_seqpool_cvm_grad,
ops::FusedSeqpoolCVMGradOpCPUKernel<float>)
Loading