Skip to content

[MPS][Inductor] Add _print_Where method to MetalExprPrinter for ReflectionPad support#169648

Closed
lingebeng wants to merge 2 commits intopytorch:mainfrom
lingebeng:linhaifeng/bug_fix/inductor_01
Closed

[MPS][Inductor] Add _print_Where method to MetalExprPrinter for ReflectionPad support#169648
lingebeng wants to merge 2 commits intopytorch:mainfrom
lingebeng:linhaifeng/bug_fix/inductor_01

Conversation

@lingebeng
Copy link
Contributor

@lingebeng lingebeng commented Dec 5, 2025

The MetalExprPrinter class was missing a _print_Where() method, causing sympy Where expressions to be emitted as raw Where(...) function calls in generated Metal Shading Language (MSL) code. Since Where is not a standard MSL function,compilation failed with "undeclared identifier 'Where'" error.

This PR adds the missing _print_Where() method to convert Where(condition, true_val, false_val) to Metal's C-style ternary operator condition ? true_val : false_val, following the same pattern as CppPrinter.

Fixes #169643

cc @kulinseth @malfet @DenisVieriu97 @jhavukainen @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

@pytorch-bot
Copy link

pytorch-bot bot commented Dec 5, 2025

🔗 Helpful Links

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

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

✅ No Failures

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

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

@malfet malfet added topic: bug fixes topic category module: mps Related to Apple Metal Performance Shaders framework ciflow/mps Run MPS tests (subset of trunk) labels Dec 5, 2025
@malfet
Copy link
Contributor

malfet commented Dec 5, 2025

@lingebeng Let's wait for CI, but something tells me you'll have to uncomment one of @expectedFailureMps conditions
If not, it would be nice to add a test

@malfet malfet added the release notes: mps Release notes category label Dec 5, 2025
@malfet malfet self-requested a review December 5, 2025 15:46
@malfet malfet added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Dec 5, 2025
Copy link
Contributor

@malfet malfet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised I haven't run into it before
And yes, test_reflection_pad2d_dynamic_shapes_mps fails with unexpected success

@pytorch-bot pytorch-bot bot removed the ciflow/mps Run MPS tests (subset of trunk) label Dec 5, 2025
@malfet malfet added the ciflow/mps Run MPS tests (subset of trunk) label Dec 5, 2025
@malfet
Copy link
Contributor

malfet commented Dec 5, 2025

@pytorchbot merge -f "Lint + MPS are green"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

umechand-amd pushed a commit to ROCm/pytorch that referenced this pull request Dec 8, 2025
…ctionPad support (pytorch#169648)

The `MetalExprPrinter` class was missing a `_print_Where()` method, causing sympy `Where` expressions to be emitted as raw `Where(...)` function calls in generated Metal Shading Language (MSL) code. Since `Where` is not a standard MSL function,compilation failed with "undeclared identifier 'Where'" error.

This PR adds the missing `_print_Where()` method to convert `Where(condition, true_val, false_val)` to Metal's C-style ternary operator `condition ? true_val : false_val`, following the same pattern as `CppPrinter`.

Fixes pytorch#169643

Pull Request resolved: pytorch#169648
Approved by: https://github.com/malfet

Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com>
JacobSzwejbka pushed a commit that referenced this pull request Dec 8, 2025
…ctionPad support (#169648)

The `MetalExprPrinter` class was missing a `_print_Where()` method, causing sympy `Where` expressions to be emitted as raw `Where(...)` function calls in generated Metal Shading Language (MSL) code. Since `Where` is not a standard MSL function,compilation failed with "undeclared identifier 'Where'" error.

This PR adds the missing `_print_Where()` method to convert `Where(condition, true_val, false_val)` to Metal's C-style ternary operator `condition ? true_val : false_val`, following the same pattern as `CppPrinter`.

Fixes #169643

Pull Request resolved: #169648
Approved by: https://github.com/malfet

Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mps Run MPS tests (subset of trunk) Merged module: inductor module: mps Related to Apple Metal Performance Shaders framework open source release notes: mps Release notes category topic: bug fixes topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MPS][Inductor] ReflectionPad{1,2,3}d compilation fails with "undeclared identifier 'Where'" in generated MSL code

4 participants