tensorflow/lite/kernels/internal/logsoftmax_quantized_test.cc
// Runs the LogSoftmax and compares against the float reference implementation
// and the quantized reference implementation.
Runs the LogSoftmax and compares against the float reference implementation
and the quantized reference implementation.
Runs the LogSoftmax and compares against the float reference implementation and the quantized reference implementation .
void RunOneLogSoftmaxTest(const uint8* input_data,
                          const RuntimeShape& shape_common, int32 input_offset,
                          const double input_scale, int stride, float beta) {
  const int buffer_size = shape_common.FlatSize();
  std::vector<uint8> optimized_logsoftmax_output(buffer_size);
  std::vector<uint8> reference_float_logsoftmax_output(buffer_size);
  std::vector<uint8> reference_quant_logsoftmax_output(buffer_size);
  RunLogSoftmaxFloatReference(input_data, shape_common, input_offset,
                              input_scale, stride, beta,
                              reference_float_logsoftmax_output.data());
  int32 input_beta_multiplier;
  int input_beta_left_shift;
  int32 reverse_scaling_divisor;
  int reverse_scaling_right_shift;
  static const int kScaledDiffIntegerBits = 5;
  tflite::PreprocessLogSoftmaxScalingExp(
      beta, input_scale, kScaledDiffIntegerBits, &input_beta_multiplier,
      &input_beta_left_shift, &reverse_scaling_divisor,
      &reverse_scaling_right_shift);
  reverse_scaling_right_shift *= -1;
  const int diff_min = -tflite::CalculateInputRadius(kScaledDiffIntegerBits,
                                                     input_beta_left_shift);
  SoftmaxParams params;
  float table[256];
  params.input_multiplier = input_beta_multiplier;
  params.input_left_shift = input_beta_left_shift;
  params.reverse_scaling_divisor = reverse_scaling_divisor;
  params.reverse_scaling_right_shift = reverse_scaling_right_shift;
  params.diff_min = diff_min;
  params.scale = 1.0f / 16.0f;
  params.zero_point = 255;
  params.table = table;
  optimized_ops::PopulateSoftmaxLookupTable(&params, input_scale, beta);
  optimized_ops::LogSoftmax(params, input_scale, shape_common, input_data,
                            shape_common, optimized_logsoftmax_output.data());
  reference_ops::LogSoftmax(params, shape_common, input_data, shape_common,
                            reference_quant_logsoftmax_output.data());
  CheckOutputData<uint8_t>(optimized_logsoftmax_output.data(),
                           reference_float_logsoftmax_output.data(),
                           shape_common, "Optimized vs float reference", false);
  CheckOutputData<uint8_t>(optimized_logsoftmax_output.data(),
                           reference_quant_logsoftmax_output.data(),
                           shape_common, "Optimized vs quant reference", false);
  CheckOutputData<uint8_t>(reference_quant_logsoftmax_output.data(),
                           reference_float_logsoftmax_output.data(),
                           shape_common, "Quant reference vs float reference",
                           false);
}
void RunOneLogSoftmaxTest ( const uint8 * input_data , const RuntimeShape & shape_common , int32 input_offset , const double input_scale , int stride , float beta ) { const int buffer_size = shape_common . FlatSize ( ) ; std :: vector < uint8 > optimized_logsoftmax_output ( buffer_size ) ; std :: vector < uint8 > reference_float_logsoftmax_output ( buffer_size ) ; std :: vector < uint8 > reference_quant_logsoftmax_output ( buffer_size ) ; RunLogSoftmaxFloatReference ( input_data , shape_common , input_offset , input_scale , stride , beta , reference_float_logsoftmax_output . data ( ) ) ; int32 input_beta_multiplier ; int input_beta_left_shift ; int32 reverse_scaling_divisor ; int reverse_scaling_right_shift ; static const int kScaledDiffIntegerBits = 5 ; tflite :: PreprocessLogSoftmaxScalingExp ( beta , input_scale , kScaledDiffIntegerBits , & input_beta_multiplier , & input_beta_left_shift , & reverse_scaling_divisor , & reverse_scaling_right_shift ) ; reverse_scaling_right_shift *= -1 ; const int diff_min = - tflite :: CalculateInputRadius ( kScaledDiffIntegerBits , input_beta_left_shift ) ; SoftmaxParams params ; float table [ 256 ] ; params . input_multiplier = input_beta_multiplier ; params . input_left_shift = input_beta_left_shift ; params . reverse_scaling_divisor = reverse_scaling_divisor ; params . reverse_scaling_right_shift = reverse_scaling_right_shift ; params . diff_min = diff_min ; params . scale = 1.0f / 16.0f ; params . zero_point = 255 ; params . table = table ; optimized_ops :: PopulateSoftmaxLookupTable ( & params , input_scale , beta ) ; optimized_ops :: LogSoftmax ( params , input_scale , shape_common , input_data , shape_common , optimized_logsoftmax_output . data ( ) ) ; reference_ops :: LogSoftmax ( params , shape_common , input_data , shape_common , reference_quant_logsoftmax_output . data ( ) ) ; CheckOutputData < uint8_t > ( optimized_logsoftmax_output . data ( ) , reference_float_logsoftmax_output . data ( ) , shape_common , " " , false ) ; CheckOutputData < uint8_t > ( optimized_logsoftmax_output . data ( ) , reference_quant_logsoftmax_output . data ( ) , shape_common , " " , false ) ; CheckOutputData < uint8_t > ( reference_quant_logsoftmax_output . data ( ) , reference_float_logsoftmax_output . data ( ) , shape_common , " " , false ) ; }
Runs the LogSoftmax and compares against the float reference implementation
and the quantized reference implementation.
Runs the LogSoftmax and compares against the float reference implementation and the quantized reference implementation .
// diff_min has a negative value, and is used to limit the maximum magnitude // of the diffs, which are <= 0.