Add validated selective XNNPACK INT8 variant
Browse files- .gitattributes +1 -0
- README.md +19 -19
- xnnpack/NOTES.md +49 -8
- xnnpack/config.json +31 -0
- xnnpack/u2netp_xnnpack_int8.pte +3 -0
.gitattributes
CHANGED
|
@@ -36,3 +36,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 36 |
coreml/u2netp_coreml_fp16.pte filter=lfs diff=lfs merge=lfs -text
|
| 37 |
coreml/u2netp_coreml_fp32.pte filter=lfs diff=lfs merge=lfs -text
|
| 38 |
xnnpack/u2netp_xnnpack_fp32.pte filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 36 |
coreml/u2netp_coreml_fp16.pte filter=lfs diff=lfs merge=lfs -text
|
| 37 |
coreml/u2netp_coreml_fp32.pte filter=lfs diff=lfs merge=lfs -text
|
| 38 |
xnnpack/u2netp_xnnpack_fp32.pte filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
xnnpack/u2netp_xnnpack_int8.pte filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -24,6 +24,7 @@ revision `ac7e1c817ecab7c7dff5ce6b1abba61cd213ff29`.
|
|
| 24 |
| `coreml/u2netp_coreml_fp16.pte` | coreml | fp16 |
|
| 25 |
| `coreml/u2netp_coreml_fp32.pte` | coreml | fp32 |
|
| 26 |
| `xnnpack/u2netp_xnnpack_fp32.pte` | xnnpack | fp32 |
|
|
|
|
| 27 |
|
| 28 |
The exports take RGB float32 `[1,3,320,320]` input in `[0,1]` and return one
|
| 29 |
float32 `[1,1,320,320]` foreground logit map. Image-maximum scaling and ImageNet
|
|
@@ -34,34 +35,33 @@ speed and may shift mask boundaries; FP32 preserves the reference more closely.
|
|
| 34 |
|
| 35 |
## XNNPACK quantization
|
| 36 |
|
| 37 |
-
INT8
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 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 |
```
|
| 57 |
-
config.json
|
| 58 |
-
coreml/config.json
|
| 59 |
coreml/u2netp_coreml_fp16.pte 3.3 MB
|
| 60 |
coreml/u2netp_coreml_fp32.pte 5.5 MB
|
| 61 |
-
xnnpack/config.json
|
| 62 |
-
xnnpack/NOTES.md
|
| 63 |
xnnpack/u2netp_xnnpack_fp32.pte 4.6 MB
|
| 64 |
-
|
|
|
|
| 65 |
```
|
| 66 |
|
| 67 |
## Compatibility
|
|
|
|
| 24 |
| `coreml/u2netp_coreml_fp16.pte` | coreml | fp16 |
|
| 25 |
| `coreml/u2netp_coreml_fp32.pte` | coreml | fp32 |
|
| 26 |
| `xnnpack/u2netp_xnnpack_fp32.pte` | xnnpack | fp32 |
|
| 27 |
+
| `xnnpack/u2netp_xnnpack_int8.pte` | xnnpack | selective int8 / fp32 |
|
| 28 |
|
| 29 |
The exports take RGB float32 `[1,3,320,320]` input in `[0,1]` and return one
|
| 30 |
float32 `[1,1,320,320]` foreground logit map. Image-maximum scaling and ImageNet
|
|
|
|
| 35 |
|
| 36 |
## XNNPACK quantization
|
| 37 |
|
| 38 |
+
The INT8 variant selectively quantizes four expensive convolutions with static
|
| 39 |
+
INT8 activations and per-channel INT8 weights. Sensitive layers and skip
|
| 40 |
+
connections remain FP32; public input and output types are unchanged.
|
| 41 |
|
| 42 |
+
On an Apple M1 Pro, interleaved ExecuTorch runs measured **87 ms** median versus
|
| 43 |
+
**156 ms** for FP32 (1.78× faster; 30 runs after five warm-ups). Device speedups
|
| 44 |
+
will vary. Across 13 images outside calibration, exported masks averaged
|
| 45 |
+
**0.9953 IoU** against FP32 (minimum 0.9868), at a foreground threshold of 0.5.
|
| 46 |
+
These measure export agreement, not accuracy against ground-truth masks.
|
| 47 |
+
Choose FP32 when boundary precision matters.
|
| 48 |
|
| 49 |
+
Full-network INT8 remains unpublished because it loses substantial foreground
|
| 50 |
+
detail. See [XNNPACK precision notes](xnnpack/NOTES.md) for the selective recipe,
|
| 51 |
+
calibration, validation and rejected alternatives.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
## Repository structure
|
| 54 |
|
| 55 |
```
|
| 56 |
+
config.json 28 B
|
| 57 |
+
coreml/config.json 1.5 kB
|
| 58 |
coreml/u2netp_coreml_fp16.pte 3.3 MB
|
| 59 |
coreml/u2netp_coreml_fp32.pte 5.5 MB
|
| 60 |
+
xnnpack/config.json 1.5 kB
|
| 61 |
+
xnnpack/NOTES.md 6.5 kB
|
| 62 |
xnnpack/u2netp_xnnpack_fp32.pte 4.6 MB
|
| 63 |
+
xnnpack/u2netp_xnnpack_int8.pte 4.0 MB
|
| 64 |
+
LICENSE 11.4 kB
|
| 65 |
```
|
| 66 |
|
| 67 |
## Compatibility
|
xnnpack/NOTES.md
CHANGED
|
@@ -1,8 +1,48 @@
|
|
| 1 |
# XNNPACK precision experiments
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
## Static INT8
|
| 8 |
|
|
@@ -34,11 +74,12 @@ Those mask changes outweigh the size and latency improvements.
|
|
| 34 |
|
| 35 |
## Mixed INT8/FP32
|
| 36 |
|
| 37 |
-
The
|
| 38 |
-
`side2`, and `outconv`
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
gain was small. This candidate is
|
|
|
|
| 42 |
|
| 43 |
## Host size and latency
|
| 44 |
|
|
|
|
| 1 |
# XNNPACK precision experiments
|
| 2 |
|
| 3 |
+
FP32 and selective INT8 are published. Full-network static INT8, an earlier
|
| 4 |
+
mixed INT8/FP32 recipe and FP16 were rejected because they changed the masks.
|
| 5 |
+
|
| 6 |
+
## Selective INT8 (published)
|
| 7 |
+
|
| 8 |
+
The final recipe quantizes only `stage1d.rebnconvin`, `stage1d.rebnconv1d`,
|
| 9 |
+
`stage2d.rebnconvin` and `stage2.rebnconvin`. These convolutions dominate host
|
| 10 |
+
latency. Remaining convolutions, concatenations and residual additions stay
|
| 11 |
+
FP32. Public I/O and normalization are unchanged.
|
| 12 |
+
|
| 13 |
+
PT2E uses per-channel symmetric INT8 weights and per-tensor affine INT8
|
| 14 |
+
activations with HistogramObserver. The weight observer minimum scale is
|
| 15 |
+
float32 epsilon. Calibration uses the same 13 pinned upstream images listed
|
| 16 |
+
below. Export scripts download these images automatically.
|
| 17 |
+
|
| 18 |
+
ExecuTorch 1.4.1's concatenation annotator ignores its filter argument, so
|
| 19 |
+
module exclusions alone do not keep skip connections in FP32. The export
|
| 20 |
+
selects only convolution operators, with an explicit module filter. Weight
|
| 21 |
+
attributes are allowed through this filter because they lack module-stack
|
| 22 |
+
metadata. This avoids quantizing unrelated concatenations.
|
| 23 |
+
|
| 24 |
+
Actual `.pte` execution was checked against the published FP32 `.pte` on the
|
| 25 |
+
three upstream images below plus ten COCO val2017 images, IDs 139, 285, 632,
|
| 26 |
+
724, 776, 785, 802, 872, 885 and 1000. None was used for calibration. Average
|
| 27 |
+
mask IoU was 0.9953, minimum 0.9868; probability MAE ranged from 0.00015 to
|
| 28 |
+
0.00543. All-black and all-white inputs also produced finite outputs.
|
| 29 |
+
|
| 30 |
+
| Image | Selective INT8 mask IoU | Probability MAE |
|
| 31 |
+
| ----------- | ---------------------- | --------------- |
|
| 32 |
+
| `bike.jpg` | 0.9947 | 0.00158 |
|
| 33 |
+
| `boat.jpg` | 0.9956 | 0.00152 |
|
| 34 |
+
| `whisk.png` | 0.9992 | 0.00055 |
|
| 35 |
+
|
| 36 |
+
On an Apple M1 Pro, 30 interleaved ExecuTorch runs after five warm-ups measured
|
| 37 |
+
156.0 ms median for FP32 and 87.4 ms for selective INT8 (1.78× faster). File
|
| 38 |
+
sizes were 4,610,948 and 4,007,684 bytes. These are host measurements, exclude
|
| 39 |
+
RNE preprocessing/rendering, and need on-device confirmation. This small
|
| 40 |
+
sample measures conversion agreement, not ground-truth segmentation accuracy.
|
| 41 |
+
|
| 42 |
+
The event-traced ExecuTorch 1.4.1 runtime and cloned profiler confirmed all
|
| 43 |
+
four selected convolutions execute as quantized XNNPACK kernels. Over five
|
| 44 |
+
real-input executions, the delegate accounted for 99.36% of method time and
|
| 45 |
+
the portable input `amax` for 0.63%.
|
| 46 |
|
| 47 |
## Static INT8
|
| 48 |
|
|
|
|
| 74 |
|
| 75 |
## Mixed INT8/FP32
|
| 76 |
|
| 77 |
+
The earlier candidate excluded convolutions in `stage1`, `stage2`, `stage1d`,
|
| 78 |
+
`stage2d`, `side1`, `side2`, and `outconv`, using the same calibration data.
|
| 79 |
+
The concatenation-filter issue described above still quantized skip connections,
|
| 80 |
+
including those inside excluded modules. Agreement improved, but the boat mask
|
| 81 |
+
still fell to 0.9410 IoU and the latency gain was small. This candidate is not
|
| 82 |
+
published. The selective recipe above replaces this approach.
|
| 83 |
|
| 84 |
## Host size and latency
|
| 85 |
|
xnnpack/config.json
CHANGED
|
@@ -38,6 +38,37 @@
|
|
| 38 |
}
|
| 39 |
},
|
| 40 |
"size_bytes": 4610948
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
]
|
| 43 |
}
|
|
|
|
| 38 |
}
|
| 39 |
},
|
| 40 |
"size_bytes": 4610948
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"file": "u2netp_xnnpack_int8.pte",
|
| 44 |
+
"precision": "int8",
|
| 45 |
+
"methods": {
|
| 46 |
+
"forward": {
|
| 47 |
+
"inputs": [
|
| 48 |
+
{
|
| 49 |
+
"shape": [
|
| 50 |
+
1,
|
| 51 |
+
3,
|
| 52 |
+
320,
|
| 53 |
+
320
|
| 54 |
+
],
|
| 55 |
+
"dtype": "float32"
|
| 56 |
+
}
|
| 57 |
+
],
|
| 58 |
+
"outputs": [
|
| 59 |
+
{
|
| 60 |
+
"shape": [
|
| 61 |
+
1,
|
| 62 |
+
1,
|
| 63 |
+
320,
|
| 64 |
+
320
|
| 65 |
+
],
|
| 66 |
+
"dtype": "float32"
|
| 67 |
+
}
|
| 68 |
+
]
|
| 69 |
+
}
|
| 70 |
+
},
|
| 71 |
+
"size_bytes": 4007684
|
| 72 |
}
|
| 73 |
]
|
| 74 |
}
|
xnnpack/u2netp_xnnpack_int8.pte
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:da8fa0843810bd47ab16000d00b4654ebb6e97aae2c9f29d07b11549fb55e8e3
|
| 3 |
+
size 4007684
|