This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
[DOC]Add modelscope example #1578
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e04083f
add modelscope example
intellinjun f3f7db9
Update README.md
intellinjun fa7c2dc
update support model
intellinjun c4a62e7
Merge branch 'modelscope_example' of https://github.com/intel/intel-e…
intellinjun f7ac33f
Update README.md
intellinjun 58b70ef
update requirements
intellinjun 75c640b
update README
intellinjun f4f4d38
Merge branch 'main' into modelscope_example
intellinjun 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# ModelScope with ITREX | ||
|
||
Intel® Extension for Transformers(ITREX) support almost all the LLMs in Pytorch format from ModelScope such as phi, Qwen, ChatGLM, Baichuan, gemma, etc. | ||
|
||
## Usage Example | ||
|
||
ITREX provides a script that demonstrates the use of modelscope. Use numactl to improve performance and run it with the following command: | ||
```bash | ||
OMP_NUM_THREADS=num_cores numactl -l -C 0-num_cores-1 python run_modelscope_example.py --model=qwen/Qwen-7B --prompt=你好 | ||
``` | ||
|
||
## Supported and Validated Models | ||
We have validated the majority of existing models using modelscope==1.13.1: | ||
* [qwen/Qwen-7B](https://www.modelscope.cn/models/qwen/Qwen-7B/summary) | ||
* [ZhipuAI/ChatGLM-6B](https://www.modelscope.cn/models/ZhipuAI/ChatGLM-6B/summary)(transformers=4.33.1) | ||
* [ZhipuAI/chatglm2-6b](https://www.modelscope.cn/models/ZhipuAI/chatglm2-6b/summary)(transformers=4.33.1) | ||
* [ZhipuAI/chatglm3-6b](https://www.modelscope.cn/models/ZhipuAI/chatglm3-6b/summary)(transformers=4.33.1) | ||
* [baichuan-inc/Baichuan2-7B-Chat](https://www.modelscope.cn/models/baichuan-inc/Baichuan2-7B-Chat/summary)(transformers=4.33.1) | ||
* [baichuan-inc/Baichuan2-13B-Chat](https://www.modelscope.cn/models/baichuan-inc/Baichuan2-13B-Chat/summary)(transformers=4.33.1) | ||
* [LLM-Research/Phi-3-mini-4k-instruct](https://www.modelscope.cn/models/LLM-Research/Phi-3-mini-4k-instruct/summary) | ||
* [LLM-Research/Phi-3-mini-128k-instruct](https://www.modelscope.cn/models/LLM-Research/Phi-3-mini-128k-instruct/summary) | ||
* [AI-ModelScope/gemma-2b](https://www.modelscope.cn/models/AI-ModelScope/gemma-2b/summary) | ||
|
||
If you encounter any problems, please let us know. |
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,13 @@ | ||
intel_extension_for_transformers | ||
neural-speed | ||
lm-eval | ||
sentencepiece | ||
gguf | ||
--extra-index-url https://download.pytorch.org/whl/cpu | ||
torch==2.3.0+cpu | ||
transformers | ||
intel_extension_for_pytorch==2.3.0 | ||
tiktoken | ||
transformers_stream_generator | ||
zipfile38 | ||
modelscope |
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,30 @@ | ||
from transformers import TextStreamer | ||
from modelscope import AutoTokenizer | ||
from intel_extension_for_transformers.transformers import AutoModelForCausalLM | ||
from typing import List, Optional | ||
import argparse | ||
|
||
def main(args_in: Optional[List[str]] = None) -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--model", type=str, help="Model name: String", required=True, default="qwen/Qwen-7B") | ||
parser.add_argument( | ||
"-p", | ||
"--prompt", | ||
type=str, | ||
help="Prompt to start generation with: String (default: empty)", | ||
default="你好,你可以做点什么?", | ||
) | ||
parser.add_argument("--benchmark", action="store_true") | ||
parser.add_argument("--use_neural_speed", action="store_true") | ||
args = parser.parse_args(args_in) | ||
print(args) | ||
model_name = args.model # Modelscope model_id or local model | ||
prompt = args.prompt | ||
model = AutoModelForCausalLM.from_pretrained(model_name, load_in_4bit=True, model_hub="modelscope") | ||
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) | ||
inputs = tokenizer(prompt, return_tensors="pt").input_ids | ||
streamer = TextStreamer(tokenizer) | ||
outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,6 +322,7 @@ class _BaseQBitsAutoModelClass: | |
"whisper", | ||
"qwen2", | ||
"gemma", | ||
"phi3", | ||
"tinyllama", | ||
] | ||
|
||
|
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.
please add the requirment.txt