修复 Tensor.min/max 转换:用 amin/amax 对齐 Paddle 约简语义 - #725
Merged
Merged
Conversation
paddle.Tensor.min/max 在指定 axis 时只返回极值,Torch 的 min/max(dim=) 会返回 (values, indices)。改为 amin/amax,并补上 keepdim 在全局约简时的形状。
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.
背景
paddle.Tensor.max/paddle.Tensor.min在指定axis时只返回极值 Tensor。原先对照映射到torch.Tensor.max/torch.Tensor.min,Torch 在dim=路径会返回(values, indices),对照拿到的不是 Paddle 的约简结果。paddle.Tensor.min也未走ReduceRule,axis=None且keepdim=True时全局约简的形状也对不齐。修改内容
tester/paddle_to_torch/mapping.jsonpaddle.Tensor.max改为torch.amax,补axis/keepdim默认值;paddle.Tensor.min改为ReduceRule+torch.amin,同样补默认值。tester/paddle_to_torch/rules.pyReduceRule.PADDLE_APIS增加paddle.Tensor.min;Tensor.max/Tensor.min共用amin/amax路径,避免min/max(dim=)返回 namedtuple;axis is None and keepdim时把标量 reshape 成[1] * x.dim(),与 Paddle 一致。验证
python -m py_compile tester/paddle_to_torch/rules.pypython -c 'import json; json.load(open("tester/paddle_to_torch/mapping.json"))'ruff check tester/paddle_to_torch/rules.py与ruff format --check tester/paddle_to_torch/rules.pypython tools/check_comment_ratio.py(staged 评论比例 20%)git diff --cached --check未执行:仓库
pre-commit run --files ...(hook 环境拉取不稳定);未跑engineV4.py端到端 accuracy。