Skip to content

Conversation

crashbussy
Copy link
Contributor

@crashbussy crashbussy commented May 20, 2025

PR Category

Execute Infrastructure

PR Types

New features

Description

paddle.tril paddle.Tensor.tril paddle.triu支持0-Size。

修改历程介绍如下:
本次 PR 旨在补充 paddle.trilpaddle.triu 在 XPU 上对 0-size tensor 的适配。具体修改如下:

  • PaddleAPITest report/0size_tensor 中检索 paddle.trilpaddle.triu 的错误日志,未发现报错(注意!这个理解是错误的,因为PaddleAPITest可能最近重新整理了下目录,在下面的comment中可以看到解释);
  1. 代码检查:
    查阅以下 kernel 实现文件:

    • paddle/phi/kernels/xpu/tril_triu_kernel.cc
    • paddle/phi/kernels/xpu/tril_triu_grad_kernel.cc
    • paddle/phi/kernels/tril_triu_kernel.h
    • paddle/phi/kernels/tril_triu_grad_kernel.h

    发现无需修改代码逻辑。(注意!这个理解是错误的,在后面的comment中有解释。仍然需要修改kernel)

  2. 最新的原因说明:
    根据DanielSun11的提示。PaddleAPITest 有报错信息。日志所在的路径:
    PaddleAPITest/report/0size_tensor_gpu/20250319/compare_with_torch/coredump_error/error_log.log
    image

paddle/phi/kernels/impl/tril_triu_kernel_impl.h 中TriuKernel TrilKernel 并无法很好的支持0 size Tensor。当遇到0 size Tensor时没及时返回导致GPU版本的实现中launch了cuda kernel,进而出现cuda error 9 这个报错。

添加单测:

在test/legacy_test/test_tril_triu_op.py中添加0 size tensor输入的单测(在原有基础上新增了0size的情况):

回测结果
image

api_config_pass.txt log.log 这里是全部回测log

  1. 发现的问题:
    https://github.com/PFCCLab/PaddleAPITest/tree/main/report/0size_tensor_gpu/20250319
    我从这个地址进入,并没有在20250319文件夹中找到compare_with_torch文件夹。因此在搜索报错时并没有发现有报错信息。DanielSun11提供了一个日志的路径PaddleAPITest/report/0size_tensor_gpu/20250319/compare_with_torch/coredump_error/error_log.log,但似乎我在PaddleAPITest中找不到这个文件,根据DanielSun11的回答, PaddleAPITest可能最近重新整理了下目录,所以从第一个地址进入是没有这个文件的。

Pcard-67164

Copy link

paddle-bot bot commented May 20, 2025

你的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.

@paddle-bot paddle-bot bot added the contributor External developers label May 20, 2025
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label May 20, 2025
@crashbussy
Copy link
Contributor Author

遇到了clone过程超时的问题导致必要的check不通过。求助,我应该如何修改。

@DanielSun11
Copy link
Contributor

PR 描述写的很nice,但是需要完善如下几点:

  • PaddleAPITest 有报错信息。日志所在的路径:
    PaddleAPITest/report/0size_tensor_gpu/20250319/compare_with_torch/coredump_error/error_log.log
    image
  • paddle/phi/kernels/impl/tril_triu_kernel_impl.h TriuKernel TrilKernel 并无法很好的支持0 size Tensor。当遇到0 size Tensor时没及时返回导致GPU版本的实现中launch了cuda kernel,进而出现cuda error 9 这个报错。
  • 请完善上述修改后添加对应的CPU GPU单测case,并用paddleAPITest回测失败的config

@crashbussy
Copy link
Contributor Author

crashbussy commented May 20, 2025

非常感谢@DanielSun11 指出的问题
https://github.com/PFCCLab/PaddleAPITest/tree/main/report/0size_tensor_gpu/20250319
我从这个地址进入,并没有在20250319文件夹中找到compare_with_torch文件夹。因此在搜索报错时并没有发现有报错信息。你提供了一个日志的路径PaddleAPITest/report/0size_tensor_gpu/20250319/compare_with_torch/coredump_error/error_log.log,但似乎我在PaddleAPITest中找不到这个文件
屏幕截图 2025-05-20 220829

@DanielSun11
Copy link
Contributor

PaddleAPITest可能最近重新整理了下目录
试一下这个路径:https://github.com/PFCCLab/PaddleAPITest/tree/main/report/0size_tensor_gpu/20250319/accuracy/coredump_error/error_log.log

另外,请一并报名任务 343 paddle.Tensor.tril

@crashbussy
Copy link
Contributor Author

crashbussy commented May 20, 2025

@DanielSun11已经报名任务 343 paddle.Tensor.tril。
对paddle/phi/kernels/impl/tril_triu_kernel_impl.h和paddle/phi/kernels/impl/tril_triu_grad_kernel_impl.h(正向和反向)都做了修改。包含0size的单测已经添加,在test/legacy_test/test_tril_triu_op.py中添加0 size tensor输入的单测(在原有基础上新增了0size的情况)。新增test/xpu/test_tril_triu_xpu_0size_op.py,用于xpu上0size的单测。

@DanielSun11
Copy link
Contributor

DanielSun11 commented May 20, 2025

@DanielSun11已经报名任务 343 paddle.Tensor.tril。 对paddle/phi/kernels/impl/tril_triu_kernel_impl.h和paddle/phi/kernels/impl/tril_triu_grad_kernel_impl.h(正向和反向)都做了修改。包含0size的单测已经添加,在test/legacy_test/test_tril_triu_op.py中添加0 size tensor输入的单测(在原有基础上新增了0size的情况)。新增test/xpu/test_tril_triu_xpu_0size_op.py,用于xpu上0size的单测。

👍 ACK
PR 标题请添加上编号343

@crashbussy crashbussy changed the title [0-size Tensor No.350,351] Add 0-size Tensor support for paddle.tril paddle.triu API. [0-size Tensor No.343, 350, 351] Add 0-size Tensor support for paddle.tril paddle.triu API. May 21, 2025
@crashbussy
Copy link
Contributor Author

crashbussy commented May 24, 2025

@crashbussy 你好,这个任务是需要对kernel的前反向来添加0-size的支持的,不能只添加前向部分,还需要添加对应的测试,测试的话是继承OpTest这个基类来对算子进行前反向的测试,可以参考上面已有的例子把输入构造为0-size tensor的即可,流水线的话是需要研发来approval才会继续进行检查,需要你那边先修改好代码,再来找研发来approval运行流水线检查

好的,再次感谢您细心指导。我已经修改了对应反向部分,也在test_tril_triu_op.py中增加了对应的反向测试,已经在本地检查通过了。是否能帮忙联系研发老师帮忙看看。

前向测试可以直接使用test_check_output来测试,不需要写一个新的,周六周日是休息日,一般都是不上班的,周一的时候研发老师就会来看了

非常感谢,前向测试改为直接使用test_check_output测试。主要是启航计划本周结营,所以想赶一赶进度,在本周日前完成。

@DanielSun11
Copy link
Contributor

请重新构建一下:PR-CI-Hygon-DCU-Test

Copy link
Contributor

@DanielSun11 DanielSun11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

out_gpu = paddle.triu(x_gpu)
assert out_gpu.shape == x_gpu.shape

def test_0size_api_with_backward():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成 def test_0size_api_with_backward(self) :?

@@ -326,6 +326,52 @@ def test_base_api(self):
fetch_list=[triu_out],
)

def test_0size_api():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def test_0size_api(self):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def test_0size_api(self):

是的,在之前的版本中,这个单测代码需要修改,当时也发现了这个问题。但目前根据@fangfangssj的建议,‘前向测试可以直接使用test_check_output来测试,不需要写一个新的’,我就重写了单测部分,旧的版本已经删除了。

@crashbussy
Copy link
Contributor Author

请重新构建一下:PR-CI-Hygon-DCU-Test

已重新构建

@crashbussy
Copy link
Contributor Author

@DanielSun11 还有16个check未完成。其中是否有需要您approve才能进行的。

@crashbussy
Copy link
Contributor Author

@DanielSun11 所有check均已完成。

@DanielSun11
Copy link
Contributor

有两个Required CI出现了异常,似乎不是代码改动的关系。请稍后在本PR中添加评论 /re-run all-failed

重新运行下失败的CI。

@crashbussy
Copy link
Contributor Author

/re-run all-failed

2 similar comments
@crashbussy
Copy link
Contributor Author

/re-run all-failed

@crashbussy
Copy link
Contributor Author

/re-run all-failed

@crashbussy crashbussy requested a review from DanielSun11 May 27, 2025 01:38
Copy link
Contributor

@DanielSun11 DanielSun11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DanielSun11
Copy link
Contributor

请补充下paddleAPITest的回测结果,然后等待 @wanghuancoder review&merge

@crashbussy
Copy link
Contributor Author

image @DanielSun11 paddleAPITest的回测已全部通过

这里是paddleAPITest的回测结果

@crashbussy
Copy link
Contributor Author

api_config_pass.txt log.log 这里是全部回测log

这里是回测结果文件

@crashbussy
Copy link
Contributor Author

请补充下paddleAPITest的回测结果,然后等待 @wanghuancoder review&merge

好的,已补充回测结果。

@crashbussy
Copy link
Contributor Author

@wanghuancoder 已完成 paddle.tril、paddle.Tensor.tril 和 paddle.triu 对 0-Size 张量的支持,PR已就绪,等待您的代码评审与合并。

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paddle/phi/kernels/xpu/tril_triu_kernel.cc
paddle/phi/kernels/xpu/tril_triu_grad_kernel.cc
这两个也得修复一下

@crashbussy
Copy link
Contributor Author

@wanghuancoder 已修复文件
paddle/phi/kernels/xpu/tril_triu_kernel.cc
paddle/phi/kernels/xpu/tril_triu_grad_kernel.cc

@crashbussy crashbussy requested a review from wanghuancoder May 27, 2025 08:20
@crashbussy
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@crashbussy
Copy link
Contributor Author

/re-run all-failed

@crashbussy
Copy link
Contributor Author

@wanghuancoder 已通过所有check,等待您的审核通过。

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wanghuancoder wanghuancoder merged commit 263f2e0 into PaddlePaddle:develop May 28, 2025
71 of 73 checks passed
@luotao1
Copy link
Contributor

luotao1 commented May 28, 2025

hi, @crashbussy

  • 非常感谢你对飞桨的贡献,我们正在运营一个PFCC组织。PFCC是飞桨开源的贡献者俱乐部,只有给飞桨合入过代码的开发者才能加入,俱乐部里每两周会有一次例会(按兴趣参加),也会时不时办线下meetup面基,详情可见 https://github.com/luotao1 主页说明。
  • 如果你对PFCC有兴趣,请发送邮件至 ext_paddle_oss@baidu.com,我们会邀请你加入~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants