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

请教一个cast grad的相关问题 #70530

Open
houj04 opened this issue Dec 28, 2024 · 0 comments
Open

请教一个cast grad的相关问题 #70530

houj04 opened this issue Dec 28, 2024 · 0 comments
Assignees
Labels

Comments

@houj04
Copy link
Contributor

houj04 commented Dec 28, 2024

请提出你的问题 Please ask your question

背景:某个项目需求,我在梳理某硬件设备上能跑的飞桨算子,发现该硬件上面实现了cast算子,但是没有实现cast_grad算子。
可是这个硬件设备能正常跑训练,如果缺算子的话应该跑不起来啊。于是去翻代码,发现CPU和GPU都有这个反向算子的实现,分别位于:
paddle/phi/kernels/gpu/cast_grad_kernel.cu
paddle/phi/kernels/cpu/cast_grad_kernel.cc
然后我又找到有这个东西
paddle/phi/ops/yaml/backward.yaml
其中有一段是这样写的:

- backward_op : cast_grad
  forward : cast (Tensor x, DataType dtype) -> Tensor(out)
  args : (Tensor x, Tensor out_grad)
  output : Tensor(x_grad)
  invoke : cast (out_grad, x.dtype())
  composite: cast_grad(x, out_grad, x_grad)
  no_need_buffer : x

从字面意思上看,我直观理解,当遇到cast grad算子的时候,就跑去执行cast的前向算子。
那问题来了:
1、想请教下这个backward.yaml的作用,是不是上面我直观理解的那样。有没有更详细的解释呢(例如,它是如何发挥作用的,这个yaml文件是怎么影响算子构建和计算图执行的)。
2、都有这个backward.yaml了,为啥CPU和GPU上还单独有一个cast grad的kernel呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants