-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve llama models performance (#587)
* fix(bench): allow launch from top directory * feat(decoder): add attention layout to exporter * feat(decoder): set attention_layout to BSH for llama This reduces encoding (prefill) time. * fix(bench): make sure max_new_tokens are generated * perf(llama3): add generation benchmark * docs(benchmark): update Mistral results * docs(benchmark): new Llama2-7b results with 8 cores * perf(tgi): update Llama-2-7b results * docs(benchmark): update Llama13B results on 8 cores * feat(tgi): bump router version to 2.0.2 * Update docs/source/_toctree.yml Co-authored-by: Michael Benayoun <[email protected]> --------- Co-authored-by: Michael Benayoun <[email protected]>
- Loading branch information
1 parent
18460aa
commit 707fff4
Showing
26 changed files
with
143 additions
and
29 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
20 changes: 10 additions & 10 deletions
20
benchmark/text-generation-inference/llama-7b/tgi-results.csv
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
model_id,concurrent requests,throughput (t/s),Time-to-first-token @ P50 (s),average latency (ms) | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,1,13.84493535907894,0.435653425001874,70.64353697527179 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,2,25.213946432976638,0.4359589194991713,70.55276283551507 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,4,43.26619632041904,0.43764654000005976,71.40762554352298 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,8,81.7002047989417,0.46597404000203824,74.66130438229308 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,16,148.73365777295837,0.8807341205010744,79.46121462672393 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,32,241.07605116636378,2.58607812900118,91.31557495460669 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,64,338.6319898631105,6.262418706501194,118.3833058616551 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,128,410.3968188304912,12.920248634000018,167.830813359929 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,256,478.76738958996015,29.621474924000722,257.6998219293685 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,512,496.5535875105274,44.485632503998204,329.7294857727593 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,1,13.811941495564616,0.3781782309997652,71.37198062194233 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,2,23.461539426271507,0.3602376449998701,71.70553820509232 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,4,45.45448705790145,0.3612828944997091,73.58663426819392 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,8,71.13444471932405,0.3752646894999998,74.85884378373552 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,16,138.54599491404485,0.6447374934998606,81.11484812939682 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,32,247.32811870027916,1.0393478490004782,85.0958261705239 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,64,391.3595246354876,2.2831421710016,99.36474989676213 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,128,464.82600069905294,3.342431744500118,120.29151899306808 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,256,526.7164477974997,6.532527566999306,160.52458146930456 | ||
huggingface/NousResearch/Llama-2-7b-chat-hf,512,506.7975712115936,27.33909000099993,260.14547684970137 |
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,43 @@ | ||
from tempfile import TemporaryDirectory | ||
|
||
from transformers import AutoTokenizer | ||
|
||
from benchmark import run | ||
from optimum.neuron import NeuronModelForCausalLM | ||
from optimum.neuron.modeling_decoder import get_available_cores | ||
|
||
|
||
def main(): | ||
NUM_CORES = 8 | ||
num_cores = get_available_cores() | ||
if num_cores < NUM_CORES: | ||
raise ValueError(f"This benchmark can only run on an instance with at least {NUM_CORES} cores.") | ||
|
||
model_configurations = { | ||
"Llama-3-8B-BS1": ["meta-llama/Meta-Llama-3-8B", 1, 4096], | ||
"Llama-3-8B-BS4": ["meta-llama/Meta-Llama-3-8B", 4, 4096], | ||
"Llama-3-8B-BS8": ["meta-llama/Meta-Llama-3-8B", 8, 4096], | ||
"Llama-3-8B-BS16": ["meta-llama/Meta-Llama-3-8B", 16, 4096], | ||
"Llama-3-8B-BS32": ["meta-llama/Meta-Llama-3-8B", 32, 4096], | ||
} | ||
|
||
for model_name, model_configuration in model_configurations.items(): | ||
model_id, batch_size, seq_length = model_configuration | ||
model = NeuronModelForCausalLM.from_pretrained( | ||
model_id, | ||
export=True, | ||
batch_size=batch_size, | ||
sequence_length=seq_length, | ||
auto_cast_type="fp16", | ||
num_cores=NUM_CORES, | ||
) | ||
with TemporaryDirectory() as tmpdir: | ||
model.save_pretrained(tmpdir) | ||
tokenizer = AutoTokenizer.from_pretrained(model_id) | ||
tokenizer.save_pretrained(tmpdir) | ||
json_path = f"{model_name}.json" | ||
run(tmpdir, 256, 2048, json_path=json_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,61 @@ | ||
<!--- | ||
Copyright 2024 The HuggingFace Team. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# Llama-3-8b performance on AWS Inferentia2 (Latency & Througput) | ||
|
||
How fast is Llama-3-8b on Inferentia2? Let's figure out! | ||
|
||
For this benchmark we will use the following configurations: | ||
|
||
| Model type | batch_size | sequence_length | | ||
|----------------|------------|-----------------| | ||
| Llama3 8b BS1 | 1 | 4096 | | ||
| Llama3 8b BS4 | 4 | 4096 | | ||
| Llama3 8b BS8 | 8 | 4096 | | ||
| Llama3 8b BS16 | 16 | 4096 | | ||
| Llama3 8b BS32 | 32 | 4096 | | ||
|
||
*Note: all models are compiled to use 4 devices corresponding to 8 cores on the `inf2.48xlarge` instance.* | ||
|
||
*Note: please refer to the [inferentia2 product page](https://aws.amazon.com/ec2/instance-types/inf2/) for details on the available instances.* | ||
|
||
## Time to first token | ||
|
||
The time to first token is the time required to process the input tokens and generate the first output token. | ||
It is a very important metric, as it corresponds to the latency directly perceived by the user when streaming generated tokens. | ||
|
||
We test the time to first token for increasing context sizes, from a typical Q/A usage, to heavy Retrieval Augmented Generation (RAG) use-cases. | ||
|
||
Time to first token is expressed in **seconds**. | ||
|
||
 | ||
|
||
## Inter-token Latency | ||
|
||
The inter-token latency corresponds to the average time elapsed between two generated tokens. | ||
|
||
It is expressed in **milliseconds**. | ||
|
||
 | ||
|
||
### Throughput | ||
|
||
Unlike some other benchmarks, we evaluate the throughput using generated tokens only, by dividing their number | ||
by the end-to-end latency. | ||
|
||
Throughput is expressed in **tokens/second**. | ||
|
||
 |
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