Skip to content

Commit bff198b

Browse files
JakeStevensfacebook-github-bot
authored andcommitted
Restore Conv1d Channel Last Fix
Summary: D93658558 accidentally dropped the conv1d check which was added shortly before it, affecting indexing and resulting in incorrect results Differential Revision: D96488193
1 parent b40d6fe commit bff198b

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

backends/cadence/generic/operators/op_quantized_conv2d.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,13 @@ void quantized_conv2d_nhwc(
511511
// Depthwise is defined by in_channels == groups; depthwise weights have one
512512
// fewer dim than regular weights because the IC dim (always 1) was squeezed.
513513
const bool is_depthwise =
514-
!conv1d && c == groups && weight.dim() < input.dim();
514+
c == groups && weight.dim() < input.dim();
515515
int oc, wh, ww, wc;
516516
if (is_depthwise) {
517-
// Depthwise weight is [KH, KW, OC]
518-
wh = static_cast<int>(weight.size(0));
519-
ww = static_cast<int>(weight.size(1));
520-
oc = static_cast<int>(weight.size(2));
517+
// Depthwise weight: conv2d=[KH, KW, OC], conv1d=[K, OC]
518+
wh = static_cast<int>(conv1d ? 1 : weight.size(0));
519+
ww = static_cast<int>(conv1d ? weight.size(0) : weight.size(1));
520+
oc = static_cast<int>(conv1d ? weight.size(1) : weight.size(2));
521521
wc = 1;
522522
} else {
523523
// Regular weight is [OC, WH, WW, WC] or for conv1d [OC, WW, WC]

backends/cadence/hifi/operators/op_quantized_conv2d_nhwc_out.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,16 @@ void xa_opt_quantized_conv2d_nhwc(
184184
// fewer dim than regular weights because the IC dim (always 1) was
185185
// squeezed.
186186
bool is_depthwise =
187-
!conv1d && input_channels == groups && weight.dim() < input.dim();
187+
input_channels == groups && weight.dim() < input.dim();
188188
WORD32 kernel_height;
189189
WORD32 kernel_width;
190190
WORD32 kernel_channels;
191191
WORD32 out_channels;
192192
if (is_depthwise) {
193-
// Depthwise weight is [KH, KW, OC]
194-
kernel_height = weight.size(0);
195-
kernel_width = weight.size(1);
196-
out_channels = weight.size(2);
193+
// Depthwise weight: conv2d=[KH, KW, OC], conv1d=[K, OC]
194+
kernel_height = conv1d ? 1 : weight.size(0);
195+
kernel_width = conv1d ? weight.size(0) : weight.size(1);
196+
out_channels = conv1d ? weight.size(1) : weight.size(2);
197197
kernel_channels = 1;
198198
} else {
199199
// Regular weight is [OC, IC, KH, KW] or for conv1d [OC, K, IC]
@@ -385,13 +385,13 @@ void quantized_conv2d_nhwc(
385385
// Depthwise is defined by in_channels == groups; depthwise weights have one
386386
// fewer dim than regular weights because the IC dim (always 1) was squeezed.
387387
const bool is_depthwise =
388-
!conv1d && c == groups && weight.dim() < input.dim();
388+
c == groups && weight.dim() < input.dim();
389389
int oc, wh, ww, wc;
390390
if (is_depthwise) {
391-
// Depthwise weight is [KH, KW, OC]
392-
wh = weight.size(0);
393-
ww = weight.size(1);
394-
oc = weight.size(2);
391+
// Depthwise weight: conv2d=[KH, KW, OC], conv1d=[K, OC]
392+
wh = conv1d ? 1 : weight.size(0);
393+
ww = conv1d ? weight.size(0) : weight.size(1);
394+
oc = conv1d ? weight.size(1) : weight.size(2);
395395
wc = 1;
396396
} else {
397397
// Regular weight is [OC, WH, WW, WC] or for conv1d [OC, WW, WC]

0 commit comments

Comments
 (0)