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

[Misc] add non cuda hf benchmark_througput #8653

Open
wants to merge 2 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
11 changes: 7 additions & 4 deletions benchmarks/benchmark_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,17 @@ def run_hf(
use_beam_search: bool,
max_batch_size: int,
trust_remote_code: bool,
device: str,
) -> float:
assert not use_beam_search
is_cuda = device == "cuda"
if is_cuda:
llm = llm.cuda()
Comment on lines +238 to +240
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply .cuda only when device=="cuda"

llm = AutoModelForCausalLM.from_pretrained(
model, torch_dtype=torch.float16, trust_remote_code=trust_remote_code)
model, torch_dtype=torch.float16 if is_cuda else torch.float32, trust_remote_code=trust_remote_code)
if llm.config.model_type == "llama":
# To enable padding in the HF backend.
tokenizer.pad_token = tokenizer.eos_token
llm = llm.cuda()

pbar = tqdm(total=len(requests))
start = time.perf_counter()
Expand All @@ -264,7 +267,7 @@ def run_hf(
input_ids = tokenizer(batch, return_tensors="pt",
padding=True).input_ids
llm_outputs = llm.generate(
input_ids=input_ids.cuda(),
input_ids=input_ids.cuda() if is_cuda else input_ids,
do_sample=not use_beam_search,
num_return_sequences=n,
temperature=1.0,
Expand Down Expand Up @@ -341,7 +344,7 @@ def main(args: argparse.Namespace):
assert args.tensor_parallel_size == 1
elapsed_time = run_hf(requests, args.model, tokenizer, args.n,
args.use_beam_search, args.hf_max_batch_size,
args.trust_remote_code)
args.trust_remote_code, args.device)
elif args.backend == "mii":
elapsed_time = run_mii(requests, args.model, args.tensor_parallel_size,
args.output_len)
Expand Down
Loading