Skip to content

[Accuracy diff No.15] Fix accuracy diff for cumprod API - #212

Merged
wanghuancoder merged 2 commits into
PFCCLab:mainfrom
ooooo-create:fix_cumprod
Jun 4, 2025
Merged

wanghuancoder merged 2 commits into
PFCCLab:mainfrom
ooooo-create:fix_cumprod

Conversation

@ooooo-create

@ooooo-create ooooo-create commented May 30, 2025 •

Copy link
Copy Markdown
Contributor

Torch 和 numpy 在 dtype 为 None,处理输入时,如果输入整数精度小于平台的默认整数时,会使用平台默认整数,cast 成 int64,所以直接设定 dtype 为 x.dtype

all config in 5_accuracy/accuracy_4.txt,5_accuracy/accuracy_6.txt and 5_accuracy/accuracy_error_1.txt has passed.
图片

@paddle-bot

paddle-bot Bot commented May 30, 2025

Copy link
Copy Markdown

Thanks for your contribution!

@ooooo-create

Copy link
Copy Markdown
Contributor Author

@cangtianhuang @Cutelemon6 This pr is ready to be reviewed, Thanks!

@Cutelemon6 Cutelemon6 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

同学你好!修复通过的 api 配置可以从 accuracy_error_1.txt 中移动到 accuracy_9.txt (新建一个吧)。

在 torch 模拟 paddle api 层面,int32 dtype 输入确实没有对齐 paddle api 行为。在 paddle api 设计的层面,需要决定一下 dtype == None 时保持输出 dtype 和输入 dtype 一致(paddle 实现),还是说防止溢出计算时提升到更高精度进行计算(torch 实现)。

image

Comment on lines -829 to -845
if dim is None:
x = x.flatten()
axis = 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

paddle 和 torch 的 api 在面对 dim == None / 缺省时的行为一致吗,如果一致可以删去。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

两者都不能为 None,paddle 在 api 层面设置了默认值,但其实默认值 None 会报错的,实现中实际需要的是整数,需要去改下,或者去适配 None 的时候 flatten(这个是 numpy 的行为),但是没看见别人反馈,应该是都没有使用默认值的情况,但是其他 cum 开头的函数确实会 flatten,感觉这个得去 Paddle 仓库提个 issue 问问。

在 paddle api 设计的层面,需要决定一下 dtype == None 时保持输出 dtype 和输入 dtype 一致(paddle 实现),还是说防止溢出计算时提升到更高精度进行计算(torch 实现)

我感觉提升比较好,但是有个流水线监控的很紧,很难通过,这个应该也要去 Paddle 问问😂

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

我理解一下你的意思,并尝试回答一下:

  1. Q: "paddle 在 api 层面设置了默认值,但其实默认值 None 会报错的,实现中实际需要的是整数,需要去改下" => torch 不接受 axis == None (对应到 paddle 配置的输入就是 dim == None),所以需要进行转换。
    A: 那这个就和删掉的 829 - 831 的意思是一致的。具体是 829,831
  2. Q: "或者去适配 None 的时候 flatten(这个是 numpy 的行为),但是没看见别人反馈,应该是都没有使用默认值的情况" => 对 dim == None,将 x 输入展平,应该是目前没有 dim == None / 缺省输入的配置。
    A: 与 830 一致了,原有代码就是对齐 paddle 输入 dim == None时,torch 需要将 x 展平。
  3. Q: “但是其他 cum 开头的函数确实会 flatten,感觉这个得去 Paddle 仓库提个 issue 问问。”
    A: 我们只需要关注这个 api 的情况就可以。

@ooooo-create ooooo-create Jun 2, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! 可能我描述的不太好,我想说的是 paddle 本身的问题,paddle 本身 dim 缺省默认的 None 是会报错的
图片

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

噢好的,那就只考虑 dim != None 的情况就可以,配置出现使 paddle api 报错的概率很低。

@Cutelemon6 Cutelemon6 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

paddle.cumprod(x=Tensor([3, 4],"int32"), dim=0, )
paddle.cumsum(Tensor([1, 32000],"float16"), axis=-1, )
paddle.einsum("i, i", Tensor([2],"float64"), Tensor([1],"float64"), )
paddle.einsum("ij,ij->j", Tensor([10, 2],"float64"), Tensor([1, 2],"float64"), )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里不用再mv到tester/api_config/5_accuracy/accuracy_9.txt了。tester/api_config/5_accuracy/accuracy_gpu_error.txt作为筛选出来的问题清单。用于快速回归测试使用。即便是Paddle没有问题,PaddleAPITest有问题,也不需要维护tester/api_config/5_accuracy/accuracy_gpu_error.txt了。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

好的,已修改~

@Cutelemon6 Cutelemon6 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@wanghuancoder wanghuancoder left a comment

Copy link
Copy Markdown
Collaborator

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 584d701 into PFCCLab:main Jun 4, 2025
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jun 10, 2025
@ooooo-create
ooooo-create deleted the fix_cumprod branch September 29, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants