Skip to content

[Typing] Fix TypeVar misuse in triton_heuristics - #184412

Closed
malfet wants to merge 3 commits into
gh/malfet/912/basefrom
gh/malfet/912/head
Closed

malfet wants to merge 3 commits into
gh/malfet/912/basefrom
gh/malfet/912/head

Conversation

@malfet

@malfet malfet commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

The _T TypeVar was declared with bound=_KernelType, where _KernelType is a CompiledKernel | StaticallyLaunchedCudaKernel | StaticallyLaunchedXpuKernel union.
A union bound doesn't give a TypeVar any real constraining power; the spec-correct form for "exactly one of these three" is a constrained TypeVar (positional arguments).
Switch to that, keep _KernelType as an explicit TypeAlias for the few sites that genuinely want the union (return types, local annotations), and pin the two definitions together with an import-time assert so they can't silently drift.
The three aggregate CompileResult[_KernelType] sites become CompileResult[Any] since a constrained TypeVar can't be parameterized with the union itself.

Fixes #184159
Authored by Claude

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

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented May 19, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit 92f2aa0 with merge base 2aa7215 (image):

NEW FAILURE - The following job has failed:

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.

@malfet
malfet requested a review from jansel May 19, 2026 21:09
@malfet malfet added the topic: not user facing topic category label May 19, 2026
[ghstack-poisoned]
malfet added a commit that referenced this pull request May 19, 2026
The `_T` TypeVar was declared with `bound=_KernelType`, where `_KernelType` is a `CompiledKernel | StaticallyLaunchedCudaKernel | StaticallyLaunchedXpuKernel` union.
A union bound doesn't give a TypeVar any real constraining power; the spec-correct form for "exactly one of these three" is a constrained TypeVar (positional arguments).
Switch to that, keep `_KernelType` as an explicit `TypeAlias` for the few sites that genuinely want the union (return types, local annotations), and pin the two definitions together with an import-time assert so they can't silently drift.
The three aggregate `CompileResult[_KernelType]` sites become `CompileResult[Any]` since a constrained TypeVar can't be parameterized with the union itself.

Fixes #184159
Authored by Claude

ghstack-source-id: cf43a51
Pull-Request: #184412

@Skylion007 Skylion007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't get why they can't be parameteized with a Union


def _make_launcher(
self, compile_result: CompileResult[_KernelType]
self, compile_result: CompileResult[Any]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feel like there should be able to be something more specific used than Any here.

[ghstack-poisoned]
malfet added a commit that referenced this pull request May 22, 2026
The `_T` TypeVar was declared with `bound=_KernelType`, where `_KernelType` is a `CompiledKernel | StaticallyLaunchedCudaKernel | StaticallyLaunchedXpuKernel` union.
A union bound doesn't give a TypeVar any real constraining power; the spec-correct form for "exactly one of these three" is a constrained TypeVar (positional arguments).
Switch to that, keep `_KernelType` as an explicit `TypeAlias` for the few sites that genuinely want the union (return types, local annotations), and pin the two definitions together with an import-time assert so they can't silently drift.
The three aggregate `CompileResult[_KernelType]` sites become `CompileResult[Any]` since a constrained TypeVar can't be parameterized with the union itself.

Fixes #184159
Authored by Claude

ghstack-source-id: fb3e03b
Pull-Request: #184412
@malfet

malfet commented May 22, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 22, 2026
@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 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10-mi355 / test (distributed, 1, 4, linux.rocm.gpu.gfx950.2)

Details for Dev Infra team Raised by workflow job

@jansel

jansel commented May 22, 2026

Copy link
Copy Markdown
Contributor

@claude explain those CI failures, are they related?

@claude

claude Bot commented May 22, 2026 •

Copy link
Copy Markdown

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


  • Analyze CI failures
  • Determine if failures are related to PR changes

CI Failure Analysis

No, the CI failures are not related to this PR.

The single failure (trunk / linux-jammy-rocm-py3.10-mi355 / test (distributed, 1, 4, linux.rocm.gpu.gfx950.2)) is an AWS S3 permissions error, not a test failure:

User: arn:aws:sts::308535385114:assumed-role/gha_workflow_s3_and_ecr_read_only/gha-ecr-login
is not authorized to perform: s3:PutObject on resource:
"arn:aws:s3:::gha-artifacts/pytorch/pytorch/26272391427/1/artifact/logs-test-distributed-1-4-linux.rocm.gpu.gfx950.2_77333053558.zip"
because no identity-based policy allows the s3:PutObject action

The CI runner's IAM role (gha_workflow_s3_and_ecr_read_only) lacks s3:PutObject permission to upload test log artifacts. The role name itself says "read_only" — this is an infrastructure/permissions misconfiguration, completely unrelated to the typing changes in triton_heuristics.py.

The cancelled job (test (default, 3, 10, linux.rocm.gpu.gfx950.1)) was likely cancelled as a downstream consequence or resource issue on the same ROCm runner pool.

TL;DR: Infrastructure issue with ROCm CI runners' S3 permissions. Safe to retry or override.


@malfet

malfet commented May 26, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: trunk / linux-jammy-rocm-py3.10-mi355 / test (distributed, 1, 4, linux.rocm.gpu.gfx950.2), trunk / linux-jammy-rocm-py3.10-mi355 / test (default, 3, 10, linux.rocm.gpu.gfx950.1)

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

tinglvv pushed a commit that referenced this pull request May 28, 2026
The `_T` TypeVar was declared with `bound=_KernelType`, where `_KernelType` is a `CompiledKernel | StaticallyLaunchedCudaKernel | StaticallyLaunchedXpuKernel` union.
A union bound doesn't give a TypeVar any real constraining power; the spec-correct form for "exactly one of these three" is a constrained TypeVar (positional arguments).
Switch to that, keep `_KernelType` as an explicit `TypeAlias` for the few sites that genuinely want the union (return types, local annotations), and pin the two definitions together with an import-time assert so they can't silently drift.
The three aggregate `CompileResult[_KernelType]` sites become `CompileResult[Any]` since a constrained TypeVar can't be parameterized with the union itself.

Fixes #184159
Authored by Claude

Pull Request resolved: #184412
Approved by: https://github.com/jansel, https://github.com/Skylion007
khushi-411 pushed a commit to khushi-411/pytorch that referenced this pull request Jun 1, 2026
The `_T` TypeVar was declared with `bound=_KernelType`, where `_KernelType` is a `CompiledKernel | StaticallyLaunchedCudaKernel | StaticallyLaunchedXpuKernel` union.
A union bound doesn't give a TypeVar any real constraining power; the spec-correct form for "exactly one of these three" is a constrained TypeVar (positional arguments).
Switch to that, keep `_KernelType` as an explicit `TypeAlias` for the few sites that genuinely want the union (return types, local annotations), and pin the two definitions together with an import-time assert so they can't silently drift.
The three aggregate `CompileResult[_KernelType]` sites become `CompileResult[Any]` since a constrained TypeVar can't be parameterized with the union itself.

Fixes pytorch#184159
Authored by Claude

Pull Request resolved: pytorch#184412
Approved by: https://github.com/jansel, https://github.com/Skylion007
@github-actions
github-actions Bot deleted the gh/malfet/912/head branch June 26, 2026 02:28
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
The `_T` TypeVar was declared with `bound=_KernelType`, where `_KernelType` is a `CompiledKernel | StaticallyLaunchedCudaKernel | StaticallyLaunchedXpuKernel` union.
A union bound doesn't give a TypeVar any real constraining power; the spec-correct form for "exactly one of these three" is a constrained TypeVar (positional arguments).
Switch to that, keep `_KernelType` as an explicit `TypeAlias` for the few sites that genuinely want the union (return types, local annotations), and pin the two definitions together with an import-time assert so they can't silently drift.
The three aggregate `CompileResult[_KernelType]` sites become `CompileResult[Any]` since a constrained TypeVar can't be parameterized with the union itself.

Fixes pytorch#184159
Authored by Claude

Pull Request resolved: pytorch#184412
Approved by: https://github.com/jansel, https://github.com/Skylion007
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
The `_T` TypeVar was declared with `bound=_KernelType`, where `_KernelType` is a `CompiledKernel | StaticallyLaunchedCudaKernel | StaticallyLaunchedXpuKernel` union.
A union bound doesn't give a TypeVar any real constraining power; the spec-correct form for "exactly one of these three" is a constrained TypeVar (positional arguments).
Switch to that, keep `_KernelType` as an explicit `TypeAlias` for the few sites that genuinely want the union (return types, local annotations), and pin the two definitions together with an import-time assert so they can't silently drift.
The three aggregate `CompileResult[_KernelType]` sites become `CompileResult[Any]` since a constrained TypeVar can't be parameterized with the union itself.

Fixes pytorch#184159
Authored by Claude

Pull Request resolved: pytorch#184412
Approved by: https://github.com/jansel, https://github.com/Skylion007
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 topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants