Skip to content

Conversation

@Manfredss
Copy link
Contributor

@Manfredss Manfredss commented Nov 11, 2025

PR Category

User Experience

PR Types

New Features

Description

任务:No. 6 bitwise_xor_ , No.42 bitwise_xor

修改内容

  1. 下沉 bitwise_xor 和 bitwise_xor_ 到 cpp
  2. 支持参数别名:
    • input 作为 x 的别名
    • other 作为 y 的别名
  3. test/legacy_test/test_inplace.py 中添加参数别名测试用例

@paddle-bot
Copy link

paddle-bot bot commented Nov 11, 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.

@zhwesky2010 zhwesky2010 changed the title [API Compatibility No.6] Add parameter alias support for bitwise_xor_ -part [API Compatibility No.6] Add parameter alias support for bitwise_xor_ Nov 11, 2025
@Manfredss
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Manfredss
Copy link
Contributor Author

/re-run all-failed

@luotao1 luotao1 changed the title [API Compatibility No.6] Add parameter alias support for bitwise_xor_ [API Compatibility No.6] Add parameter alias support for bitwise_xor_ -part Nov 13, 2025
@Manfredss Manfredss closed this Nov 13, 2025
@Manfredss Manfredss reopened this Nov 13, 2025
@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@4df7c64). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #76341   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         2           
  Lines              ?         3           
  Branches           ?         0           
===========================================
  Hits               ?         3           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Manfredss
Copy link
Contributor Author

@luotao1 @zhwesky2010

Hi, 我注意到有两个 CI 失败:

  • CI / Distribute-stable-formers / formers-Test
  • CI-Build / Slice / Slice test

经过分析,这两个失败应该与本 PR 的改动无关,原因如下:

  1. 本 PR 仅修改了 bitwise_xor_ API 的参数别名支持,不涉及:

    • 分布式训练相关功能
    • 张量切片相关功能
    • 任何模型训练逻辑
  2. 改动范围极小且独立:只在 logic.py 添加了装饰器,以及对应的单元测试

  3. 从其他类似的 API 兼容性 PR(如 bitwise_or_)来看,应该不会影响这些无关的测试

@luotao1
Copy link
Contributor

luotao1 commented Nov 14, 2025

CI / Distribute-stable-formers / formers-Test

非required流水线不用管,目前还在调试中

CI-Build / Slice / Slice test

等研发review过后,我会进行豁免

@Manfredss
Copy link
Contributor Author

/re-run all-failed

- op : bitwise_xor
name : [paddle.bitwise_xor, paddle.Tensor.bitwise_xor]
args_alias :
x : [input]
Copy link
Contributor

Choose a reason for hiding this comment

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

这个用use_default_mapping : True 就可以


# other
add_doc_and_signature(
"bitwise_xor_",
Copy link
Contributor

Choose a reason for hiding this comment

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

这个是bitwise_xor还是bitwise_xor_?

前者是非inplace的,后者是inplace的

Copy link
Contributor Author

@Manfredss Manfredss Nov 17, 2025

Choose a reason for hiding this comment

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

修复列表里写的是 bitwise_xor_,所以这里写的 bitwise_xor_。这个 API 只能通过装饰器来修改

但 bitwise_xor 是能够 cpp 下沉的,所以有些疑惑 @zhwesky2010

if TYPE_CHECKING:
from paddle import Tensor

# @overload
Copy link
Contributor

Choose a reason for hiding this comment

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

这些不需要

``paddle.bitwise_xor`` supports broadcasting. If you want know more about broadcasting, please refer to please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Copy link
Contributor

Choose a reason for hiding this comment

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

下沉后原来的bitwise_xor需要删除掉,从_C_ops中导入

@Manfredss
Copy link
Contributor Author

Manfredss commented Nov 20, 2025

我觉得不能删去 logic.pybitwise_xor 的定义,因为测试代码 test_bitwise_op.py 中

self.python_api = paddle.tensor.logic.bitwise_xor

框架会使用 inspect.getfullargspec() 来获取函数签名信息,如果直接导入会报错

ValueError: no signature found for builtin <built-in function bitwise_xor>
TypeError: unsupported callable

bitwise_xor 需要支持参数别名 (input, other),这要使用 @param_two_alias;要支持 out 参数,这需要 python 层的处理器;要支持静态图模式,这需要调用 _bitwise_op 辅助函数。以上

如果直接从 _C_op 导入,这些功能会无法实现。

最后需要确认一下,API 兼容性增强 No.6 针对的是 bitwise_xor 还是 bitwise_xor_?多谢解答! @luotao1 @zhwesky2010

@Manfredss
Copy link
Contributor Author

/re-run all-failed

@zhwesky2010
Copy link
Contributor

@Manfredss 以表格中的字符串为准。与表格一一对应就行。

return _C_ops.bitwise_or_(x, y)


@param_two_alias(["x", "input"], ["y", "other"])
Copy link
Contributor

@zhwesky2010 zhwesky2010 Nov 24, 2025

Choose a reason for hiding this comment

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

写了下沉就不要写装饰器了。

两者选其一就可,另外下沉inplace API(bitwise_xor_)之前需要先把非inplace原版(bitwise_xor)也下沉了,因为两者是复用的一个kernel。

@Manfredss
Copy link
Contributor Author

@zhwesky2010 已根据意见完成修改,烦请再 review 一下,谢谢!



@inplace_apis_in_dygraph_only
@ParamAliasDecorator({"x": ["input"], "y": ["other"]})
Copy link
Contributor

@zhwesky2010 zhwesky2010 Dec 2, 2025

Choose a reason for hiding this comment

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

这个也下沉吧?

args_alias:
use_default_mapping : True

- op : bitwise_xor
Copy link
Contributor

Choose a reason for hiding this comment

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

下沉后原来的python 层API需要删掉,只有c++接口了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#76341 (comment) 主要是这个问题,所以我还留着

Copy link
Contributor

@zhwesky2010 zhwesky2010 Dec 2, 2025

Choose a reason for hiding this comment

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

把两个一起下沉了就行了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

@Manfredss Manfredss force-pushed the ApiEnhance6 branch 2 times, most recently from 7bad604 to d5240bf Compare December 3, 2025 06:54
@zhwesky2010
Copy link
Contributor

zhwesky2010 commented Dec 3, 2025

我觉得不能删去 logic.pybitwise_xor 的定义,因为测试代码 test_bitwise_op.py 中

self.python_api = paddle.tensor.logic.bitwise_xor

框架会使用 inspect.getfullargspec() 来获取函数签名信息,如果直接导入会报错

ValueError: no signature found for builtin <built-in function bitwise_xor>
TypeError: unsupported callable

bitwise_xor 需要支持参数别名 (input, other),这要使用 @param_two_alias;要支持 out 参数,这需要 python 层的处理器;要支持静态图模式,这需要调用 _bitwise_op 辅助函数。以上

如果直接从 _C_op 导入,这些功能会无法实现。

最后需要确认一下,API 兼容性增强 No.6 针对的是 bitwise_xor 还是 bitwise_xor_?多谢解答! @luotao1 @zhwesky2010

这些都不是问题。除非_C_ops前有很复杂的逻辑,或者组合实现的API,都可以下沉。
直接在logic.py从_C_ops导入bitwise_xor,老静态图模式可以移除,凡是下沉的都没有维护这个分支。
不确定是bitwise_xor还是bitwise_xor_,不如两个都直接改了。

if TYPE_CHECKING:
from paddle import Tensor


Copy link
Contributor

Choose a reason for hiding this comment

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

下沉后,需要移除之前的python api,就没有这一层逻辑了。直接走c++

@Manfredss Manfredss closed this Dec 4, 2025
@Manfredss Manfredss reopened this Dec 4, 2025
x: Tensor,
y: Tensor,
out: Tensor | None = None,
name: str | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

签名统一参照其他的:

(x, y, name, *, out)

x_np = np.random.randint(-10, 10, [])
y_np = np.random.randint(-10, 10, [])
out_np = eval(f'np.{api.__name__}(x_np, y_np)')
out_np = eval(f'np.{api.__name__.lstrip("_")}(x_np, y_np)')
Copy link
Contributor

Choose a reason for hiding this comment

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

zero_dim这里为啥需要改

Copy link
Contributor Author

@Manfredss Manfredss Dec 12, 2025

Choose a reason for hiding this comment

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

这里的改动是因为测试会有报错

======================================================================
ERROR: test_dygraph_binary (__main__.TestBinaryAPI.test_dygraph_binary)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\Xue\ML\PaddleDebug\test\legacy_test\test_zero_dim_binary_api.py", line 170, in test_dygraph_binary
    out_np = eval(f'np.{api.__name__}(x_np, y_np)')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in <module>
  File "C:\Users\tzy12\anaconda3\envs\paddle\Lib\site-packages\numpy\__init__.py", line 808, in __getattr__
    raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")
AttributeError: module 'numpy' has no attribute '_bitwise_xor'. Did you mean: 'bitwise_xor'?

----------------------------------------------------------------------
Ran 6 tests in 0.508s

Inplace version of ``bitwise_xor`` API, the output Tensor will be inplaced with input ``x``.
Please refer to :ref:`api_paddle_bitwise_xor`.
"""
out_shape = broadcast_shape(x.shape, y.shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

下沉后,这个逻辑可能会丢掉了,需要测一下

return paddle.bitwise_xor(var, self.y)


class TestDygraphInplacBitwiseXorAlias1(TestDygraphInplacBitwiseAnd):
Copy link
Contributor

Choose a reason for hiding this comment

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

paddle.bitwise_xor测一下compat情况下的用法

Copy link
Contributor Author

@Manfredss Manfredss Dec 12, 2025

Choose a reason for hiding this comment

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

bitwise_xor_ 需要吗?好像 bitwise_xor_ 用了 compat 会有 segfault 的情况,我认为可能是 bitwise_xor_ 下沉了但是 ops.yaml 里没有 bitwise_xor_ 的定义。需要添加吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

bitwise_xor_ 需要吗?好像 bitwise_xor_ 用了 compat 会有 segfault 的情况,我认为可能是 bitwise_xor_ 下沉了但是 ops.yaml 里没有 bitwise_xor_ 的定义。需要添加吗?

ops.yaml里不需要bitwise_xor_定义,会根据bitwise_xor的inplace字段,来生成bitwise_xor_

两者本质是共享一个kernel的,只在输出out处理这里有些区别。

Copy link
Contributor

Choose a reason for hiding this comment

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

bitwise_xor_ 需要吗?好像 bitwise_xor_ 用了 compat 会有 segfault 的情况,我认为可能是 bitwise_xor_ 下沉了但是 ops.yaml 里没有 bitwise_xor_ 的定义。需要添加吗?

先按标准来测试,不要绕过,先提前暴露问题。
这里的segfault是不是触发了什么底层机制的问题?因为目前还没有inplace的API下沉过。

@Manfredss
Copy link
Contributor Author

/re-run all-failed

@Manfredss Manfredss changed the title [API Compatibility No.6] Add parameter alias support for bitwise_xor_ -part [API Compatibility No.6] Sink bitwise_xor and bitwise_xor_ to cpp -part Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants