mlcommons / mlcommons/endpoints

Tokenizer boundary impact

Open
#278 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
21
Forks
28
Avg merge
3d 17h
Merged PRs (30d)
13

Description

Overview

The client and the server interact by sending text to each other. Specifically, the client sends a prompt to the server which tokenizes it, and then return the response in text. The response from the server can be a single chunk (non-streaming) or can be divided into multiple chunks (streaming). In case of streaming response, the client will receive a stream of chunks of text and aggregate them to run the tokenizer at the end and count the tokens. This is used to derive metrics such as TPOT and TPS. TTFT is computed by just observing when the first chunk arrives - so it is less impacted.
The concern is that the chunk boundary can lead to different token counts. For instance, with o200k_harmony tokenizer:

' Infrastructure' — rank 70223
Split point Left Left tokens Right Right tokens Total
' Infrast' | 'ructure' ' Infrast' [' In', 'fr', 'ast'] 'ructure' ['r', 'uct', 'ure'] 6
' uncertainties' — rank 97628
Split point Left tokens Right tokens Total
' unce' | 'rtainties' [' un', 'ce'] ['r', 'ta', 'int', 'ies'] 6
' information' — rank 2164
Split point Left tokens Right tokens Total
' ' | 'information' [' '] ['information'] 2
' infor' | 'mation' [' in', 'for'] ['m', 'ation'] 4
' inform' | 'ation' [' inform'] ['ation'] 2
'function' — rank 2706
Split point Left tokens Right tokens Total
'f' | 'unction' ['f'] ['unction'] 2
'func' | 'tion' ['func'] ['tion'] 2
'functi' | 'on' ['fun', 'ct', 'i'] ['on'] 4
' something' — rank 3543
Split point Left tokens Right tokens Total
' some' | 'thing' [' some'] ['thing'] 2
' somethin' | 'g' [' som', 'eth', 'in'] ['g'] 4
' available' — rank 2839
Split point Left tokens Right tokens Total
' avail' | 'able' [' avail'] ['able'] 2
' avai' | 'lable' [' av', 'ai'] ['l', 'able'] 4
Full split table for 'function'
'f'       | 'unction'   -> ['f']              + ['unction']          = 2 tokens
'fu'      | 'nction'    -> ['fu']             + ['n', 'ction']       = 3 tokens
'fun'     | 'ction'     -> ['fun']            + ['ction']            = 2 tokens
'func'    | 'tion'      -> ['func']           + ['tion']             = 2 tokens
'funct'   | 'ion'       -> ['fun', 'ct']      + ['ion']              = 3 tokens
'functi'  | 'on'        -> ['fun', 'ct', 'i'] + ['on']               = 4 tokens  ← worst
'functio' | 'n'         -> ['fun', 'ct', 'io']+ ['n']                = 4 tokens

Challenge

The token count will be generated by looking at individual chunks returned by the server over OpenAI API completion protocol. This might not be the exact same number of tokens that are generated by the server, but in the absence of any viable alternative, is the best course of action.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or implementation entry point; begin by tracing token counting for streamed responses received through the OpenAI API completion protocol. Done is not defined: clarify the intended counting behavior, the acceptable boundary error, and how it should be verified against whole-response tokenization.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.