diff --git a/backends/arm/scripts/aot_arm_compiler.py b/backends/arm/scripts/aot_arm_compiler.py index 81ca626a031..5c89c79a960 100644 --- a/backends/arm/scripts/aot_arm_compiler.py +++ b/backends/arm/scripts/aot_arm_compiler.py @@ -981,8 +981,6 @@ def _to_channels_last(x): calibration_samples = [example_inputs] for sample in calibration_samples: - if not args.cortex_m_explicit_layout: - sample = tuple(_to_channels_last(x) for x in sample) prepared(*sample) model_quant = convert_pt2e(prepared) diff --git a/backends/cortex_m/test/models/test_mobilenet_v2.py b/backends/cortex_m/test/models/test_mobilenet_v2.py index 9bc99e4bf2c..7a3bc9ecfe3 100644 --- a/backends/cortex_m/test/models/test_mobilenet_v2.py +++ b/backends/cortex_m/test/models/test_mobilenet_v2.py @@ -37,10 +37,7 @@ } # Use larger sample set for calibration to get better quantization -calibration_samples = [ - (torch.randn(1, 3, 224, 224).to(memory_format=torch.channels_last),) - for _ in range(100) -] +calibration_samples = [(torch.randn(1, 3, 224, 224),) for _ in range(100)] test_cases = { "mobilenet_v2": McuTestCase( diff --git a/backends/cortex_m/test/models/test_mobilenet_v3.py b/backends/cortex_m/test/models/test_mobilenet_v3.py index 08633d54dd6..3a6f0a5004f 100644 --- a/backends/cortex_m/test/models/test_mobilenet_v3.py +++ b/backends/cortex_m/test/models/test_mobilenet_v3.py @@ -39,10 +39,7 @@ } # Use bigger sample set for calibration. -calibration_samples = [ - (torch.randn(1, 3, 232, 232).to(memory_format=torch.channels_last),) - for i in (range(100)) -] +calibration_samples = [(torch.randn(1, 3, 232, 232),) for _ in range(100)] test_cases = { "mobilenet_v3_small": McuTestCase( diff --git a/docs/source/backends/arm-cortex-m/arm-cortex-m-overview.md b/docs/source/backends/arm-cortex-m/arm-cortex-m-overview.md index 9094ab96d51..47eb2fceeb7 100644 --- a/docs/source/backends/arm-cortex-m/arm-cortex-m-overview.md +++ b/docs/source/backends/arm-cortex-m/arm-cortex-m-overview.md @@ -100,6 +100,9 @@ quantized = convert_pt2e(prepared) quantized_exported_program = torch.export.export(quantized, (example_input,)) ``` +Calibration observes logical tensor values, so calibration inputs do not need +to use the same memory format as the export example. + ### 2. Lower to edge and apply Cortex-M passes Lower to the edge dialect with the backend's `EdgeCompileConfig`, then run the `CortexMPassManager` to replace quantized subgraphs with CMSIS-NN operator implementations: