Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions backends/arm/scripts/aot_arm_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions backends/cortex_m/test/models/test_mobilenet_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions backends/cortex_m/test/models/test_mobilenet_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions docs/source/backends/arm-cortex-m/arm-cortex-m-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading