fix(nxp): check the conv/linear node's user count in BatchNorm fusion#20601
fix(nxp): check the conv/linear node's user count in BatchNorm fusion#20601durvesh1992 wants to merge 2 commits into
Conversation
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.
🔗 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. ❌ 1 Cancelled JobAs of commit 4537786 with merge base b331ebd ( CANCELLED JOB - The following job was cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
This PR needs a
|
|
CC @MartinPavella @roman-janik-nxp , @novak-vaclav @durvesh1992 , do you mind to add a corresponding unit test as you described in the Test plan? |
Cover both passes: a conv/linear with a single user has its BatchNorm fused away, while a conv/linear whose output feeds an additional consumer keeps its BatchNorm (fusion is skipped) and the numerical result is preserved. The multi-user cases fail without the node_.users fix in this PR.
|
Thanks for the review @robert-kalmar! I've added unit tests in |
|
Heads up on the red EasyCLA check: the Meta CLA check passes, and I'm actively sorting out the Linux Foundation EasyCLA corporate authorization on my end (getting allowlisted under the company CCLA). The code and tests are ready for review in the meantime — I'll get the EasyCLA green as soon as the corporate approval lands. This same authorization also covers my other two ExecuTorch PRs (#20603, #20608). |
Summary
The
_is_conv/_is_linearclosures in the NXP BatchNorm fusion passes checklen(node.users)instead oflen(node_.users).node_is the closure's parameter (the conv/linear node being tested), butnoderesolves to the enclosingfor node in graph_module.graph.nodesloop 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.pybackends/nxp/aten_passes/fuse_batch_norm_with_linear_pass.pyTest plan
Reproduced on a small
torch.fxgraph where the conv has two consumers (BatchNorm + a relu), so fusion must be skipped:The linear pass contains the identical typo and the identical one-character fix.
cc @robert-kalmar @JakeStevens @digantdesai @rascani