Skip to content
Open
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
51 changes: 51 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-73691/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# PaddlePaddle__Paddle-73691

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

## Source

| Field | Value |
| --- | --- |
| Repo | `PaddlePaddle/Paddle` |
| PR | [73691](https://github.com/PaddlePaddle/Paddle/pull/73691) |
| PR title | `[0-size Tensor No.159、161、163] Add 0-size Tensor support for conv1d` |
| Base commit | `3efb8dbb51547f0235a402135c54ed83c2f12d61` |
| Gold commit | `8fb677bc3c9678fb9ef31044f9ba624616a3ee06` |
| Merged at | `2025-07-01` |
| Task type | `bug_fix` |
| Resource | CPU |
| Scope | C++ Operator Kernel |

## Summary

Fix `paddle.nn.functional.conv1d`, `conv2d`, `conv3d` to correctly handle 0-size tensors in CPU/GPU/XPU kernels by adding early-return logic when input has 0 elements, and fixing InferMeta to correctly compute output shapes for 0-size inputs.

## Why This Is A Good SWE-Paddle Candidate

- It is derived from a merged Paddle bug-fix PR rather than a synthetic issue.
- The target behavior is isolated to the C++ operator kernel level and requires rebuilding Paddle from source.
- The failure is deterministic: the base revision fails when processing 0-size tensors due to missing early-return logic in conv kernels and incorrect InferMeta shape computation.
- The task has clear regression coverage for existing non-zero-size behavior.
- The task runs on CPU and does not require distributed execution, external services, or additional datasets.

## Files

- `proposal.md`: candidate proposal for maintainer triage.
- `instruction.md`: self-contained problem statement for the coding agent.
- `solution/code.patch`: gold implementation patch (C++ kernel changes).
- `tests/test.patch`: tests exposing the target behavior.
- `tests/test.sh`: minimal target test command.
- `environment/README.md`: environment and reproduction notes.

## Verification

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

Expected behavior:

| Revision state | Existing behavior (P2P) | conv F2P |
| --- | ---: | ---: |
| Base + `tests/test.patch` | PASS | FAIL |
| Base + `tests/test.patch` + `solution/code.patch` | PASS | PASS |
52 changes: 52 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-73691/environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Environment Notes

## Expected Environment

- Repository: `PaddlePaddle/Paddle`
- Base commit: `3efb8dbb51547f0235a402135c54ed83c2f12d61`
- Gold commit: `8fb677bc3c9678fb9ef31044f9ba624616a3ee06`
- Resource: CPU
- GPU required: no
- Patch type: C++ kernel (CPU/GPU/XPU backends) + InferMeta + Symbolic Shape
- Python dependencies: PaddlePaddle (source build), NumPy

The verifier should execute against the Paddle source revision represented by the selected patch state. A source build is required since the patch modifies C++ kernel code, InferMeta, and symbolic shape inference.

## Build Instructions

1. Check out `PaddlePaddle/Paddle` at the base commit.
2. Apply `tests/test.patch`.
3. Build Paddle from source (CPU-only build is sufficient):
```bash
mkdir build && cd build
cmake .. -DWITH_GPU=OFF -DWITH_TESTING=ON -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
```
4. Install the built Paddle package.

## Run Order

1. Check out `PaddlePaddle/Paddle` at the base commit.
2. Build and install Paddle from source.
3. Apply `tests/test.patch`.
4. Run the P2P tests; existing non-zero-size behavior should pass.
5. Run the 0-size tensor tests; the target case should fail before the fix.
6. Apply `solution/code.patch`.
7. Rebuild Paddle from source.
8. Reinstall Paddle package.
9. Run `bash tests/test.sh`; all target tests should pass.

## Minimal Test Command

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

## Expected Matrix

| Revision state | P2P | conv F2P |
| --- | ---: | ---: |
| Base + test patch | PASS | FAIL |
| Base + test patch + solution patch | PASS | PASS |

No GPU, distributed runtime, external service, or additional dataset is required.
61 changes: 61 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-73691/instruction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 修复 `paddle.nn.functional.conv1d/conv2d/conv3d` 对 0-size Tensor 的处理

## 详细描述

当 `paddle.nn.functional.conv1d/conv2d/conv3d` 的输入为 0-size Tensor 时,当前 CPU/GPU/XPU kernel 实现会直接进入后续计算逻辑,导致 kernel 内部对空数据执行计算或产生其他错误。同时,InferMeta 对 0-size 输入的输出形状计算也不正确。

典型表现包括:

- kernel 在执行卷积计算时崩溃或报错
- 0-size Tensor 输入无法通过 `conv1d/conv2d/conv3d` 算子
- InferMeta 计算出的输出形状不正确

例如:

```python
import numpy as np
import paddle

paddle.disable_static()

# conv1d 0-size tensor 输入
x = paddle.to_tensor(np.random.randn(0, 1, 2).astype('float32'))
filter = paddle.to_tensor(np.random.randn(1, 1, 2).astype('float32'))
out = paddle.nn.functional.conv1d(x, filter)
# 期望返回 shape 为 (0, 1, 1) 的全零 Tensor

# conv2d 0-size tensor 输入
x = paddle.to_tensor(np.random.random([0, 3, 4, 4]).astype('float32'))
filter = paddle.to_tensor(np.random.random([2, 3, 3, 3]).astype('float32'))
out = paddle.nn.functional.conv2d(x, filter)
# 期望返回 shape 为 (0, 2, 2, 2) 的全零 Tensor

# conv3d 0-size tensor 输入
x = paddle.to_tensor(np.random.random([4, 3, 0, 8, 8]).astype('float32'))
filter = paddle.to_tensor(np.random.random([5, 3, 3, 3, 3]).astype('float32'))
out = paddle.nn.functional.conv3d(x, filter, padding=1)
# 期望返回 shape 为 (4, 5, 0, 8, 8) 的全零 Tensor
```

上述调用中输入包含 0-size 维度。按照 API 语义,0-size Tensor 的卷积操作应正常返回正确 shape 的全零 Tensor。

需要在 CPU/GPU/XPU kernel 层添加 0-size 早期返回处理,并修复 InferMeta 的形状计算逻辑:
- 在卷积前向 kernel 中,检查输入 `input.numel() == 0` 并使用 `phi::Full` 填充全零后直接返回
- 在卷积反向 kernel 中,检查输入 `input.numel() == 0` 并分配内存后直接返回
- 在 InferMeta 中,修复对 0-size 输入的输出形状计算

## 验收说明

- 当输入为 0-size Tensor 时,`paddle.nn.functional.conv1d/conv2d/conv3d` 应正常完成,返回正确 shape 的全零 Tensor
- 输出的 shape 应与输入一致
- 非 0-size Tensor 输入下的 conv1d/conv2d/conv3d 行为不得退化
- 梯度计算也应正常工作(0-size Tensor 的梯度也为全零 Tensor)

## 技术要求

- 熟悉 C++ 和 Paddle PHI kernel 开发
- 了解 Tensor shape、0-size Tensor 和 kernel 执行路径
- 了解 conv1d/conv2d/conv3d 算子的输入输出语义
- 了解 Paddle CPU/GPU/XPU kernel 的实现模式
- 了解 InferMeta 的形状推导机制
- 需要从源码编译 Paddle 以验证修改
60 changes: 60 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-73691/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SWE-Paddle Task Proposal: PaddlePaddle__Paddle-73691

## 1. 来源信息

- Instance ID: `PaddlePaddle__Paddle-73691`
- PR 链接: https://github.com/PaddlePaddle/Paddle/pull/73691
- PR 标题: `[0-size Tensor No.159、161、163] Add 0-size Tensor support for conv1d`
- Base commit: `3efb8dbb51547f0235a402135c54ed83c2f12d61`
- Gold commit: `8fb677bc3c9678fb9ef31044f9ba624616a3ee06`
- Merged at: 2025-07-01
- 你的身份: contributor

## 2. 问题一句话

`paddle.nn.functional.conv1d/conv2d/conv3d` 在输入为 0-size Tensor 时,CPU/GPU/XPU kernel 未处理 0-size 边界情况导致崩溃或报错,需要在 kernel 入口添加 0-size 早期返回逻辑,并修复 InferMeta 的形状计算。

## 3. 为什么适合作为 SWE-Paddle 样本

- **真实性**: 来自 Paddle「0-size Tensor 机制建设」系列任务,是真实研发需求。
- **代表性**: 覆盖 C++ kernel 层面的 0-size Tensor 边界处理,涉及 CPU/GPU/XPU 三端 kernel、梯度 kernel 和 InferMeta。
- **边界清楚**: 目标仅限输入为 0-size 时的 kernel 早期返回和形状计算;正向非零尺寸输入不应受影响。
- **非平凡性**: 修复需要在多个 kernel 中添加 `input.numel() == 0` 的早期返回,并使用 `phi::Full` 填充全零,同时修复 InferMeta 对 0-size 输入的形状推导,涉及对 kernel 执行流程和形状推导机制的理解。
- **回归护栏明确**: 目标 F2P 可覆盖 0-size Tensor 输入的 `conv1d/conv2d/conv3d` 算子测试;同文件中已有的标准测试用例可作为 P2P 护栏。

## 4. 任务类型和标签

- 任务类型: `bug_fix`
- 执行后端: `cpu`
- 设备范围: `cpu_only`
- 模块标签: `[operator_kernel, conv1d, conv2d, conv3d, 0-size_tensor, cpu_kernel, gpu_kernel, xpu_kernel]`

## 5. 验证思路

- 目标测试命令: `bash tests/test.sh`
- 目标测试文件:
- `test/legacy_test/test_functional_conv1d.py`(`TestFunctionalConv1D_ZeroSize`)
- `test/legacy_test/test_functional_conv2d.py`(`TestFunctionalConv2D_ZeroSize`)
- `test/legacy_test/test_functional_conv3d.py`(`TestFunctionalConv3D_ZeroSize2`)
- P2P 候选: 同文件中已有的 `TestFunctionalConv1DError`、`TestFunctionalConv2DError`、`TestFunctionalConv3DError` 等标准算子测试用例。
- 修复前预期: `base_commit` + `tests/test.patch` 后,0-size Tensor 输入的算子测试失败(kernel 崩溃或报错)。
- 修复后预期: 继续应用 `solution/code.patch` 并重新编译后,0-size Tensor 输入正常返回全零 Tensor,P2P 存量测试仍然通过。

## 6. 环境与资源

- 是否能提供 Docker: 无
- Dockerfile 或镜像地址: 暂无
- Paddle 来源: `PaddlePaddle/Paddle` source checkout at `base_commit`,需要源码编译。
- OS / Python / CUDA / cuDNN / 其他关键依赖: Linux CPU + Python + numpy;编译需要 CMake、GCC;不要求 CUDA/cuDNN(CPU 编译即可验证)。
- 硬件: CPU 即可(编译和测试均不需要 GPU)。
- patch 类型: 含 C++ kernel 修改(CPU/GPU/XPU 三端)+ InferMeta + 符号推导,需要重新编译 Paddle。
- 最小测试命令: `bash tests/test.sh`
- 是否有 oracle 日志: 无

## 7. 风险自查

- 泄露风险: 正式 `instruction.md` 只描述「conv1d/conv2d/conv3d 对 0-size Tensor 输入的行为异常」,不指出具体 `input.numel() == 0` 分支逻辑或具体代码位置。
- 环境风险: 中。任务涉及 C++ kernel 修改,需要源码编译 Paddle,编译时间较长。
- flaky 风险: 低。测试使用固定的 0-size Tensor 构造,不依赖随机数差异或多设备同步。
- 拆分风险: 低。该 PR 目标集中在 `conv1d/conv2d/conv3d` 的 CPU/GPU/XPU kernel 0-size 早期返回和 InferMeta 形状修复,测试明确指向新增的 ZeroSize 测试类,适合作为一个独立样本。
- 其他不确定点: 完整任务包阶段应确认新增 F2P 在 `base_commit` 编译后确实失败。注意该 PR 同时修改了前向和反向 kernel,以及 InferMeta 和符号推导。
Loading