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

[NewIR]Add embedding grad cpp api #57183

Merged
merged 8 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/manual_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "paddle/fluid/pir/dialect/operator/ir/manual_api.h"
#include "build/paddle/fluid/pir/dialect/operator/ir/pd_api.h"
#include "paddle/fluid/pir/dialect/operator/ir/api_builder.h"
#include "paddle/fluid/pir/dialect/operator/ir/op_type.h"
#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h"
Expand Down Expand Up @@ -43,5 +44,24 @@ void set_parameter(pir::OpResult parameter, const std::string& name) {
name);
}

pir::OpResult embedding_grad(pir::OpResult x,
pir::OpResult weight,
pir::OpResult out_grad,
int64_t padding_idx,
bool sparse) {
if (weight.type().isa<paddle::dialect::DenseTensorType>()) {
if (sparse) {
return paddle::dialect::embedding_grad_sparse(
x, weight, out_grad, padding_idx, sparse);
} else {
return paddle::dialect::embedding_grad_dense(
x, weight, out_grad, padding_idx, sparse);
}
} else {
PADDLE_THROW(phi::errors::Unimplemented(
"Now we do not support sparse weight embedding_grad."));
}
}

} // namespace dialect
} // namespace paddle
7 changes: 7 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/manual_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ pir::OpResult get_parameter(const std::string& name,
phi::DataType dtype,
const std::vector<int64_t>& shape);
void set_parameter(pir::OpResult parameter, const std::string& name);

pir::OpResult embedding_grad(pir::OpResult x,
pir::OpResult weight,
pir::OpResult out_grad,
int64_t padding_idx = -1,
bool sparse = false);

} // namespace dialect
} // namespace paddle