Skip to content

#15: Track first chunks and fix TPOT calculation#23

Merged
nv-alicheng merged 9 commits intomainfrom
bugfix/alicheng-remove-first-chunk-tpot
Nov 14, 2025
Merged

#15: Track first chunks and fix TPOT calculation#23
nv-alicheng merged 9 commits intomainfrom
bugfix/alicheng-remove-first-chunk-tpot

Conversation

@nv-alicheng
Copy link
Copy Markdown
Collaborator

@nv-alicheng nv-alicheng commented Nov 13, 2025

Fix #15

What does this PR do?

Changes the output JSONL file to contain the list of chunks rather than an accumulated. This is used so that the TPOT calculation can accurately calculate the number of tokens in the first chunk so they can be excluded from the 'number of tokens' to be averaged over.

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)

@nv-alicheng nv-alicheng requested a review from a team as a code owner November 13, 2025 10:18
@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 13, 2025

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

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @nv-alicheng, 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 for streaming responses by refining how output tokens are counted. It modifies the internal representation of streaming outputs from a concatenated string to a structured list of chunks, allowing the system to differentiate and exclude the initial response chunk from TPOT averaging. This ensures more accurate performance metrics for language models, particularly in streaming scenarios.

Highlights

  • Accurate TPOT Calculation: The primary goal of this PR is to improve the accuracy of Token Per Output Token (TPOT) calculations by ensuring that the tokens from the first generated chunk of a streaming response are correctly excluded from the average token count.
  • Output Format Change: The output JSONL file now stores streaming responses as a list of chunks (e.g., [first_chunk, rest_of_chunks_joined]) instead of a single accumulated string. This change facilitates the precise identification and handling of the first chunk.
  • Streaming Response Handling: Modifications have been made to how streaming responses are processed and recorded, specifically in endpoint_client/worker.py and metrics/recorder.py, to capture and store individual chunks, especially the first one.
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

@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 correctly refactors the TPOT calculation by changing how response chunks are stored and processed. Instead of a single joined string, the output now preserves chunk separation, allowing for a more accurate exclusion of the first chunk's tokens from the metric. The addition of a progress bar in the benchmark command is a great usability improvement.

My review includes a critical fix to remove a sys.exit() call that could cause abrupt process termination, and a couple of suggestions to improve code clarity and maintainability. Overall, the changes are well-implemented and the tests have been updated accordingly.

Copy link
Copy Markdown
Collaborator

@nvzhihanj nvzhihanj left a comment

Choose a reason for hiding this comment

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

LGTM, @arekay-nv to review as well

@nvzhihanj nvzhihanj changed the title Track first chunks and fix TPOT calculation #15: Track first chunks and fix TPOT calculation Nov 13, 2025
Copy link
Copy Markdown
Collaborator

@arekay-nv arekay-nv left a comment

Choose a reason for hiding this comment

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

Thanks @nv-alicheng !

@nv-alicheng nv-alicheng merged commit 5349546 into main Nov 14, 2025
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2025
@arekay-nv arekay-nv deleted the bugfix/alicheng-remove-first-chunk-tpot branch April 2, 2026 03:06
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.

Feat: Add first-chunk support for the http client and recorder

4 participants