Skip to content

[API Compatibility] Change compatibility apis to ChangePrefixMatcher, inject paddle.enable_compat() -part#895

Open
Manfredss wants to merge 2 commits into
PaddlePaddle:masterfrom
Manfredss:patch_compat
Open

[API Compatibility] Change compatibility apis to ChangePrefixMatcher, inject paddle.enable_compat() -part#895
Manfredss wants to merge 2 commits into
PaddlePaddle:masterfrom
Manfredss:patch_compat

Conversation

@Manfredss

Copy link
Copy Markdown
Collaborator

PR Docs

For the 23 torch.* APIs that are aligned through paddle.compat.*, switch the
converter to the "prefix-only + enable_compat" strategy instead of mapping each to
paddle.compat.X explicitly:

  1. api_mapping.json — change those 23 entries from
    ChangeAPIMatcher → paddle.compat.X to {"Matcher": "ChangePrefixMatcher"}, so
    torch.X(...) converts to paddle.X(...) with arguments untouched
    (e.g. torch.sort(a, dim=-1)paddle.sort(a, dim=-1)).
  2. transformer/import_transformer.py — inject import paddle +
    paddle.enable_compat() right after the imports of any converted file, so the
    prefix-only paddle.X calls resolve to the torch-aligned paddle.compat.X
    implementations at runtime. (Included explicitly + deduped so it is valid even
    when torch was imported as a submodule alias, e.g. import torch.nn as nn.)
  3. tests/apibase.pypaddle.enable_compat() flips global state (an
    import torch → Paddle proxy + paddle.* aliases). Disable it before each
    PyTorch reference run (_ensure_paddle_compat_disabled()), so the reference
    always executes against real PyTorch, including across multiple run() calls in
    one test. (No-op until Paddle is first imported, so it does not change torch/paddle
    import ordering.)

PR APIs

torch.allclose
torch.equal
torch.max
torch.median
torch.min
torch.nanmedian
torch.nn.AvgPool1d
torch.nn.AvgPool2d
torch.nn.AvgPool3d
torch.nn.Linear
torch.nn.MultiheadAttention
torch.nn.softmax
torch.nn.Unfold
torch.nn.functional.linear
torch.nn.functional.log_softmax
torch.nn.functional.pad
torch.nn.functional.scaled_dot_product_attention
torch.nn.functional.softmax
torch.nn.functional.unfold
torch.seed
torch.sort
torch.split
torch.unique

related Paddle PR:

Co-authored by Claude.

@Manfredss Manfredss closed this Jun 29, 2026
@Manfredss Manfredss reopened this Jun 29, 2026
@Manfredss Manfredss marked this pull request as draft June 29, 2026 12:59
@Manfredss Manfredss marked this pull request as ready for review June 29, 2026 13:00
@paddle-bot paddle-bot Bot added the contributor External developers label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant