Skip to content

Conversation

@DongBaiYue
Copy link
Contributor

@DongBaiYue DongBaiYue commented Aug 7, 2025

PR Category

Operator Mechanism

PR Types

Improvements

Description

This PR introduces PyTorch API compatibility aliases and resolves type checking issues:

  1. Added PyTorch-compatible parameter aliases:
API param alias
torch.as_tensor place device
torch.finfo dtype type
torch.is_complex x input
torch.nn.functional.pad x input

Usage Example:

# Traditional Paddle call t1 = paddle.to_tensor([1, 2], place=paddle.CPUPlace()) # New PyTorch-compatible call t2 = paddle.to_tensor([1, 2], device=paddle.CPUPlace()) # Maps to `place=paddle.CPUPlace()` 
  1. Fixed DecoratorBase Type Annotation
    in python/paddle/utils/decorator_utils.py, Modified type hint from _DecoratedFunc[_P, _R] to _F to pass the following test:
from mypy import api code = """ import paddle a = paddle.to_tensor(data=.123456789) """ # 检查字符串形式的代码 result = api.run(["-c", code]) # 结果包含三部分 stdout, stderr, exit_status = result print("标准输出:", stdout) print("标准错误:", stderr) print("退出状态:", exit_status) # 0 表示成功,1 表示类型错误 

Others

Added comprehensive unittests for all new alias parameters.

docs pr

pcard-67164

@paddle-bot
Copy link

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

@paddle-bot paddle-bot bot added the contributor External developers label Aug 7, 2025
@DongBaiYue DongBaiYue changed the title torch.as_tensor, torch.finfo, torch.is_complex, torch.nn.functional.pad [API compatibility] torch.as_tensor, torch.finfo, torch.is_complex, torch.nn.functional.pad Aug 7, 2025
@codecov-commenter
Copy link

Codecov Report

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

Additional details and impacted files
@@ Coverage Diff @@ ## develop #74456 +/- ## =========================================== Coverage ? 100.00% =========================================== Files ? 4 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.
@DongBaiYue
Copy link
Contributor Author

/re-run all-failed

@zhangbo9674 zhangbo9674 merged commit 9f97d37 into PaddlePaddle:develop Aug 11, 2025
59 of 60 checks passed
@DongBaiYue DongBaiYue deleted the 4_api branch August 12, 2025 03:17
maxiaolong001 pushed a commit to maxiaolong001/Paddle that referenced this pull request Aug 12, 2025
…orch.nn.functional.pad (PaddlePaddle#74456) * [API compatibility] paddle.to_tensor * choose suitable place * fix annotation * fix whitespace * fix getfullargspec * torch.as_tensor, torch.finfo, torch.is_complex, torch.nn.functional.pad * fix type_check * deleta example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

3 participants