Commit b1a60a2
committed
feat(qcdq): pattern passes to bridge Brevitas/DeepQuant QCDQ ONNX → integer Conv path
DeepQuant emits QCDQ-format ONNX (decomposed Quant: Div/Add/Round/Clip,
Dequant: Sub/Mul). Deeploy's existing pattern passes (QuantPatternPass,
DequantPatternPass) collapse those decompositions into single Quant/Dequant
ops, but nothing then bridges `Dequant → ... → Quant` chains into the
RequantShift/RequantizedConv integer path that the PULPOpen target's int8
kernels actually consume. This commit adds the missing bridges, getting a
real Brevitas-quantized ResNet8 from `Onnx4Deeploy -mode quant` through
the entire frontend + lowering chain (all Conv → RequantizedConv, all
Dequant→Quant pairs absorbed into RequantShift).
Passes added (Generic/TopologyOptimizationPasses/Passes.py):
- DequantQuantToRequantShiftPass: matches consecutive `Dequant → Quant`
and folds into a single RequantShift carrying the combined affine
transform. scale_d / scale_q is represented as fixed-point
mul / 2^16, zero-point delta absorbed into add. Output keeps Quant's
n_levels / signed / bit_width.
- SkipInputQuantDequantPass: drops the trailing Dequant of the leading
`(graph_input) → Quant → Dequant → ...` activation-quantization pair,
so the int8 output of the input Quant feeds directly into the first
integer op (RequantizedConv). Equivalent to feeding the network an
fp32 input that gets pre-quantized — no precision loss beyond what
Brevitas's input QuantIdentity already imposes.
Both registered in PULPOptimizer right after QuantPatternPass /
DequantPatternPass and before the existing RequantMerge stack.
PULPOpen-side patches:
- _merge_conv_rq_fun (PULPOpen/TopologyOptimizationPasses/Passes.py)
now absorbs a bias-bearing Conv's bias into the requant add term,
matching what _merge_gemm_rq_fun has done all along. Required when
upstream Brevitas models use bias=True Conv (typical after Conv+BN
folding, since BN's beta + running stats land in the Conv bias).
This keeps RequantizedConv at the 4-input shape PULPConv2DParser /
PULPDWConv2DParser require (X, W, mul, merged_add).
- _remove_only_singleton_reduce_mean (CommonExtensions/.../
LoweringOptimizationPasses.py) now also reads the `axes` attribute
(opset 13 form). The pre-patch code looked only at `node.inputs[1]`
(opset 18+ form), which is what every opset-13 ONNX produced by
DeepQuant fails against.
Validated end-to-end on Brevitas-quantized ResNet8 (Onnx4Deeploy
`-mode quant`):
python testMVP.py -d ... -t Tests/Models/ResNet8_Quant -p Siracusa ...
→ QuantPatternPass / DequantPatternPass: fold Div/Add/Round/Clip + Sub/Mul ✓
→ DequantQuantToRequantShiftPass: 13 Dequant→Quant pairs folded into
RequantShift ✓
→ SkipInputQuantDequantPass: leading input dequant dropped ✓
→ PULPConvRequantMergePass: 9 Conv+RequantShift pairs → 9 RequantizedConv ✓
→ All Conv binding succeeded with int8/int32 bias/int32 mul/int32 add ✓
(One narrow type-check failure remains downstream on one of the new
RequantShift instances — likely an attribute representation quirk on the
gs.Constant-wrapped n_levels/signed/div — to be addressed in a follow-up.
The structural integration is in.)1 parent c4870e1 commit b1a60a2
4 files changed
Lines changed: 167 additions & 7 deletions
File tree
- Deeploy
- CommonExtensions/OptimizationPasses/TopologyOptimizationPasses
- Targets
- Generic/TopologyOptimizationPasses
- PULPOpen
- TopologyOptimizationPasses
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
533 | | - | |
534 | | - | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
535 | 540 | | |
536 | | - | |
| 541 | + | |
537 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
538 | 546 | | |
539 | 547 | | |
540 | 548 | | |
| |||
Lines changed: 139 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1177 | 1177 | | |
1178 | 1178 | | |
1179 | 1179 | | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
227 | 228 | | |
228 | 229 | | |
229 | 230 | | |
| 231 | + | |
| 232 | + | |
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
| |||
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
179 | 189 | | |
180 | 190 | | |
181 | 191 | | |
| |||
0 commit comments