支持更多 Paddle Tensor API 的 Torch 精度对齐 - #707
Merged
Merged
Conversation
cangtianhuang
enabled auto-merge (squash)
August 9, 2026 07:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
支持的 API
paddle.Tensor.add_paddle.Tensor.contiguouspaddle.Tensor.copy_paddle.Tensor.flatten_paddle.Tensor.multiply_paddle.Tensor.put_along_axis_paddle.Tensor.scale_paddle.Tensor.subtract_paddle.Tensor.topaddle.randint主要改动
Tensor 原地算子
复用 main 分支已有的
_C_ops转换规则,为对应的paddle.Tensor.*方法增加映射,避免重复实现相同的原地计算逻辑。涉及:
add_flatten_multiply_put_along_axis_scale_subtract_add_和subtract_补充以下兼容处理:alpha参数。float32与bfloat16等混合 dtype 输入下 Paddle 和 Torch 行为不一致的问题。put_along_axis_同时兼容_C_ops使用的arr参数名和 Tensor 方法使用的x接收者参数名。paddle.Tensor.copy_inspect.signature获取签名的内建方法增加手工参数绑定。self、other和blocking参数。blocking转换为 Torchcopy_的non_blocking参数。copy_加入 forward-only API,避免对原地修改后的 Tensor 执行无意义的反向精度比较。paddle.Tensor.contiguous直接映射到
torch.Tensor.contiguous,沿用 main 分支现有的 Tensor 方法调用机制。paddle.Tensor.to新增独立转换规则,处理 Paddle 与 Torch 在设备和 dtype 参数上的差异:
gpu、gpu:<id>转换为 Torch 的cuda、cuda:<id>。torch.dtype。self、args元数据,避免这些内部参数被重复传递给torch.Tensor.to。paddle.randint新增到
torch.randint的参数映射:shape列表转换为 Torch 接受的 tuple。low和high参数顺序。torch.int64,与 Paddle 默认行为对齐。locals().get("dtype")读取可选参数,避免缺省 dtype 时产生未定义变量错误。