Repository navigation
ConvertQONNXtoFINN applies weight_scale twice for QuantConv2d layers with Int32Bias, causing signal attenuation and all-zero outputs #1651
Replies: 1 comment 1 reply
|
Hi @ggiordano-cpu, Thank you for this detailed analysis, your systematic debugging is really helpful. This does indeed look like a bug in the bias extraction / scale handling for quantized biases. There was a "recent" fix in QONNX that addresses bias extraction for Conv/ConvTranspose layers with quantized biases (like Int32Bias):
This fix isn't in FINN
If the issue persists on dev, could you provide a minimal reproducible example (e.g., a small Brevitas model with a single QuantConv2d layer using Int32Bias that triggers the duplicate Mul nodes)? That would help us investigate further. Thanks again for the detailed report. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi FINN team,
I've been debugging an issue where a custom SqueezeNet-style QAT model (Brevitas, 4-bit weights/activations, Int32Bias on every QuantConv2d) produced all-zero outputs on real hardware (Kria KR260) despite the PyTorch model reaching ~67% validation accuracy and the runtime-writable weight files being verified correct.
Root cause found
Inspecting step_qonnx_to_finn.onnx (the model right after ConvertQONNXtoFINN), every Conv node in the network is followed by two consecutive Mul nodes before reaching MultiThreshold.
Taking my Conv_4 (layer3.expand) as an example:
Here is the topology from Netron showing the redundant multipliers:
Evidence
For a representative layer, I traced the chain with a real input sample and cross-checked against the PyTorch/Brevitas ground truth via forward hooks:
I confirmed Mul_1's factor equals input_scale * weight_scale (verified input_scale via a hook on the preceding activation: 10.786230 × 0.032544 = 0.351027), and that Mul_2's factor is exactly weight_scale on its own, matching the value stored in the original Quant node that quantizes that Conv's weights in the pre-conversion QONNX graph.
I then checked this systematically across all 18 Conv layers in the network: for every single one, the Mul_2 factor matches the corresponding weight's Quant scale from the original QONNX file exactly. The resulting attenuation factor (1/weight_scale) ranges from 14.6x to 122x depending on the layer.
Crucially, the issue was reproduced both with the Python execution of step_qonnx_to_finn.onnx (via qonnx.core.onnx_exec) and on the synthesized FPGA design, producing identical behavior. This confirms the bug is fully contained within the intermediate ONNX model manipulation and rules out DMA, PYNQ drivers, or bitstream synthesis issues.
Fix and validation
As a workaround, I wrote a script that removes the redundant second Mul for each Conv -> Mul -> Mul pattern (rewiring the downstream consumer to read from Mul_1's output directly), applied before streamlining. After this patch:
Without the patch, the unmodified pipeline consistently produces all-zero outputs on hardware for the same model/inputs.
Question
Is this a known limitation of how ConvertQONNXtoFINN handles the weight-scale absorption for QuantConv2d with bias, or is this an actual bug? I'd be happy to put together a minimal reproducible example (a single QuantConv2d + bias, isolated from the rest of the network) if that would help narrow this down further.
Environment
FINN version/commit: v0.10.1 (commit 39f0c9a)
QONNX version/commit: commit fd61cfeebbdaba351abf7e9d54cd785d7776fa4
Brevitas version: 0.13.0
Python version: 3.10.12
ONNX version: 1.17.0
PyTorch version: 2.0.1+cu117
Target board: Kria KR260
Model: custom SqueezeNet-style CNN, fully sequential Fire blocks (no Concat), weight_bit_width=4 on most layers, Int32Bias on every QuantConv2d, Int8ActPerTensorFloat on input.
Thanks for your time and for the great framework!
All reactions