Repository navigation
native_group_norm: Handle non-contiguous tensors, rather than throwing - #186414
Closed
benjaminglass1 wants to merge 33 commits into
Closed
benjaminglass1 wants to merge 33 commits into
benjaminglass1 wants to merge 33 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186414
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 2 PendingAs of commit bb2b9e9 with merge base 526b9ce ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Jun 5, 2026
This was referenced Jun 10, 2026
benjaminglass1
marked this pull request as ready for review
June 10, 2026 17:24
benjaminglass1
requested review from
Chillee,
kshitij12345,
mruberry and
zou3519
as code owners
June 10, 2026 17:24
slayton58
approved these changes
Jul 24, 2026
This was referenced Jul 24, 2026
Collaborator
|
Starting merge as part of PR stack under #190794 |
pytorchmergebot
pushed a commit
that referenced
this pull request
Jul 25, 2026
Take a bunch of cases where we check for (ptr == nullptr) and just make them implicit bool(ptr), as well as some assorted reformatting. Pull Request resolved: #190246 Approved by: https://github.com/slayton58 ghstack dependencies: #186414
pytorchmergebot
pushed a commit
that referenced
this pull request
Jul 25, 2026
Pull Request resolved: #190794 Approved by: https://github.com/slayton58, https://github.com/Skylion007 ghstack dependencies: #186414, #190246
Harsha0Sree
pushed a commit
to Harsha0Sree/pytorch
that referenced
this pull request
Jul 25, 2026
pytorch#186414) `native_group_norm` and `native_group_norm_backward` have always assumed contiguity for some tensors, and asserted it for others. The assertions cause unexpected behavior for `vmap`, which may batch in non-contiguous ways. The assumptions (obviously) can cause memory access errors. This PR changes the implementations to instead call `contiguous()` with an appropriate memory format, which fixes vmap and the OOB accesses without using any extra memory in situations where callers have already ensured contiguous inputs. This does mean that a situation which previously threw an error (non-contiguous X) now succeeds silently with an extra allocation. It's unlikely that anyone is relying on this behavior, however, since most people would have been calling `native_group_norm` through `nn.functional.group_norm`, which already did calls to `contiguous()`. Additional important changes: 1. Short-circuit evaluation has been made more consistent, triggering whenever N == 0 and returning empty (or zero, for backward) tensors without ever calling the native kernels. 2. The code now throws errors if either the number of channels or flattened inner size is 0, since the results are non-sensical (and incompatible with gradcheck) in either of those two cases. 3. This PR removes a bypass for the `contiguous()` calls on the XPU backward pass (in `derivatives.yaml`). This is because XPU is already calling `contiguous()` internally, so the bypass was misleading to begin with. See https://github.com/intel/torch-xpu-ops/blob/main/src/ATen/native/xpu/sycl/GroupNormKernels.cpp#L1371. 4. Two VMAP tests have been skipped for `native_group_norm`. They were previously XFAILs that failed on the first OpInfo test (i.e. relatively quickly), but now that they succeed they take 3-5 minutes each to run, which is just too long for our pipeline. 5. The `CompositeExplicitAutograd` operator `math_group_norm` now does some basic validation on inputs to match the other `group_norm` operators. Pull Request resolved: pytorch#186414 Approved by: https://github.com/slayton58
Harsha0Sree
pushed a commit
to Harsha0Sree/pytorch
that referenced
this pull request
Jul 25, 2026
Take a bunch of cases where we check for (ptr == nullptr) and just make them implicit bool(ptr), as well as some assorted reformatting. Pull Request resolved: pytorch#190246 Approved by: https://github.com/slayton58 ghstack dependencies: pytorch#186414
Harsha0Sree
pushed a commit
to Harsha0Sree/pytorch
that referenced
this pull request
Jul 25, 2026
Pull Request resolved: pytorch#190794 Approved by: https://github.com/slayton58, https://github.com/Skylion007 ghstack dependencies: pytorch#186414, pytorch#190246
aws-kingrj
pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
pytorch#186414) `native_group_norm` and `native_group_norm_backward` have always assumed contiguity for some tensors, and asserted it for others. The assertions cause unexpected behavior for `vmap`, which may batch in non-contiguous ways. The assumptions (obviously) can cause memory access errors. This PR changes the implementations to instead call `contiguous()` with an appropriate memory format, which fixes vmap and the OOB accesses without using any extra memory in situations where callers have already ensured contiguous inputs. This does mean that a situation which previously threw an error (non-contiguous X) now succeeds silently with an extra allocation. It's unlikely that anyone is relying on this behavior, however, since most people would have been calling `native_group_norm` through `nn.functional.group_norm`, which already did calls to `contiguous()`. Additional important changes: 1. Short-circuit evaluation has been made more consistent, triggering whenever N == 0 and returning empty (or zero, for backward) tensors without ever calling the native kernels. 2. The code now throws errors if either the number of channels or flattened inner size is 0, since the results are non-sensical (and incompatible with gradcheck) in either of those two cases. 3. This PR removes a bypass for the `contiguous()` calls on the XPU backward pass (in `derivatives.yaml`). This is because XPU is already calling `contiguous()` internally, so the bypass was misleading to begin with. See https://github.com/intel/torch-xpu-ops/blob/main/src/ATen/native/xpu/sycl/GroupNormKernels.cpp#L1371. 4. Two VMAP tests have been skipped for `native_group_norm`. They were previously XFAILs that failed on the first OpInfo test (i.e. relatively quickly), but now that they succeed they take 3-5 minutes each to run, which is just too long for our pipeline. 5. The `CompositeExplicitAutograd` operator `math_group_norm` now does some basic validation on inputs to match the other `group_norm` operators. Pull Request resolved: pytorch#186414 Approved by: https://github.com/slayton58
aws-kingrj
pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
Take a bunch of cases where we check for (ptr == nullptr) and just make them implicit bool(ptr), as well as some assorted reformatting. Pull Request resolved: pytorch#190246 Approved by: https://github.com/slayton58 ghstack dependencies: pytorch#186414
aws-kingrj
pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
Pull Request resolved: pytorch#190794 Approved by: https://github.com/slayton58, https://github.com/Skylion007 ghstack dependencies: pytorch#186414, pytorch#190246
MelindaTan
pushed a commit
to MelindaTan/pytorch
that referenced
this pull request
Jul 31, 2026
pytorch#186414) `native_group_norm` and `native_group_norm_backward` have always assumed contiguity for some tensors, and asserted it for others. The assertions cause unexpected behavior for `vmap`, which may batch in non-contiguous ways. The assumptions (obviously) can cause memory access errors. This PR changes the implementations to instead call `contiguous()` with an appropriate memory format, which fixes vmap and the OOB accesses without using any extra memory in situations where callers have already ensured contiguous inputs. This does mean that a situation which previously threw an error (non-contiguous X) now succeeds silently with an extra allocation. It's unlikely that anyone is relying on this behavior, however, since most people would have been calling `native_group_norm` through `nn.functional.group_norm`, which already did calls to `contiguous()`. Additional important changes: 1. Short-circuit evaluation has been made more consistent, triggering whenever N == 0 and returning empty (or zero, for backward) tensors without ever calling the native kernels. 2. The code now throws errors if either the number of channels or flattened inner size is 0, since the results are non-sensical (and incompatible with gradcheck) in either of those two cases. 3. This PR removes a bypass for the `contiguous()` calls on the XPU backward pass (in `derivatives.yaml`). This is because XPU is already calling `contiguous()` internally, so the bypass was misleading to begin with. See https://github.com/intel/torch-xpu-ops/blob/main/src/ATen/native/xpu/sycl/GroupNormKernels.cpp#L1371. 4. Two VMAP tests have been skipped for `native_group_norm`. They were previously XFAILs that failed on the first OpInfo test (i.e. relatively quickly), but now that they succeed they take 3-5 minutes each to run, which is just too long for our pipeline. 5. The `CompositeExplicitAutograd` operator `math_group_norm` now does some basic validation on inputs to match the other `group_norm` operators. Pull Request resolved: pytorch#186414 Approved by: https://github.com/slayton58
MelindaTan
pushed a commit
to MelindaTan/pytorch
that referenced
this pull request
Jul 31, 2026
Take a bunch of cases where we check for (ptr == nullptr) and just make them implicit bool(ptr), as well as some assorted reformatting. Pull Request resolved: pytorch#190246 Approved by: https://github.com/slayton58 ghstack dependencies: pytorch#186414
MelindaTan
pushed a commit
to MelindaTan/pytorch
that referenced
this pull request
Jul 31, 2026
Pull Request resolved: pytorch#190794 Approved by: https://github.com/slayton58, https://github.com/Skylion007 ghstack dependencies: pytorch#186414, pytorch#190246
This was referenced Aug 1, 2026
jansel
added a commit
that referenced
this pull request
Aug 9, 2026
Root cause: export recorded guards from metadata-only layout, broadcast, and view decisions that used example-shape truth for symbolic size-one checks. In the issue repro, temporal slicing feeds GroupNormSpatial through flatten, reshape, and group_norm; those checks excluded valid values from the declared Dim range. Use static proofs for optional metadata fast paths that can safely fall back, while preserving guard-based behavior for normal torch.compile broadcasting. Preserve the original requested fake-view shape across retries, avoid specializing unknown source dimensions when reshaping to a size-one target, and directly flatten the statically size-one leading-dimension case needed by the repro. Symbolic group_norm inputs clone into a statically known-safe memory format instead of invoking guard-producing contiguity checks. After rebasing over #186414, native_group_norm owns concrete input and affine contiguity. Keep only the high-level symbolic input clone here and pass weight and bias through unchanged, avoiding duplicate validation and conversions while retaining the guard-free symbolic path. Accuracy runs also reapply the existing determinism setup after benchmark model construction. Some model constructors reset global determinism flags, which otherwise makes the eager-vs-eager check fail before the compiler path runs. Fixes #143463 Generated by my agent Test Plan: ```bash .venv/bin/python -m pip install -e . -v --no-build-isolation .venv/bin/python test/export/test_export.py TestDynamismExpression.test_reshape_view_static_size_one_before_dynamic_dim TestDynamismExpression.test_group_norm_spatial_dynamic_temporal_dim TestDynamismExpression.test_reshape_view_backed_size_oblivious TestDynamismExpression.test_view_unify_cross_symbols -q .venv/bin/python test/export/test_export.py TestDynamismExpression.test_group_norm_spatial_dynamic_temporal_dim_cuda -q .venv/bin/python test/export/test_export.py TestExport.test_dim_dynamic -q .venv/bin/python test/test_dynamic_shapes.py TestUbackedOps.test_unbacked_reshape1 TestUbackedOps.test_backed_size_oblivious_broadcast -q .venv/bin/python -m py_compile torch/_refs/__init__.py test/export/test_export.py CPATH=/usr/lib/gcc/x86_64-redhat-linux/11/include lintrunner -a git diff --check git diff --cached --check ``` ghstack-source-id: e954362 Pull-Request: #186032
minmingzhu
pushed a commit
to minmingzhu/torch-xpu-ops
that referenced
this pull request
Sep 15, 2026
XFailed in PyTorch: pytorch/pytorch@6d13b65 PR correctly addressing the issue in PyTorch: pytorch/pytorch#186414 Fixes: intel#4044 Signed-off-by: Artur Kłoniecki <[email protected]> Co-authored-by: Benedykt Bela <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
native_group_normandnative_group_norm_backwardhave always assumed contiguity for some tensors, and asserted it for others. The assertions cause unexpected behavior forvmap, which may batch in non-contiguous ways. The assumptions (obviously) can cause memory access errors. This PR changes the implementations to instead callcontiguous()with an appropriate memory format, which fixes vmap and the OOB accesses without using any extra memory in situations where callers have already ensured contiguous inputs.This does mean that a situation which previously threw an error (non-contiguous X) now succeeds silently with an extra allocation. It's unlikely that anyone is relying on this behavior, however, since most people would have been calling
native_group_normthroughnn.functional.group_norm, which already did calls tocontiguous().Additional important changes:
contiguous()calls on the XPU backward pass (inderivatives.yaml). This is because XPU is already callingcontiguous()internally, so the bypass was misleading to begin with. See https://github.com/intel/torch-xpu-ops/blob/main/src/ATen/native/xpu/sycl/GroupNormKernels.cpp#L1371.native_group_norm. They were previously XFAILs that failed on the first OpInfo test (i.e. relatively quickly), but now that they succeed they take 3-5 minutes each to run, which is just too long for our pipeline.CompositeExplicitAutogradoperatormath_group_normnow does some basic validation on inputs to match the othergroup_normoperators.