Document rejected XNNPACK quantization candidates and profiler results
Browse files- README.md +20 -0
- xnnpack/NOTES.md +78 -0
README.md
CHANGED
|
@@ -32,6 +32,25 @@ opaque RGBA grayscale mask; use its foreground intensity as an alpha mask when
|
|
| 32 |
compositing the original image. Fine structures can be missed. FP16 favors
|
| 33 |
speed and may shift mask boundaries; FP32 preserves the reference more closely.
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
## Repository structure
|
| 36 |
|
| 37 |
```
|
|
@@ -40,6 +59,7 @@ coreml/config.json 1.5 kB
|
|
| 40 |
coreml/u2netp_coreml_fp16.pte 3.3 MB
|
| 41 |
coreml/u2netp_coreml_fp32.pte 5.5 MB
|
| 42 |
xnnpack/config.json 888 B
|
|
|
|
| 43 |
xnnpack/u2netp_xnnpack_fp32.pte 4.6 MB
|
| 44 |
LICENSE 11.4 kB
|
| 45 |
sha256.json 314 B
|
|
|
|
| 32 |
compositing the original image. Fine structures can be missed. FP16 favors
|
| 33 |
speed and may shift mask boundaries; FP32 preserves the reference more closely.
|
| 34 |
|
| 35 |
+
## XNNPACK quantization
|
| 36 |
+
|
| 37 |
+
INT8 was exported and tested but is not published: foreground masks drift too
|
| 38 |
+
far from the FP32 reference. A mixed INT8/FP32 candidate preserved more detail
|
| 39 |
+
but still changed boundaries materially.
|
| 40 |
+
|
| 41 |
+
Mask IoU against the shipped FP32 `.pte`, with a probability threshold of 0.5,
|
| 42 |
+
on three upstream images held out from quantization calibration:
|
| 43 |
+
|
| 44 |
+
| Image | Static INT8 | Mixed INT8/FP32 |
|
| 45 |
+
| ----------- | ----------- | --------------- |
|
| 46 |
+
| `bike.jpg` | 0.6692 | 0.9629 |
|
| 47 |
+
| `boat.jpg` | 0.8703 | 0.9410 |
|
| 48 |
+
| `whisk.png` | 0.9387 | 0.9945 |
|
| 49 |
+
|
| 50 |
+
These are export-agreement checks, not ground-truth segmentation accuracy.
|
| 51 |
+
See [XNNPACK precision notes](xnnpack/NOTES.md) for calibration, size/latency
|
| 52 |
+
results, the rejected FP16 trial, and profiler findings.
|
| 53 |
+
|
| 54 |
## Repository structure
|
| 55 |
|
| 56 |
```
|
|
|
|
| 59 |
coreml/u2netp_coreml_fp16.pte 3.3 MB
|
| 60 |
coreml/u2netp_coreml_fp32.pte 5.5 MB
|
| 61 |
xnnpack/config.json 888 B
|
| 62 |
+
xnnpack/NOTES.md 4.3 kB
|
| 63 |
xnnpack/u2netp_xnnpack_fp32.pte 4.6 MB
|
| 64 |
LICENSE 11.4 kB
|
| 65 |
sha256.json 314 B
|
xnnpack/NOTES.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# XNNPACK precision experiments
|
| 2 |
+
|
| 3 |
+
Only FP32 is published. Static INT8, mixed INT8/FP32, and FP16 candidates were
|
| 4 |
+
exported and executed, but rejected because they changed the foreground masks.
|
| 5 |
+
The absence of an INT8 file is a quality decision, not an export failure.
|
| 6 |
+
|
| 7 |
+
## Static INT8
|
| 8 |
+
|
| 9 |
+
The experiment used PT2E `prepare_pt2e` / `convert_pt2e`,
|
| 10 |
+
`XNNPACKQuantizer`, and `get_symmetric_quantization_config(is_per_channel=True)`:
|
| 11 |
+
static INT8 activations with per-channel INT8 weights. Public inputs and
|
| 12 |
+
outputs remained float32. The export included the same image-maximum and
|
| 13 |
+
ImageNet normalization as FP32, and returned foreground logits before sigmoid.
|
| 14 |
+
|
| 15 |
+
Calibration used 13 RGB images from the upstream repository at commit
|
| 16 |
+
`ac7e1c817ecab7c7dff5ce6b1abba61cd213ff29`, resized to 320×320:
|
| 17 |
+
`0002-01.jpg`, `0003.jpg`, `girl.png`, `hockey.png`, `horse.jpg`, `im_01.png`,
|
| 18 |
+
`im_14.png`, `im_21.png`, `im_27.png`, `lamp2_meitu_1.jpg`, `long.jpg`,
|
| 19 |
+
`rifle1.jpg`, and `sailboat3.jpg`.
|
| 20 |
+
|
| 21 |
+
The three images below were held out from calibration. Results compare actual
|
| 22 |
+
ExecuTorch `.pte` execution against the shipped FP32 `.pte`. Mask IoU uses a
|
| 23 |
+
foreground-probability threshold of 0.5; MAE is measured after sigmoid in [0,1].
|
| 24 |
+
These measure conversion agreement, not accuracy against ground-truth masks.
|
| 25 |
+
|
| 26 |
+
| Image | Static INT8 mask IoU | Static INT8 probability MAE | Mixed INT8 mask IoU | Mixed INT8 probability MAE |
|
| 27 |
+
| ----------- | -------------------- | --------------------------- | ------------------- | -------------------------- |
|
| 28 |
+
| `bike.jpg` | 0.6692 | 0.09813 | 0.9629 | 0.01421 |
|
| 29 |
+
| `boat.jpg` | 0.8703 | 0.04655 | 0.9410 | 0.02156 |
|
| 30 |
+
| `whisk.png` | 0.9387 | 0.06170 | 0.9945 | 0.00458 |
|
| 31 |
+
|
| 32 |
+
Static INT8 is smaller and faster, but loses substantial foreground detail.
|
| 33 |
+
Those mask changes outweigh the size and latency improvements.
|
| 34 |
+
|
| 35 |
+
## Mixed INT8/FP32
|
| 36 |
+
|
| 37 |
+
The second candidate kept `stage1`, `stage2`, `stage1d`, `stage2d`, `side1`,
|
| 38 |
+
`side2`, and `outconv` in FP32, quantizing the remaining network with the same
|
| 39 |
+
calibration data. Preserving these early and final high-resolution blocks
|
| 40 |
+
improved agreement, but the boat mask still fell to 0.9410 IoU and the latency
|
| 41 |
+
gain was small. This candidate is also not published.
|
| 42 |
+
|
| 43 |
+
## Host size and latency
|
| 44 |
+
|
| 45 |
+
Interleaved measurements used the same bicycle input, three warm-up calls,
|
| 46 |
+
then 20 executions per candidate through ExecuTorch on an Apple M1 Pro running
|
| 47 |
+
macOS 26.5.2, with torch 2.14.0, ExecuTorch 1.4.1 and torchao 0.18.0.
|
| 48 |
+
|
| 49 |
+
| Candidate | File size | Median inference |
|
| 50 |
+
| -------------------------- | --------- | ---------------- |
|
| 51 |
+
| FP32 (published) | 4.61 MB | 217 ms |
|
| 52 |
+
| Static INT8 (rejected) | 1.36 MB | 64 ms |
|
| 53 |
+
| Mixed INT8/FP32 (rejected) | 2.61 MB | 215 ms |
|
| 54 |
+
|
| 55 |
+
Other export/build work was running on the host, so these are indicative
|
| 56 |
+
comparisons rather than isolated device benchmarks. They exclude RNE image
|
| 57 |
+
preprocessing and rendering. The small calibration/validation sample does not
|
| 58 |
+
prove that every quantization strategy is unsuitable; it establishes why these
|
| 59 |
+
particular candidates were not shipped. A future attempt needs more calibration
|
| 60 |
+
coverage and a larger independent quality evaluation before publication.
|
| 61 |
+
|
| 62 |
+
## FP16 trial
|
| 63 |
+
|
| 64 |
+
An XNNPACK FP16 candidate kept input normalization and public I/O in FP32 and
|
| 65 |
+
fused each Conv/BatchNorm pair before converting the network to FP16. Eager
|
| 66 |
+
agreement looked promising, but the actual exported runtime shifted the bicycle
|
| 67 |
+
mask to 0.9549 IoU (probability MAE 0.01111) against the shipped FP32 model.
|
| 68 |
+
It is not published either. This result is specific to the XNNPACK FP16
|
| 69 |
+
candidate; the published CoreML FP16 artifact was validated separately.
|
| 70 |
+
|
| 71 |
+
## Delegation
|
| 72 |
+
|
| 73 |
+
A local event-traced ExecuTorch 1.4.1 build and `executorch-profiler` measured
|
| 74 |
+
five FP32 executions: 99.68% of elapsed time was inside the XNNPACK delegate and
|
| 75 |
+
0.31% was the portable `amax` input reduction. Convolution dominated execution.
|
| 76 |
+
These are timing shares, not a count of delegated graph operators. Removing
|
| 77 |
+
the reduction would not address the main cost and would change the upstream
|
| 78 |
+
image-dependent input normalization.
|