MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Nudge

Function Nudge

tensorflow/core/kernels/fake_quant_ops_functor.h:41–61  ·  view source on GitHub ↗

Gymnastics with nudged zero point is to ensure that real zero maps to an integer, which is required for e.g. zero-padding in convolutional layers. Outputs nudged_min, nudged_max, nudged_scale.

Source from the content-addressed store, hash-verified

39// an integer, which is required for e.g. zero-padding in convolutional layers.
40// Outputs nudged_min, nudged_max, nudged_scale.
41EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void Nudge(
42 const float min, const float max, const int quant_min, const int quant_max,
43 float* nudged_min, float* nudged_max, float* scale) {
44 const float quant_min_float = static_cast<float>(quant_min);
45 const float quant_max_float = static_cast<float>(quant_max);
46 *scale = (max - min) / (quant_max_float - quant_min_float);
47 const float zero_point_from_min = quant_min_float - min / *scale;
48 const uint16 nudged_zero_point = [zero_point_from_min, quant_min,
49 quant_min_float, quant_max,
50 quant_max_float] {
51 if (zero_point_from_min < quant_min_float) {
52 return static_cast<uint16>(quant_min);
53 }
54 if (zero_point_from_min > quant_max_float) {
55 return static_cast<uint16>(quant_max);
56 }
57 return static_cast<uint16>(StdRound(zero_point_from_min));
58 }();
59 *nudged_min = (quant_min_float - nudged_zero_point) * (*scale);
60 *nudged_max = (quant_max_float - nudged_zero_point) * (*scale);
61}
62
63template <typename T>
64using ConstScalar = typename tensorflow::TTypes<T>::ConstScalar;

Callers 6

operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85

Calls 1

StdRoundFunction · 0.85

Tested by

no test coverage detected