Skip to content

[API Compatibility No.122] Align paddle.neg with PyTorch API#78216

Open
seasameye wants to merge 2 commits intoPaddlePaddle:developfrom
seasameye:test_neg
Open

[API Compatibility No.122] Align paddle.neg with PyTorch API#78216
seasameye wants to merge 2 commits intoPaddlePaddle:developfrom
seasameye:test_neg

Conversation

@seasameye
Copy link

PR Category

User Experience

PR Types

Improvements

Description

本次修改增强了 Paddle 的 paddle.neg API 与 PyTorch 的兼容性,便于 PyTorch 代码无缝迁移到 Paddle。

主要改动:

  1. 参数别名支持

    • neg 添加 @param_one_alias(["x", "input"]) 装饰器。
    • input 可作为 x 的别名
  2. out 参数支持

    • 在函数签名中新增 out: Tensor | None = None
    • 动态图模式下,若提供 out,计算结果写入预分配张量;否则返回计算结果。
    • 静态图模式下,out 张量直接传入算子。
  3. 文档更新

    • docstring 中添加 Alias 说明:Alias: ``input``.
    • 添加 out 参数说明与使用示例。
  4. 测试补充

    • test/legacy_test/test_api_compatibility.py 中新增 TestNeg 测试类。

是否引起精度变化

@paddle-bot
Copy link

paddle-bot bot commented Mar 8, 2026

你的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 Mar 8, 2026
np.testing.assert_allclose(fetches[i + 1], ref_out[1])


class TestDsplitAPI(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

这些不是这个PR的修改内容,拉下最新develop,处理下冲突

Copy link
Author

Choose a reason for hiding this comment

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

好的,老师~

@codecov-commenter
Copy link

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #78216   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         8           
  Branches           ?         0           
===========================================
  Hits               ?         8           
  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.



# Test row_stack compatibility
class TestRowStackAPI(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

这里不要修改非neg的内容

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Compatibility contributor External developers HappyOpenSource 快乐开源活动issue与PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants