Skip to content

[inductor] Fix cpp-wrapper SyntaxError when Triton kernel has docstrings#176796

Closed
desertfire wants to merge 2 commits intogh/desertfire/668/basefrom
gh/desertfire/668/head
Closed

[inductor] Fix cpp-wrapper SyntaxError when Triton kernel has docstrings#176796
desertfire wants to merge 2 commits intogh/desertfire/668/basefrom
gh/desertfire/668/head

Conversation

@desertfire
Copy link
Copy Markdown
Contributor

@desertfire desertfire commented Mar 7, 2026

Stack from ghstack (oldest at bottom):

With autotune_at_compile_time=False, the Triton kernel source is
embedded in a C++ raw string inside the outer Python r"""..."""
wrapper. If a user-defined Triton kernel contains """ (e.g. a
docstring), it prematurely terminates the outer string, causing a
SyntaxError. Fixed by adding backslash.

Authored with Claude.

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

With autotune_at_compile_time=False, the Triton kernel source is
embedded in a C++ raw string inside the outer Python r"""..."""
wrapper. If a user-defined Triton kernel contains """ (e.g. a
docstring), it prematurely terminates the outer string, causing a
SyntaxError. Fix by converting """ to escaped '''.

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 7, 2026

🔗 Helpful Links

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

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

✅ You can merge normally! (10 Unrelated Failures)

As of commit 6666515 with merge base dc49385 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

desertfire added a commit that referenced this pull request Mar 7, 2026
With autotune_at_compile_time=False, the Triton kernel source is
embedded in a C++ raw string inside the outer Python r"""..."""
wrapper. If a user-defined Triton kernel contains """ (e.g. a
docstring), it prematurely terminates the outer string, causing a
SyntaxError. Fix by converting """ to escaped '''.

Authored with Claude.

ghstack-source-id: c5ef4a0
Pull Request resolved: #176796
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 7, 2026

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

…has docstrings"

With autotune_at_compile_time=False, the Triton kernel source is
embedded in a C++ raw string inside the outer Python r"""..."""
wrapper. If a user-defined Triton kernel contains """ (e.g. a
docstring), it prematurely terminates the outer string, causing a
SyntaxError. Fix by converting """ to escaped '''.

Authored with Claude.

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

[ghstack-poisoned]
desertfire added a commit that referenced this pull request Mar 8, 2026
Summary: With autotune_at_compile_time=False, the Triton kernel source is
embedded in a C++ raw string inside the outer Python r"""..."""
wrapper. If a user-defined Triton kernel contains """ (e.g. a
docstring), it prematurely terminates the outer string, causing a
SyntaxError. Fixed by adding backslash.

ghstack-source-id: 774a85f
Pull Request resolved: #176796
@desertfire
Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 9, 2026
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 9, 2026

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@pytorch-bot pytorch-bot Bot added the ciflow/torchtitan Run TorchTitan integration tests label Mar 10, 2026
@desertfire
Copy link
Copy Markdown
Contributor Author

@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

EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
…ngs (pytorch#176796)

With autotune_at_compile_time=False, the Triton kernel source is
embedded in a C++ raw string inside the outer Python r"""..."""
wrapper. If a user-defined Triton kernel contains """ (e.g. a
docstring), it prematurely terminates the outer string, causing a
SyntaxError. Fixed by adding backslash.

Authored with Claude.

Pull Request resolved: pytorch#176796
Approved by: https://github.com/Skylion007, https://github.com/mlazos
ghstack dependencies: pytorch#176745
@github-actions github-actions Bot deleted the gh/desertfire/668/head branch April 10, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor release notes: inductor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants