Skip to content

[TEST] Fix hw_classification violation in test/nn/test_convolution.py - #1

Closed
Sanskaaar1 wants to merge 13 commits into
mainfrom
test/test_convolutions.py
Closed

Sanskaaar1 wants to merge 13 commits into
mainfrom
test/test_convolutions.py

Conversation

@Sanskaaar1

Copy link
Copy Markdown
Owner

Summary

Apply hardware classification structure following #186918 guidelines.

Changes:

  • Remove CUDA-hardcoded test_thnn_conv_strided_padded_dilated from TestConvolutionNN (GENERIC) — it violated single-responsibility with @unittest.skipIf(not TEST_CUDA) and device="cuda"
  • Merge its unique non-batched assertion into the existing ACCELERATOR version in TestConvolutionNNDeviceType
  • Remove unused TEST_CUDA import

Classifications:

  • TestConvolutionNN — hw_classification = HardwareClassification.GENERIC (40 tests)
  • TestConvolutionNNDeviceType — hw_classification = HardwareClassification.ACCELERATOR (1069 tests)
  • TestConvolutionNNCUDA — hw_classification = HardwareClassification.CUDA (48 tests)

Test Plan

python test/nn/test_convolution.py -v -k test_thnn_conv_strided_padded_dilated
OK — 2 tests (skipped=1)

python test/nn/test_convolution.py --hw-classification GENERIC
OK — Ran 40

python test/nn/test_convolution.py --hw-classification CUDA
OK — Ran 48 (skipped=1, xfail=1)

python test/nn/test_convolution.py --hw-classification ACCELERATOR
OK — Ran 1069 (skipped=426, xfail=25)

python test/nn/test_convolution.py
OK — Ran 1157 (skipped=427, xfail=26)

cc @RiyaP2508

ezyang and others added 13 commits August 8, 2026 13:41
…192081)

Add once-per-process API usage logs for backward passes, split by the set
of devices they span, so we can assess how much real workloads rely on
multithreaded autograd before changing its default. The check walks the
graph roots in compute_dependencies and emits two independent signals that
may both fire for the same pass:

- torch.autograd.multidevice_backward when two distinct non-CPU devices
  are observed.
- torch.autograd.gpu_cpu_backward when a single non-CPU device runs
  alongside CPU nodes.

Multi-device (multiple accelerators in one backward) is the case that
genuinely benefits from multithreaded autograd and is expected to be rare;
the GPU + CPU case is expected to be common. Each log fires at most once
per process, and the per-node device inspection is skipped entirely once
both have fired.

Test Plan: Built, then ran each case in a fresh process with
PYTORCH_API_USAGE_STDERR=1 and grepped the emitted events:

```
a = torch.randn(4, requires_grad=True, device="cuda")
b = torch.randn(4, requires_grad=True, device="cpu")
(a.sum() + b.sum()).backward()

a = torch.randn(4, requires_grad=True, device="cuda")
(a * 2).sum().backward()

a = torch.randn(4, requires_grad=True, device="cpu")
(a * 2).sum().backward()
```

The GPU + CPU, single-accelerator, and CPU-only cases behaved as
described. The multi-device path was not exercised at runtime (the test
host has a single GPU); its logic mirrors the GPU + CPU path and was
verified by inspection.

Authored with assistance from an AI coding assistant.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pull Request resolved: pytorch#192081
Approved by: https://github.com/soulitzer
Fixes pytorch#177116

Another MPS Graph issue...

To explain it shortly: on M1/M2 (Apple7/8 GPUs), the MPSGraph matmul kernel reads past the end of the K (reduction) dimension once K > 32768, when both GEMM output dims M and N are >= 16. Each output element is a K-term dot product and the kernel sums a few extra terms beyond K, using whatever data happens to sit in memory past the operands.

Performance below is just to show that there are no regressions, any kind of speedup that we see below can just be attributed to noise since we are running effectively the same function for backwards (just dispatched with mm instead of having graph inside of the backward)

<details>
<summary> Performance for backward on base M2:</summary>

| input shape | weight shape | bias | function | before us | after us | speedup |
|---|---|---|---|---|---|---|
| (128, 64) | (32, 64) | no | _mps_linear_backward_input | 39.3 | 39.7 | 0.99x |
| (128, 64) | (32, 64) | no | _mps_linear_backward_weights | 45.1 | 41.4 | 1.09x |
| (2, 3, 4, 5, 64) | (32, 64) | yes | _mps_linear_backward_input | 51.0 | 40.8 | 1.25x |
| (2, 3, 4, 5, 64) | (32, 64) | yes | _mps_linear_backward_weights | 50.9 | 46.4 | 1.10x |
| (32000, 128) | (16, 128) | yes | _mps_linear_backward_input | 176.2 | 176.5 | 1.00x |
| (32000, 128) | (16, 128) | yes | _mps_linear_backward_weights | 663.6 | 665.2 | 0.99x |
| (512, 1024) | (1024, 1024) | yes | _mps_linear_backward_input | 380.5 | 382.7 | 0.99x |
| (512, 1024) | (1024, 1024) | yes | _mps_linear_backward_weights | 411.7 | 406.9 | 1.01x |
| (64, 128) | (256, 128) | yes | _mps_linear_backward_input | 41.2 | 41.7 | 0.99x |
| (64, 128) | (256, 128) | yes | _mps_linear_backward_weights | 53.0 | 49.9 | 1.06x |
| (8, 128) | (40000, 128) | yes | _mps_linear_backward_input | 339.7 | 341.1 | 1.00x |
| (8, 128) | (40000, 128) | yes | _mps_linear_backward_weights | 577.9 | 578.9 | 1.00x |
| (8, 512, 768) | (3072, 768) | yes | _mps_linear_backward_input | 6530.9 | 6529.4 | 1.00x |
| (8, 512, 768) | (3072, 768) | yes | _mps_linear_backward_weights | 7304.7 | 7269.9 | 1.00x |
| (8, 512, 768) | (768, 768) | yes | _mps_linear_backward_input | 1692.4 | 1692.1 | 1.00x |
| (8, 512, 768) | (768, 768) | yes | _mps_linear_backward_weights | 1927.4 | 1880.9 | 1.02x |

</details>

<details>

<summary> Performance for backward on M5 Pro:</summary>

| input shape | weight shape | bias | function | before us | after us | speedup |
|---|---|---|---|---|---|---|
| (128, 64) | (32, 64) | no | _mps_linear_backward_input | 32.8 | 32.1 | 1.02x |
| (128, 64) | (32, 64) | no | _mps_linear_backward_weights | 38.2 | 33.9 | 1.13x |
| (2, 3, 4, 5, 64) | (32, 64) | yes | _mps_linear_backward_input | 36.7 | 33.2 | 1.11x |
| (2, 3, 4, 5, 64) | (32, 64) | yes | _mps_linear_backward_weights | 46.2 | 40.4 | 1.14x |
| (32000, 128) | (16, 128) | yes | _mps_linear_backward_input | 68.3 | 67.1 | 1.02x |
| (32000, 128) | (16, 128) | yes | _mps_linear_backward_weights | 142.2 | 135.5 | 1.05x |
| (512, 1024) | (1024, 1024) | yes | _mps_linear_backward_input | 213.6 | 212.9 | 1.00x |
| (512, 1024) | (1024, 1024) | yes | _mps_linear_backward_weights | 221.8 | 216.7 | 1.02x |
| (64, 128) | (256, 128) | yes | _mps_linear_backward_input | 33.6 | 34.1 | 0.98x |
| (64, 128) | (256, 128) | yes | _mps_linear_backward_weights | 45.4 | 40.0 | 1.14x |
| (8, 128) | (40000, 128) | yes | _mps_linear_backward_input | 227.6 | 230.4 | 0.99x |
| (8, 128) | (40000, 128) | yes | _mps_linear_backward_weights | 226.4 | 220.4 | 1.03x |
| (8, 512, 768) | (768, 768) | yes | _mps_linear_backward_input | 837.9 | 833.1 | 1.01x |
| (8, 512, 768) | (768, 768) | yes | _mps_linear_backward_weights | 912.6 | 908.6 | 1.00x |
| (8, 512, 768) | (3072, 768) | yes | _mps_linear_backward_input | 3270.6 | 3264.4 | 1.00x |
| (8, 512, 768) | (3072, 768) | yes | _mps_linear_backward_weights | 3490.9 | 3463.4 | 1.01x |

</details>
Pull Request resolved: pytorch#183535
Approved by: https://github.com/malfet
…ytorch#182986) (pytorch#182986)

Summary:

Adds the triton-style inner tree reduction kernel for sum in the caffe2/ATen CUDA backend, including partitioned launch variants, tests, and the output/input offset handling from D104676317 so TensorIterator output strides and strided outer input rows are preserved.

Test Plan:
arc lint -a fbcode/caffe2/aten/src/ATen/native/cuda/ReduceSumProdKernel.cu xplat/caffe2/aten/src/ATen/native/cuda/ReduceSumProdKernel.cu fbcode/caffe2/test/test_reductions.py xplat/caffe2/test/test_reductions.py

buck2 test fbcode//caffe2/test:torch_cuda_cuda -- TestInnerTreeSum

Differential Revision: D100024904

Pull Request resolved: pytorch#182986
Approved by: https://github.com/karthickai
This PR enables hipFile in PyTorch by adding mappings to hipify and updating cmake files, adds more tests for GDS, and also adds a helper variable and a function to facilitate tests' skip condition.
hipFile only ships with ROCm on ROCm 7.14 and later, therefore hipFile is only required after that version.

Authored with Claude.

Pull Request resolved: pytorch#191069
Approved by: https://github.com/jeffdaily
as title, reviewed claude changes manually, also added a point to claude.md to prevent it from adding plain asserts in the future

Pull Request resolved: pytorch#192517
Approved by: https://github.com/janeyx99
…Bag kernel (pytorch#192571) (pytorch#192571)

Summary:

`bfe()` in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the
[pos, pos+len) bit field of a packed word and returns it as a float. It is the
inner primitive of `dequantize_intx()`, so every
`quantized::embedding_bag_{byte,4bit}_rowwise_offsets` call on a GPU goes
through it.

The `#ifdef USE_ROCM` branch read:

    return *reinterpret_cast<float*>((val >> pos) && ((1u << len) - 1u));

which has two defects:

- `&&` (logical AND) is used where `&` (bitwise AND) was intended, so the
  expression collapses to 0 or 1 instead of the requested bit field.
- the resulting `bool` is then reinterpreted as a `float*` and dereferenced,
  i.e. a load from address 0 or 1.

This is not a subtle numerical issue: on an AMD GPU the null load aborts the
process with

    Memory access fault by GPU node-2 (Agent handle: 0x...) on address (nil).

so quantized embedding-bag lookups could never have run on ROCm. The line has
been unchanged since the file was added in July 2021.

Use the bitwise AND and convert with `__uint2float_rn`, which yields the same
value the CUDA branch computes with the `bfe.u32` PTX instruction. Both branches
end in that same conversion, so only the bit-field extraction itself stays under
the `#ifdef` and the conversion is shared between them. NVIDIA codegen and the
CPU implementations are unchanged.

The explanatory comment carried the same `&&` typo and is most likely where the
ROCm expression was copied from; it is corrected and hoisted to describe the
function as a whole rather than just one branch.

Test Plan:
New test `test_embedding_bag_rowwise_offsets_cuda` in
`test/quantization/core/test_quantized_op.py` runs
`quantized::embedding_bag_byte_rowwise_offsets` and
`quantized::embedding_bag_4bit_rowwise_offsets` on GPU and asserts the output is
finite and agrees with the CPU implementation. Both bit widths are covered
because `bfe()` is shared by them through `dequantize_intx()`, with a different
`len`.

    python test/quantization/core/test_quantized_op.py -k test_embedding_bag_rowwise_offsets_cuda

Run on an AMD GPU (ROCm): passes. The whole `TestQuantizedEmbeddingOps` class
passes as well (7 tests).

As a negative control, reverting just this fix makes the new test abort with the
GPU memory fault quoted in the summary, so the test does pin the behaviour it
claims to.

Differential Revision: D115065161

Pull Request resolved: pytorch#192571
Approved by: https://github.com/Skylion007, https://github.com/vadimkantorov
…nel (pytorch#191803)

Rework the reduction in `fused_matmul_reduce_scatter` so it is no longer an
exposed memory-bandwidth-bound kernel at the end of the op.

The existing implementation computes per-destination GEMM partials, exchanges
them with the all-to-all pipeline, then reduces with a final `torch.sum` /
`torch.mean` over `stacked_partials`. That reduction is a separate kernel that
only starts after the communication and GEMM work has completed, so all of its
memory traffic sits on the critical path. Splitting it into smaller adds
overlapped with the pipeline was also tried, and still left the reduction
reads/writes exposed.

This keeps the all-to-all pipeline and replaces that final `torch.sum` with a
single Triton kernel that reads the bf16/fp16 partials, accumulates in fp32
registers, and stores the low-precision output once. The contract is unchanged:
bf16 on the wire, fp32 accumulation, one rounding on store.

`torch.sum` is a poor fit here rather than merely unoptimized. On these shapes it
reaches 23-43% of HBM peak against the Triton kernel's 82-88%, at identical DRAM
traffic, because ATen's `reduce_kernel` is instruction-bound: for a reduction of
extent 2-8 it executes roughly ten times the instructions per output element,
most of them index arithmetic and configuration branches rather than the handful
of adds the reduction needs. That cost is structural to a kernel whose reduction
strategy lives in runtime data, so it is not reachable by tuning.

Scope stays narrow: low-precision output with the reduction over the leading
dim, which is the layout the all-to-all pipeline produces. Everything else,
including scaled matmul, keeps `torch.sum` via the existing fallback.

A separate schedule for the two-rank case, which accumulates through `addmm`'s C
operand and removes the reduction kernel entirely, will follow in its own PR.

Performance
-----------

<img width="1853" height="810" alt="image" src="https://github.com/user-attachments/assets/981462f6-5403-43c0-8131-3fb849016ae4" />

GB300, bf16. `A` is `[M, K_per_rank]`, `B` is `[K_per_rank, N]`, output is
`[M/TP, N]`. Per-rank GEMM throughput (`2 * M * N * K_per_rank / time`) in
TFLOP/s, median of 15 timed rounds of 10 back-to-back calls after warmup,
slowest rank. All figures are CUDA graph replay; the eager picture is discussed
below. `unfused` is `torch.mm` followed by `dist.reduce_scatter_tensor`, and is
included only as a reference point -- the change itself is `torch.sum` vs
`Triton`.

TP=4:

| N | K_per_rank | M | unfused | torch.sum | Triton | Triton/sum |
| --- | --- | --- | --- | --- | --- | --- |
| 7168 | 2048 | 8192 | 770 | 880 | 987 | 1.12 |
| 7168 | 2048 | 32768 | 850 | 1038 | 1150 | 1.11 |
| 12288 | 4096 | 8192 | 1136 | 1251 | 1337 | 1.07 |
| 12288 | 4096 | 32768 | 1238 | 1400 | 1496 | 1.07 |
| 5120 | 1280 | 8192 | 557 | 539 | 594 | 1.10 |
| 5120 | 1280 | 32768 | 622 | 747 | 848 | 1.13 |
| 5120 | 6400 | 8192 | 1270 | 1425 | 1531 | 1.07 |
| 5120 | 6400 | 32768 | 1332 | 1454 | 1516 | 1.04 |
| 4096 | 2048 | 8192 | 728 | 726 | 825 | 1.14 |
| 4096 | 2048 | 32768 | 816 | 1013 | 1115 | 1.10 |
| 2048 | 1024 | 8192 | 334 | 298 | 304 | 1.02 |
| 2048 | 1024 | 32768 | 490 | 521 | 588 | 1.13 |

Over the full grid (6 shapes x M in {4096, 8192, 16384, 32768}) the Triton
reducer is 1.02x to 1.14x, median 1.09x.

TP=2, where the reduction is over only two partials and `torch.sum` is at its
worst:

| N | K_per_rank | M | unfused | torch.sum | Triton | Triton/sum |
| --- | --- | --- | --- | --- | --- | --- |
| 7168 | 4096 | 8192 | 1175 | 1219 | 1441 | 1.18 |
| 7168 | 4096 | 32768 | 1231 | 1322 | 1555 | 1.18 |
| 12288 | 8192 | 8192 | 1429 | 1424 | 1521 | 1.07 |
| 12288 | 8192 | 32768 | 1455 | 1460 | 1560 | 1.07 |
| 5120 | 2560 | 8192 | 903 | 973 | 1271 | 1.31 |
| 5120 | 2560 | 32768 | 1015 | 931 | 1181 | 1.27 |
| 5120 | 12800 | 8192 | 1488 | 1517 | 1538 | 1.01 |
| 5120 | 12800 | 32768 | 1559 | 1567 | 1641 | 1.05 |
| 4096 | 4096 | 8192 | 1106 | 1240 | 1510 | 1.22 |
| 4096 | 4096 | 32768 | 1224 | 1178 | 1362 | 1.16 |
| 2048 | 2048 | 8192 | 682 | 612 | 758 | 1.24 |
| 2048 | 2048 | 32768 | 826 | 787 | 1010 | 1.28 |

Same grid: 1.01x to 1.32x, median 1.19x. The gain tracks how much of the op the
reduction is, so it is largest at small `K_per_rank` (thin GEMM, unchanged
reduction) and smallest at large `K_per_rank`, where the GEMM dominates.

For sizing the Triton dependency: measured in isolation the reducer is 2.0x to
3.2x faster than `torch.sum`, but the reduction is only 7-15% of the operator at
these shapes, which is why the end-to-end numbers above are 1.0x-1.3x rather
than 2x.

Eager is a wash and can be slightly negative: 0.86x to 1.14x, median 0.97x at
TP=4 and 1.05x at TP=2. The Triton kernel has the better GPU time but costs
about 10 us more to launch than `torch.sum`, which is not recovered until
capture removes launch cost. Gating the reducer on eager-vs-captured would lose
more than it saves and is deliberately not done.

Accuracy did not regress: relative L2 error against an fp32 reduce-scatter
reference is 2.36e-3 before and after, since the reduction math is unchanged.

Test plan:
- `lintrunner -a -- torch/distributed/_symmetric_memory/__init__.py test/distributed/test_symmetric_memory.py`
- `python test/distributed/test_symmetric_memory.py -k test_fused_matmul_reduce_scatter`
- `python test/distributed/test_symmetric_memory.py -k test_fused_matmul_reduce_scatter_bfloat16_custom_reduce`
  (checks the eager result against the fallback and then captures the op in a
  CUDA graph and rechecks, since graph replay is the regime this targets)
- `python test/test_reductions.py -k cuda`
- Benchmark above via `torchrun --nproc_per_node={2,4}`, which also checks the
  reducer against an fp32 reduce-scatter reference

This PR was authored with the help of an AI assistant.

Co-authored-by: Codex <[email protected]>
Co-authored-by: Claude <[email protected]>
Pull Request resolved: pytorch#191803
Approved by: https://github.com/ngimel
pytorch#192623)

… enabled

`use_pg_for_symm_mem_rendezvous` moved the RendezvousRequest and block handle exchanges off the TCPStore, since the store gets overloaded during rendezvous at large rank counts, but multicast setup was left behind: the multicast handle exchange, the per-rank success flag, and the barrier after peer handles are imported hit the store. This routes tthem through the process group when the option is set. The multicast handle uses a real broadcast (`pg_broadcast`) rather than the store path's allgather-and-keep-element-0. The POSIX-fd path is unchanged, exchanging the multicast fd over `ipc_channel` as before.

The barrier moves too as for large jobs the aggregate request rate from all groups is problematic rather than any single exchange; The success flag is carried as `uint8_t` because `pg_all_gather` memcpys into its result vector and `std::vector<bool>` packs bits, leaving no usable `data()` to copy into.
`test_rendezvous_via_pg_allgather` asserted an exact allgather count, so it now derives the expected range from whether the handle got a multicast pointer.

Test Plan:

On 2x GB200 (NVLink fabric handles, multicast supported):

```
python test/distributed/test_symmetric_memory.py -v
```

134 tests, 1 pre-existing failure (`LoweringTest.test_custom_op_symm_mem_realization`, an `alloc_id` size mismatch that also reproduces without this change and passes in isolation). The NCCL flight recorder around a PG rendezvous confirms nothing is left on the store, and `multimem_all_gather_out` over the resulting pointer confirms the PG-exchanged multicast handle works:

```
nccl ops: ['nccl:_all_gather_base',    # RendezvousRequest
           'nccl:_all_gather_base',    # block handles
           'nccl:all_reduce_barrier',  # post-import barrier
           'nccl:broadcast',           # multicast handle
           'nccl:_all_gather_base']    # multicast success flag
```

This PR was authored with the assistance of an AI coding agent (Claude Code).
Pull Request resolved: pytorch#192623
Approved by: https://github.com/ezyang
…internal) (pytorch#192615)

✴️ iz2: (opened by Ivan's agent on his behalf)

pytorch#177692 ("CPU support for stateless RNG APIs") added `aten/src/ATen/native/PhiloxStatelessRNG.cpp` but did not register it in `build_variables.bzl`. When that PR was imported internally, the entry was added to the internal copy of `build_variables.bzl` before it landed. The two copies of the file have been out of sync since.

This adds the same single line to the OSS copy, so `build_variables.bzl` matches on both sides.

The entry goes into `aten_native_source_non_codegen_list`, in sorted position between `PackedSequence.cpp` and `PixelShuffle.cpp`.

### Build impact

No effect on the default CMake build. `aten/src/ATen/CMakeLists.txt` has an if/else on `BUILD_LITE_INTERPRETER`: the `append_filelist("aten_native_source_non_codegen_list" ...)` call is only in the `ON` branch, while the default `OFF` branch composes `all_cpu_cpp` from `file(GLOB native_cpp "native/*.cpp")`, which already picks this file up. The two branches are mutually exclusive, so there is no double-add.

The change does add the file to the source list used by the `BUILD_LITE_INTERPRETER=ON` branch and by the buck path (`aten_native_source_list` → `buckbuild.bzl`, `pt_template_srcs.bzl`), where it is currently absent. That is a real change in source composition for those configurations rather than pure metadata, so it is worth calling out — though it is the composition the file's own `native_functions.yaml` CPU dispatch entries imply. The equivalent internal buck build already compiles this file from a list containing this exact line.

### Verification

- `build_variables.bzl` on this branch is byte-identical to the internal copy as of internal master `63074c69e3aa` (both 79151 bytes, matching md5). Before this change the OSS copy was 79100 bytes and the only difference between the two files was this one line, in one direction — there were no OSS-only lines.
- `lintrunner` is clean.

Byte-identity is stated against that named internal snapshot; it is not a claim about future drift.

Pull Request resolved: pytorch#192615
Approved by: https://github.com/pytorchgreenlight, https://github.com/Skylion007
The GENERIC class TestConvolutionNN contained test_thnn_conv_strided_padded_dilated
which hardcoded "cuda" device and used @unittest.skipIf(not TEST_CUDA), violating
the GENERIC single-responsibility principle. A device-agnostic version already
existed in TestConvolutionNNDeviceType (ACCELERATOR).

Removed the CUDA-hardcoded duplicate from the GENERIC class and merged its unique
non-batched assertion (non-batched input must match batched-then-squeezed) into the
ACCELERATOR version, preserving full test coverage across all accelerators instead
of just CUDA.
@Sanskaaar1 Sanskaaar1 closed this Aug 10, 2026
Sanskaaar1 pushed a commit that referenced this pull request Aug 31, 2026
`at::divup(x, y)` computes `(x + y - 1) / y`. The addition overflows for large `x` or `y`, and the result then silently rounds **down** instead of up — `divup(2, INT64_MAX)` returns `0`, not `1`. Guarded with `c10::add_overflows`, falling back to a form that cannot overflow.

Every caller today passes loop extents and chunk counts, so for most of them this is latent. One caller does reach it: `PoolingParams1D::valid_output_end` bounds the `max_pool1d` output range with `divup`, and a large stride there yields a window starting past the end of the input — a segfault. That is the stacked PR on top of this one; splitting it out because `divup` is used well beyond pooling (softmax, moments, the parallel-loop chunking itself) and deserves its own CI signal.

## Performance

Free on the happy path. Measured on an M-series arm64 laptop, `-O3`. Both variants live in **one binary** and are **raced round-robin within each trial**, so thermal drift and frequency changes hit them equally — A/B-ing two libtorch builds measures code layout instead of the change, and gave me a spurious ~9% swing that reproduces as same-build drift. Cycles are from a calibrated dependent-add chain (~4.4 GHz). Numbers below reproduce to three decimals across runs; discard the first run of any such benchmark, it is thermal warm-up.

| | old `(x+y-1)/y` | guarded | delta |
|---|---|---|---|
| **y runtime** (holds an `sdiv`), throughput | 0.448 ns | 0.449 ns | +0.2% |
| **y runtime**, latency | 2.629 ns | 2.407 ns | **−8.4%** |
| **y compile-time constant** (=16), throughput | 0.171 ns | 0.209 ns | +22.2% |
| **y compile-time constant** (=16), latency | 1.330 ns | 1.334 ns | +0.3% |

**Runtime divisor — free, and the loop is divider-bound, not issue-bound.** A bare `sdiv` with nothing else in the loop measures **0.449 ns / ~1.9 cyc**, which is exactly what both variants cost, so the guard's extra instructions are absorbed entirely by the divider's throughput. Latency actually *improves*: the guard's `adds` replaces the old `add`/`sub` pair ahead of the divide.

```asm
old                      guarded
  add  x8, x0, x1          sub  x8, x1, #1
  sub  x8, x8, #1          adds x8, x0, x8
  sdiv x0, x8, x1          b.vs  <fallback>     ; predicted not-taken
                           sdiv x0, x8, x1
```

**Constant divisor — where the cost is.** With `y` a compile-time constant there is no division at all; it folds to a shift, leaving 5 cheap ALU ops, and the guard's 2 extra instructions are a real +22% — of **+0.038 ns/call**. Only `moments_utils.h` (`kChunkSize = 16`) has such a constant among the callers; `SoftMaxKernel.cpp`'s `CHUNK_SIZE` is a runtime `std::min(...)` and takes the free path above. In `moments_utils.h`, `divup` runs once per row of a reduction, ahead of that row's entire Welford loop — in a replica of that shape the difference does not clear the noise floor at any row size.

I also tried `x / y + (x % y > 0)`, which needs no guard at all. It is equivalent on throughput but ~34% worse on runtime-divisor latency, because it puts `msub`/`cmp`/`cinc` *after* the divide instead of ahead of it. Happy to switch if the extra header include is a concern.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#195035
Approved by: https://github.com/Skylion007

Co-authored-by: Claude Opus 5 <[email protected]>
Sanskaaar1 pushed a commit that referenced this pull request Sep 8, 2026
`at::divup(x, y)` computes `(x + y - 1) / y`. The addition overflows for large `x` or `y`, and the result then silently rounds **down** instead of up — `divup(2, INT64_MAX)` returns `0`, not `1`. Guarded with `c10::add_overflows`, falling back to a form that cannot overflow.

Every caller today passes loop extents and chunk counts, so for most of them this is latent. One caller does reach it: `PoolingParams1D::valid_output_end` bounds the `max_pool1d` output range with `divup`, and a large stride there yields a window starting past the end of the input — a segfault. That is the stacked PR on top of this one; splitting it out because `divup` is used well beyond pooling (softmax, moments, the parallel-loop chunking itself) and deserves its own CI signal.

## Performance

Free on the happy path. Measured on an M-series arm64 laptop, `-O3`. Both variants live in **one binary** and are **raced round-robin within each trial**, so thermal drift and frequency changes hit them equally — A/B-ing two libtorch builds measures code layout instead of the change, and gave me a spurious ~9% swing that reproduces as same-build drift. Cycles are from a calibrated dependent-add chain (~4.4 GHz). Numbers below reproduce to three decimals across runs; discard the first run of any such benchmark, it is thermal warm-up.

| | old `(x+y-1)/y` | guarded | delta |
|---|---|---|---|
| **y runtime** (holds an `sdiv`), throughput | 0.448 ns | 0.449 ns | +0.2% |
| **y runtime**, latency | 2.629 ns | 2.407 ns | **−8.4%** |
| **y compile-time constant** (=16), throughput | 0.171 ns | 0.209 ns | +22.2% |
| **y compile-time constant** (=16), latency | 1.330 ns | 1.334 ns | +0.3% |

**Runtime divisor — free, and the loop is divider-bound, not issue-bound.** A bare `sdiv` with nothing else in the loop measures **0.449 ns / ~1.9 cyc**, which is exactly what both variants cost, so the guard's extra instructions are absorbed entirely by the divider's throughput. Latency actually *improves*: the guard's `adds` replaces the old `add`/`sub` pair ahead of the divide.

```asm
old                      guarded
  add  x8, x0, x1          sub  x8, x1, #1
  sub  x8, x8, #1          adds x8, x0, x8
  sdiv x0, x8, x1          b.vs  <fallback>     ; predicted not-taken
                           sdiv x0, x8, x1
```

**Constant divisor — where the cost is.** With `y` a compile-time constant there is no division at all; it folds to a shift, leaving 5 cheap ALU ops, and the guard's 2 extra instructions are a real +22% — of **+0.038 ns/call**. Only `moments_utils.h` (`kChunkSize = 16`) has such a constant among the callers; `SoftMaxKernel.cpp`'s `CHUNK_SIZE` is a runtime `std::min(...)` and takes the free path above. In `moments_utils.h`, `divup` runs once per row of a reduction, ahead of that row's entire Welford loop — in a replica of that shape the difference does not clear the noise floor at any row size.

I also tried `x / y + (x % y > 0)`, which needs no guard at all. It is equivalent on throughput but ~34% worse on runtime-divisor latency, because it puts `msub`/`cmp`/`cinc` *after* the divide instead of ahead of it. Happy to switch if the extra header include is a concern.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#195035
Approved by: https://github.com/Skylion007

Co-authored-by: Claude Opus 5 <[email protected]>
Sanskaaar1 pushed a commit that referenced this pull request Sep 28, 2026
…rm (pytorch#195574)

`aten::rms_norm` declares `Tensor? weight=None`, but `rms_norm_composite` gates the weight multiply on `weight_opt.has_value()` alone. A C++ caller forwarding a possibly-undefined Tensor where an optional is expected produces an engaged optional holding an undefined tensor, and that reaches `upcasted_result.mul(<undefined>)`:

```
Expected a proper Tensor but got None (or an undefined Tensor in C++) for argument #1 'other'
```

`at::layer_norm` accepts the same call, because `math_native_layer_norm` also checks `.defined()`. That asymmetry is the bug.

The MPS branch of `rms_norm_symint` had the same gate and would have handed an undefined weight to `_fused_rms_norm_mps`, so it is fixed here rather than left as a twin of the one being removed. I have no MPS hardware; that half is reasoned from the source and left to CI.

### Test

The failure is only reachable from C++ — Python cannot construct an engaged optional holding an undefined tensor — so the regression test is a gtest in `undefined_tensor_test.cpp`, which `aten/tools/run_tests.sh` already runs. It went there rather than `math_kernel_test.cpp`, which is built but appears in no runner list and so would not have gated this PR.

This machine's Device Guard policy refuses to launch freshly linked gtest binaries, so the assertions were exercised through a `cpp_extension` against a locally built `torch_cpu`. Same harness before and after:

```
before:  engaged-but-undefined  : THREW -> Expected a proper Tensor but got None ...
after:   engaged-but-undefined  : ok, numel=6
```

and the test's own assertion, plus a check that a real weight is still applied:

```
equal(undef, nullopt)  : true
max abs diff           : 0
weight still applied   : true
```

### Related

pytorch#193936 adds `torch::nn::RMSNorm` and currently works around this by converting an undefined weight to `std::nullopt` before calling `at::rms_norm`. If this lands first, that conversion and its comment can be dropped there.

Developed with AI assistance (Claude); I reproduced the failure, wrote the fix and ran the checks above.

Pull Request resolved: pytorch#195574
Approved by: https://github.com/drisspg

Co-authored-by: Claude Opus 5 <[email protected]>
Sanskaaar1 pushed a commit that referenced this pull request Oct 8, 2026
…nction` in `const_data_ptr` (pytorch#199781)

otherwise tests such as `test/test_overrides.py::TestTorchFunctionRedispatchOpsDeviceCUDA::test_redispatch_topk_cutedsl_optimized_deterministic_cuda_float32` fail with e.g.,

```
test_overrides.py::TestTorchFunctionRedispatchOpsDeviceCUDA::test_redispatch_topk_cutedsl_optimized_deterministic_cuda_float32 - Exception: you cannot skip two levels of __torch_function__, you need to run one level of __torch_function__ before being able to skip again.
2026-10-05T08:02:28.466965Z 01E Exception raised from THPModule_skip_one_hop_torch_function at /opt/pytorch/pytorch/torch/csrc/utils/disable_torch_function.cpp:292 (most recent call first):
2026-10-05T08:02:28.466966Z 01E frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0xd0 (0xfffff4c13890 in /usr/local/lib/python3.12/dist-packages/torch/lib/libc10.so)
2026-10-05T08:02:28.466967Z 01E frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, char const*) + 0x7c (0xfffff48383c4 in /usr/local/lib/python3.12/dist-packages/torch/lib/libc10.so)
2026-10-05T08:02:28.466968Z 01E frame pytorch#2: <unknown function> + 0x12e2eec (0xffffeece2eec in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466969Z 01E frame pytorch#3: /usr/bin/python() [0x503fec]
2026-10-05T08:02:28.466969Z 01E frame pytorch#4: _PyObject_MakeTpCall + 0x78 (0x4c2c48 in /usr/bin/python)
2026-10-05T08:02:28.466970Z 01E frame pytorch#5: _PyEval_EvalFrameDefault + 0x8a0 (0x564354 in /usr/bin/python)
2026-10-05T08:02:28.466971Z 01E frame pytorch#6: /usr/bin/python() [0x4c6d6c]
2026-10-05T08:02:28.466971Z 01E frame pytorch#7: /usr/bin/python() [0x4c3a84]
2026-10-05T08:02:28.466972Z 01E frame pytorch#8: PyObject_CallFunctionObjArgs + 0x80 (0x4c3944 in /usr/bin/python)
2026-10-05T08:02:28.466972Z 01E frame pytorch#9: <unknown function> + 0x1e394cc (0xffffef8394cc in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466973Z 01E frame pytorch#10: torch::handle_torch_function_no_python_arg_parser(c10::ArrayRef<_object*>, _object*, _object*, char const*, _object*, char const*, torch::TorchFunctionName) + 0x1c (0xffffef802d5c in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466974Z 01E frame pytorch#11: <unknown function> + 0x1e11904 (0xffffef811904 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466975Z 01E frame pytorch#12: <unknown function> + 0x6c8e80 (0xffffee0c8e80 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466976Z 01E frame pytorch#13: /usr/bin/python() [0x4cc00c]
2026-10-05T08:02:28.466976Z 01E frame pytorch#14: <unknown function> + 0x12e2e28 (0xffffeece2e28 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466977Z 01E frame pytorch#15: /usr/bin/python() [0x503fec]
2026-10-05T08:02:28.466978Z 01E frame pytorch#16: _PyObject_MakeTpCall + 0x78 (0x4c2c48 in /usr/bin/python)
2026-10-05T08:02:28.466978Z 01E frame pytorch#17: _PyEval_EvalFrameDefault + 0x8a0 (0x564354 in /usr/bin/python)
2026-10-05T08:02:28.466979Z 01E frame pytorch#18: /usr/bin/python() [0x4c6d6c]
2026-10-05T08:02:28.466979Z 01E frame pytorch#19: /usr/bin/python() [0x4c3a84]
2026-10-05T08:02:28.466980Z 01E frame pytorch#20: PyObject_CallFunctionObjArgs + 0x80 (0x4c3944 in /usr/bin/python)
2026-10-05T08:02:28.466981Z 01E frame pytorch#21: <unknown function> + 0x1e394cc (0xffffef8394cc in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466981Z 01E frame pytorch#22: torch::handle_torch_function_no_python_arg_parser(c10::ArrayRef<_object*>, _object*, _object*, char const*, _object*, char const*, torch::TorchFunctionName) + 0x1c (0xffffef802d5c in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466983Z 01E frame pytorch#23: <unknown function> + 0x1e11904 (0xffffef811904 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466983Z 01E frame pytorch#24: <unknown function> + 0x6c8e80 (0xffffee0c8e80 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466984Z 01E frame pytorch#25: /usr/bin/python() [0x4cc00c]
2026-10-05T08:02:28.466985Z 01E frame pytorch#26: PyObject_Vectorcall + 0x4c (0x4c37fc in /usr/bin/python)
2026-10-05T08:02:28.466985Z 01E frame pytorch#27: _PyEval_EvalFrameDefault + 0x8a0 (0x564354 in /usr/bin/python)
2026-10-05T08:02:28.466986Z 01E frame pytorch#28: PyObject_Vectorcall + 0x4c (0x4c37fc in /usr/bin/python)
2026-10-05T08:02:28.466989Z 01E frame pytorch#29: <unknown function> + 0x9cf8e4 (0xffffee3cf8e4 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466989Z 01E frame pytorch#30: <unknown function> + 0x1fd39f0 (0xffffef9d39f0 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466990Z 01E frame pytorch#31: <unknown function> + 0x1e38644 (0xffffef838644 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466991Z 01E frame pytorch#32: <unknown function> + 0x2179b44 (0xffffe4179b44 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_cpu.so)
2026-10-05T08:02:28.466992Z 01E frame pytorch#33: <unknown function> + 0xab0f6f8 (0xffffecb0f6f8 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_cpu.so)
2026-10-05T08:02:28.466993Z 01E frame pytorch#34: <unknown function> + 0xa47ada0 (0xffffec47ada0 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_cpu.so)
2026-10-05T08:02:28.466993Z 01E frame pytorch#35: <unknown function> + 0xa47ab7c (0xffffec47ab7c in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_cpu.so)
2026-10-05T08:02:28.466994Z 01E frame pytorch#36: at::_ops::topk::call(at::Tensor const&, c10::SymInt, long, bool, bool) + 0x160 (0xffffec47aa78 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_cpu.so)
2026-10-05T08:02:28.466995Z 01E frame pytorch#37: <unknown function> + 0x2014450 (0xffffefa14450 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466996Z 01E frame pytorch#38: /usr/bin/python() [0x503fb4]
2026-10-05T08:02:28.466997Z 01E frame pytorch#39: PyObject_Call + 0x6c (0x4c512c in /usr/bin/python)
2026-10-05T08:02:28.466997Z 01E frame pytorch#40: <unknown function> + 0x12e2e28 (0xffffeece2e28 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.466998Z 01E frame pytorch#41: /usr/bin/python() [0x503fec]
2026-10-05T08:02:28.466998Z 01E frame pytorch#42: _PyObject_MakeTpCall + 0x78 (0x4c2c48 in /usr/bin/python)
2026-10-05T08:02:28.466999Z 01E frame pytorch#43: _PyEval_EvalFrameDefault + 0x8a0 (0x564354 in /usr/bin/python)
2026-10-05T08:02:28.467000Z 01E frame pytorch#44: /usr/bin/python() [0x4c6d6c]
2026-10-05T08:02:28.467000Z 01E frame pytorch#45: /usr/bin/python() [0x4c3a84]
2026-10-05T08:02:28.467001Z 01E frame pytorch#46: PyObject_CallFunctionObjArgs + 0x80 (0x4c3944 in /usr/bin/python)
2026-10-05T08:02:28.467001Z 01E frame pytorch#47: <unknown function> + 0x1e394cc (0xffffef8394cc in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.467002Z 01E frame pytorch#48: torch::handle_torch_function_no_python_arg_parser(c10::ArrayRef<_object*>, _object*, _object*, char const*, _object*, char const*, torch::TorchFunctionName) + 0x1c (0xffffef802d5c in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.467003Z 01E frame pytorch#49: <unknown function> + 0x1e33f78 (0xffffef833f78 in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.467004Z 01E frame pytorch#50: <unknown function> + 0x201428c (0xffffefa1428c in /usr/local/lib/python3.12/dist-packages/torch/lib/libtorch_python.so)
2026-10-05T08:02:28.467005Z 01E frame pytorch#51: /usr/bin/python() [0x503fb4]
2026-10-05T08:02:28.467005Z 01E frame pytorch#52: PyObject_Call + 0x6c (0x4c512c in /usr/bin/python)
2026-10-05T08:02:28.467006Z 01E frame pytorch#53: _PyEval_EvalFrameDefault + 0x3f1c (0x5679d0 in /usr/bin/python)
2026-10-05T08:02:28.467006Z 01E frame pytorch#54: _PyObject_Call_Prepend + 0xc4 (0x4c4724 in /usr/bin/python)
2026-10-05T08:02:28.467007Z 01E frame pytorch#55: /usr/bin/python() [0x5294d0]
2026-10-05T08:02:28.467007Z 01E frame pytorch#56: PyObject_Call + 0x6c (0x4c512c in /usr/bin/python)
2026-10-05T08:02:28.467008Z 01E frame pytorch#57: _PyEval_EvalFrameDefault + 0x3f1c (0x5679d0 in /usr/bin/python)
2026-10-05T08:02:28.467009Z 01E frame pytorch#58: /usr/bin/python() [0x4c6de4]
2026-10-05T08:02:28.467009Z 01E frame pytorch#59: _PyEval_EvalFrameDefault + 0x3f1c (0x5679d0 in /usr/bin/python)
2026-10-05T08:02:28.467010Z 01E frame pytorch#60: /usr/bin/python() [0x4c6de4]
2026-10-05T08:02:28.467010Z 01E frame pytorch#61: _PyEval_EvalFrameDefault + 0x3f1c (0x5679d0 in /usr/bin/python)
2026-10-05T08:02:28.467013Z 01E frame pytorch#62: /usr/bin/python() [0x4c6e48]
2026-10-05T08:02:28.467014Z 01E
2026-10-05T08:02:28.467014Z 01E
2026-10-05T08:02:28.467014Z 01E Caused by sample input at index 0: SampleInput(input=Tensor[size=(256, 4096), device="cuda:0", dtype=torch.float32], args=(64), kwargs={}, broadcasts_input=False, name='')
2026-10-05T08:02:28.467015Z 01E
2026-10-05T08:02:28.467016Z 01E To execute this test, run the following from the base repo dir:
2026-10-05T08:02:28.467016Z 01E     PYTORCH_OPINFO_SAMPLE_INPUT_INDEX=0 python test/test_overrides.py TestTorchFunctionRedispatchOpsDeviceCUDA.test_redispatch_topk_cutedsl_optimized_deterministic_cuda_float32
2026-10-05T08:02:28.467017Z 01E
2026-10-05T08:02:28.467017Z 01E This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
2026-10-05T08:02:28.467018Z 01E !!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
2026-10-05T08:02:28.467019Z 01E ===================== 1 failed, 13903 deselected in 2.03s ======================
2026-10-05T08:02:28.467019Z 01E Got exit code 1
2026-10-05T08:02:28.467020Z 01E FAILED CONSISTENTLY: test/test_overrides.py::TestTorchFunctionRedispatchOpsDeviceCUDA::test_redispatch_topk_cutedsl_optimized_deterministic_cuda_float32
```

authored with codex
Pull Request resolved: pytorch#199781
Approved by: https://github.com/Skylion007, https://github.com/albanD
Sanskaaar1 pushed a commit that referenced this pull request Nov 6, 2026
Trims down the cross product of OpInfo sample inputs for the various max
pooling related entries.

> Authored with an AI assistant (Metamate).
>
> `nn.functional.max_pool2d`, `nn.functional.max_pool3d`, `max_pool2d_with_indices_backward` and `nn.functional.max_pool1d` are the #1, pytorch#2, pytorch#5 and pytorch#6 most expensive OpInfo entries in CI over the last week (~60M test-sec combined); `max_unpool{1,2,3}d` reuse the same sample generator.
>
> Removed duplication:
> - 1d: every tuple arg duplicated its scalar (`(3,)` vs `3`, etc.), identical once the Python arg parser expands scalars
> - 2d: `padding=1` duplicated `padding=(1, 1)`, likewise
> - `max_pool2d_with_indices_backward`: `return_indices=False`, which its wrapper ignores
>
> Dropped coverage (all remaining values are still fully crossed):
> - batch=1 (batch=2 and unbatched are kept)
> - square 2d/3d kernels (scalar `kernel_size=3`); only the asymmetric tuple remains
> - explicit 2d/3d strides with equal per-dim values (scalar `stride=2`). `(2, 1)` / `(2, 1, 2)` become `(1, 2)` / `(1, 2, 3)`, whose per-dim values all differ (so swapping any two changes the output) and whose windows overlap along some dims while tiling along others. 2d still overlaps along all dims with `dilation` > 1; 3d no longer can, since three distinct strides can't all be below its effective kernels (at most 3). 2d's fixed W becomes 5 instead of 6
> - `max_unpool*d` grad variants no longer keep any sample whose random indices happen to be unique, only `stride=None` (non-overlapping, so always unique) on the smallest max_pool input
> - the >25-window Inductor path (below) is now covered for float, batched, forward-only input; the dropped scalar `kernel_size=3` samples also sent integer dtypes, unbatched input and backward down it. CUDA/XPU f16 max_pool3d runs only its first sample (`inductor_one_sample`), which was a 27-element window and is now 18, so that config no longer reaches it
>
> Dropping scalar `kernel_size=3` removed the only 3d window above Inductor's 25-element threshold, so the new `test_max_pool3d_large_kernel` covers that non-unrolled reduction lowering directly, with and without padding plus a `ceil_mode` partial window (the padded case is skipped on Halide, which can't schedule that reduction).
>
> `test_proxy_tensor.py`'s symbolic `make_fx` xfail for `max_pool2d_with_indices_backward` is removed because its trigger left the samples, not because it was fixed: a direct OpOverload call can't bind a scalar SymInt to `int[N]`. `test_op_overload_scalar_symint_for_int_list` keeps that tracked.
>
> The first sample has an overlapping explicit stride and a partial `ceil_mode` window (1d puts the larger signal size first; 2d/3d get it from the odd W), since `inductor_one_sample` configs only run the first sample.
>
> Samples per dtype, unique in parentheses where it differs; grad and no-grad counts match. Old max_unpool grad-variant counts varied by dtype, as their filter depended on random values:
>
> | OpInfo | before | after |
> |---|---|---|
> | nn.functional.max_pool1d | 864 (96) | 64 |
> | nn.functional.max_pool2d | 1440 (960) | 192 |
> | max_pool2d_with_indices_backward | 1440 (480) | 96 |
> | nn.functional.max_pool3d | 576 | 128 |
> | nn.functional.max_unpool1d | 144 (24) | 16 (12) |
> | nn.functional.max_unpool1d (grad) | 13-18 | 4 (3) |
> | nn.functional.max_unpool2d | 288 (152) | 32 (28) |
> | nn.functional.max_unpool2d (grad) | 28-35 | 8 |
> | nn.functional.max_unpool3d | 96 (84) | 16 (14) |
> | nn.functional.max_unpool3d (grad) | 9-12 | 4 |
>
> Test Plan (CPU + CUDA, local build):
> ```
> python test/test_ops.py -k "max_pool or max_unpool"
> python test/test_ops_gradients.py -k "max_pool or max_unpool"
> python test/test_meta.py -k "max_pool or max_unpool"
> python test/test_decomp.py -k "max_pool or max_unpool"
> python test/test_proxy_tensor.py -k "max_pool or scalar_symint"
> python test/inductor/test_torchinductor_opinfo.py -k "max_pool or max_unpool"
> python test/inductor/test_torchinductor.py -k test_max_pool3d_large_kernel
> ```

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.