Skip to content

fix(nxp): check the conv/linear node's user count in BatchNorm fusion#20601

Open
durvesh1992 wants to merge 1 commit into
pytorch:mainfrom
durvesh1992:fix/nxp-fuse-bn-single-user-check
Open

fix(nxp): check the conv/linear node's user count in BatchNorm fusion#20601
durvesh1992 wants to merge 1 commit into
pytorch:mainfrom
durvesh1992:fix/nxp-fuse-bn-single-user-check

Conversation

@durvesh1992

Copy link
Copy Markdown

Summary

The _is_conv / _is_linear closures in the NXP BatchNorm fusion passes check len(node.users) instead of len(node_.users).

node_ is the closure's parameter (the conv/linear node being tested), but node resolves to the enclosing for node in graph_module.graph.nodes loop variable — which at the call site (_is_conv(bn_node.args[0])) is always the BatchNorm node.

The single-user guard exists to prevent fusion when the conv/linear output feeds consumers other than the BatchNorm, because folding the BatchNorm into the conv/linear weights changes that output for all consumers. Due to the typo the guard inspected the BatchNorm's user count rather than the conv/linear's, so a conv/linear with multiple consumers was still fused — corrupting the other consumers' inputs.

Affected files:

  • backends/nxp/aten_passes/fuse_batch_norm_with_conv_pass.py
  • backends/nxp/aten_passes/fuse_batch_norm_with_linear_pass.py

Test plan

Reproduced on a small torch.fx graph where the conv has two consumers (BatchNorm + a relu), so fusion must be skipped:

  • Before: the pass fuses anyway → model output max-abs-diff vs. reference ≈ 76.2 (corrupted).
  • After: the pass is correctly a no-op → diff 0.0.
  • After, single-consumer conv: still fuses correctly, numerics preserved (diff ≈ 3.8e-6).

The linear pass contains the identical typo and the identical one-character fix.

The _is_conv / _is_linear closures in the NXP BatchNorm fusion passes
checked len(node.users) instead of len(node_.users). node_ is the
closure parameter (the conv/linear node being tested), but node
resolves to the enclosing 'for node in graph_module.graph.nodes' loop
variable, which at the call site is always the BatchNorm node.

The single-user guard is meant to prevent fusion when the conv/linear
output feeds consumers other than the BatchNorm, since folding the
BatchNorm into the conv/linear weights changes that output for all of
them. Because of the typo the guard inspected the BatchNorm's user
count, so a conv/linear with multiple consumers was still fused,
corrupting the other consumers' inputs.
@pytorch-bot

pytorch-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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 Jun 29, 2026
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Missing ID

  • ❌ The email address for the commit (d14a781) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant