Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatML update for th gpt-3.5-turbo-0613 and gpt-4 #506

Closed
codemee opened this issue Jun 28, 2023 · 1 comment
Closed

ChatML update for th gpt-3.5-turbo-0613 and gpt-4 #506

codemee opened this issue Jun 28, 2023 · 1 comment

Comments

@codemee
Copy link

codemee commented Jun 28, 2023

Describe the feature or improvement you're requesting

The chatml.md document said every message is represented as

<|im_start|>{role}\n{text}<|im_end|>\n

That would add 5 more tokens beside the text itself.

This is correct for the gpt-3.5-turbo-0301 model. As the gpt-3.5-turbo-0613 and gpt-4 models, it seems that every message is represneted as the following form

<|im_start|>{role}\n{text}<|im_end|>

For eample

>>> openai.ChatCompletion.create(
... model="gpt-3.5-turbo-0613",
... messages=[{"role":"user", "content":"hello"}])
<OpenAIObject chat.completion id=chatcmpl-7WK2PVLogo1vxUXDAgApf9JWbXsET at 0x1da6e756210> JSON: {
  "id": "chatcmpl-7WK2PVLogo1vxUXDAgApf9JWbXsET",
  "object": "chat.completion",
  "created": 1687937877,
  "model": "gpt-3.5-turbo-0613",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I assist you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 9,
    "total_tokens": 17
  }
}

>>> encoder.encode("hello")
[15339]

Accorsing to the response, the prompt_tokens is 8, if we follow the rule described in the chatml.md, it's represened as

<|im_start|>user\nhello<|im_end|>\n<|im_start|>assistant\n

That would be 9 tokens. My guess is that there's no need for the '\n' after the <|im_end|> token.

How can I make sure for that? Thanks.

Additional context

No response

@athyuttamre
Copy link
Collaborator

The original ChatML documentation was true for the gpt-3.5-turbo-0301 model, but the details of ChatML have since changed for subsequent models. We don't have current plans to document the underlying structure, but are looking into better tools for estimating token count up front.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants