Skip to content

Conversation

@Enigmatisms
Copy link
Contributor

PR Category

Operator Mechanism

PR Types

New features

Description

增加了 paddle.compat.Unfold。原始的paddle.nn.Unfold与PyTorch 中的nn.Unfold 操作主要有两点不同:

  • padding 输入更加灵活:可以指定四个方向的 padding,而非左右/上下 对称 padding,本PR的 compat.Unfold 因此也限制了用户输入 Size4 padding(会报错提示用户使用 nn.Unfold
  • (重要):PyTorch 的参数可以以 Tensor 输入。目前本 PR 只做到了动态图下 Tensor 输入,静态图的 Tensor 转 list 的 tolist() 方法无法使用,故不做 C++ 端处理可能(目前没有发现好的方法)无法正确转换输入。
  • 增加了对应的单元测试:test_compat_unfold.py

Pcard-89620

@paddle-bot
Copy link

paddle-bot bot commented Aug 12, 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.

@codecov-commenter
Copy link

codecov-commenter commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@39e0b4f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/tensor/compat.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #74572   +/-   ##
==========================================
  Coverage           ?   95.83%           
==========================================
  Files              ?        3           
  Lines              ?       24           
  Branches           ?        0           
==========================================
  Hits               ?       23           
  Misses             ?        1           
  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.

@Enigmatisms
Copy link
Contributor Author

/re-run all failed

1 similar comment
@Enigmatisms
Copy link
Contributor Author

/re-run all failed

@Enigmatisms Enigmatisms force-pushed the unfold_api branch 3 times, most recently from f79c073 to 8cddbad Compare August 18, 2025 02:15
@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -0,0 +1,121 @@
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.

For default, it will be [1, 1].
Examples:
.. code-block:: python
>>> import paddle
Copy link
Member

Choose a reason for hiding this comment

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

code-block 下需要空一行

>>> unfold = paddle.compat.Unfold(kernel_size=[3, 3])
>>> result = unfold(x)
>>> print(result.shape)
[100, 27, 49284]
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

可以先合入,但后续英文文档和中文文档要一起让 @sunzhongkai588 review 下

@zhangbo9674 zhangbo9674 merged commit eec5412 into PaddlePaddle:develop Aug 19, 2025
72 of 73 checks passed
Luckycheng222 pushed a commit to Luckycheng222/Paddle that referenced this pull request Aug 25, 2025
…addlePaddle#74572)

* [API-Compat] Add paddle.compat.Unfold that supports tensor inputs.

* [API-Compat] Fixed pre-commit problem

* [API-Compat] Fixed merging precomit failure
@Enigmatisms Enigmatisms deleted the unfold_api branch August 29, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants