|
|
|
@ -50,8 +50,8 @@ DEFINE_bool(ernie_large, false, "Test ernie large");
|
|
|
|
|
DEFINE_bool(with_accuracy_layer, true,
|
|
|
|
|
"Calculate the accuracy while label is in the input");
|
|
|
|
|
DEFINE_bool(enable_fp32, true, "Enable FP32 type prediction");
|
|
|
|
|
DEFINE_bool(enable_bf16, true, "Enable BF16 type prediction");
|
|
|
|
|
DEFINE_bool(enable_int8, true, "Enable INT8 type prediction");
|
|
|
|
|
DEFINE_bool(enable_bf16, false, "Enable BF16 type prediction");
|
|
|
|
|
DEFINE_bool(enable_int8, false, "Enable INT8 type prediction");
|
|
|
|
|
DEFINE_int32(warmup_batch_size, 100, "batch size for quantization warmup");
|
|
|
|
|
// setting iterations to 0 means processing the whole dataset
|
|
|
|
|
DEFINE_int32(iterations, 0, "number of batches to process");
|
|
|
|
@ -639,8 +639,9 @@ void TestPrediction(const PaddlePredictor::Config *config,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SummarizeAccuracy(float avg_acc_fp32, float avg_acc_int8,
|
|
|
|
|
int compared_idx) {
|
|
|
|
|
void SummarizeAccuracy(float avg_acc_ref, float avg_acc, int compared_idx) {
|
|
|
|
|
std::string data_type_name = "INT8";
|
|
|
|
|
if (FLAGS_enable_bf16) data_type_name = "BF16";
|
|
|
|
|
PADDLE_ENFORCE_LE(
|
|
|
|
|
compared_idx, 2,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
@ -659,12 +660,12 @@ void SummarizeAccuracy(float avg_acc_fp32, float avg_acc_int8,
|
|
|
|
|
LOG(INFO) << "--- Accuracy summary --- ";
|
|
|
|
|
LOG(INFO) << "Accepted " << prefix
|
|
|
|
|
<< "drop threshold: " << FLAGS_quantized_accuracy
|
|
|
|
|
<< ". (condition: (FP32_" << prefix << " - INT8_" << prefix
|
|
|
|
|
<< ") <= threshold)";
|
|
|
|
|
<< ". (condition: (FP32_" << prefix << " - " << data_type_name
|
|
|
|
|
<< "_" << prefix << ") <= threshold)";
|
|
|
|
|
LOG(INFO) << "FP32: avg " << prefix << std::fixed << std::setw(6)
|
|
|
|
|
<< std::setprecision(4) << avg_acc_fp32;
|
|
|
|
|
LOG(INFO) << "INT8: avg " << prefix << std::fixed << std::setw(6)
|
|
|
|
|
<< std::setprecision(4) << avg_acc_int8;
|
|
|
|
|
<< std::setprecision(4) << avg_acc_ref;
|
|
|
|
|
LOG(INFO) << data_type_name << ": avg " << prefix << std::fixed
|
|
|
|
|
<< std::setw(6) << std::setprecision(4) << avg_acc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SummarizePerformance(const char *title, float sample) {
|
|
|
|
@ -677,7 +678,8 @@ void SummarizePerformance(const char *title, float sample) {
|
|
|
|
|
|
|
|
|
|
void SummarizePerformance(const char *title_fp32, float sample_latency_fp32,
|
|
|
|
|
const char *title, float sample_latency) {
|
|
|
|
|
SummarizePerformance(title_fp32, sample_latency_fp32);
|
|
|
|
|
if (FLAGS_enable_fp32) SummarizePerformance(title_fp32, sample_latency_fp32);
|
|
|
|
|
if (FLAGS_enable_int8 || FLAGS_enable_bf16)
|
|
|
|
|
SummarizePerformance(title, sample_latency);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -733,7 +735,7 @@ void CompareAccuracy(
|
|
|
|
|
const std::vector<std::vector<PaddleTensor>> &output_slots_quant,
|
|
|
|
|
const std::vector<std::vector<PaddleTensor>> &output_slots_ref,
|
|
|
|
|
int compared_idx) {
|
|
|
|
|
if ((FLAGS_enable_fp32 && FLAGS_enable_int8) &&
|
|
|
|
|
if ((FLAGS_enable_fp32 && (FLAGS_enable_int8 || FLAGS_enable_bf16)) &&
|
|
|
|
|
(output_slots_quant.size() == 0 || output_slots_ref.size()) == 0)
|
|
|
|
|
throw std::invalid_argument(
|
|
|
|
|
"CompareAccuracy: output_slots vector is empty.");
|
|
|
|
@ -741,7 +743,7 @@ void CompareAccuracy(
|
|
|
|
|
float avg_acc_quant = 0.0;
|
|
|
|
|
float avg_acc_ref = 0.0;
|
|
|
|
|
|
|
|
|
|
if (FLAGS_enable_int8)
|
|
|
|
|
if (FLAGS_enable_int8 || FLAGS_enable_bf16)
|
|
|
|
|
avg_acc_quant = CompareAccuracyOne(output_slots_quant, compared_idx);
|
|
|
|
|
|
|
|
|
|
if (FLAGS_enable_fp32)
|
|
|
|
@ -751,9 +753,9 @@ void CompareAccuracy(
|
|
|
|
|
|
|
|
|
|
if (FLAGS_enable_fp32) CHECK_GT(avg_acc_ref, 0.0);
|
|
|
|
|
|
|
|
|
|
if (FLAGS_enable_int8) CHECK_GT(avg_acc_quant, 0.0);
|
|
|
|
|
if (FLAGS_enable_int8 || FLAGS_enable_bf16) CHECK_GT(avg_acc_quant, 0.0);
|
|
|
|
|
|
|
|
|
|
if (FLAGS_enable_fp32 && FLAGS_enable_int8)
|
|
|
|
|
if (FLAGS_enable_fp32 && (FLAGS_enable_int8 || FLAGS_enable_bf16))
|
|
|
|
|
CHECK_LE(avg_acc_ref - avg_acc_quant, FLAGS_quantized_accuracy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|