Skip to content

Commit 43afe51

Browse files
msluszniakSS-JIA
authored andcommitted
Vulkan: do not partition batch norm on a non-4d input
add_native_batch_norm_node() asserts VK_CHECK_COND(in_sizes.size() == 4, "BatchNorm only support 4d tensor") on both the input and the output sizes, but the partitioner claims the node at any rank. A batch norm on rank-3 activations, which is every conv1d model, lowers cleanly and then aborts at execute time. Decline the node instead so it falls back. Split out of pytorch#22399, which is now scoped to constant_pad_nd.
1 parent a489948 commit 43afe51

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎backends/vulkan/op_registry.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,13 +1756,30 @@ def register_embedding_q4gsw():
17561756
# =============================================================================
17571757

17581758

1759+
def _check_batch_norm_is_4d(node: torch.fx.Node) -> bool:
1760+
"""Only support batch norm on a 4d input.
1761+
1762+
add_native_batch_norm_node() asserts
1763+
VK_CHECK_COND(in_sizes.size() == 4, "BatchNorm only support 4d tensor") on
1764+
both the input and the output, so partitioning a batch norm whose input is
1765+
not 4d yields a .pte that lowers cleanly and then aborts at execute time.
1766+
Any conv1d model reaches here with rank-3 activations.
1767+
"""
1768+
input_node = node.args[0]
1769+
if not isinstance(input_node, torch.fx.Node):
1770+
return False
1771+
val = input_node.meta.get("val")
1772+
return val is not None and val.dim() == 4
1773+
1774+
17591775
@update_features(exir_ops.edge.aten._native_batch_norm_legit_no_training.default)
17601776
def register_native_batch_norm_legit_no_training():
17611777
return OpFeatures(
17621778
inputs_storage=utils.CHANNELS_PACKED_TEXTURE,
17631779
inputs_dtypes=utils.FP_T,
17641780
supports_prepacking=True,
17651781
supports_resize=True,
1782+
are_node_inputs_supported_fn=_check_batch_norm_is_4d,
17661783
)
17671784

17681785

0 commit comments

Comments
 (0)