Skip to content

[native_aot] topk: first AOT declaration (fp32/bf16 radix kernels) + e2e tests - #190899

Closed
slayton58 wants to merge 75 commits into
gh/slayton58/116/basefrom
gh/slayton58/116/head
Closed

slayton58 wants to merge 75 commits into
gh/slayton58/116/basefrom
gh/slayton58/116/head

Conversation

@slayton58

@slayton58 slayton58 commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Human Notes:

Finally do a thing! Add topk as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py

On an H100, against the kernels a spin develop embedded:

.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ 1 Pending, 5 Unrelated Failures

As of commit a31a8f6 with merge base 335414f (image):

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

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.

[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Jul 23, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: b90f68e
Pull-Request: #190899
slayton58 added a commit that referenced this pull request Jul 23, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: b90f68e
Pull-Request: #190899
slayton58 added a commit that referenced this pull request Jul 23, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: b90f68e
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Jul 24, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: 53658bb
Pull-Request: #190899
[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the release notes: releng release notes category label Jul 24, 2026
slayton58 added a commit that referenced this pull request Jul 24, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites; b200-native-aot.yml builds with cuda-arch-list
10.0a on a GPU-less builder and tests on a B200 (path-triggered +
nightly). This lands with the first op so the AOT path is exercised in
CI from this commit onward.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: 055f00d
Pull-Request: #190899
slayton58 added a commit that referenced this pull request Jul 24, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites; b200-native-aot.yml builds with cuda-arch-list
10.0a on a GPU-less builder and tests on a B200 (path-triggered +
nightly). This lands with the first op so the AOT path is exercised in
CI from this commit onward.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: 055f00d
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Jul 24, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites; b200-native-aot.yml builds with cuda-arch-list
10.0a on a GPU-less builder and tests on a B200 (path-triggered +
nightly). This lands with the first op so the AOT path is exercised in
CI from this commit onward.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: fbf9a8a
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Jul 24, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites; b200-native-aot.yml builds with cuda-arch-list
10.0a on a GPU-less builder and tests on a B200 (path-triggered +
nightly). This lands with the first op so the AOT path is exercised in
CI from this commit onward.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: 6e3fc05
Pull-Request: #190899
slayton58 added a commit that referenced this pull request Jul 24, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites; b200-native-aot.yml builds with cuda-arch-list
10.0a on a GPU-less builder and tests on a B200 (path-triggered +
nightly). This lands with the first op so the AOT path is exercised in
CI from this commit onward.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: 6e3fc05
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Jul 24, 2026
…e2e tests

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16,
off-grid shapes, and deterministic mode keep their JIT eligibility.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites; b200-native-aot.yml builds with cuda-arch-list
10.0a on a GPU-less builder and tests on a B200 (path-triggered +
nightly). This lands with the first op so the AOT path is exercised in
CI from this commit onward.

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

ghstack-source-id: d49c923
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Sep 11, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: 13ebf14
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Sep 11, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: e6e7706
Pull-Request: #190899
slayton58 added a commit that referenced this pull request Sep 11, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: e6e7706
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Sep 11, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: 23b349b
Pull-Request: #190899
slayton58 added a commit that referenced this pull request Sep 11, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: 23b349b
Pull-Request: #190899
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Sep 11, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: ae0cdad
Pull-Request: #190899
@slayton58 slayton58 added ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/docker labels Sep 11, 2026
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Sep 11, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: 956f098
Pull-Request: #190899
@slayton58 slayton58 removed ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/docker labels Sep 14, 2026
[ghstack-poisoned]
slayton58 added a commit that referenced this pull request Sep 14, 2026
…e2e tests

Human Notes:

Finally do a thing! Add `topk` as an AOT-provided override in libtorch_cuda.

Claude:

Declares a 48-point grid (fp32/bf16 x N{2048..16384} x K{64,128,256}
x both determinism modes) over the radix-select kernel. The det
specialization (stable prefix-sum gather + lex (ord, -idx) sort) is
bit-exact vs aten including tie resolution, so det-mode calls are
served AOT too; the dispatch chain keys on
deterministicAlgorithms(). The kernel gains
in_dtype and index_dtype compile parameters; the AOT route writes
int64 indices directly (no widening copy). build(spec) lives beside
the JIT wrappers, so both routes compile the same class. fp16 and
off-grid shapes keep their JIT eligibility, as do calls the prelude
declines: a non-last dim, largest/sorted false, sub-full-wave M, or a
base pointer less aligned than the kernels were compiled for.

ARCHS is stated rather than defaulted, and covers Hopper as well as
Blackwell: measured on an H100, the AOT kernels beat aten on 48/48 of
the grid, median 2.16x (min 1.26x at M=4096/N=2048, max 2.99x at
M=256/N=4096 fp32). Both spellings of each capability are listed --
archs_from_cuda_arch_list maps 9.0 and 9.0a to different nvcc targets,
and a wheel built with the plain list would otherwise export trees
generation then filters out.

CI: a native_aot test config (test.sh) asserts the wheel actually
embeds the kernels -- a silently artifact-free wheel would make every
routing test vacuously pass on the JIT/aten fallbacks -- then runs the
python_native suites. One build+test pair per capability in
native-aot.yml: cuda-arch-list 9.0a tested on linux.aws.h100 and
10.0a on linux.dgx.b200, both built on a GPU-less builder
(path-triggered + nightly). test_uncovered_fp32_served_by_jit_layer
skips below sm_100, since the JIT topk override is gated there while
these AOT kernels are not. This lands with the first op so the AOT path
is exercised in CI from this commit onward.

covered_axes() and cpp_covers() decline a dim other than the last, largest=False
and sorted=False, matching the stub's gates. Coverage wider than the stub is not
wrong -- the stub declines and stock aten serves -- but it costs those calls
their JIT route, since coverage subtracts them from it (review: #190899).

Authored with an AI assistant (Claude Code).

Test Plan:

```
.venv/bin/python test/python_native/test_native_aot.py
# incl. det-mode routing + bit-exact-with-ties tests
# (test_deterministic_mode_routes_to_aot_bit_exact,
#  test_deterministic_ties_bit_exact)
.venv/bin/python test/python_native/test_topk_radix_kernel.py
.venv/bin/python test/python_native/test_topk_cutedsl.py
```

On an H100, against the kernels a `spin develop` embedded:

```
.venv/bin/python test/python_native/test_native_aot.py    # 11 tests, 1 skipped
.venv/bin/python test/python_native/test_aot_manifest.py  # 18 tests
.venv/bin/python test/python_native/test_registry.py      # 35 tests
```

ghstack-source-id: dfed271
Pull-Request: #190899
@slayton58

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 pushed a commit that referenced this pull request Sep 14, 2026
Human Notes:

Fix the manywheel build issue on 3.10 that caused the revert of #190899

Codex:

The native-AOT verdict considers CPython 3.10 and 3.11 supported by the pinned
DSL wheels, but install_cutlass_dsl returned success without installing anything
below Python 3.12. Once the first declaration enabled stage 2, CUDA manywheel
therefore failed when it required the missing cutlass and tvm_ffi modules.

Remove the duplicate interpreter gate so stage 2 remains the single owner of
eligibility, and select the CUDA 13 extra so those builds install the matching
dialect runtime.

Once installation was enabled, Python 3.10 exposed a second issue in parallel
export. Affected CPython releases start the forkserver through python -c without
first applying the parent process's sys.path. The server therefore preloaded the
checkout's torch instead of the newly installed wheel, silently swallowed that
failed import, and forked workers with torch's one-import guard set.

Preload torch once on CPython releases containing the forkserver fix. On older
releases, disable only preloading so each worker imports torch after restoring
the parent's sys.path. This keeps direct exporter invocation correct as well as
the stage-2 path. Unrelated builder import failures are also reported as such
instead of being misdiagnosed as missing DSL runtimes.

Changing only the stage-2 working directory would leave direct invocation
broken. A custom preload helper could preserve copy-on-write imports on affected
Pythons, but adds an environment protocol and path rewriting for a startup
optimization. Version-gated preloading keeps the compatibility path smaller.

Skipping native-AOT below Python 3.12 would be smaller, but would unnecessarily
omit embedded kernels from supported wheels.

Authored with assistance from an AI coding assistant.

Test Plan:

```
PYTHONPATH=. python tools/test/test_native_aot_tools.py
```

```
bash -n .ci/pytorch/common_utils.sh
```
Pull Request resolved: #196747
Approved by: https://github.com/ngimel
zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 16, 2026
…le-runner rebase

The pytorchmergebot rebase onto main brought in pytorch#195699, which routes the
XPU manywheel build through the unified build_all.sh job. That commit's
template change merged cleanly, but the pre-rendered generated workflow was
taken textually from main, where the script still lived at
.ci/manywheel/build_all.sh. This branch moved it to .ci/wheel/linux/, so
manywheel-xpu-build failed with "No such file or directory" and
workflow-checks/lint flagged the generated file as stale. Regenerating from
the merged template fixes exactly that one line.

The same rebase also brought in the native-aot workflow (pytorch#190899), whose
paths filter names .ci/manywheel/build.sh. That entry is repointed to the
moved script so edits to the Linux build script keep triggering the
workflow.

Test Plan:

```
uv run --no-project --python 3.10 --with jinja2 --with typing_extensions --with pyyaml python .github/scripts/generate_ci_workflows.py
git diff --stat   # only generated-linux-binary-manywheel-nightly.yml, 1 line
grep -rn '\.ci/manywheel' .github .ci   # empty
lintrunner .github/workflows/native-aot.yml .github/workflows/generated-linux-binary-manywheel-nightly.yml
```

Authored with an AI assistant.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@github-actions
github-actions Bot deleted the gh/slayton58/116/head branch November 19, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/b200 ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: releng release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants