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

Commit e7f5b1d

Browse files
[NeuralChat] Support deepseek-coder models in NeuralChat (#1251)
* Support deepseek-coder model Signed-off-by: lvliang-intel <liang1.lv@intel.com>
1 parent 08c6d63 commit e7f5b1d

File tree

9 files changed

+94
-6
lines changed

9 files changed

+94
-6
lines changed

intel_extension_for_transformers/neural_chat/chatbot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def build_chatbot(config: PipelineConfig=None):
134134
elif "solar" in config.model_name_or_path.lower():
135135
from .models.solar_model import SolarModel
136136
adapter = SolarModel(config.model_name_or_path, config.task)
137+
elif "deepseek-coder" in config.model_name_or_path.lower():
138+
from .models.deepseek_coder_model import DeepseekCoderModel
139+
adapter = DeepseekCoderModel(config.model_name_or_path, config.task)
137140
elif "opt" in config.model_name_or_path.lower() or \
138141
"gpt" in config.model_name_or_path.lower() or \
139142
"flan-t5" in config.model_name_or_path.lower() or \
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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
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 DeepseekCoderModel(BaseModel):
30+
def match(self):
31+
"""
32+
Check if the provided model_path matches the current model.
33+
34+
Returns:
35+
bool: True if the model_path matches, False otherwise.
36+
"""
37+
return "deepseek-coder" in self.model_name.lower()
38+
39+
def get_default_conv_template(self) -> Conversation:
40+
"""
41+
Get the default conversation template for the given model path.
42+
43+
Returns:
44+
Conversation: A default conversation template.
45+
"""
46+
return get_conv_template("deepseek-coder")

intel_extension_for_transformers/neural_chat/models/model_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ def load_model(
668668
return
669669

670670
if re.search("llama", model.config.architectures[0], re.IGNORECASE) and \
671-
not re.search("magicoder", model_name, re.IGNORECASE):
671+
(not re.search("magicoder", model_name, re.IGNORECASE) and
672+
not re.search("deepseek-coder", model_name, re.IGNORECASE)):
672673
# unwind broken decapoda-research config
673674
model.generation_config.pad_token_id = 0
674675
model.generation_config.bos_token_id = 1

intel_extension_for_transformers/neural_chat/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cchardet
33
einops
44
evaluate
55
fastapi==0.103.2
6-
fschat==0.2.32
6+
fschat==0.2.35
77
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
88
huggingface_hub
99
intel_extension_for_pytorch

intel_extension_for_transformers/neural_chat/requirements_hpu.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cchardet
22
einops
33
evaluate
44
fastapi==0.103.2
5-
fschat==0.2.32
5+
fschat==0.2.35
66
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
77
intel_extension_for_pytorch
88
neural-compressor

intel_extension_for_transformers/neural_chat/requirements_pc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cchardet
33
einops
44
evaluate
55
fastapi==0.103.2
6-
fschat==0.2.32
6+
fschat==0.2.35
77
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
88
neural-compressor
99
numpy==1.23.5

intel_extension_for_transformers/neural_chat/requirements_xpu.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cchardet
22
einops
33
evaluate
44
fastapi==0.103.2
5-
fschat==0.2.32
5+
fschat==0.2.35
66
neural-compressor
77
numpy==1.23.5
88
pydantic==1.10.13
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 intel_extension_for_transformers.neural_chat import build_chatbot, PipelineConfig
19+
from intel_extension_for_transformers.neural_chat.utils.common import get_device_type
20+
import unittest
21+
22+
class TestStarCoderModel(unittest.TestCase):
23+
def setUp(self):
24+
return super().setUp()
25+
26+
def tearDown(self) -> None:
27+
return super().tearDown()
28+
29+
def test_code_gen(self):
30+
config = PipelineConfig(
31+
model_name_or_path="/tf_dataset2/models/nlp_toolkit/deepseek-coder-6.7b-instruct")
32+
chatbot = build_chatbot(config=config)
33+
result = chatbot.predict("def print_hello_world():")
34+
print(result)
35+
self.assertIn("Hello World", str(result))
36+
37+
if __name__ == "__main__":
38+
unittest.main()

intel_extension_for_transformers/neural_chat/tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ face_alignment==1.3.5
1212
facexlib @ git+https://github.com/Spycsh/facexlib@master
1313
fastapi==0.103.2
1414
ffmpeg-python==0.2.0
15-
fschat==0.2.32
15+
fschat==0.2.35
1616
gfpgan
1717
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
1818
git+https://github.com/UKPLab/sentence-transformers.git@5c838a705c24c2dfd151a71674c99d09d014c1a9

0 commit comments

Comments
 (0)