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

This directory converts merged Paddle PR #78823 into a SWE-Paddle community task package.

## Source

| Field | Value |
| --- | --- |
| Repository | `PaddlePaddle/Paddle` |
| PR | [78823](https://github.com/PaddlePaddle/Paddle/pull/78823) |
| PR title | `[API Compatibility] add pin_memory for randint` |
| Base commit | `c3a5e799eb9e390f830c9e6c3fbea2e9370afa7f` |
| Gold commit | `ddb483237539d4d23c7dbbd44e3a360439c780ed` |
| Merged at | `2026-05-12` |
| Task type | `bug_fix` |
| Track | Python API compatibility |
| Resource | CUDA or XPU for complete verification; CPU-only for limited error-path coverage |

## Summary

Make `pin_memory=True` use consistent place-conversion semantics across tensor creation, random generation (including `randint`), and audio window creation. CPU placement must use the available CUDA/XPU pinned allocator, explicit accelerator and already-pinned places must resolve consistently, and builds without a pinned allocator must report an explicit unsupported error.

## Scope

The gold change is Python-only and covers place handling used by tensor creation and random APIs. The upstream regression tests exercise CUDA, XPU, already-pinned, CPU fallback, and unsupported CPU-only behavior; hardware-dependent cases remain conditional.

## Artifacts

- `proposal.md`: original candidate proposal and source rationale.
- `instruction.md`: self-contained task requirements for the coding agent.
- `environment/README.md`: checkout, build, device, and reproduction notes.
- `solution/code.patch`: exact production-file diff from base to gold commit.
- `tests/test.patch`: exact test-file diff from base to gold commit.
- `tests/test.sh`: strict wrapper for the five target test files.

## Verification

From a built Paddle checkout with the patches applied in the documented order:

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

A CPU-only run is not complete verification because accelerator allocator branches are unavailable or skipped.
52 changes: 52 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-78823/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: `c3a5e799eb9e390f830c9e6c3fbea2e9370afa7f`
- Gold commit: `ddb483237539d4d23c7dbbd44e3a360439c780ed`
- Patch type: Python production and test files
- Python dependency: `pytest`
- Complete resource requirement: one CUDA or XPU device with a matching Paddle source build

## Checkout and build

Start from a clean checkout of the exact base commit. The tests import Paddle's compiled runtime and instantiate device places, so use a Paddle installation built from this checkout (or an equivalent build whose Python source is overlaid by this checkout). A source build is recommended to keep the Python API and compiled extension aligned with the historical revision.

Follow Paddle's build prerequisites for the selected backend. CUDA validation requires a CUDA-enabled build and compatible CUDA/cuDNN runtime; XPU validation requires an XPU-enabled build and runtime. No dataset, network service, multi-device topology, or distributed setup is required.

## Device limitations

- CUDA builds can validate CUDA-place conversion, CUDA pinned allocation, CPU-to-CUDA-pinned behavior, and CUDA-conditional API tests.
- XPU builds can validate XPU-place conversion, XPU pinned allocation, and CPU-to-XPU-pinned behavior.
- CPU-only builds have no pinned allocator. They can validate the explicit `Pinning memory is not supported` path and some mocked branch coverage, but accelerator-dependent tests are skipped or cannot allocate pinned memory. A green CPU-only run is therefore not complete task verification.

## Patch application order

From the Paddle repository root, assuming this task directory is available as `$TASK_DIR`:

```bash
git checkout c3a5e799eb9e390f830c9e6c3fbea2e9370afa7f
git apply "$TASK_DIR/tests/test.patch"
bash "$TASK_DIR/tests/test.sh" # expected to expose failures before the fix
git apply "$TASK_DIR/solution/code.patch"
bash "$TASK_DIR/tests/test.sh" # expected to pass on a compatible build/device
```

Apply the test patch before the solution patch. Both patches are rooted at the Paddle repository root.

## Exact test command

`tests/test.sh` runs:

```bash
python -m pytest \
test/legacy_test/test_to_pinned_place.py \
test/legacy_test/test_eager_tensor.py \
test/legacy_test/test_rand.py \
test/legacy_test/test_randint_op.py \
test/legacy_test/test_randperm_op.py \
-q
```

Run it from the root of the built Paddle checkout. Before applying the solution, new tests requiring the missing behavior should fail on a compatible accelerator build. After applying the solution, all applicable tests should pass; backend-conditional skips are expected when that backend is unavailable.
45 changes: 45 additions & 0 deletions swe-paddle/tasks/PaddlePaddle__Paddle-78823/instruction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Unify pinned-memory place behavior for creation APIs

## Problem

Paddle's dynamic tensor-creation and random-generation APIs do not handle `pin_memory=True` consistently. In particular, calls such as `randint(..., device="cpu", pin_memory=True)` can reject CPU placement even when the build provides a CUDA or XPU pinned-host allocator, while related APIs contain differing conversion behavior.

Implement consistent pinned-memory place semantics across the affected creation paths without changing normal behavior when pinned memory is not requested.

## Required behavior

When `pin_memory=True` is active on a supported dynamic execution path:

- An already CUDA-pinned or XPU-pinned place remains unchanged.
- A CUDA place resolves to CUDA pinned host memory.
- An XPU place resolves to XPU pinned host memory.
- A CPU place resolves to an available pinned host allocator:
- use XPU pinned memory in an XPU-enabled build;
- otherwise use CUDA pinned memory in a CUDA-enabled build;
- if neither allocator is compiled in, raise `RuntimeError` with a clear message containing `Pinning memory is not supported`.
- Unsupported place kinds raise the same explicit `RuntimeError` rather than silently falling back.

The CPU behavior applies whether the device is supplied as a string or as a Paddle place object. Preserve existing device defaults, shapes, dtypes, gradient flags, output semantics, and static/PIR behavior outside the dynamic pinned-memory path.

## Affected API families

Apply these semantics consistently to:

- tensor conversion/creation, including `tensor`;
- shape- and value-based creators such as `full`, `full_like`, `eye`, `arange`, `empty`, and `empty_like`;
- random creators, including `rand`, `randn`, `randint`, and `randperm`;
- audio window creation paths that expose the same `device` and `pin_memory` behavior.

`randint` must support CPU placement with `pin_memory=True` on CUDA- or XPU-enabled builds and return a tensor with the requested shape on the corresponding pinned place.

## Verification

The implementation must pass the target tests in:

- `test/legacy_test/test_to_pinned_place.py`
- `test/legacy_test/test_eager_tensor.py`
- `test/legacy_test/test_rand.py`
- `test/legacy_test/test_randint_op.py`
- `test/legacy_test/test_randperm_op.py`

Verify both successful allocator-backed branches and explicit unsupported behavior. Accelerator tests may remain conditional on compile-time support, but a CPU-only run must not be represented as complete CUDA/XPU validation. Do not delete tests, weaken assertions, or bypass unsupported-device checks.
Loading