diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc index 2c7393f456..dcf6dac7a5 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc @@ -40,6 +40,9 @@ void ReduceCPUKernel::InitKernel(const CNodePtr &kernel_node) { } shape_ = AnfAlgo::GetInputDeviceShape(kernel_node, 0); CheckAxis(kernel_node); + if (shape_.empty()) { + shape_.push_back(1); + } for (size_t i = 0; i < shape_.size(); ++i) { if (shape_[i] <= 0) { MS_LOG(EXCEPTION) << "shape value is invalid."; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_gpu_kernel.h index 00b9f2fbbf..e3764185d8 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_gpu_kernel.h @@ -40,8 +40,10 @@ class BinaryCrossEntropyGpuKernel : public GpuKernel { T *weight = GetDeviceAddress(inputs, 2); T *loss = GetDeviceAddress(outputs, 0); T *tmp_loss = GetDeviceAddress(workspace, 0); - BinaryCrossEntropyLoss(input_size_, reduction_, input_x, input_y, weight, loss, tmp_loss, - reinterpret_cast(stream_ptr)); + if (input_size_ > 0) { + BinaryCrossEntropyLoss(input_size_, reduction_, input_x, input_y, weight, loss, tmp_loss, + reinterpret_cast(stream_ptr)); + } return true; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_grad_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_grad_kernel.h index 6a2bbcaaba..25b08ac014 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_grad_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/binary_cross_entropy_grad_kernel.h @@ -42,8 +42,10 @@ class BinaryCrossEntropyGradGpuKernel : public GpuKernel { T *dloss = GetDeviceAddress(inputs, 2); T *weight = GetDeviceAddress(inputs, 3); T *dx = GetDeviceAddress(outputs, 0); - BinaryCrossEntropyLossGrad(input_size_, reduction_, input_x, input_y, weight, dloss, dx, - reinterpret_cast(stream_ptr)); + if (input_size_ > 0) { + BinaryCrossEntropyLossGrad(input_size_, reduction_, input_x, input_y, weight, dloss, dx, + reinterpret_cast(stream_ptr)); + } return true; } @@ -52,7 +54,6 @@ class BinaryCrossEntropyGradGpuKernel : public GpuKernel { for (size_t i = 0; i < input_shape.size(); i++) { input_size_ *= input_shape[i]; } - string reduction = GetAttr(kernel_node, "reduction"); if (reduction == "none") { reduction_ = 0;