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

fix reduce_mean_op_xpu op bug for cvrq #7

Merged
merged 1 commit into from
Sep 13, 2023
Merged
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
8 changes: 8 additions & 0 deletions paddle/fluid/operators/reduce_ops/reduce_mean_op_xpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ReduceMeanGradXPUKernel : public framework::OpKernel<T> {

bool reduce_all = ctx.Attr<bool>("reduce_all");
auto reduce_dims = ctx.Attr<std::vector<int>>("dim");
bool keep_dim = ctx.Attr<bool>("keep_dim");

std::vector<int> xdims;
for (int i = 0; i < input->dims().size(); i++) {
Expand All @@ -114,6 +115,13 @@ class ReduceMeanGradXPUKernel : public framework::OpKernel<T> {
reduce_numel *= xdims[d];
}

if (keep_dim != true) {
sort(reduce_dims.begin(), reduce_dims.end());
for (auto& d : reduce_dims) {
ydims.insert(ydims.begin() + d, 1);
}
}

float val = 1.0f / static_cast<float>(reduce_numel);

auto& dev_ctx = ctx.template device_context<DeviceContext>();
Expand Down