Skip to content

[inductor][test] Cover nested-cat view bounds and chunk values (#205202) - #205202

Closed
Z-Ghostshell wants to merge 1 commit into
pytorch:mainfrom
Z-Ghostshell:export-D131637630
Closed

Z-Ghostshell wants to merge 1 commit into
pytorch:mainfrom
Z-Ghostshell:export-D131637630

Conversation

@Z-Ghostshell

@Z-Ghostshell Z-Ghostshell commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Add regression coverage for #204346. PR #192575 already fixes the implementation by freezing the backing layout before a noncontiguous reshape records its index map. This diff changes tests only.

Both tests compile the issue's graphs with comprehensive padding. test_nested_cat_returned_expand checks that every returned tensor fits inside its storage before any output is read; test_nested_cat_chunk_values compares the chunk outputs with eager using assertEqual. Both turn off Dynamo's canonicalize_output_graph_node_order, which the Dynamo test harness enables: the bug depends on the traced output order, and with canonicalization the chunk case passes even without the fix. The earlier dynamic=True variants are removed because dynamic shapes are not padded by default, so they did not exercise the bug.

Agent details

Prepared with an AI assistant. The author must inspect the exact code before GitHub export. No landing or review-gate bypass is authorized.

Test Plan:
Ran on an NVIDIA PG509-210 (A100, sm80, driver 580.126.09) with the published torch 2.15.0+cu132 / Triton 3.9.0 wheels in an isolated venv, loading this test file directly rather than a source build. The runner instantiates the CUDA tests from the file; --old-view restores the pre-#192575 View.create in-process (backing layout looked up with freeze=False).

python run_nested_cat.py test_padding.py              # x3
python run_nested_cat.py test_padding.py --old-view   # x3
arc lint fbcode/caffe2/test/inductor/test_padding.py

With the fix, both tests pass in 3/3 runs. With the old View.create, both fail in 3/3 runs: the expand test at the storage-bounds check (257964 not less than or equal to 254016, stride (0, 1344, 27, 1)), and the chunk test with 16198/16320 mismatched elements and a max absolute difference of 4.16, matching the issue. In the previous revision the chunk test passed without the fix because of the harness's output canonicalization; turning it off makes both tests real fail-before guards.

Not run: a clean current-master native build, XPU, or the rest of test_padding.py. arc lint passes.

Differential Revision: D131637630

@pytorch-bot

pytorch-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

This PR adds `NestedCatPaddingTest` to test/inductor/test_padding.py as
regression coverage for # 204346, with storage-bounds and value checks on nested
cat/chunk graphs compiled with comprehensive padding. The review recommends
Approve and labels every point non-blocking. The most useful follow-ups: say in
the code that the chunk test is not a fail-before guard, make the dynamic=True
cases actually test padding or drop them, and let the tests run on XPU.

Findings (7):

[minor] test/inductor/test_padding.py:1031
Non-blocking: `test_nested_cat_chunk_values` doesn't catch the regression it is
named for. The PR body says that with the old `View.create` restored, "the two
chunk cases pass in the unittest environment" and are "not independent
fail-before oracles", so both parametrizations pass with or without the # 192575
fix. Either find out why the standalone repro fails but this `TestCase` version
passes and make the test fail before the fix, or add a comment saying it is
forward/smoke coverage, so readers don't take it as a guard for # 204346.

[minor] test/inductor/test_padding.py:1072
Non-blocking: the `dynamic=True` variants never test padding of dynamic shapes.
`pad_dynamic_shapes` defaults to False (config.py:1806), and
`Layout._pad_strides` returns strides unchanged whenever a size or stride is
symbolic (ir.py:4809-4814), only bumping `num_comprehensive_padding` after it
actually pads. In the chunk test the `if not dynamic:` guard hides this, so the
dynamic run is a plain dynamic-shape correctness check. That contradicts the
description's claim that both static and dynamic compilation use comprehensive
padding. In the expand test, `assertGreater(metrics.num_comprehensive_padding,
0)` (:1028) can only pass under dynamic=True because the literal `expand(1, 48,
49, 27)` (:1008) turns the symbols into constants, so the dynamic case repeats
the static check. Either patch `pad_dynamic_shapes=True` and avoid literal
sizes, or drop the `dynamic` parametrization. Either way, add a comment
explaining the asymmetric guard.

[minor] test/inductor/test_padding.py:1069
Non-blocking: use `assertEqual` instead of `self.assertTrue(same(...,
fp64_ref=reference))`. On failure the assertion only says "False is not true",
and the details go to `log.error`. `same()` compares with broadcasting
`torch.allclose`/RMSE (torch/_dynamo/utils.py:3876, 3901), so a wrongly shaped
but broadcastable output still passes. CLAUDE.md:81 asks for `assertEqual` on
tensors, which the expand test already uses (:1027). `self.assertEqual(fn(x,
other), actual)`, with explicit atol/rtol if needed, would check shapes and give
a useful diff. Nit: the generator variable in `tuple(x.cpu() for x in actual)`
shadows the input `x` from :1053.

[minor] test/inductor/test_padding.py:1076
Non-blocking: `only_for="cuda"` silently drops XPU. The rest of the file runs on
any GPU through `GPU_TYPE`/`@​ requires_gpu()`, and `run_tests()` runs whenever
`HAS_GPU` is true (:1080), XPU included. Nothing in these tests is
CUDA-specific, since every tensor is created on the `device` parameter.
`instantiate_device_type_tests` defaults to `allow_xpu=False`. Use the existing
idiom `only_for=GPU_TYPE, allow_xpu=True`
(test/inductor/test_triton_helpers.py:608-611), or say why the tests are
CUDA-only.

[info] test/inductor/test_padding.py:984
Non-blocking: say in the code what the tests guard (:984, :1000, :1031). Neither
test mentions # 204346 or the `View.create` freeze fix; only the PR body does.
Without that context, the fuzzer-style body (`v1[..., 0:1:60]`,
`v20`/`v24`/`v35_0`, unused chunk halves) is hard to follow. Add a short
docstring like the one on `test_reduction_comprehensive_padding_stride`
(:964-969) that names the issue and says the storage-bounds check is the
assertion that fails before the fix.

(2 more not shown, see the review run)

Reviewed commit: 50a734b (NOT the current head 27ee416)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 27ee416 with merge base 76745a9 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@meta-codesync

meta-codesync Bot commented Nov 16, 2026

Copy link
Copy Markdown

@Z-Ghostshell has exported this pull request. If you are a Meta employee, you can view the originating Diff in D131637630.

@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 17, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of 50a734b: nothing blocking; ready for human review.

This PR adds NestedCatPaddingTest to test/inductor/test_padding.py as regression coverage for # 204346, with storage-bounds and value checks on nested cat/chunk graphs compiled with comprehensive padding. The review recommends Approve and labels every point non-blocking. The most useful follow-ups: say in the code that the chunk test is not a fail-before guard, make the dynamic=True cases actually test padding or drop them, and let the tests run on XPU.

⚪ 7 non-blocking findings

def test_nested_cat_chunk_values(self, device, dynamic):

Non-blocking: test_nested_cat_chunk_values doesn't catch the regression it is named for. The PR body says that with the old View.create restored, "the two chunk cases pass in the unittest environment" and are "not independent fail-before oracles", so both parametrizations pass with or without the # 192575 fix. Either find out why the standalone repro fails but this TestCase version passes and make the test fail before the fix, or add a comment saying it is forward/smoke coverage, so readers don't take it as a guard for # 204346.


if not dynamic:

Non-blocking: the dynamic=True variants never test padding of dynamic shapes. pad_dynamic_shapes defaults to False (config.py:1806), and Layout._pad_strides returns strides unchanged whenever a size or stride is symbolic (ir.py:4809-4814), only bumping num_comprehensive_padding after it actually pads. In the chunk test the if not dynamic: guard hides this, so the dynamic run is a plain dynamic-shape correctness check. That contradicts the description's claim that both static and dynamic compilation use comprehensive padding. In the expand test, assertGreater(metrics.num_comprehensive_padding, 0) (:1028) can only pass under dynamic=True because the literal expand(1, 48, 49, 27) (:1008) turns the symbols into constants, so the dynamic case repeats the static check. Either patch pad_dynamic_shapes=True and avoid literal sizes, or drop the dynamic parametrization. Either way, add a comment explaining the asymmetric guard.


self.assertTrue(

Non-blocking: use assertEqual instead of self.assertTrue(same(..., fp64_ref=reference)). On failure the assertion only says "False is not true", and the details go to log.error. same() compares with broadcasting torch.allclose/RMSE (torch/_dynamo/utils.py:3876, 3901), so a wrongly shaped but broadcastable output still passes. CLAUDE.md:81 asks for assertEqual on tensors, which the expand test already uses (:1027). self.assertEqual(fn(x, other), actual), with explicit atol/rtol if needed, would check shapes and give a useful diff. Nit: the generator variable in tuple(x.cpu() for x in actual) shadows the input x from :1053.


instantiate_device_type_tests(NestedCatPaddingTest, globals(), only_for="cuda")

Non-blocking: only_for="cuda" silently drops XPU. The rest of the file runs on any GPU through GPU_TYPE/@ requires_gpu(), and run_tests() runs whenever HAS_GPU is true (:1080), XPU included. Nothing in these tests is CUDA-specific, since every tensor is created on the device parameter. instantiate_device_type_tests defaults to allow_xpu=False. Use the existing idiom only_for=GPU_TYPE, allow_xpu=True (test/inductor/test_triton_helpers.py:608-611), or say why the tests are CUDA-only.


class NestedCatPaddingTest(TestCase):

Non-blocking: say in the code what the tests guard (:984, :1000, :1031). Neither test mentions # 204346 or the View.create freeze fix; only the PR body does. Without that context, the fuzzer-style body (v1\[..., 0:1:60\], v20/v24/v35_0, unused chunk halves) is hard to follow. Add a short docstring like the one on test_reduction_comprehensive_padding_stride (:964-969) that names the issue and says the storage-bounds check is the assertion that fails before the fix.


def _assert_valid_storage_bounds(self, value):

Non-blocking: _assert_valid_storage_bounds re-implements an existing utility. torch._prims_common.compute_required_storage_length(shape, strides, storage_offset) (torch/_prims_common/init.py:1916) computes the same quantity and returns 0 for empty tensors. The hand-rolled (size - 1) * stride goes wrong for zero-size dims, though that can't happen with these shapes today. Keep the separate stride >= 0 check, and add a msg= with the size, stride, offset and nbytes so a bounds failure says which output broke.


metrics.reset()

Non-blocking: the setup block is duplicated (:1015-1022 and :1057-1064). The metrics.reset() + config.patch(...) + no_grad() + compile + bounds-loop sequence could be a small helper. The patch could use the dict form the file uses elsewhere (:905, :978) instead of mixing keyword arguments with **{"triton.cudagraphs": False}.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 17, 2026
…ch#205202)

Summary:

Add regression coverage for pytorch#204346. PR pytorch#192575 already fixes the implementation by freezing the backing layout before a noncontiguous reshape records its index map. This diff changes tests only.

Both tests compile the issue's graphs with comprehensive padding. `test_nested_cat_returned_expand` checks that every returned tensor fits inside its storage before any output is read; `test_nested_cat_chunk_values` compares the chunk outputs with eager using `assertEqual`. Both turn off Dynamo's `canonicalize_output_graph_node_order`, which the Dynamo test harness enables: the bug depends on the traced output order, and with canonicalization the chunk case passes even without the fix. The earlier `dynamic=True` variants are removed because dynamic shapes are not padded by default, so they did not exercise the bug.

### Agent details

Prepared with an AI assistant. The author must inspect the exact code before GitHub export. No landing or review-gate bypass is authorized.

Test Plan:
Ran on an NVIDIA PG509-210 (A100, sm80, driver 580.126.09) with the published torch 2.15.0+cu132 / Triton 3.9.0 wheels in an isolated venv, loading this test file directly rather than a source build. The runner instantiates the CUDA tests from the file; `--old-view` restores the pre-pytorch#192575 `View.create` in-process (backing layout looked up with `freeze=False`).

```sh
python run_nested_cat.py test_padding.py              # x3
python run_nested_cat.py test_padding.py --old-view   # x3
arc lint fbcode/caffe2/test/inductor/test_padding.py
```

With the fix, both tests pass in 3/3 runs. With the old `View.create`, both fail in 3/3 runs: the expand test at the storage-bounds check (`257964 not less than or equal to 254016`, stride `(0, 1344, 27, 1)`), and the chunk test with 16198/16320 mismatched elements and a max absolute difference of 4.16, matching the issue. In the previous revision the chunk test passed without the fix because of the harness's output canonicalization; turning it off makes both tests real fail-before guards.

Not run: a clean current-master native build, XPU, or the rest of `test_padding.py`. `arc lint` passes.

Differential Revision: D131637630
@meta-codesync meta-codesync Bot changed the title [inductor][test] Cover nested-cat view bounds and chunk values [inductor][test] Cover nested-cat view bounds and chunk values (#205202) Nov 18, 2026
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 18, 2026
@meta-codesync

meta-codesync Bot commented Nov 18, 2026

Copy link
Copy Markdown

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged meta-exported module: inductor ready for review Automated review passed, ready for a final review by a maintainer. topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants