-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
118 changed files
with
204 additions
and
185 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,7 @@ | ||
# Running Hugging Face Transformers model using BigDL-LLM on Intel CPU | ||
|
||
This folder contains examples of running any Hugging Face Transformers model on BigDL-LLM (using the standard AutoModel APIs): | ||
|
||
- [Model](Model): examples of running Hugging Face Transformers models (e.g., LLaMA2, ChatGLM2, Falcon, MPT, Baichuan2, etc.) using INT4 optimizations | ||
- [More-Data-Types](More-Data-Types): examples of applying other low bit optimizations (NF4/INT5/INT8, etc.) | ||
- [Save-Load](Save-Load): examples of saving and loading low-bit models |
43 changes: 43 additions & 0 deletions
43
python/llm/example/CPU/HF-Transformers-AutoModels/Save-Load/README.md
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 @@ | ||
# BigDL-LLM Transformers Low-Bit Inference Pipeline for Large Language Model | ||
|
||
In this example, we show a pipeline to apply BigDL-LLM low-bit optimizations (including INT8/INT5/INT4) to any Hugging Face Transformers model, and then run inference on the optimized low-bit model. | ||
|
||
## Prepare Environment | ||
We suggest using conda to manage environment: | ||
```bash | ||
conda create -n llm python=3.9 | ||
conda activate llm | ||
|
||
pip install --pre --upgrade bigdl-llm[all] | ||
``` | ||
|
||
## Run Example | ||
```bash | ||
python ./transformers_low_bit_pipeline.py --repo-id-or-model-path decapoda-research/llama-7b-hf --low-bit sym_int5 --save-path ./llama-7b-sym_int5 | ||
``` | ||
arguments info: | ||
- `--repo-id-or-model-path`: str value, argument defining the huggingface repo id for the large language model to be downloaded, or the path to the huggingface checkpoint folder, the value is 'decapoda-research/llama-7b-hf' by default. | ||
- `--low-bit`: str value, options are sym_int4, asym_int4, sym_int5, asym_int5 or sym_int8. (sym_int4 means symmetric int 4, asym_int4 means asymmetric int 4, etc.). Relevant low bit optimizations will be applied to the model. | ||
- `--save-path`: str value, the path to save the low-bit model. Then you can load the low-bit directly. | ||
- `--load-path`: optional str value. The path to load low-bit model. | ||
|
||
|
||
## Sample Output for Inference | ||
### 'decapoda-research/llama-7b-hf' Model | ||
```log | ||
Prompt: Once upon a time, there existed a little girl who liked to have adventures. She wanted to go to places and meet new people, and have fun | ||
Output: Once upon a time, there existed a little girl who liked to have adventures. She wanted to go to places and meet new people, and have fun. She wanted to be a princess, and she wanted to be a pirate. She wanted to be a superhero, and she wanted to be | ||
Model and tokenizer are saved to ./llama-7b-sym_int5 | ||
``` | ||
|
||
### Load low-bit model | ||
Command to run: | ||
```bash | ||
python ./transformers_low_bit_pipeline.py --load-path ./llama-7b-sym_int5 | ||
``` | ||
Output log: | ||
```log | ||
Prompt: Once upon a time, there existed a little girl who liked to have adventures. She wanted to go to places and meet new people, and have fun | ||
Output: Once upon a time, there existed a little girl who liked to have adventures. She wanted to go to places and meet new people, and have fun. She wanted to be a princess, and she wanted to be a pirate. She wanted to be a superhero, and she wanted to be | ||
``` | ||
|
56 changes: 56 additions & 0 deletions
56
python/llm/example/CPU/HF-Transformers-AutoModels/Save-Load/transformers_low_bit_pipeline.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,56 @@ | ||
# | ||
# Copyright 2016 The BigDL Authors. | ||
# | ||
# 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. | ||
# | ||
|
||
import argparse | ||
from bigdl.llm.transformers import AutoModelForCausalLM | ||
from transformers import LlamaTokenizer, TextGenerationPipeline | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description='Transformer save_load example') | ||
parser.add_argument('--repo-id-or-model-path', type=str, default="decapoda-research/llama-7b-hf", | ||
help='The huggingface repo id for the large language model to be downloaded' | ||
', or the path to the huggingface checkpoint folder') | ||
parser.add_argument('--low-bit', type=str, default="sym_int4", | ||
choices=['sym_int4', 'asym_int4', 'sym_int5', 'asym_int5', 'sym_int8'], | ||
help='The quantization type the model will convert to.') | ||
parser.add_argument('--save-path', type=str, default=None, | ||
help='The path to save the low-bit model.') | ||
parser.add_argument('--load-path', type=str, default=None, | ||
help='The path to load the low-bit model.') | ||
args = parser.parse_args() | ||
model_path = args.repo_id_or_model_path | ||
low_bit = args.low_bit | ||
load_path = args.load_path | ||
if load_path: | ||
model = AutoModelForCausalLM.load_low_bit(load_path) | ||
tokenizer = LlamaTokenizer.from_pretrained(load_path) | ||
else: | ||
# load_in_low_bit in bigdl.llm.transformers will convert | ||
# the relevant layers in the model into corresponding int X format | ||
model = AutoModelForCausalLM.from_pretrained(model_path, load_in_low_bit=low_bit, trust_remote_code=True) | ||
tokenizer = LlamaTokenizer.from_pretrained(model_path, trust_remote_code=True) | ||
|
||
pipeline = TextGenerationPipeline(model=model, tokenizer=tokenizer, max_new_tokens=32) | ||
input_str = "Once upon a time, there existed a little girl who liked to have adventures. She wanted to go to places and meet new people, and have fun" | ||
output = pipeline(input_str)[0]["generated_text"] | ||
print(f"Prompt: {input_str}") | ||
print(f"Output: {output}") | ||
|
||
save_path = args.save_path | ||
if save_path: | ||
model.save_low_bit(save_path) | ||
tokenizer.save_pretrained(save_path) | ||
print(f"Model and tokenizer are saved to {save_path}") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
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,7 @@ | ||
# Running PyTorch model using BigDL-LLM on Intel CPU | ||
|
||
This folder contains examples of running any PyTorch model on BigDL-LLM (with "one-line code change"): | ||
|
||
- [Model](Model): examples of running PyTorch models (e.g., Openai Whisper, LLaMA2, ChatGLM2, Falcon, MPT, Baichuan2, etc.) using INT4 optimizations | ||
- [More-Data-Types](More-Data-Types): examples of applying other low bit optimizations (NF4/INT5/INT8, etc.) | ||
- [Save-Load](Save-Load): examples of saving and loading low-bit models |
Empty file.
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,18 @@ | ||
# BigDL-LLM Examples on Intel CPU | ||
|
||
This folder contains examples of running BigDL-LLM on Intel CPU: | ||
|
||
- [HF-Transformers-AutoModels](HF-Transformers-AutoModels): running any Hugging Face Transformers model on BigDL-LLM (using the standard AutoModel APIs) | ||
- [PyTorch-Models](PyTorch-Models): running any PyTorch model on BigDL-LLM (with "one-line code change") | ||
- [Native-Models](Native-Models): converting & running LLM in `llama`/`chatglm`/`bloom`/`gptneox`/`starcoder` model family using native (cpp) implementation | ||
- [LangChain](LangChain): running LangChain applications on BigDL-LLM | ||
|
||
## System Support | ||
**Hardware**: | ||
- Intel® Core™ processors | ||
- Intel® Xeon® processors | ||
|
||
**Operating System**: | ||
- Ubuntu 20.04 or later | ||
- CentOS 7 or later | ||
- Windows 10/11, with or without WSL |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
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,7 @@ | ||
# Running Hugging Face Transformers model using BigDL-LLM on Intel GPU | ||
|
||
This folder contains examples of running any Hugging Face Transformers model on BigDL-LLM (using the standard AutoModel APIs): | ||
|
||
- [Model](Model): examples of running Hugging Face Transformers models (e.g., LLaMA2, ChatGLM2, Falcon, MPT, Baichuan2, etc.) using INT4 optimizations | ||
- [More-Data-Types](More-Data-Types): examples of applying other low bit optimizations (NF4/INT5/INT8, etc.) | ||
- [Save-Load](Save-Load): examples of saving and loading low-bit models |
Empty file.
Empty file.
Empty file.
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,7 @@ | ||
# Running PyTorch model using BigDL-LLM on Intel GPU | ||
|
||
This folder contains examples of running any PyTorch model on BigDL-LLM (with "one-line code change"): | ||
|
||
- [Model](Model): examples of running PyTorch models (e.g., Openai Whisper, LLaMA2, ChatGLM2, Falcon, MPT, Baichuan2, etc.) using INT4 optimizations | ||
- [More-Data-Types](More-Data-Types): examples of applying other low bit optimizations (NF4/INT5/INT8, etc.) | ||
- [Save-Load](Save-Load): examples of saving and loading low-bit models |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,26 @@ | ||
# BigDL-LLM Examples on Intel GPU | ||
|
||
This folder contains examples of running BigDL-LLM on Intel GPU: | ||
|
||
- [HF-Transformers-AutoModels](HF-Transformers-AutoModels): running any Hugging Face Transformers model on BigDL-LLM (using the standard AutoModel APIs) | ||
- [PyTorch-Models](PyTorch-Models): running any PyTorch model on BigDL-LLM (with "one-line code change") | ||
- [QLoRA-FineTuning](QLoRA-FineTuning): running QLoRA finetuning on BigDL-LLM | ||
|
||
|
||
## System Support | ||
**Hardware**: | ||
- Intel Arc™ A-Series Graphics | ||
- Intel Data Center GPU Flex Series | ||
- Intel Data Center GPU Max Series | ||
|
||
**Operating System**: | ||
- Ubuntu 20.04 or later (Ubuntu 22.04 is preferred) | ||
|
||
## Requirements | ||
To apply Intel GPU acceleration, there’re several steps for tools installation and environment preparation. | ||
|
||
Step 1, please refer to our [driver installation](https://dgpu-docs.intel.com/driver/installation.html) for general purpose GPU capabilities. | ||
> **Note**: IPEX 2.0.110+xpu requires Intel GPU Driver version is [Stable 647.21](https://dgpu-docs.intel.com/releases/stable_647_21_20230714.html). | ||
Step 2, you also need to download and install [Intel® oneAPI Base Toolkit](https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html). OneMKL and DPC++ compiler are needed, others are optional. | ||
> **Note**: IPEX 2.0.110+xpu requires Intel® oneAPI Base Toolkit's version >= 2023.2.0. |
Oops, something went wrong.