Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-78301/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# PaddlePaddle__Paddle-78301

This directory converts Paddle PR #78301 into a SWE-Paddle community task candidate.

## Source

| Field | Value |
| --- | --- |
| Repository | `PaddlePaddle/Paddle` |
| PR | [78301](https://github.com/PaddlePaddle/Paddle/pull/78301) |
| PR title | `[API Compatibility] align paddle.nn.Layer.to/paddle.Tensor.to -part` |
| Base commit | `fd041ffe2d941d7219090cb12f6ffb10860dc851` |
| Squash commit | `d6e41b70154ba52525884afdc15c2a9d763a2cae` |
| Merged at | `2026-04-03T07:08:36Z` |
| Track | `C` (feature_or_api) |
| Task type | `feature_enhancement` |
| Resource | CPU |

## Summary

Align the public conversion call forms of `paddle.nn.Layer.to` and `paddle.Tensor.to`. The task covers positional and keyword dtype/device/reference-Tensor arguments, blocking options, `copy`, no-argument calls, invalid-input errors, and recursive in-place layer conversion.

## Why This Task

- It comes from a merged API-compatibility fix with a clear user-visible contract.
- It requires consistent overload parsing across two public APIs rather than a signature-only change.
- It exercises success paths, argument conflicts, invalid input, layer identity, and recursive sublayer conversion.
- Its Python-only scope is suitable for CPU verification while remaining non-trivial.

Only the behavior merged in PR #78301 is in scope. Follow-up PRs referenced by `proposal.md` are intentionally excluded from the gold patch and acceptance criteria.

## Files

- `proposal.md`: approved candidate proposal and scope.
- `instruction.md`: self-contained problem statement for the coding agent.
- `solution/code.patch`: gold patch for non-test source files.
- `tests/test.patch`: target behavior tests, including a same-dtype positional `copy=True` case that requires a distinct result.
- `tests/test.sh`: minimal F2P/P2P test command.
- `environment/README.md`: base revision, run order, and verification risks.

## Verification

From a Paddle source checkout at the base commit, apply `tests/test.patch` and run:

```bash
bash tests/test.sh
```

The target tests should fail before `solution/code.patch` is applied and pass afterward. The existing `TestLayerTo::test_main` node is included as a P2P regression guard.
37 changes: 37 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-78301/environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Environment Notes

## Expected Environment

- Repository: `PaddlePaddle/Paddle`
- Base commit: `fd041ffe2d941d7219090cb12f6ffb10860dc851`
- Resource: CPU
- GPU required: no
- Build path: Paddle source checkout at the base commit with a base-compatible Paddle Python installation. The task changes Python sources only, so the verifier may use a Python overlay on an existing compatible build; otherwise build and install Paddle from the base checkout.

## Run Order

1. Check out `PaddlePaddle/Paddle` at the base commit.
2. Apply `tests/test.patch`.
3. Run `bash tests/test.sh`; at least the target behavior should fail before the fix.
4. Apply `solution/code.patch`.
5. Run `bash tests/test.sh` again; the target behavior and P2P guard should pass.

## Minimal Test Command

```bash
bash tests/test.sh
```

## Verification Scope

- F2P targets: `TestLayerAndTensorToAPI` and `TestTensorToCopyCompatibility::test_copy_as_positional_argument` in `test/legacy_test/test_api_compatibility_part3.py`.
- P2P guard: `TestLayerTo::test_main` in `test/legacy_test/test_base_layer.py`.
- The standalone copy case passes `copy=True` as the third positional value to a same-dtype conversion and requires a distinct result. The base parser ignores that positional value, so this case is expected to fail before the fix and pass afterward.

## Risks

- A compatible Paddle build is required even though the patch itself is Python-only.
- The source test class changes Paddle's global dynamic/static mode in `tearDown`. Run the target class and the P2P guard in separate pytest processes so their global modes cannot leak into one another.
- The legacy P2P guard uses eager-only gradient internals and must run with `FLAGS_enable_pir_api=0`; otherwise it fails before exercising `Layer.to`.
- Later follow-up fixes to these APIs are outside this task. Verification must use the stated base commit and only the supplied patches.
- Verification was completed with a base-compatible local Paddle build and Python-source overlays. Maintainers should reproduce the Run/Test/Fix sequence in the designated verifier environment.
23 changes: 23 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-78301/instruction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 对齐 Tensor 与 Layer 的转换调用行为

Paddle 的 Tensor 和神经网络 Layer 转换接口目前无法一致地支持常见调用形式。请调整它们的可观察行为,使下列用法能够可靠工作。

## 行为要求

- 接受 dtype、device 或参考 Tensor 作为第一个位置参数。
- 在适用场景中,支持同时以位置参数传入 device 和 dtype。
- 支持以关键字参数传入 `device` 和 `dtype`。
- 支持 `blocking`、`non_blocking` 和 `copy` 的合法位置参数或关键字参数形式。
- 允许不传参数的转换调用。
- 同时指定 `blocking` 和 `non_blocking` 时抛出 `TypeError`。
- 位置参数过多或存在未知关键字参数时抛出 `TypeError`。
- 第一个位置参数无法识别时抛出 `ValueError`。
- Layer 转换应原地执行、返回同一个 Layer 对象,并递归应用于子层。
- 传入参考 Tensor 时,目标对象应采用其转换属性。

## 验收标准

- Tensor 转换支持 dtype、device、参考 Tensor、阻塞选项和复制语义。
- Layer 转换支持对应的 dtype、device、参考 Tensor 和阻塞选项调用,并保持对象身份不变。
- 嵌套 Layer 和已注册 buffer 均得到一致转换;按照本任务目标行为,dtype 转换也适用于整数 buffer。
- 现有 Layer 转换回归测试继续通过。
13 changes: 10 additions & 3 deletions swe-paddle/tasks/PaddlePaddle__Paddle-78301/proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,31 @@
- 目标测试文件:
- `test/legacy_test/test_api_compatibility_part3.py`
- `test/legacy_test/test_base_layer.py`
- 目标测试类:`TestLayerAndTensorToAPI`;P2P 护栏为 `TestLayerTo::test_main`
- 目标测试类:`TestLayerAndTensorToAPI`、`TestTensorToCopyCompatibility`;P2P 护栏为 `TestLayerTo::test_main`
- 目标测试命令:

```bash
export PYTHONPATH="$(pwd)/test/legacy_test:$(pwd)/test/dygraph_to_static${PYTHONPATH:+:$PYTHONPATH}"
export FLAGS_enable_pir_api=0
python -m pytest \
test/legacy_test/test_api_compatibility_part3.py::TestLayerAndTensorToAPI \
-q
python -m pytest \
test/legacy_test/test_api_compatibility_part3.py::TestTensorToCopyCompatibility::test_copy_as_positional_argument \
-q
python -m pytest \
test/legacy_test/test_base_layer.py::TestLayerTo::test_main \
-q
```

- 关键 F2P 场景:
- `Layer.to` 和 `Tensor.to` 接受 dtype、device、参考 Tensor 的位置参数,以及对应的关键字参数组合。
- 支持 `blocking`、`non_blocking` 和 `copy` 的合法调用形式;测试补丁应至少增加一个 `Tensor.to(dtype='float64', copy=True)` 或等价的 `copy` smoke case。新增 benchmark 测试可以补充原 PR 未覆盖的边界,但不能引入 #78593 之后的语义。
- 支持 `blocking`、`non_blocking` 和 `copy` 的合法调用形式;测试补丁增加同 dtype Tensor 的位置参数用例 `tensor.to(paddle.float64, True, True)`,并验证 `copy=True` 返回不同对象。该用例不得引入 #78593 之后的语义。
- 同时设置互相冲突的阻塞参数时抛出 `TypeError`;无参数调用保持合法;参数过多或未知关键字抛出 `TypeError`;无法识别的首个位置参数抛出 `ValueError`。
- `Layer.to` 返回原对象,并对子层执行一致的转换。
- 按 #78301 合入时的行为,使用 dtype 转换 Layer 时,测试中的整数 buffer 也会转换到目标 dtype。后续 #78839 对这一行为的修正不纳入本任务。
- 修复前预期:在 `base_commit` 上应用围绕 #78301 目标行为构造的 `tests/test.patch` 后,新增兼容性用例应出现失败或错误。例如 dtype 作为首个位置参数时会被错误解释为 device,部分位置参数组合、无参数调用或阻塞参数冲突无法按目标行为执行,且新增的 Layer/Tensor 统一调用场景不能全部通过。
- 修复后预期:继续应用仅来自 #78301 非测试文件的 `solution/code.patch` 后,`TestLayerAndTensorToAPI` 及指定的既有 Layer 回归测试全部通过,并满足 #78301 合入时的参数解析和转换行为。
- 修复后预期:继续应用仅来自 #78301 非测试文件的 `solution/code.patch` 后,`TestLayerAndTensorToAPI`、`TestTensorToCopyCompatibility::test_copy_as_positional_argument` 及指定的既有 Layer 回归测试全部通过,并满足 #78301 合入时的参数解析和转换行为。
- P2P 候选:`test/legacy_test/test_base_layer.py::TestLayerTo::test_main` 在 #78301 中未被修改,可作为 Layer.to 既有行为回归护栏;完整任务包阶段还应从同模块中挑选未被 `test.patch` 修改、且在 base 和修复后都通过的存量用例。

## 6. 环境与资源
Expand Down
Loading