pub struct QSoftmax {
pub input_multiplier: i32,
pub input_left_shift: i32,
pub diff_min: i32,
}Expand description
Int8 softmax over a row of logits, bit-exact with TFLite’s int8 softmax
(the TFLite Micro reference kernel, which CMSIS-NN’s arm_softmax_s8 also
reproduces), in gemmlowp fixed point (C++ QSoftmaxFixedPoint1D).
The output is on TFLite’s probability grid, scale 1/256 and zero point
-128: -128 is 0 and 127 is 255/256. The three parameters depend only on the
input tensor’s scale and the softmax’s beta; compute them on the host with
calibration::build_softmax (std feature), as TFLite Micro does, or write
them out as constants.
For each row: subtract the maximum, take exp((x - max) * input_scale * beta) in Q5.26 -> Q0.31 for every x - max >= diff_min (the rest
contribute 0), sum the terms in Q12.19, invert the sum by Newton-Raphson and
scale each term by it. Pure integer arithmetic.
Fields§
§input_multiplier: i32Q0.31 multiplier of input_scale * beta.
input_left_shift: i32Left shift applied with the multiplier, 0..=31.
diff_min: i32At most 0: a logit this far or further below the row’s maximum gets probability 0.