Skip to content

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

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

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

Conversation

@shafeeqi-meta

@shafeeqi-meta shafeeqi-meta commented Feb 26, 2026 •

Copy link
Copy Markdown

Summary:

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 commented Feb 26, 2026

Copy link
Copy Markdown

This appears to be a diff that was exported from phabricator, but the PR author does not have sufficient permissions to run CI. @shafeeqi-meta, please do step 2 of internal wiki to get write access so you do not need to get CI approvals in the future. If you think this is a mistake, please contact the Pytorch Dev Infra team.

@pytorch-bot

pytorch-bot Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit 4aefd2c with merge base 1d7fb59 (image):

NEW FAILURES - The following jobs have failed:

  • Lint / lintrunner-noclang-all / lint (gh)
    >>> Lint for torch/_inductor/codegen/wrapper.py:

    AI verdict: AI verdict: related

    The lint failure is caused by new code introduced in this commit: getattr(type(obj), &quot;_make&quot;) on line 118 of torch/_inductor/codegen/wrapper.py triggers linter rule B009, and the test file has a formatting issue. Both files were added/modified by this PR.

    Full reasoning on HUD →

  • trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 1, 8, linux.rocm.gpu.gfx950.1) (gh)
    test/inductor/test_torchinductor_codegen_dynamic_shapes.py::DynamicShapesCodegenCpuTests::test_nan_assert_inside_triton_kernel_dynamic_shapes_cpu

    AI verdict: AI verdict: probably not related

    The commit only modifies the user-defined Triton kernel codegen path (user_autotune), while the failing test test_nan_assert_inside_triton_kernel uses regular torch.compile on a standard function. The _sanitize_for_repr function added by this commit is never invoked during the failing test's execution.

    Full reasoning on HUD →

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: mmarthmm / name: Martha Martinez (4aefd2c)

@pytorch-bot

pytorch-bot Bot commented Feb 26, 2026

Copy link
Copy Markdown

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.

@meta-codesync

meta-codesync Bot commented Feb 26, 2026

Copy link
Copy Markdown

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

shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Feb 26, 2026
…en (pytorch#175900)

Summary:

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.

Differential Revision: D92433313
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Feb 26, 2026
…en (pytorch#175900)

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.

Differential Revision: D92433313
@meta-codesync

meta-codesync Bot commented Feb 26, 2026

Copy link
Copy Markdown

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

shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Feb 26, 2026
…en (pytorch#175900)

Summary:

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.

Differential Revision: D92433313
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Feb 26, 2026
…en (pytorch#175900)

Summary:

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.

Differential Revision: D92433313
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Feb 28, 2026
…en (pytorch#175900)

Summary:

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.

Differential Revision: D92433313
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Feb 28, 2026
…en (pytorch#175900)

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.

Differential Revision: D92433313
@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 (#175900) Apr 9, 2026
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Apr 9, 2026
…en (pytorch#175900)

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

Differential Revision: D92433313
@pytorch-bot pytorch-bot Bot added ciflow/trunk Trigger trunk jobs on your pull request ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests labels May 1, 2026
@pytorch-bot

pytorch-bot Bot commented May 4, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request May 4, 2026
…en (pytorch#175900)

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
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request May 5, 2026
…en (pytorch#175900)

Summary:

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
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request May 7, 2026
…en (pytorch#175900)

Summary:

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
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request May 14, 2026
…en (pytorch#175900)

Summary:

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
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Jun 11, 2026
…en (pytorch#175900)

Summary:

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
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Jun 11, 2026
…en (pytorch#175900)

Summary:

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
shafeeqi-meta added a commit to shafeeqi-meta/pytorch that referenced this pull request Jun 11, 2026
…en (pytorch#175900)

Summary:

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

jansel commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

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

@claude

claude Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 50s —— View job


CI failure analysis

  • Inspect the NEW lint failure on wrapper.py
  • Check the BROKEN TRUNK failures against merge base
  • Determine which failures are related to this PR

Short answer: Only the lint failure is caused by this PR. The other 8 are pre-existing broken-trunk failures unrelated to your change.


❌ Related to this PR (1 failure)

Lint / lintrunner-noclang-all — this one is real and from this PR's new code.

_sanitize_for_repr in torch/_inductor/codegen/wrapper.py:109 trips bugbear rule B009 (both RUFF and FLAKE8):

if isinstance(obj, tuple) and hasattr(obj, "_fields"):
    return getattr(type(obj), "_make")(            # <-- B009: getattr with a constant attr
        _sanitize_for_repr(getattr(obj, field)) for field in obj._fields
    )

getattr(type(obj), "_make") uses a constant string attribute, which B009 flags as no safer than direct access. Fix is to call the attribute directly:

if isinstance(obj, tuple) and hasattr(obj, "_fields"):
    return type(obj)._make(
        _sanitize_for_repr(getattr(obj, field)) for field in obj._fields
    )

(The inner getattr(obj, field) is fine — field is a variable, not a constant.) There was also a format warning on the same file; running lintrunner -a will fix both.

Fix this →


✅ NOT related to this PR (8 failures)

Dr. CI classifies all of these as BROKEN TRUNK — they also fail on the merge base commit 780edd2, so they are not introduced by this PR:

Failure Cause
inductor-cpu-build / build-osdc (x2) + verify-cachebench-cpu-build Executing the custom container implementation failed — infra/runner issue
inductor_huggingface test requires accelerate. install it with pip install accelerate — missing dependency in env
inductor_torchbench (fastNLP_Bert, torch_multimodal_clip) Pre-existing benchmark model failures on trunk
py3.14t-clang18 test_logs_out Pre-existing dynamo logging test failure on trunk
torchtitan_features_integration Pre-existing torchtitan feature-test failure on trunk

These are infra/environment/pre-existing problems. Rebasing onto viable/strict would avoid them.


Recommendation: Run lintrunner -a locally and push the fix — that's the only failure attributable to this change. Want me to apply the lint fix to the branch?
· Lint job

…en (pytorch#175900)

Summary:

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#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 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 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 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 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
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
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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants