Skip to content

修复 Tensor.min/max 转换:用 amin/amax 对齐 Paddle 约简语义 - #725

Merged
feixi139 merged 1 commit into
PFCCLab:mainfrom
feixi139:fix-tensor-min-max-reduce
Sep 7, 2026
Merged

feixi139 merged 1 commit into
PFCCLab:mainfrom
feixi139:fix-tensor-min-max-reduce

Conversation

@feixi139

@feixi139 feixi139 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

背景

paddle.Tensor.max / paddle.Tensor.min 在指定 axis 时只返回极值 Tensor。原先对照映射到 torch.Tensor.max / torch.Tensor.min,Torch 在 dim= 路径会返回 (values, indices),对照拿到的不是 Paddle 的约简结果。paddle.Tensor.min 也未走 ReduceRuleaxis=Nonekeepdim=True 时全局约简的形状也对不齐。

修改内容

  • tester/paddle_to_torch/mapping.json
    • paddle.Tensor.max 改为 torch.amax,补 axis/keepdim 默认值;
    • paddle.Tensor.min 改为 ReduceRule + torch.amin,同样补默认值。
  • tester/paddle_to_torch/rules.py
    • ReduceRule.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.py
  • python -c 'import json; json.load(open("tester/paddle_to_torch/mapping.json"))'
  • ruff check tester/paddle_to_torch/rules.pyruff format --check tester/paddle_to_torch/rules.py
  • python tools/check_comment_ratio.py(staged 评论比例 20%)
  • git diff --cached --check

未执行:仓库 pre-commit run --files ...(hook 环境拉取不稳定);未跑 engineV4.py 端到端 accuracy。

paddle.Tensor.min/max 在指定 axis 时只返回极值,Torch 的 min/max(dim=)
会返回 (values, indices)。改为 amin/amax,并补上 keepdim 在全局约简时的形状。
@feixi139
feixi139 merged commit ae7d9d4 into PFCCLab:main Sep 7, 2026
1 check passed
@feixi139
feixi139 deleted the fix-tensor-min-max-reduce branch September 7, 2026 08:59
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.

1 participant