Sigmoid
The quantized sigmoid function is defined as follows:
where $Q$ is the quantization (scaling) factor. We use $2$ instead of $e$ to avoid floating point operations.
Implementation
1
VirtualConst(0)
Create constant zero tensor for comparisons
2
Gte
Compute ge0 = (z >= 0) to track sign of input
3
Sub
Compute neg_z = -z for absolute value calculation
4
Select
Compute abs_z = select(ge0, z, -z) (absolute value)
5
VirtualPow2
Compute `pow2 = 2^{
6
VirtualConst(Q)
Load quantization constant Q
7
Mul
Compute Q² = Q * Q
8
Div
Compute `div_Q_pow = Q / 2^{
9
Mul
Compute `mul_Q_pow = Q * 2^{
10
Select
Compute a = select(ge0, div_Q_pow, mul_Q_pow) (choose branch based on sign of z)
11
Add
Compute b = Q + a
12
Div
Compute c = Q² / b → final quantized sigmoid output σ_Q(z)
13
VirtualMove
Move final tensor c to output destination
Last updated