-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 npu_group_size
for transformers_int4_npu_win
in all-in-one benchmark api
#12316
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,7 +190,7 @@ def run_model(repo_id, test_api, in_out_pairs, local_model_hub=None, warm_up=1, | |
elif test_api == 'pipeline_parallel_gpu': | ||
result = run_pipeline_parallel_gpu(repo_id, local_model_hub, in_out_pairs, warm_up, num_trials, num_beams, low_bit, batch_size, cpu_embedding, fp16=use_fp16_torch_dtype) | ||
elif test_api == 'transformers_int4_npu_win': | ||
result = transformers_int4_npu_win(repo_id, local_model_hub, in_out_pairs, warm_up, num_trials, num_beams, low_bit, batch_size, optimize_model, transpose_value_cache) | ||
result = transformers_int4_npu_win(repo_id, local_model_hub, in_out_pairs, warm_up, num_trials, num_beams, low_bit, batch_size, optimize_model, transpose_value_cache, group_size) | ||
elif test_api == 'transformers_int4_loadlowbit_npu_win': | ||
result = run_transformer_int4_loadlowbit_npu_win(repo_id, local_model_hub, in_out_pairs, warm_up, num_trials, num_beams, low_bit, batch_size, optimize_model, transpose_value_cache) | ||
elif test_api == 'transformers_openvino': | ||
|
@@ -214,7 +214,8 @@ def run_model(repo_id, test_api, in_out_pairs, local_model_hub=None, warm_up=1, | |
round(result[in_out_pair][-1][5], 2), | ||
result[in_out_pair][-1][6] if any(keyword in test_api for keyword in ['int4_gpu', 'int4_fp16_gpu_win', 'int4_loadlowbit_gpu', 'int4_fp16_loadlowbit_gpu', 'fp16_gpu', 'deepspeed_optimize_model_gpu']) and not lookahead else 'N/A', | ||
streaming if 'win' in test_api else 'N/A', | ||
use_fp16_torch_dtype if 'pipeline_parallel_gpu' in test_api else 'N/A'], | ||
use_fp16_torch_dtype if 'pipeline_parallel_gpu' in test_api else 'N/A', | ||
group_size], | ||
) | ||
|
||
|
||
|
@@ -589,9 +590,9 @@ def run_transformer_int4_gpu(repo_id, | |
file.seek(0, os.SEEK_END) | ||
global line_counter | ||
if file.tell() == 0: | ||
csv_writer.writerow(["", "model", "1st token avg latency (ms)", "2+ avg latency (ms/token)", "encoder time (ms)", "input/output tokens", "batch_size", "actual input/output tokens", "num_beams", "low_bit", "cpu_embedding", "model loading time (s)", "peak mem (GB)", "streaming", "use_fp16_torch_dtype"]) | ||
csv_writer.writerow(["", "model", "1st token avg latency (ms)", "2+ avg latency (ms/token)", "encoder time (ms)", "input/output tokens", "batch_size", "actual input/output tokens", "num_beams", "low_bit", "cpu_embedding", "model loading time (s)", "peak mem (GB)", "streaming", "use_fp16_torch_dtype", "npu_group_size"]) | ||
line_counter +=1 | ||
csv_writer.writerow([line_counter-1, repo_id, first_token_latency, rest_token_latency, encoder_time, input_output_tokens, batch_size, actual_input_output_tokens, num_beams, low_bit, '', load_time, peak_mem, streaming, use_fp16_torch_dtype]) | ||
csv_writer.writerow([line_counter-1, repo_id, first_token_latency, rest_token_latency, encoder_time, input_output_tokens, batch_size, actual_input_output_tokens, num_beams, low_bit, '', load_time, peak_mem, streaming, use_fp16_torch_dtype, group_size]) | ||
line_counter += 1 | ||
|
||
model.to('cpu') | ||
|
@@ -611,7 +612,8 @@ def transformers_int4_npu_win(repo_id, | |
low_bit, | ||
batch_size, | ||
optimize_model, | ||
transpose_value_cache): | ||
transpose_value_cache, | ||
npu_group_size): | ||
from ipex_llm.transformers.npu_model import AutoModel, AutoModelForCausalLM | ||
from transformers import AutoTokenizer, LlamaTokenizer | ||
|
||
|
@@ -623,17 +625,20 @@ def transformers_int4_npu_win(repo_id, | |
st = time.perf_counter() | ||
if repo_id in CHATGLM_IDS: | ||
model = AutoModel.from_pretrained(model_path, load_in_low_bit=low_bit, trust_remote_code=True, | ||
optimize_model=optimize_model, max_context_len=max_context_len, max_prompt_len=int(in_out_len[0]), transpose_value_cache=transpose_value_cache, | ||
optimize_model=optimize_model, max_context_len=max_context_len, max_prompt_len=int(in_out_len[0]), | ||
quantization_group_size=npu_group_size, transpose_value_cache=transpose_value_cache, | ||
torch_dtype=torch.float16, attn_implementation="eager").eval() | ||
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True) | ||
elif repo_id in LLAMA_IDS: | ||
model = AutoModelForCausalLM.from_pretrained(model_path, load_in_low_bit=low_bit, trust_remote_code=True, torch_dtype=torch.float16, | ||
optimize_model=optimize_model, max_context_len=max_context_len, max_prompt_len=int(in_out_len[0]), transpose_value_cache=transpose_value_cache, | ||
optimize_model=optimize_model, max_context_len=max_context_len, max_prompt_len=int(in_out_len[0]), | ||
quantization_group_size=npu_group_size, transpose_value_cache=transpose_value_cache, | ||
use_cache=True, attn_implementation="eager").eval() | ||
tokenizer = LlamaTokenizer.from_pretrained(model_path, trust_remote_code=True) | ||
else: | ||
model = AutoModelForCausalLM.from_pretrained(model_path, load_in_low_bit=low_bit, trust_remote_code=True, torch_dtype=torch.float16, | ||
optimize_model=optimize_model, max_context_len=max_context_len, max_prompt_len=int(in_out_len[0]), transpose_value_cache=transpose_value_cache, | ||
optimize_model=optimize_model, max_context_len=max_context_len, max_prompt_len=int(in_out_len[0]), | ||
quantization_group_size=npu_group_size, transpose_value_cache=transpose_value_cache, | ||
use_cache=True, attn_implementation="eager").eval() | ||
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True) | ||
end = time.perf_counter() | ||
|
@@ -2193,6 +2198,8 @@ def run_pipeline_parallel_gpu(repo_id, | |
optimize_model = conf['optimize_model'] | ||
if 'group_size' in conf: | ||
group_size = conf['group_size'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove above if. |
||
if 'npu_group_size' in conf: | ||
group_size = conf['npu_group_size'] | ||
lookahead = False | ||
transpose_value_cache = True | ||
if 'transpose_value_cache' in conf: | ||
|
@@ -2225,7 +2232,7 @@ def run_pipeline_parallel_gpu(repo_id, | |
conf['low_bit'], conf['cpu_embedding'], batch_size, streaming, use_fp16_torch_dtype, lookahead, task, optimize_model, transpose_value_cache, group_size) | ||
df = pd.DataFrame(results, columns=['model', '1st token avg latency (ms)', '2+ avg latency (ms/token)', 'encoder time (ms)', | ||
'input/output tokens', 'batch_size', 'actual input/output tokens', 'num_beams', 'low_bit', 'cpu_embedding', | ||
'model loading time (s)', 'peak mem (GB)', 'streaming', 'use_fp16_torch_dtype']) | ||
'model loading time (s)', 'peak mem (GB)', 'streaming', 'use_fp16_torch_dtype', 'npu_group_size']) | ||
if "pipeline" in api or "deepspeed" in api: | ||
if torch.distributed.get_rank() == 0: | ||
df.index += max(line_counter - 1, 0) | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make group_size value "N/A" for other test_api? Maybe confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, we will fix this in next PR . 😊