-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor structure, add python sample
- Loading branch information
1 parent
7cab496
commit 4d4942e
Showing
13 changed files
with
254 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Benchmark Vanilla GenAI | ||
|
||
This sample script demonstrates how to benchmark an LLMModel in OpenVINO GenAI. The script includes functionality for warm-up iterations, generating text, and calculating various performance metrics. | ||
|
||
# ov.genai.PerfMetrics structure | ||
ov.genai.PerfMetrics is a structure which holds performance metric for each generate call. Each generate call calcualtes the following metrics: | ||
- mean_ttft | ||
- std_ttft | ||
- mean_tpot | ||
- std_tpot | ||
- load_time | ||
- mean_generate_duration | ||
- std_generate_duration | ||
- mean_tokenization_duration | ||
- std_tokenization_duration | ||
- mean_detokenization_duration | ||
- std_detokenization_duration | ||
- mean_throughput | ||
- std_throughput | ||
- num_generated_tokens | ||
- num_input_tokens | ||
|
||
Performance metrics can be added to one another and accumulated using the += operator or the + operator. In that case the mean values accumulated by several generate calls will be calculated. | ||
|
||
|
||
## Download and convert the model and tokenizers | ||
|
||
The `--upgrade-strategy eager` option is needed to ensure `optimum-intel` is upgraded to the latest version. | ||
|
||
It's not required to install [../../requirements.txt](../../requirements.txt) for deployment if the model has already been exported. | ||
|
||
```sh | ||
pip install --upgrade-strategy eager -r ../../requirements.txt | ||
optimum-cli export openvino --trust-remote-code --model TinyLlama/TinyLlama-1.1B-Chat-v1.0 TinyLlama-1.1B-Chat-v1.0 | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
python benchmark_vanilla_genai.py [OPTIONS] | ||
``` | ||
|
||
### Options | ||
|
||
- `-p, --prompt` (default: `"The Sky is blue because"`): The prompt to generate text. | ||
- `-m, --model` (default: `""`): Path to the model and tokenizers base directory. | ||
- `-nw, --num_warmup` (default: `1`): Number of warmup iterations. | ||
- `-n, --num_iter` (default: `3`): Number of iterations. | ||
- `-d, --device` (default: `"CPU"`): Device to run the model on. | ||
|
||
|
48 changes: 48 additions & 0 deletions
48
samples/python/benchmark_vanilla_genai/benchmark_vanilla_genai.py
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,48 @@ | ||
# Copyright (C) 2023-2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import argparse | ||
import openvino_genai as ov_genai | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Help command") | ||
parser.add_argument("-p", "--prompt", type=str, default="The Sky is blue because", help="Prompt") | ||
parser.add_argument("-m", "--model", type=str, default=".", help="Path to model and tokenizers base directory") | ||
parser.add_argument("-nw", "--num_warmup", type=int, default=1, help="Number of warmup iterations") | ||
parser.add_argument("-n", "--num_iter", type=int, default=3, help="Number of iterations") | ||
parser.add_argument("-n", "--num_new_tokens", type=int, default=3, help="Maximal number of new tokens") | ||
parser.add_argument("-d", "--device", type=str, default="CPU", help="Device") | ||
|
||
args = parser.parse_args() | ||
|
||
prompt = args.prompt | ||
model_path = args.model | ||
device = args.device | ||
num_warmup = args.num_warmup | ||
num_iter = args.num_iter | ||
|
||
|
||
config = ov_genai.GenerationConfig() | ||
config.max_new_tokens = args.num_new_tokens | ||
|
||
pipe = ov_genai.LLMPipeline(model_path, device) | ||
|
||
for _ in range(num_warmup): | ||
pipe.generate(prompt, config) | ||
|
||
res = pipe.generate(prompt, config) | ||
metrics = res.metrics | ||
for _ in range(num_iter - 1): | ||
res = pipe.generate(prompt, config) | ||
metrics += res.metrics | ||
|
||
print(f"Load time: {metrics.load_time} ms") | ||
print(f"Generate time: {metrics.mean_generate_duration} ± {metrics.std_generate_duration} ms") | ||
print(f"Tokenization time: {metrics.mean_tokenization_duration} ± {metrics.std_tokenization_duration} ms") | ||
print(f"Detokenization time: {metrics.mean_detokenization_duration} ± {metrics.std_detokenization_duration} ms") | ||
print(f"ttft: {metrics.mean_ttft} ± {metrics.std_ttft} ms") | ||
print(f"tpot: {metrics.mean_tpot} ± {metrics.std_tpot} ms") | ||
print(f"Tokens/s: {metrics.mean_throughput} ± {metrics.std_throughput}") | ||
|
||
if __name__ == "__main__": | ||
main() |
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
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.