fix: Fix failed request count in report#169
Conversation
Signed-off-by: Rashid Kaleem <230885705+arekay-nv@users.noreply.github.com>
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an inaccuracy in reporting failed requests within the benchmark results. It introduces a dedicated mechanism to track and report the exact number of failed samples, enhancing the reliability and detail of performance metrics. The changes involve modifying the report structure, updating its generation and display, and adding comprehensive unit tests to validate the fix. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly identifies that the previous method for calculating failed requests (total - successful) was inaccurate and introduces a new n_samples_failed field to the report for a more precise count. The changes to add this field, populate it, and display it in the summary are well-implemented. However, I've identified a significant issue in how the failed count is calculated: it doesn't respect the performance window defined by the STOP_PERFORMANCE_TRACKING event. This inconsistency with other metrics can lead to incorrect reports. I've provided a detailed comment with a suggested fix for this issue.
| test_started_at=test_started_at, | ||
| n_samples_issued=sample_statuses["total_sent"], | ||
| n_samples_completed=sample_statuses["completed"], | ||
| n_samples_failed=self.get_error_count(), |
There was a problem hiding this comment.
The get_error_count() method counts all ERROR events in the database, without filtering for the performance window defined by STOP_PERFORMANCE_TRACKING. This is inconsistent with how n_samples_issued and n_samples_completed are calculated (they respect the performance window via get_sample_statuses).
This can lead to incorrect metrics. For example, if a sample is issued and fails after the performance window closes, it will be counted in n_samples_failed but not in n_samples_issued, which could lead to confusing results like n_samples_failed > n_samples_issued.
To ensure consistency, get_error_count() should be modified to only count errors for samples that were issued within the performance window. A similar filtering logic is already used in get_sample_statuses() and derive_TTFT().
Here is a suggested implementation for get_error_count:
def get_error_count(self) -> int:
stop_ts = self.stop_performance_tracking_timestamp_ns
where_clause = ""
if stop_ts != float("inf"):
# Filter for errors associated with samples issued before the stop timestamp.
where_clause = f"""
AND sample_uuid IN (
SELECT DISTINCT sample_uuid FROM events
WHERE event_type = '{SessionEvent.LOADGEN_ISSUE_CALLED.value}'
AND timestamp_ns < {stop_ts}
)
"""
query = f"""
SELECT COUNT(*) AS error_count
FROM events
WHERE event_type = '{SessionEvent.ERROR.value}'
{where_clause}
"""
result = self.cur_.execute(query).fetchone()
return result[0] if result else 0Additionally, a test case that includes a STOP_PERFORMANCE_TRACKING event and errors both inside and outside the performance window should be added to verify the fix.
There was a problem hiding this comment.
Pull request overview
This PR addresses #144 by ensuring benchmark/report outputs include a non-zero failed/error count when request errors occur, rather than inferring failures from total - successful.
Changes:
- Add
n_samples_failedto the metricsReportmodel and include it in JSON + display output. - Populate
n_samples_failedfrom recordedSessionEvent.ERRORevents when creating reports. - Use
report.n_samples_failedfor thefailedfield inresults.json, and update unit tests accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tests/unit/metrics/test_reporter.py |
Extends report and JSON serialization assertions to include n_samples_failed. |
src/inference_endpoint/metrics/reporter.py |
Adds n_samples_failed to Report, prints it in display(), and sets it during create_report(). |
src/inference_endpoint/commands/benchmark.py |
Writes failed to results.json using report.n_samples_failed instead of total - successful. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| test_started_at=test_started_at, | ||
| n_samples_issued=sample_statuses["total_sent"], | ||
| n_samples_completed=sample_statuses["completed"], | ||
| n_samples_failed=self.get_error_count(), |
There was a problem hiding this comment.
n_samples_failed is derived from get_error_count(), but get_error_count() counts all ERROR events across the entire DB and does not apply the same STOP_PERFORMANCE_TRACKING / “performance window” filtering used by get_sample_statuses(), TTFT, and latency. This can make n_samples_failed inconsistent with n_samples_issued/n_samples_completed (which are window-filtered). Consider updating the error-count query to apply the same window filter (and ideally count distinct sample UUIDs if this is meant to be “samples failed”).
| n_samples_failed=self.get_error_count(), | |
| n_samples_failed=sample_statuses["failed"], |
| "total": total, | ||
| "successful": success_count, | ||
| "failed": total - success_count, | ||
| "failed": report.n_samples_failed, |
There was a problem hiding this comment.
Switching failed to report.n_samples_failed changes the implied invariant of the JSON output (typically total == successful + failed). As implemented, successful is still report.n_samples_completed while failed is an ERROR-event count, so successful + failed can exceed total, and failed may be outside the same STOP_PERFORMANCE_TRACKING window used for total/successful. Consider aligning the semantics (e.g., compute successful as “completed without any ERROR” and failed as distinct sample UUIDs with ERROR within the same window, or rename fields in results.json if you intend to expose an error-event count).
| "failed": report.n_samples_failed, | |
| "error_events": report.n_samples_failed, |
Signed-off-by: Rashid Kaleem <230885705+arekay-nv@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| n_samples_issued: int | ||
| n_samples_completed: int | ||
| n_samples_failed: int | ||
| duration_ns: int |
| COUNT(*) AS error_count | ||
| COUNT(DISTINCT sample_uuid) AS error_count | ||
| FROM events | ||
| WHERE event_type = '{SessionEvent.ERROR.value}' |
| "results": { | ||
| "total": total, | ||
| "successful": success_count, | ||
| "failed": total - success_count, | ||
| "failed": report.n_samples_failed, | ||
| "elapsed_time": elapsed_time, | ||
| "qps": estimated_qps, | ||
| }, |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| stop_ts = self.stop_performance_tracking_timestamp_ns | ||
|
|
||
| where_clause = "" | ||
| if stop_ts != float("inf"): | ||
| where_clause = f""" | ||
| AND sample_uuid IN ( | ||
| SELECT DISTINCT sample_uuid FROM events | ||
| WHERE event_type = '{SessionEvent.LOADGEN_ISSUE_CALLED.value}' | ||
| AND timestamp_ns < {stop_ts} | ||
| ) | ||
| """ | ||
|
|
||
| return self.cur_.execute(f""" | ||
| SELECT | ||
| COUNT(*) AS error_count | ||
| COUNT(DISTINCT sample_uuid) AS error_count | ||
| FROM events | ||
| WHERE event_type = '{SessionEvent.ERROR.value}' | ||
| {where_clause} | ||
| """).fetchone()[0] |
| "results": { | ||
| "total": total, | ||
| "successful": success_count, | ||
| "failed": total - success_count, | ||
| "failed": report.n_samples_failed, | ||
| "elapsed_time": elapsed_time, | ||
| "qps": estimated_qps, |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| ) | ||
| total = report.n_samples_issued | ||
| success_count = report.n_samples_completed | ||
| success_count = total - report.n_samples_failed |
| n_samples_completed: int | ||
| duration_ns: int | ||
| n_samples_failed: int | ||
| duration_ns: int | None |
What does this PR do?
Addresses #144
Type of change
Related issues
Testing
Checklist