@@ -1001,9 +1001,6 @@ class ReplaceConvWithChannelLastConvPass(RemoveOrReplacePassInterface):
10011001 @property
10021002 def targets (self ) -> list [EdgeOpOverload ]:
10031003 return [
1004- exir_ops .edge .cadence .conv1d .default ,
1005- exir_ops .edge .cadence .conv2d .default ,
1006- exir_ops .edge .cadence .conv3d .default ,
10071004 exir_ops .edge .cadence .quantized_conv1d_ncl .per_tensor ,
10081005 exir_ops .edge .cadence .quantized_depthwise_conv1d_ncl .per_tensor ,
10091006 exir_ops .edge .cadence .quantized_conv2d_nchw .per_tensor ,
@@ -1088,38 +1085,24 @@ def _change_depthwise_weight_to_hwc(
10881085
10891086 def maybe_remove_or_replace (self , node : torch .fx .Node ) -> bool :
10901087 assert isinstance (node .target , EdgeOpOverload )
1091- quantized_op = node .target in {
1092- exir_ops .edge .cadence .quantized_conv1d_ncl .per_tensor ,
1093- exir_ops .edge .cadence .quantized_depthwise_conv1d_ncl .per_tensor ,
1094- exir_ops .edge .cadence .quantized_conv2d_nchw .per_tensor ,
1095- }
1096-
1097- # Check if already in NHWC/NLC layout
1098- if not quantized_op and len (node .args ) == 8 and node .args [- 1 ] is True :
1099- return False
11001088
11011089 # Get input shape to determine if it's 1D or 2D
11021090 input_node = get_arg (node , "input" , torch .fx .Node )
11031091 input_shape = input_node .meta ["val" ].shape
11041092 is_2d = len (input_shape ) == 4
11051093
11061094 # Determine the new op target
1107- if quantized_op :
1108- if is_2d :
1109- new_op = exir_ops .edge .cadence .quantized_conv2d_nhwc .per_tensor
1110- else :
1111- assert len (input_shape ) == 3
1112- if (
1113- node .target
1114- == exir_ops .edge .cadence .quantized_depthwise_conv1d_ncl .per_tensor
1115- ):
1116- new_op = (
1117- exir_ops .edge .cadence .quantized_depthwise_conv1d_nlc .per_tensor
1118- )
1119- else :
1120- new_op = exir_ops .edge .cadence .quantized_conv1d_nlc .per_tensor
1095+ if is_2d :
1096+ new_op = exir_ops .edge .cadence .quantized_conv2d_nhwc .per_tensor
11211097 else :
1122- new_op = node .target
1098+ assert len (input_shape ) == 3
1099+ if (
1100+ node .target
1101+ == exir_ops .edge .cadence .quantized_depthwise_conv1d_ncl .per_tensor
1102+ ):
1103+ new_op = exir_ops .edge .cadence .quantized_depthwise_conv1d_nlc .per_tensor
1104+ else :
1105+ new_op = exir_ops .edge .cadence .quantized_conv1d_nlc .per_tensor
11231106
11241107 graph = node .graph
11251108
@@ -1148,15 +1131,8 @@ def maybe_remove_or_replace(self, node: torch.fx.Node) -> bool:
11481131 # For regular conv: [OC, IC, KH, KW] -> [OC, KH, KW, IC]
11491132 weight_nhwc = self ._change_nchw_to_nhwc (graph , weight_node )
11501133
1151- # Non-quantized ops need to set the last optional argument to True
1152- channel_last_arg = [] if quantized_op else [True ]
1153-
11541134 # Create new args with transposed input/weights
1155- new_args = (
1156- (input_nhwc , weight_nhwc )
1157- + tuple (node .args [2 :])
1158- + tuple (channel_last_arg )
1159- )
1135+ new_args = (input_nhwc , weight_nhwc ) + tuple (node .args [2 :])
11601136
11611137 # Create the new conv operation
11621138 new_conv = graph .call_function (new_op , new_args , node .kwargs )
0 commit comments