Skip to content

Raise inoperative error guards in ExportSession, XNNPACK node_visitor, and Samsung conv1d - #22373

Open
AxelNoun wants to merge 4 commits into
pytorch:mainfrom
AxelNoun:fix/unraised-error-checks
Open

AxelNoun wants to merge 4 commits into
pytorch:mainfrom
AxelNoun:fix/unraised-error-checks

Conversation

@AxelNoun

@AxelNoun AxelNoun commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Error-guard sites that construct a failure which cannot actually fire. This PR inserts the missing raise (or replaces an always-true assert with the file's existing check_or_raise) so the documented failure mode is the one callers see.

Updated for main at 5e21c13: the two ExportSession guards were fixed upstream in the meantime by #21748, so the only code change left in export/export.py is the message typo. The regression tests for those two guards are kept, since nothing else covers them.

File What happens on main today Reachability
export/export.py ExportSession.print_delegation_info Both guards already raise (#21748). Remaining here: the message says "atleast", and no test pins either guard. Reachable. ExportSession is in executorch.export.__all__ and is @experimental. A pipeline with no lowering stage, or one that lists TO_EDGE_TRANSFORM_AND_LOWER / TO_BACKEND without having run it, reaches each guard. This PR fixes the wording and adds export/tests/test_print_delegation_info.py for both.
backends/xnnpack/operators/node_visitor.py per-channel axis else assert f"Unsupported weight per channel quantization axis ..." — the f-string is always truthy, so the assertion never fires. An assert would also disappear under python -O. Not reachable on a normal export. The only call that passes swap_in_out_for_weights=True is backends/xnnpack/operators/op_conv2d.py:102, and that visitor already check_or_raises the axis to 0 (depthwise) or 1 (transpose) before define_tensor. This change restores a guard that can actually raise if that else is ever entered; it does not fix a mis-serialized .pte on the current conv2d path.
backends/samsung/_passes/conv1d_to_conv2d.py update_kernel else RuntimeError("Weight of 1d conv should be constant tensor or Parameter obj") is built and discarded; weight_node.meta["val"] is still unsqueezed. Not reachable on a normal Parameter / lifted-constant / buffer conv1d export. Those cases are handled by the preceding branches (the buffer branch was added on main by #22725). The else is the leftover for a weight that is none of those. This change only makes that documented RuntimeError actually raise if the branch is entered.

Test plan

Tests cover only the two reachable ExportSession guards. There is intentionally no test for the XNNPACK else and none for the Samsung else: both are unreachable on a normal export, and a test that injects that state would exercise a situation the production callers do not produce.

export/tests is already in pytest.ini testpaths:

pytest export/tests/test_print_delegation_info.py

Measured on 89cf698 (merge of main 5e21c13), CPython 3.12, torch 2.15.0.dev20261004+cpu:

  • export/tests/test_print_delegation_info.py: 2 passed.
  • Negative control — git checkout origin/main -- export/export.py, same run: AssertionError: 'at least one of the lowering stages' not found in 'No delegation info available, atleast one of the lowering stages should be present', 1 failed / 1 passed.
  • pytest export/tests --ignore=export/tests/test_target_recipes.py: 8 failed / 172 passed on this branch, and the same 8 failed / 170 passed on main alone. The 8 are a local-environment gap (exir/_serialize/program.fbs is copied in by the build, which this checkout has not run), not a regression. test_target_recipes.py does not collect locally (no coremltools).

CI

Rebased onto main (merge commit; the conflict in export/export.py was resolved in favour of main's _raise_if_released call, keeping the typo fix). The six reds triaged earlier on 12c3858 came from the merge base and their upstream fixes (#22802, #22754) are now in this branch.

One external status, MLTEC_elastic - GitHubPOC (NXP Bamboo), is red here and on every open PR I sampled (8/8 at the time of writing); it is not reachable from this change, which touches three Python files and adds one test.

cc @nil-is-all @digantdesai

@AxelNoun
AxelNoun requested a review from digantdesai as a code owner August 31, 2026 22:32
@pytorch-bot

pytorch-bot Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 89cf698 with merge base 5e21c13 (image):

NEW FAILURE - The following job has failed:

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

@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 Aug 31, 2026
@AxelNoun

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: none"

@pytorchbot label "release notes: none"

@pytorch-bot pytorch-bot Bot added the release notes: none Do not include this in the release notes label Aug 31, 2026
@nil-is-all nil-is-all added enhancement Not as big of a feature, but technically not a bug. Should be easy to fix module: cleanup Issues/PRs which cleanup code across the repository labels Sep 10, 2026
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@nil-is-all

Copy link
Copy Markdown
Contributor

Thanks @AxelNoun, running CI again

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AxelNoun

Copy link
Copy Markdown
Contributor Author

Thanks @AxelNoun, running CI again

Thanks ! @nil-is-all

@AxelNoun

Copy link
Copy Markdown
Contributor Author

Thanks @nil-is-all. I triaged the 6 failures on 12c3858. All of them are already present on the merge base df6147a, none come from this PR:

The workflows check out the PR head rather than a merge with main, so re-running on 12c3858 would reproduce the same six reds, since the fixes only landed after df6147a. Happy to merge main in (500849b is green on all of these) if you'd prefer a green run; otherwise this should be reviewable as is. @digantdesai, could you take a look?

@nil-is-all

Copy link
Copy Markdown
Contributor

Thanks @nil-is-all. I triaged the 6 failures on 12c3858. All of them are already present on the merge base df6147a, none come from this PR:

The workflows check out the PR head rather than a merge with main, so re-running on 12c3858 would reproduce the same six reds, since the fixes only landed after df6147a. Happy to merge main in (500849b is green on all of these) if you'd prefer a green run; otherwise this should be reviewable as is. @digantdesai, could you take a look?

Hi @AxelNoun, I agree the CI failures seem irrelevant. Would like to get a final OK from @digantdesai and then merge. Thanks for the ping

@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Sep 22, 2026
quant_params.axis = 0
else:
assert f"Unsupported weight per channel quantization axis for depthwise conv2d / conv_transpose2d : {quant_params.axis}, expecting 0 / 1."
check_or_raise(

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.

shoudln't we use 'why()'?

@digantdesai

Copy link
Copy Markdown
Contributor

Please rebase, and make sure CI is green. Thanks.

@nil-is-all nil-is-all added the need-user-input The issue needs more information from the reporter before moving forward label Sep 24, 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) enhancement Not as big of a feature, but technically not a bug. Should be easy to fix module: cleanup Issues/PRs which cleanup code across the repository need-user-input The issue needs more information from the reporter before moving forward release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants