Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Time between token

From noriwiki


개요

Time between token(TBT)는 LLM의 성능을 평가하는 지표중 하나로, 모델이 첫번째 토큰을 생성한후(TTFT)각 후속 토큰을 생성하는 데 걸리는 평균 시간을 의미한다.

TBT는 다음과 같이 정의된다: TBT = [math]\displaystyle{ \frac{T_{\text{total}} - T_{\text{first}}}{N - 1} }[/math] 여기서,

  • [math]\displaystyle{ T_{\text{total}} }[/math] = 전체 응답 생성 시간
  • [math]\displaystyle{ T_{\text{first}} }[/math] = 첫 번째 토큰이 생성되기까지 걸린 시간 (Time to First Token, TTFT)
  • N = 전체 토큰 수
import time  
import openai  

response = openai.ChatCompletion.create(model="gpt-4", messages=[{"role": "user", "content": "Explain quantum mechanics"}], stream=True)  

first_token_time = None  
previous_token_time = None  
token_intervals = []  

for chunk in response:  
    if chunk["choices"][0]["delta"]:  
        current_time = time.time()  
        if first_token_time is None:  
            first_token_time = current_time  
        else:  
            if previous_token_time is not None:  
                token_intervals.append(current_time - previous_token_time)  
            previous_token_time = current_time  

avg_tbt = sum(token_intervals) / len(token_intervals) if token_intervals else None  
print(f"Average TBT: {avg_tbt:.3f} seconds")
Contents