-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature(MInference): add e2e benchmark using vllm (#49)
* Feature(MInference): add e2e benchmark using vllm * Feature(MInference): change the guideline Co-authored-by: Yucheng Li <[email protected]> Co-authored-by: Chengruidong Zhang <[email protected]>
- Loading branch information
1 parent
0b9c81b
commit ddfb462
Showing
5 changed files
with
117 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) 2024 Microsoft | ||
# Licensed under The MIT License [see LICENSE for details] | ||
|
||
import argparse | ||
import time | ||
|
||
import torch | ||
from transformers import AutoTokenizer | ||
from vllm import LLM, SamplingParams | ||
|
||
from minference import MInference | ||
|
||
|
||
def run_target_length(m: int, model, sampling_params, attn_type: str): | ||
# wget https://raw.githubusercontent.com/FranxYao/chain-of-thought-hub/main/gsm8k/lib_prompt/prompt_hardest.txt | ||
prompt_complex = open("./prompt_hardest.txt").read() | ||
input_ids = tokenizer(prompt_complex)["input_ids"] | ||
n = len(input_ids) | ||
b = m // n + 1 | ||
|
||
new_input_ids = (input_ids * b)[:m] | ||
prompt = tokenizer.decode(new_input_ids) | ||
|
||
s = 0 | ||
T = 10 | ||
for _ in range(T): | ||
torch.cuda.synchronize() | ||
start = time.time() | ||
with torch.no_grad(): | ||
outputs = llm.generate([prompt], sampling_params) | ||
torch.cuda.synchronize() | ||
s += time.time() - start | ||
print(attn_type, m, s / T) | ||
return s / T | ||
|
||
|
||
if __name__ == "__main__": | ||
args = argparse.ArgumentParser() | ||
args.add_argument( | ||
"--model_name", | ||
type=str, | ||
default="gradientai/Llama-3-8B-Instruct-Gradient-1048k", | ||
) | ||
args.add_argument( | ||
"--attn_type", | ||
type=str, | ||
choices=["flash_attn", "minference"], | ||
) | ||
args.add_argument("--context_window", type=int, default=100_000) | ||
args = args.parse_args() | ||
|
||
model_name = args.model_name | ||
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) | ||
|
||
sampling_params = SamplingParams( | ||
temperature=0.8, | ||
top_p=0.95, | ||
max_tokens=1, | ||
) | ||
|
||
llm = LLM( | ||
model_name, | ||
max_num_seqs=1, | ||
enforce_eager=True, | ||
max_model_len=129000, | ||
) | ||
|
||
# Patch MInference Module | ||
if args.attn_type == "minference": | ||
minference_patch = MInference("vllm", model_name) | ||
llm = minference_patch(llm) | ||
|
||
run_target_length(args.context_window, llm, sampling_params, args.attn_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024 Microsoft | ||
# Licensed under The MIT License [see LICENSE for details] | ||
|
||
# Load data | ||
wget https://raw.githubusercontent.com/FranxYao/chain-of-thought-hub/main/gsm8k/lib_prompt/prompt_hardest.txt | ||
|
||
python experiments/benchmarks/benchmark_e2e_vllm.py \ | ||
--attn_type minference \ | ||
--context_window 100_000 |