Skip to content

Commit

Permalink
[QNN EP] Fix Batch Normalization Op Builder (microsoft#17981)
Browse files Browse the repository at this point in the history
### Description
There is a gap between onnx’s definition of batch normalization and
QNN’s.

According to the formula:
onnx: `(X - input_mean) / sqrt(input_var + epsilon) * scale + B`
QNN: `X * weight + bias`

We can then deduce that:
`weight = scale / sqrt(var + epsilon)`
`bias = B – (mean * scale / sqrt(var + epsilon))`

We must calculate the weight and bias, and their quantization parameters
for QNN in QNN EP.
Therefore, `scale`, `B`, `input_mean`, and `input_var` must be static
(`initializer`).

Implementation:
Firstly, dequantize `scale`, `B`, `input_mean`, and `input_var` to
floating point.
Second, calculate `weight` and `bias`, and their quantization
parameters.
Finally, quantize `weight` and `bias`, and add them into `TensorWrapper`

### Motivation and Context
Fix QnnHTPBackendTests.BatchNorm1D and QnnHTPBackendTests.BatchNorm2D
failures
  • Loading branch information
weischan-quic authored Nov 1, 2023
1 parent 819b5a3 commit 69f0297
Show file tree
Hide file tree
Showing 2 changed files with 583 additions and 24 deletions.
Loading

0 comments on commit 69f0297

Please sign in to comment.