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

Add an option to use the relevant tokenizer #81

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions token_benchmark_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
from tqdm import tqdm

from transformers import LlamaTokenizerFast
from transformers import AutoTokenizer

def get_token_throughput_latencies(
model: str,
Expand All @@ -34,6 +34,7 @@ def get_token_throughput_latencies(
stddev_output_tokens: int,
additional_sampling_params: Optional[Dict[str, Any]] = None,
num_concurrent_requests: int = 1,
tokenizer: str = "hf-internal-testing/llama-tokenizer",
max_num_completed_requests: int = 500,
test_timeout_s=90,
llm_api="openai",
Expand All @@ -60,9 +61,7 @@ def get_token_throughput_latencies(
"""
random.seed(11111)

tokenizer = LlamaTokenizerFast.from_pretrained(
"hf-internal-testing/llama-tokenizer"
)
tokenizer = AutoTokenizer.from_pretrained(tokenizer)
get_token_length = lambda text: len(tokenizer.encode(text))

if not additional_sampling_params:
Expand Down Expand Up @@ -292,6 +291,7 @@ def run_token_benchmark(
additional_sampling_params: str,
results_dir: str,
user_metadata: Dict[str, Any],
tokenizer: str
):
"""
Args:
Expand Down Expand Up @@ -327,6 +327,7 @@ def run_token_benchmark(
stddev_output_tokens=stddev_output_tokens,
num_concurrent_requests=num_concurrent_requests,
additional_sampling_params=json.loads(additional_sampling_params),
tokenizer=tokenizer
)

if results_dir:
Expand Down Expand Up @@ -462,6 +463,14 @@ def run_token_benchmark(
"name=foo,bar=1. These will be added to the metadata field of the results. "
),
)
args.add_argument(
"--tokenizer",
type=str,
default="hf-internal-testing/llama-tokenizer",
help=(
"Tokenizer to use for counting tokens"
),
)

if __name__ == "__main__":
env_vars = dict(os.environ)
Expand All @@ -488,4 +497,5 @@ def run_token_benchmark(
additional_sampling_params=args.additional_sampling_params,
results_dir=args.results_dir,
user_metadata=user_metadata,
tokenizer=args.tokenizer
)