MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / RunProgramGradImpl

Function RunProgramGradImpl

paddle/fluid/eager/to_static/run_program_impl.cc:675–813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

673}
674
675void RunProgramGradImpl(
676 const std::vector<paddle::Tensor> &out_grad,
677 const std::vector<paddle::framework::Scope *> &step_scope, // NOLINT
678 const paddle::framework::AttributeMap &prog_attrs,
679 const paddle::framework::AttributeMap &cuda_graph_attrs,
680 std::vector<paddle::Tensor> *x_grad,
681 std::vector<paddle::Tensor> *params_grad,
682 const int64_t &place_hash_key) {
683 // if all output vars are set to stop_gradient, grad op no need to executed
684 if (x_grad->empty() && params_grad->empty()) return;
685 auto *out_scope_vec = &step_scope;
686 PADDLE_ENFORCE_EQ(
687 out_scope_vec->size(),
688 1,
689 common::errors::InvalidArgument(
690 "The OutScope of RunProgramGradOp should only hold one scope."));
691 paddle::framework::Scope *global_inner_scope = out_scope_vec->front();
692
693 int64_t program_id = PADDLE_GET_CONST(int64_t, prog_attrs.at("program_id"));
694 int64_t cuda_graph_state =
695 PADDLE_GET_CONST(int64_t, cuda_graph_attrs.at("cuda_graph_state"));
696 int64_t cuda_graph_dispatch_key =
697 PADDLE_GET_CONST(int64_t, cuda_graph_attrs.at("cuda_graph_dispatch_key"));
698
699 bool in_sot_mode = false;
700 if (prog_attrs.count("in_sot_mode")) {
701 in_sot_mode = PADDLE_GET_CONST(bool, prog_attrs.at("in_sot_mode"));
702 }
703
704 auto place = egr::Controller::Instance().GetExpectedPlace();
705 VLOG(2) << "RunProgramGradOp use interpretercore to execute program.";
706
707 VLOG(4) << "global_inner_scope:" << global_inner_scope;
708
709 std::shared_ptr<::pir::Program> backward_program = PADDLE_GET_CONST(
710 std::shared_ptr<::pir::Program>, prog_attrs.at("backward_program"));
711
712 // Get All needed names
713 const auto &output_grad_names =
714 PADDLE_GET_CONST(std::vector<std::string>, prog_attrs.at("bo_g_names"));
715 const auto &x_grad_names =
716 PADDLE_GET_CONST(std::vector<std::string>, prog_attrs.at("bx_g_names"));
717 const auto &p_grad_names =
718 PADDLE_GET_CONST(std::vector<std::string>, prog_attrs.at("bp_g_names"));
719
720 details::Trans2ContiguousTensorsInplace(out_grad);
721
722 // share x, param, middles, output_grads, out into scope.
723 details::ShareTensorsIntoScopeWithName(
724 out_grad, output_grad_names, global_inner_scope);
725
726 auto &cache = paddle::framework::InterpreterCoreInfoCache::Instance();
727 std::shared_ptr<paddle::framework::InterpreterCore> interpreter_core =
728 nullptr;
729 VLOG(7) << "Get interpretercore for program: " << program_id
730 << ", scope ptr: " << global_inner_scope
731 << ", place_hash_key: " << place_hash_key
732 << ", cuda_graph_state: " << cuda_graph_state

Callers 1

operator()Method · 0.85

Calls 15

PADDLE_GET_CONSTFunction · 0.85
InstanceFunction · 0.85
is_use_cuda_graphFunction · 0.85
ApplyIrPassFunction · 0.85
print_collectionFunction · 0.85
RunFeedHooksFunction · 0.85
GenScopeTreeDebugInfoFunction · 0.85

Tested by

no test coverage detected