Skip to content

[Inductor] Fix Enum serialization in user-defined Triton kernel codegen (#189494) - #189494

Closed
mmarthmm wants to merge 1 commit into
pytorch:mainfrom
mmarthmm:export-D92433313
Closed

mmarthmm wants to merge 1 commit into
pytorch:mainfrom
mmarthmm:export-D92433313

Conversation

@mmarthmm

@mmarthmm mmarthmm commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Pull Request resolved: #175900

User-defined Triton kernels can have triton_meta dicts containing Enum values
(e.g., RoundingMode.even from fbgemm). When these are serialized with repr(),
they produce invalid Python syntax like <RoundingMode.even: 2>.

This adds a _sanitize_for_repr helper that recursively converts Enum values
to their underlying value via obj.value before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test test_sanitize_for_repr in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313

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

@pytorch-bot

pytorch-bot Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (6 Unrelated Failures)

As of commit dc8dd04 with merge base 0893b64 (image):

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

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

@meta-codesync

meta-codesync Bot commented Jul 9, 2026

Copy link
Copy Markdown

@mmarthmm has exported this pull request. If you are a Meta employee, you can view the originating Diff in D92433313.

@mmarthmm

Copy link
Copy Markdown
Contributor Author

@claude explain the CI failures, are they related to this PR?

@claude

claude Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Claude finished @mmarthmm's task in 54s —— View job


CI Failure Analysis

Here's a breakdown of the reported failures. Only one is actually caused by this PR — the lint failure. The rest are infrastructure/flaky.

Job Cause Related to this PR?
Lint / lintrunner-noclang-partial B950 line-too-long in wrapper.py ✅ Yes — real, needs fixing
pull / linux-jammy-py3.14-clang18 (test) git checkout failed with HTTP 408 timeout ❌ No — infra/network
pull / before-test / llm-retrieval Job was cancelled ❌ No — just retry
inductor_huggingface (flaky) Matches a known failure on trunk ❌ No — pre-existing flakiness
Details

1. Lint failure (RELATED — action needed)

The docstring you added at torch/_inductor/codegen/wrapper.py:111 is 97 characters, exceeding the project's 88-char limit (B950):

def _sanitize_for_repr(obj: Any) -> Any:
    """Convert Enum values to their underlying value for valid Python repr in code generation."""

Fix: shorten/wrap the docstring, for example:

def _sanitize_for_repr(obj: Any) -> Any:
    """Convert Enum values to their underlying value for a valid Python repr.

    Used during code generation so enums serialize as their plain value.
    """

Or run lintrunner -a locally, which will auto-fix it.

Fix this →

2. linux-jammy-py3.14-clang18 test (NOT related)

Failed during git checkout with RPC failed; HTTP 408 curl 22. No tests ran — this is a network/infra hiccup. Retry the job.

3. before-test / llm-retrieval (NOT related)

Cancelled, not failed. Just needs a retry.

4. inductor_huggingface (NOT related — flaky)

Dr. CI matched this against an existing failure on trunk, so it's pre-existing flakiness unrelated to your Enum-serialization change.

Summary: The only failure caused by this PR is the lint (a 97-char docstring exceeding the 88-char limit at wrapper.py:111). The clang18 test failure, the cancelled llm-retrieval job, and the flaky inductor_huggingface job are all infra/flaky and unrelated — retrying them should clear those. Running lintrunner -a will fix the lint. Want me to push that fix?

@meta-codesync meta-codesync Bot changed the title [Inductor] Fix Enum serialization in user-defined Triton kernel codegen [Inductor] Fix Enum serialization in user-defined Triton kernel codegen (#189494) Jul 13, 2026
mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Jul 13, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Jul 13, 2026
…en (pytorch#189494)

Summary:
Pull Request resolved: pytorch#189494

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
@mmarthmm
mmarthmm force-pushed the export-D92433313 branch 2 times, most recently from c85af32 to 85bc85a Compare July 13, 2026 16:42
mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Jul 13, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 13, 2026
mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Jul 14, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Jul 23, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Jul 28, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Jul 28, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
@mmarthmm

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@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

@mmarthmm

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: inductor"

@mmarthmm

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot 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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 STARTUP failures reported, please check workflows syntax!

Details for Dev Infra team Raised by workflow job

@mmarthmm

mmarthmm commented Aug 4, 2026

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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 STARTUP failures reported, please check workflows syntax!

Details for Dev Infra team Raised by workflow job

mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Aug 4, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
@mmarthmm

mmarthmm commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@claude explain the CI failures, are they related to this PR?

mmarthmm added a commit to mmarthmm/pytorch that referenced this pull request Aug 7, 2026
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
…en (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313
@mmarthmm

mmarthmm commented Aug 7, 2026

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

ankitbhrdwj pushed a commit to ankitbhrdwj/pytorch that referenced this pull request Aug 12, 2026
…en (pytorch#189494) (pytorch#189494)

Summary:

~~Pull Request resolved: pytorch#175900

User-defined Triton kernels can have `triton_meta` dicts containing Enum values
(e.g., `RoundingMode.even` from fbgemm). When these are serialized with `repr()`,
they produce invalid Python syntax like `<RoundingMode.even: 2>`.

This adds a `_sanitize_for_repr` helper that recursively converts Enum values
to their underlying value via `obj.value` before code generation. This handles
IntEnum, StrEnum, and any other Enum subclass generically.

Test Plan: Added unit test `test_sanitize_for_repr` in test_codegen_triton.py covering Enum, IntEnum, nested containers, namedtuples, and passthrough of non-enum values.

Reviewed By: malaybag, angelayi

Differential Revision: D92433313

Pull Request resolved: pytorch#189494
Approved by: https://github.com/angelayi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants