Skip to content

Decompose aten.var_mean.correction in to_edge - #23681

Open
usmanmateen wants to merge 1 commit into
pytorch:mainfrom
usmanmateen:fix/decompose-var-mean-correction
Open

usmanmateen wants to merge 1 commit into
pytorch:mainfrom
usmanmateen:fix/decompose-var-mean-correction

Conversation

@usmanmateen

@usmanmateen usmanmateen commented Oct 11, 2026 •

Copy link
Copy Markdown

Summary

Fixes #23680.

torch.var_mean and torch.std_mean export to aten.var_mean.correction. It isn't a core ATen op and isn't in core_aten_decompositions(), so to_edge rejected it with SpecViolationError on the portable and XNNPACK paths. Its only registered decomposition is the torch._refs one, which produces prims ops. That's why this adds a small decomposition to _default_decomposition_table instead of listing the op in additional_decomp_ops (that gives Missing out variants: {'prims::var', 'prims::sum', 'prims::div'}). The decomposition goes to aten.var.correction and aten.mean.dim, both core ATen ops with portable kernels.

Test plan

test_to_edge_decomposes_var_mean_and_std_mean in exir/program/test/test_program.py exports a module that calls both ops, runs it through the portable pybindings, and compares with eager. It fails with the SpecViolationError before this change and passes after.

I also lowered and ran these cases with to_edge and with to_edge_transform_and_lower(..., partitioner=[XnnpackPartitioner()]), comparing outputs with eager (atol=1e-5):

case before after (portable / XNNPACK)
torch.var_mean(x, dim=1, correction=0) SpecViolationError match / match
torch.var_mean(x) (dim=None) SpecViolationError match / match
torch.var_mean(x, dim=(0, 2), keepdim=True) SpecViolationError match / match
torch.var_mean(x, dim=-1, correction=2) SpecViolationError match / match
torch.std_mean(x, dim=1, unbiased=False) SpecViolationError match / match

Tested against executorch 1.5.1 and torch 2.14.1+cpu on Linux x86_64 (WSL2); _default_decomposition_table is the same on main. A set of 55 other small modules (activations, reductions, norms, convolutions, pooling, RNNs, attention, and six torchvision models) lowers and matches eager on both paths before and after. ufmt (black 24.4.2, usort 1.0.8.post1) and flake8 pass on the changed files.

This PR was authored with AI assistance (Claude Code).

cc @nil-is-all

torch.var_mean and torch.std_mean export to aten.var_mean.correction,
which is not a core ATen op and is not in the core decomposition table,
so to_edge rejected it. Its only registered decomposition is the
torch._refs one, which produces prims ops. Decompose it to
aten.var.correction and aten.mean.dim instead.

Fixes pytorch#23680
@pytorch-bot

pytorch-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 15 Awaiting Approval

As of commit 9e89edd with merge base f2575be (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@meta-cla

meta-cla Bot commented Oct 11, 2026

Copy link
Copy Markdown

Hi @usmanmateen!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: usmanmateen / name: usmanmateen (9e89edd)

@usmanmateen

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: exir"

@pytorch-bot pytorch-bot Bot added the release notes: exir Changes to any dialects and passes on these dialects, such as memory planning label Oct 11, 2026
@meta-cla

meta-cla Bot commented Oct 11, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 11, 2026
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Oct 11, 2026

This branch has not been deployed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. community: contribution PRs coming from community (excluding hardware partners) release notes: exir Changes to any dialects and passes on these dialects, such as memory planning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch.var_mean and torch.std_mean fail in to_edge: aten.var_mean.correction is not core ATen and has no core decomposition

1 participant