Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions tester/paddle_to_torch/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,11 @@ def apply(self, paddle_api: str) -> ConvertResult:

class CumprodRule(BaseRule):
def apply(self, paddle_api: str) -> ConvertResult:
pre = f"""
pre = """
dim = locals().get('dim')
if dim is None:
x = x.flatten()
axis = 0
Comment on lines -843 to -845

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 报错的概率很低。

dtype = locals().get('dtype')
if dtype is None:
dtype = x.dtype
"""
core = "result = torch.cumprod(input=x, dim=dim, dtype=dtype)"
code = Code(preprocess=pre.splitlines(), core=[core])
Expand Down