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

[PRIM][IR]support optional and invoke for more vjp code gen #57084

Merged

Conversation

Charles-hit
Copy link
Contributor

@Charles-hit Charles-hit commented Sep 7, 2023

PR types

New features

PR changes

Others

Description

Pcard-66975
背景:
在PR PR56512基础上进行反向算子vjp生成扩量工作,高优支持GPT/LLama依赖的26个高优算子vjp.
PR改动:

  • 支持invoke字段解析, 生成yaml中invoke算子vjp
    以cast_vjp为例:
std::vector<std::vector<paddle::Tensor>> cast_vjp(const Tensor& x, const Tensor& out_grad, const std::vector<std::vector<bool>>& stop_gradients) {
  std::vector<std::vector<paddle::Tensor>> vjp_res;
  for (auto arg: stop_gradients) {
    vjp_res.push_back(std::vector<paddle::Tensor>(arg.size()));
  }
  auto op_res = backend::cast<LazyTensor>(out_grad, x.dtype());
  vjp_res[0][0] = op_res;
  vjp_res = ConstructVjpResultByStopGradients(vjp_res, stop_gradients);
  return vjp_res;
}
  • 支持optional字段解析
    以layer_norm_vjp为例:
std::vector<std::vector<paddle::Tensor>> layer_norm_vjp(const Tensor& x, const paddle::optional<Tensor>& scale, const paddle::optional<Tensor>& bias, const Tensor& mean, const Tensor& variance, const Tensor& out_grad, float epsilon, int begin_norm_axis, const std::vector<std::vector<bool>>& stop_gradients) {
  std::vector<std::vector<paddle::Tensor>> vjp_res;
  for (auto arg: stop_gradients) {
    vjp_res.push_back(std::vector<paddle::Tensor>(arg.size()));
  }
  auto op_res = backend::layer_norm_grad<LazyTensor>(x, scale, bias, mean, variance, out_grad, epsilon, begin_norm_axis);
  vjp_res[0][0] = std::get<0>(op_res);
  vjp_res[1][0] = std::get<1>(op_res);
  vjp_res[2][0] = std::get<2>(op_res);
  vjp_res = ConstructVjpResultByStopGradients(vjp_res, stop_gradients);
  return vjp_res;
}

@paddle-bot
Copy link

paddle-bot bot commented Sep 7, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@Charles-hit Charles-hit merged commit 430a657 into PaddlePaddle:develop Sep 8, 2023
25 of 26 checks passed
@Charles-hit Charles-hit deleted the support_optional_and_invoke branch September 8, 2023 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants