fix gelu grad error and windows compile error and core

This commit is contained in:
luochao 2024-02-26 19:58:33 +08:00
parent e4989c18e4
commit 2500d72f11
9 changed files with 33 additions and 23 deletions

View File

@ -309,14 +309,10 @@ NodePtrList BinopGradCommon(BpropBuilder *ib, const NodePtr &x, const NodePtr &y
if (dx != nullptr) {
reduce[kIndex0] =
StaticBinopGradCommon(ib, reduce[kIndex0], shape, broadcast_shape, shift, kIndex0, &is_x_shape_dynamic);
} else {
reduce[kIndex0] = ib->OutZeros(x);
}
if (dy != nullptr) {
reduce[kIndex1] =
StaticBinopGradCommon(ib, reduce[kIndex1], shape, broadcast_shape, shift, kIndex1, &is_y_shape_dynamic);
} else {
reduce[kIndex1] = ib->OutZeros(y);
}
if (is_x_shape_dynamic || is_y_shape_dynamic) {
return DynBinopGradCommon(ib, x, y, dx, dy, shift);

View File

@ -596,7 +596,7 @@ REG_BPROP_BUILDER("Div").SetUnusedInputs({i0}).SetBody(BODYFUNC(ib) {
bool is_complex = (x_dtype_id == kNumberTypeComplex64 || x_dtype_id == kNumberTypeComplex128);
if (is_complex) {
result[kIndex0] = ib->Conj(result[kIndex0]);
result[kIndex1] = x->need_compute_grad_out() ? ib->Conj(result[kIndex1]) : ib->OutZeros(y);
result[kIndex1] = y->need_compute_grad_out() ? ib->Conj(result[kIndex1]) : ib->OutZeros(y);
}
return result;
});

View File

@ -50,14 +50,11 @@ REG_BPROP_BUILDER("ScalarMod").SetBody(BODYFUNC(ib) {
auto y = ib->GetInput(kIndex1);
auto out = ib->GetInput(kIndex2);
auto dout = ib->GetInput(kIndex3);
NodePtr dy;
if (y->need_compute_grad_out()) {
auto dx = ib->ScalarDiv(dout, y);
dy = ib->ScalarNeg(ib->ScalarMul(dx, ib->ScalarFloorDiv(x, y)));
} else {
dy = ib->OutZeros(y);
}
return {dout, dy};
NodePtr dx = x->need_compute_grad_out() ? dout : ib->OutZeros(x);
NodePtr dy = y->need_compute_grad_out()
? ib->ScalarNeg(ib->ScalarMul(ib->ScalarDiv(dout, y), ib->ScalarFloorDiv(x, y)))
: ib->OutZeros(y);
return {dx, dy};
});
REG_BPROP_BUILDER("ScalarFloorDiv").SetBody(ReturnZeros);

View File

@ -208,7 +208,12 @@ TensorPtrList FuncBackwardNode::CallBackward(const TensorPtrList &gradients_in)
const std::vector<NodePtr> cal_grads_node = func()(&ir_builder);
ValuePtrList cal_grads_values;
std::transform(cal_grads_node.begin(), cal_grads_node.end(), std::back_inserter(cal_grads_values),
[](const NodePtr &node) -> ValuePtr { return node->Value(); });
[](const NodePtr &node) -> ValuePtr {
if (node == nullptr) {
return kNone;
}
return node->Value();
});
auto gradients = PostProcess(cal_grads_values);
MS_LOG(DEBUG) << "End CallBackward: " << name();
return gradients;

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_FUNCTION_META_GRAD_H_
#define MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_FUNCTION_META_GRAD_H_
#ifndef MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_FUNCTION_FUNC_GRAD_H_
#define MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_FUNCTION_FUNC_GRAD_H_
#include <memory>
#include <utility>
@ -160,4 +160,4 @@ class FuncGrad : public AutoGrad {
};
} // namespace mindspore::pynative::autograd
#endif // MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_FUNCTION_META_GRAD_H_
#endif // MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_FUNCTION_FUNC_GRAD_H_

View File

@ -487,7 +487,7 @@ FuncGraphPtr IrBprop::GetBpropGraphFromExpander(const GradParamPtr &grad_param)
auto current_ad_param = ad_param_;
ad_param_ = std::make_shared<AdParam>();
ad_param_->tape_->debug_info()->set_name("ad_graph");
bprop_graph_run_by_single_op_ = bprop_graph_run_by_single_op_ || grad_param->use_dynamic_shape_process;
GradGraphByExpander(grad_param);
if (ad_param_->last_node_ != nullptr) {
@ -703,7 +703,6 @@ void IrBprop::GradCNode(const PrimitivePtr &prim, const CNodePtr &cnode, const G
const ValuePtrList &inputs_value, AnfNodePtrList *cnode_inputs) {
MS_EXCEPTION_IF_NULL(prim);
MS_EXCEPTION_IF_NULL(cnode);
MS_EXCEPTION_IF_NULL(grad_param);
bool jit_by_value = grad_param->is_jit_graph && grad_by_value_;
if (IsPrimitiveEquals(prim, prim::kPrimMakeTuple) || IsPrimitiveEquals(prim, prim::kPrimMakeList)) {
(void)BuildKNodeForMakeTuple(cnode);
@ -714,6 +713,13 @@ void IrBprop::GradCNode(const PrimitivePtr &prim, const CNodePtr &cnode, const G
}
MS_EXCEPTION_IF_NULL(cnode_inputs);
auto k_node = GetKnode(prim, cnode, *cnode_inputs, jit_by_value);
if (bprop_graph_run_by_single_op_ && !IsPrimitiveCNode(cnode, prim::kPrimMakeTuple) &&
std::any_of(cnode->inputs().begin() + 1, cnode->inputs().end(), [](const AnfNodePtr &node) {
MS_EXCEPTION_IF_NULL(node->abstract());
return node->abstract()->isa<abstract::AbstractSequence>();
})) {
k_node->cast<CNodePtr>()->AddAttr(kAttrIsPyboostTupleInput, MakeValue(true));
}
MS_LOG(DEBUG) << "Build knode " << k_node->DebugString();
// Set out
auto out = PyNativeAlgo::Common::CreatOutputTensorValueByAbstract(cnode->abstract());

View File

@ -24,8 +24,13 @@ namespace mindspore {
namespace kernel {
namespace pyboost {
tensor::TensorPtr GeLUGradAscendCustomize(const std::shared_ptr<OpRunner> &op, const TensorPtr &dy_tensor,
const TensorPtr &x_tensor, const TensorPtr &y_tensor) {
OpRunner::InferOpOutput(op, dy_tensor, x_tensor, y_tensor);
const TensorPtr &x_tensor, const TensorPtr &y_tensor,
OpRunnerInfo *op_runner_info) {
if (op_runner_info != nullptr) {
OpRunner::InferOpOutput(op, op_runner_info);
} else {
OpRunner::InferOpOutput(op, dy_tensor, x_tensor, y_tensor);
}
// Create device address for input/output tensors
PyBoostUtils::PrepareOpInputs(op->device_context(), op->stream_id(), dy_tensor, x_tensor, y_tensor);

View File

@ -28,7 +28,8 @@ namespace mindspore {
namespace kernel {
namespace pyboost {
tensor::TensorPtr GeLUGradAscendCustomize(const std::shared_ptr<OpRunner> &op, const TensorPtr &dy_tensor,
const TensorPtr &x_tensor, const TensorPtr &y_tensor);
const TensorPtr &x_tensor, const TensorPtr &y_tensor,
OpRunnerInfo *op_runner_info);
} // namespace pyboost
} // namespace kernel
} // namespace mindspore

View File

@ -45,7 +45,7 @@ class PyBoostOpExecute {
void COMMON_EXPORT RunPyBoostCall(OpRunnerInfo *op_runner_info, VectorRef *op_outputs);
// Clear backend for fork process.
void COMMON_EXPORT ClearBackend() { backend_ = nullptr; }
void ClearBackend() { backend_ = nullptr; }
private:
// Run op by single op graph