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

bug of counting output tokens #35

Open
irasin opened this issue Feb 22, 2024 · 0 comments
Open

bug of counting output tokens #35

irasin opened this issue Feb 22, 2024 · 0 comments

Comments

@irasin
Copy link

irasin commented Feb 22, 2024

In https://github.com/ray-project/llmperf/blob/main/token_benchmark_ray.py#L62, you have

get_token_length = lambda text: len(tokenizer.encode(text))

and then use it to calculate the tokens of the generated text, like

num_output_tokens = get_token_length(gen_text)

However, tokenzier will add special tokens during encoding phrase, here is an example

from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")

text = "hello world"

enc = tokenizer.encode(text)
print(enc) # [1, 22172, 3186]

dec = tokenizer.decode(enc)
print(dec) # <s> hello world

The token 1 should not be counted as one generated token here.

BTW, different models may have different special token rules, so it's hard to determine an easy way to get the real token number of the generated text.

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

1 participant