Skip to content

[xpu][fix] Fix reflection/replication pad output memory format to match eager behavior - #184484

Closed
guangyey wants to merge 1 commit into
gh/guangyey/342/basefrom
gh/guangyey/342/head
Closed

guangyey wants to merge 1 commit into
gh/guangyey/342/basefrom
gh/guangyey/342/head

Conversation

@guangyey

@guangyey guangyey commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator

@pytorch-bot

pytorch-bot Bot commented May 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/184484

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit c9b628e with merge base cfddb74 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@jansel

jansel commented May 20, 2026

Copy link
Copy Markdown
Contributor

@claude review these changes

@claude

claude Bot commented May 20, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 1m 38s —— View job


Review: Fix reflection/replication pad output memory format for XPU

  • Gather context (read diff, referenced issue, relevant code)
  • Analyze the fix for correctness
  • Post review feedback

Verdict: Looks good ✅

This is a straightforward and correct fix. The change adds "xpu" to the device type check at torch/_decomp/decompositions.py:5225 so that XPU uses torch.contiguous_format for the output of reflection/replication padding decompositions, matching CUDA and MPS behavior.

Why this is correct:

  1. XPU has no dedicated dispatch for reflection_pad*/replication_pad* in native_functions.yaml — it falls through to use CUDA-style kernels that write to a flat contiguous buffer with linear indexing (confirmed by ReflectionPad.cu:566 calling .contiguous() on input).

  2. The decomposition must match the eager kernel's output memory format. Without this fix, XPU would use suggest_memory_format(a) (the CPU path), potentially producing channels_last output when eager would produce contiguous — causing mismatches.

  3. The backward decomposition already handles XPU separately (line 5780: if grad_output.is_xpu: return NotImplemented), falling back to the native kernel, so no backward change is needed.

Minor note: The comment updates (lines 5220, 5223) accurately document the extended behavior — nice to see the comments kept in sync.

No issues found. Ship it.


@jansel jansel added the topic: not user facing topic category label May 20, 2026
[ghstack-poisoned]
@guangyey

Copy link
Copy Markdown
Collaborator Author

Thanks!
@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants