-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add LLaMA scripts #17020
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
Merged
kunal-vaishnavi
merged 26 commits into
microsoft:main
from
kunal-vaishnavi:kvaishnavi/add-llama-and-whisper-scripts
Aug 23, 2023
Merged
Add LLaMA scripts #17020
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d0495f7
Add LLaMA and Whisper scripts
kunal-vaishnavi 5bfde7a
Undo some linter changes
kunal-vaishnavi 2701a52
Move noqa after linter changes
kunal-vaishnavi 24ef7a0
Remove initial comments to satisfy linter
kunal-vaishnavi 9d56243
Update whisper readme
kunal-vaishnavi 78e7074
Use export and convert methods directly
kunal-vaishnavi 7210fe9
Remove Whisper scripts
kunal-vaishnavi cce84c9
Update markdown style
kunal-vaishnavi 7c18d4f
Address PR feedback
kunal-vaishnavi fc0e372
Add period at end of sentence
kunal-vaishnavi 97f8c59
Add blank end of line
kunal-vaishnavi 4f66dc9
Remove masked fill and add SmoothQuant
kunal-vaishnavi e75e807
Update all scripts
kunal-vaishnavi 7755c29
Remove masked fill
kunal-vaishnavi db1d4dc
Fix CodeQL errors
kunal-vaishnavi 6466b78
Remove unused noqa directives
kunal-vaishnavi 8cc4903
Update log verbosity level
kunal-vaishnavi bfa145e
Update README and CUDA requirements
kunal-vaishnavi 83a5af4
Address PR feedback
kunal-vaishnavi 0630df8
Update init and remove path appends
kunal-vaishnavi 1422309
Merge branch 'main' into kvaishnavi/add-llama-and-whisper-scripts
kunal-vaishnavi fae7cae
Update script invocations in README
kunal-vaishnavi 73d0576
Update benchmarking docs
kunal-vaishnavi f1e869e
Update README formatting
kunal-vaishnavi 86661d5
Update path navigation
kunal-vaishnavi eeb2a07
Update version number in README
kunal-vaishnavi 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 hidden or 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 hidden or 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
110 changes: 110 additions & 0 deletions
110
onnxruntime/python/tools/transformers/models/llama/README.md
This file contains hidden or 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,110 @@ | ||
| # LLaMA | ||
|
|
||
| ## Exporting LLaMA | ||
|
|
||
| There are two ways to export LLaMA models such as LLaMA and LLaMA2 (using LLaMA2 7B as an example). | ||
|
|
||
| Option 1: from source | ||
| ``` | ||
| $ git clone https://github.com/microsoft/onnxruntime | ||
| $ cd onnxruntime/onnxruntime/python/tools/transformers/models/llama | ||
| $ python3 convert_to_onnx.py -m meta-llama/Llama-2-7b-hf --output llama2-7b | ||
| ``` | ||
|
|
||
| Option 2: from wheel | ||
| ``` | ||
| $ python3 -m onnxruntime.transformers.models.llama.convert_to_onnx -m meta-llama/Llama-2-7b-hf --output llama2-7b | ||
| ``` | ||
|
|
||
| # Examples of Exporting LLaMA | ||
|
|
||
| Here are some additional examples for exporting LLaMA. | ||
|
|
||
| ## Export Saved Model on Disk | ||
| ``` | ||
| # From source: | ||
| $ python3 convert_to_onnx.py -m meta-llama/Llama-2-7b-hf --input ./Llama-2-7b-hf --output ./llama2-7b | ||
|
|
||
| # From wheel: | ||
| $ python3 -m onnxruntime.transformers.models.llama.convert_to_onnx -m meta-llama/Llama-2-7b-hf --input ./Llama-2-7b-hf --output ./llama2-7b | ||
| ``` | ||
|
|
||
| ## Export with Different Precision | ||
|
|
||
| FP16: | ||
| ``` | ||
| # From source: | ||
| $ python3 convert_to_onnx.py -m meta-llama/Llama-2-7b-hf --output llama2-7b --precision fp16 | ||
|
|
||
| # From wheel: | ||
| $ python3 -m onnxruntime.transformers.models.llama.convert_to_onnx -m meta-llama/Llama-2-7b-hf --output llama2-7b --precision fp16 | ||
| ``` | ||
|
|
||
| INT8: | ||
| ``` | ||
| # From source: | ||
| $ python3 convert_to_onnx.py -m meta-llama/Llama-2-7b-hf --output llama2-7b --precision int8 --quantize_embedding_layer | ||
|
|
||
| # From wheel: | ||
| $ python3 -m onnxruntime.transformers.models.llama.convert_to_onnx -m meta-llama/Llama-2-7b-hf --output llama2-7b --precision int8 --quantize_embedding_layer | ||
| ``` | ||
|
|
||
| ## Benchmark LLaMA | ||
|
|
||
| Here are some examples of how you can benchmark LLaMA. | ||
|
|
||
| Note: In the below examples, `PyTorch` refers to running in PyTorch without `torch.compile` and `PyTorch 2.0` refers to running in PyTorch with `torch.compile`. | ||
|
|
||
| ### Variants | ||
|
|
||
| 1) PyTorch (without `torch.compile`), FP32, Hugging Face `generate()` and `decode()` API | ||
| ``` | ||
| python3 benchmark.py \ | ||
| --benchmark-type hf-pt \ | ||
| --model-name meta-llama/Llama-2-7b-hf \ | ||
| --model-size 7b \ | ||
| --precision fp32 \ | ||
| --batch-size 2 \ | ||
| --device cpu \ | ||
| --prompt "Hey, are you conscious? Can you talk to me?" \ | ||
| --auth | ||
| ``` | ||
|
|
||
| 2) PyTorch 2.0 (with `torch.compile`), FP16, Hugging Face `generate()` and `decode()` API | ||
| ``` | ||
| python3 benchmark.py \ | ||
| --benchmark-type hf-pt2 \ | ||
| --model-name meta-llama/Llama-2-7b-hf \ | ||
| --model-size 7b \ | ||
| --precision fp16 \ | ||
| --batch-size 2 \ | ||
| --device cuda \ | ||
| --prompt "Hey, are you conscious? Can you talk to me?" \ | ||
| --auth | ||
| ``` | ||
|
|
||
| 3) ONNX Runtime, FP32 | ||
| ``` | ||
| python3 benchmark.py \ | ||
| --benchmark-type ort \ | ||
| --ort-model-path llama-2-onnx/7B_float32/ONNX/LlamaV2_7B_float32.onnx \ | ||
| --model-name meta-llama/Llama-2-7b-hf \ | ||
| --model-size 7b \ | ||
| --precision fp32 \ | ||
| --batch-size 1 \ | ||
| --sequence-length 16 \ | ||
| --device cpu | ||
| ``` | ||
|
|
||
| 4) ONNX Runtime, FP16 | ||
| ``` | ||
| python3 benchmark.py \ | ||
| --benchmark-type ort \ | ||
| --ort-model-path llama-2-onnx/7B_float16/ONNX/LlamaV2_7B_float16.onnx \ | ||
| --model-name meta-llama/Llama-2-7b-hf \ | ||
| --model-size 7b \ | ||
| --precision fp16 \ | ||
| --batch-size 1 \ | ||
| --sequence-length 16 \ | ||
| --device cuda | ||
| ``` | ||
8 changes: 8 additions & 0 deletions
8
onnxruntime/python/tools/transformers/models/llama/__init__.py
This file contains hidden or 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,8 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| # -------------------------------------------------------------------------- | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.append(os.path.dirname(__file__)) | ||
|
kunal-vaishnavi marked this conversation as resolved.
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.