Skip to content

在paddle.tensor中加入float,int和complex等数据转换接口 #73351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

Qin-sx
Copy link
Contributor

@Qin-sx Qin-sx commented Jun 15, 2025

PR Category

User Experience

PR Types

Improvements

Description

当前问题
paddle中没有float16和bfloat16等数据转换接口,需要用astype转换

解决方案
注册float16和bfloat16等数据转换接口

	modified:   python/paddle/base/dygraph/math_op_patch.py
	new file:   test/legacy_test/test_tensor_float16_bfloat16.py
@paddle-bot paddle-bot bot added the contributor External developers label Jun 15, 2025
@@ -104,6 +104,26 @@ def astype(self: Tensor, dtype: DTypeLike) -> Tensor:

return _C_ops.cast(self, dtype)

def float16(self: Tensor) -> Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

这个是不是得整体加,包括fp32、fp64、int32等所有类型,而不是给某两个类型增加一个函数。

实现方式建议通过一个公共函数,批量注册

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯,收到,已修改为通过公共函数批量注册

Copy link

paddle-ci-bot bot commented Jun 24, 2025

Sorry to inform you that 701fe26's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Qin-sx added 3 commits July 4, 2025 20:31
	modified:   python/paddle/base/dygraph/math_op_patch.py
	modified:   test/legacy_test/test_tensor_float16_bfloat16.py
	renamed:    test/legacy_test/test_tensor_float16_bfloat16.py -> test/legacy_test/test_tensor_type_convert_api.py
@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jul 5, 2025

@Qin-sx Qin-sx changed the title 在paddle.tensor中加入float16和bfloat16接口 在paddle.tensor中加入float,int和complex等数据接口 Jul 5, 2025
@Qin-sx Qin-sx changed the title 在paddle.tensor中加入float,int和complex等数据接口 在paddle.tensor中加入float,int和complex等数据转换接口 Jul 5, 2025
	modified:   python/paddle/pir/math_op_patch.py
	modified:   test/legacy_test/test_tensor_type_convert_api.py
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (develop@a926cd3). Learn more about missing BASE report.

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

'int32': 'int32',
'int64': 'int64',
# other
'bool': 'bool',
Copy link
Contributor

Choose a reason for hiding this comment

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

这个应该还有一些其他的用法吧,或者别名用法,也需要配置一下:
x.long、x.double、x.cfloat、x.uint8

这个要配全

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯,收到,已修改,之前是按照上面的文档的tensor type写的

@@ -37,6 +37,23 @@
DataType.INT64,
]

_supported_dtype_conversions = {
Copy link
Contributor

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.

已修改

Unit tests for all supported tensor dtype conversion methods.
"""

_supported_dtype_conversions = {
Copy link
Contributor

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.

已修改

	modified:   python/paddle/base/dygraph/math_op_patch.py
	modified:   python/paddle/pir/math_op_patch.py
	modified:   test/legacy_test/test_tensor_type_convert_api.py
Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Jul 14, 2025
@PaddlePaddle PaddlePaddle unlocked this conversation Jul 14, 2025
@zhwesky2010 zhwesky2010 reopened this Jul 14, 2025
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Jul 14, 2025
@PaddlePaddle PaddlePaddle unlocked this conversation Jul 14, 2025
Copy link

paddle-ci-bot bot commented Jul 21, 2025

Sorry to inform you that 5dc2126's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants