Skip to content

Commit 1d6e869

Browse files
author
Github Executorch
committed
Title:
Fix quantized_linear output shape in meta function. Summary: Fix incorrect output shape computation in @register_fake for cortex_m::quantized_linear. The meta function was using weights.shape[0] (in_features) instead of weights.shape[1] (out_features) to compute the output tensor shape. This is incorrect because weights are stored in transposed format [in_features, out_features] for CMSIS-NN compatibility. For MobileNetV2 with Linear(1280, 1000), this caused: - Output shape: [1, 1280] instead of [1, 1000] - Post-processing failure: "Output size doesn't match labels' size" The C++ runtime (op_quantized_linear.cpp) correctly uses weights.size(1) for out_features, but the Python meta function was inconsistent. This fix ensures the AOT-compiled .pte file has correctly shaped output tensors for any model using quantized_linear (MV2, ResNet, MV3, etc.).
1 parent 75fa61a commit 1d6e869

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

backends/cortex_m/ops/operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def quantized_linear_meta(
352352
activation_min,
353353
) -> torch.Tensor:
354354

355-
shape = (*input.shape[:-1], weights.shape[0])
355+
shape = (*input.shape[:-1], weights.shape[1])
356356
return torch.empty(shape, dtype=input.dtype, device=input.device)
357357

358358

0 commit comments

Comments
 (0)