Skip to content

Commit 2050b8a

Browse files
authored
Add Unsqueeze copy partitioner configs to reduce XNNPACK delegate fragmentation
Differential Revision: D103450015 Pull Request resolved: #19261
1 parent 54b8176 commit 2050b8a

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

backends/xnnpack/partition/config/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
SubConfig,
5656
TanhConfig,
5757
ToDimOrderCopyConfig,
58+
UnsqueezeCopyConfig,
5859
UpsampleBilinear2dConfig,
60+
ViewCopyConfig,
5961
)
6062
from executorch.backends.xnnpack.partition.config.node_configs import (
6163
BatchNormConfig,
@@ -116,7 +118,9 @@
116118
SoftmaxConfig,
117119
SquareRootConfig,
118120
SubConfig,
121+
UnsqueezeCopyConfig,
119122
UpsampleBilinear2dConfig,
123+
ViewCopyConfig,
120124
# Quant/Dequant Op Configs
121125
QuantizedPerTensorConfig,
122126
DeQuantizedPerTensorConfig,

backends/xnnpack/partition/config/generic_node_configs.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class ViewCopyConfig(GenericNodePartitionerConfig):
384384
target_name = "view_copy.default"
385385

386386
def supported_precision_types(self) -> List[ConfigPrecisionType]:
387-
return [ConfigPrecisionType.FP32]
387+
return [ConfigPrecisionType.FP32, ConfigPrecisionType.STATIC_QUANT]
388388

389389
def check_constraints(self, node: torch.fx.Node, ep: ExportedProgram) -> bool:
390390
"""
@@ -722,3 +722,24 @@ class CosConfig(GenericNodePartitionerConfig):
722722

723723
def supported_precision_types(self) -> List[ConfigPrecisionType]:
724724
return [ConfigPrecisionType.FP32]
725+
726+
727+
class UnsqueezeCopyConfig(GenericNodePartitionerConfig):
728+
target_name = "unsqueeze_copy.default"
729+
730+
def supported_precision_types(self) -> List[ConfigPrecisionType]:
731+
return [ConfigPrecisionType.FP32, ConfigPrecisionType.STATIC_QUANT]
732+
733+
def check_constraints(self, node: torch.fx.Node, ep: ExportedProgram) -> bool:
734+
if not self.check_common_constraints(node, ep):
735+
return False
736+
737+
# The XNNPACK UnsqueezeVisitor only supports unsqueeze on the trailing
738+
# dimension. Mirrors the runtime check in op_squeeze.py.
739+
dim = node.args[1]
740+
input_rank = len(node.args[0].meta["val"].shape)
741+
if dim != -1 and dim != input_rank:
742+
why(node, reason="unsqueeze_copy only supported on the trailing dimension")
743+
return False
744+
745+
return True

0 commit comments

Comments
 (0)