Skip to content

Commit

Permalink
[Metric] Fix the devision-by-zero in spec-decode metrics (#2959)
Browse files Browse the repository at this point in the history
This PR fixes the metrics serialization where the division-by-zero
may happen, producing "nan" in the serialized string and failing
JSON parsing.
  • Loading branch information
MasterJH5574 authored Oct 2, 2024
1 parent 9221620 commit f51c0f6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cpp/serve/metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ picojson::object SpecDecodeMetrics::AsJSON() const {
std::ostringstream accept_rate_label;
accept_rate_label << "accept_rate{step=" << i << "}";
double accept_rate_value =
(static_cast<double>(accept_count[i]) / static_cast<double>(accept_count[i - 1]));
accept_count[i - 1] == 0
? 0.0f
: (static_cast<double>(accept_count[i]) / static_cast<double>(accept_count[i - 1]));
accept_rate_metrics[accept_rate_label.str()] = picojson::value(accept_rate_value);
}
}
Expand Down

0 comments on commit f51c0f6

Please sign in to comment.