Skip to content

[fix] Handle case with string response#155

Merged
arekay-nv merged 3 commits intomainfrom
arekay/fix_str_response
Mar 9, 2026
Merged

[fix] Handle case with string response#155
arekay-nv merged 3 commits intomainfrom
arekay/fix_str_response

Conversation

@arekay-nv
Copy link
Copy Markdown
Collaborator

Fixes TPOT calculation when the response type is a string.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor/cleanup

Related issues

Testing

  • Tests added/updated
  • All tests pass locally
  • Manual testing completed

Checklist

  • Code follows project style
  • Pre-commit hooks pass
  • Documentation updated (if needed)

Signed-off-by: Rashid Kaleem <230885705+arekay-nv@users.noreply.github.com>
@arekay-nv arekay-nv requested a review from a team as a code owner March 6, 2026 21:41
Copilot AI review requested due to automatic review settings March 6, 2026 21:41
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2026

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 a bug in the TPOT calculation logic where the system was not correctly processing string-type responses. By explicitly converting string outputs into a list format, the change ensures that the TPOT metric is consistently and accurately computed, preventing errors and improving the robustness of the inference endpoint's metric reporting.

Highlights

  • TPOT Calculation Fix: Corrected the derive_TPOT function to properly handle cases where the output_sequence is a string instead of an expected list, ensuring accurate TPOT calculation.

🧠 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
  • src/inference_endpoint/metrics/reporter.py
    • Fixed an issue in derive_TPOT where string responses were not correctly handled, leading to incorrect TPOT calculations.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the derive_TPOT method where a string-typed output_sequence (returned by output_sequence_from_data when the response data is a plain string rather than a dict with a list) would be silently skipped instead of being properly handled. The fix wraps the string in a single-element list and adds a warning log for unexpected types.

Changes:

  • Wraps string output_sequence into a single-element list so it can be processed by the downstream TPOT logic (or gracefully skipped if < 2 chunks)
  • Adds a warning log message when output_sequence is an unexpected type (not list or string)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1078 to +1079
if isinstance(output_sequence, str):
output_sequence = [output_sequence]
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same string-wrapping logic should be applied to reasoning_sequence. When output_sequence_from_data is called with join_chunks=False and the data dict contains a string "reasoning" value, reasoning_sequence will also be a string. The isinstance(reasoning_sequence, list) check on line 1085 will silently drop it, causing reasoning tokens to be excluded from the TPOT calculation. Add a similar isinstance(reasoning_sequence, str) check to wrap it in a list, consistent with the fix for output_sequence.

Copilot uses AI. Check for mistakes.
Comment on lines +1078 to +1079
if isinstance(output_sequence, str):
output_sequence = [output_sequence]
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug fix lacks a unit test covering the string response case. The existing test_derive_tpot (line 57 in tests/unit/metrics/test_reporter.py) only uses list-based outputs from fake_outputs. A test should be added that stores a plain string (e.g., orjson.dumps("Hello, world")) as the COMPLETE event data to verify that derive_TPOT handles it gracefully without crashing. Since the string case has only one chunk and will be skipped at the len(all_chunks) < 2 check, the test should verify that derive_TPOT returns None (or skips that sample) rather than raising an error.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where string-based responses were not correctly handled during TPOT calculation. The change wraps string responses in a list, which is the correct approach. I have provided a suggestion to refactor the conditional logic for a minor improvement in efficiency and readability.

Signed-off-by: Rashid Kaleem <230885705+arekay-nv@users.noreply.github.com>
Signed-off-by: Rashid Kaleem <230885705+arekay-nv@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 9, 2026 04:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@arekay-nv arekay-nv merged commit 760fb88 into main Mar 9, 2026
8 checks passed
@arekay-nv arekay-nv deleted the arekay/fix_str_response branch March 9, 2026 16:45
@github-actions github-actions bot locked and limited conversation to collaborators Mar 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants