Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 698e589

Browse files
Enable Qwen-7B-Chat (#432)
Co-authored-by: lvliang-intel <liang1.lv@intel.com>
1 parent ba5d9e3 commit 698e589

File tree

7 files changed

+67
-6
lines changed

7 files changed

+67
-6
lines changed

intel_extension_for_transformers/neural_chat/chatbot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def build_chatbot(config: PipelineConfig=None):
6464
elif "chatglm" in config.model_name_or_path:
6565
from .models.chatglm_model import ChatGlmModel
6666
adapter = ChatGlmModel()
67+
elif "Qwen" in config.model_name_or_path:
68+
from .models.qwen_model import QwenModel
69+
adapter = QwenModel()
6770
elif "opt" in config.model_name_or_path or \
6871
"gpt" in config.model_name_or_path or \
6972
"flan-t5" in config.model_name_or_path or \
@@ -72,7 +75,7 @@ def build_chatbot(config: PipelineConfig=None):
7275
adapter = BaseModel()
7376
else:
7477
raise ValueError("NeuralChat Error: Unsupported model name or path, \
75-
only supports FLAN-T5/LLAMA/MPT/GPT/BLOOM/OPT/NEURAL-CHAT now.")
78+
only supports FLAN-T5/LLAMA/MPT/GPT/BLOOM/OPT/QWEN/NEURAL-CHAT now.")
7679

7780
# register plugin instance in model adaptor
7881
if config.plugins:

intel_extension_for_transformers/neural_chat/docs/notebooks/build_chatbot_on_spr.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"source": [
4848
"!git clone https://github.com/intel/intel-extension-for-transformers.git\n",
4949
"!cd ./intel-extension-for-transformers/intel_extension_for_transformers/neural_chat/\n",
50-
"!pip install -r requirements.txt"
50+
"!pip install -r requirements_cpu.txt"
5151
]
5252
},
5353
{

intel_extension_for_transformers/neural_chat/docs/notebooks/deploy_chatbot_on_xpu.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"source": [
5353
"!git clone https://github.com/intel/intel-extension-for-transformers.git\n",
5454
"!cd ./intel-extension-for-transformers/intel_extension_for_transformers/neural_chat/\n",
55-
"!pip install -r requirements.txt"
55+
"!pip install -r requirements_xpu.txt"
5656
]
5757
},
5858
{
@@ -139,7 +139,7 @@
139139
"metadata": {},
140140
"outputs": [],
141141
"source": [
142-
"from neural_chat import TextChatClientExecutor\n",
142+
"from intel_extension_for_transformers.neural_chat import TextChatClientExecutor\n",
143143
"executor = TextChatClientExecutor()\n",
144144
"result = executor(\n",
145145
" prompt=\"Tell me about Intel Xeon Scalable Processors.\",\n",

intel_extension_for_transformers/neural_chat/models/model_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def load_model(
330330
use_fast=False if (re.search("llama", model_name, re.IGNORECASE)
331331
or re.search("neural-chat-7b-v2", model_name, re.IGNORECASE)) else True,
332332
use_auth_token=hf_access_token,
333+
trust_remote_code=True if (re.search("qwen", model_name, re.IGNORECASE)) else False,
333334
)
334335
config = AutoConfig.from_pretrained(model_name, use_auth_token=hf_access_token)
335336
load_to_meta = model_on_meta(config)
@@ -356,6 +357,7 @@ def load_model(
356357
or re.search("opt", model_name, re.IGNORECASE)
357358
or re.search("neural-chat-7b-v1", model_name, re.IGNORECASE)
358359
or re.search("neural-chat-7b-v2", model_name, re.IGNORECASE)
360+
or re.search("qwen", model_name, re.IGNORECASE)
359361
):
360362
with smart_context_manager(use_deepspeed=use_deepspeed):
361363
model = AutoModelForCausalLM.from_pretrained(
@@ -367,7 +369,7 @@ def load_model(
367369
)
368370
else:
369371
raise ValueError(
370-
f"Unsupported model {model_name}, only supports FLAN-T5/LLAMA/MPT/GPT/BLOOM/OPT/NEURAL-CHAT now."
372+
f"Unsupported model {model_name}, only supports FLAN-T5/LLAMA/MPT/GPT/BLOOM/OPT/QWEN/NEURAL-CHAT now."
371373
)
372374

373375
if re.search("llama", model.config.architectures[0], re.IGNORECASE):
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2023 Intel Corporation
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
from .base_model import BaseModel, register_model_adapter
19+
import logging
20+
from fastchat.conversation import get_conv_template, Conversation
21+
22+
logging.basicConfig(
23+
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
24+
datefmt="%m/%d/%Y %H:%M:%S",
25+
level=logging.INFO,
26+
)
27+
logger = logging.getLogger(__name__)
28+
29+
class QwenModel(BaseModel):
30+
def match(self, model_path: str):
31+
"""
32+
Check if the provided model_path matches the current model.
33+
34+
Args:
35+
model_path (str): Path to a model.
36+
37+
Returns:
38+
bool: True if the model_path matches, False otherwise.
39+
"""
40+
return "qwen" in model_path.lower()
41+
42+
def get_default_conv_template(self, model_path: str) -> Conversation:
43+
"""
44+
Get the default conversation template for the given model path.
45+
46+
Args:
47+
model_path (str): Path to the model.
48+
49+
Returns:
50+
Conversation: A default conversation template.
51+
"""
52+
return get_conv_template("qwen-7b-chat")
53+
54+
register_model_adapter(QwenModel)

intel_extension_for_transformers/neural_chat/requirements_cpu.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
transformers>=4.32.0
22
peft
33
fschat
4-
intel_extension_for_pytorch
4+
intel_extension_for_pytorch==2.0.100
55
num2words
66
speechbrain
77
paddlepaddle
@@ -35,6 +35,7 @@ openpyxl
3535
numpy==1.23.5
3636
tiktoken==0.4.0
3737
lm_eval
38+
transformers_stream_generator==0.0.4
3839
--extra-index-url https://download.pytorch.org/whl/cpu
3940
torch==2.0.1
4041
torchaudio==2.0.2

intel_extension_for_transformers/neural_chat/requirements_xpu.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ rouge_score
2828
openpyxl
2929
numpy==1.23.5
3030
tiktoken==0.4.0
31+
transformers_stream_generator==0.0.4
3132
cchardet

0 commit comments

Comments
 (0)