-
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.
* add test_llamaindex of gpu * add llamaindex gpu tests bash * add llamaindex cpu tests bash * update name of Run LLM langchain GPU test * import llama_index in llamaindex gpu ut * update the dependency of test_llamaindex * add Run LLM llamaindex GPU test * modify import dependency of llamaindex cpu test * add Run LLM llamaindex test * update llama_model_path * delete unused model path * add LLAMA2_7B_ORIGIN_PATH in llamaindex cpu test
- Loading branch information
Showing
5 changed files
with
136 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# | ||
# 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 torch | ||
import pytest | ||
from unittest import TestCase | ||
import os | ||
from bigdl.llm.llamaindex.llms import BigdlLLM | ||
|
||
class Test_LlamaIndex_Transformers_API(TestCase): | ||
def setUp(self): | ||
self.llama_model_path = os.environ.get('LLAMA2_7B_ORIGIN_PATH') | ||
thread_num = os.environ.get('THREAD_NUM') | ||
if thread_num is not None: | ||
self.n_threads = int(thread_num) | ||
else: | ||
self.n_threads = 2 | ||
|
||
def completion_to_prompt(completion): | ||
return f"<|system|>\n</s>\n<|user|>\n{completion}</s>\n<|assistant|>\n" | ||
|
||
def messages_to_prompt(messages): | ||
prompt = "" | ||
for message in messages: | ||
if message.role == "system": | ||
prompt += f"<|system|>\n{message.content}</s>\n" | ||
elif message.role == "user": | ||
prompt += f"<|user|>\n{message.content}</s>\n" | ||
elif message.role == "assistant": | ||
prompt += f"<|assistant|>\n{message.content}</s>\n" | ||
|
||
# ensure we start with a system prompt, insert blank if needed | ||
if not prompt.startswith("<|system|>\n"): | ||
prompt = "<|system|>\n</s>\n" + prompt | ||
|
||
# add final assistant prompt | ||
prompt = prompt + "<|assistant|>\n" | ||
return prompt | ||
|
||
def test_bigdl_llm(self): | ||
llm = BigdlLLM( | ||
model_name=self.llama_model_path, | ||
tokenizer_name=self.llama_model_path, | ||
context_window=512, | ||
max_new_tokens=32, | ||
model_kwargs={}, | ||
generate_kwargs={"temperature": 0.7, "do_sample": False}, | ||
messages_to_prompt=self.messages_to_prompt, | ||
completion_to_prompt=self.completion_to_prompt, | ||
device_map="xpu", | ||
) | ||
res = llm.complete("What is AI?") | ||
assert res!=None | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main([__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,21 @@ | ||
#!/bin/bash | ||
|
||
export ANALYTICS_ZOO_ROOT=${ANALYTICS_ZOO_ROOT} | ||
export LLM_HOME=${ANALYTICS_ZOO_ROOT}/python/llm/src | ||
export LLM_INFERENCE_TEST_DIR=${ANALYTICS_ZOO_ROOT}/python/llm/test/llamaindex_gpu | ||
|
||
export USE_XETLA=OFF | ||
export SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS=1 | ||
|
||
set -e | ||
|
||
echo "# Start testing inference" | ||
start=$(date "+%s") | ||
|
||
python -m pytest -s ${LLM_INFERENCE_TEST_DIR} | ||
|
||
now=$(date "+%s") | ||
time=$((now-start)) | ||
|
||
echo "Bigdl-llm llamaindex gpu tests finished" | ||
echo "Time used:$time seconds" |
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 @@ | ||
#!/bin/bash | ||
|
||
export ANALYTICS_ZOO_ROOT=${ANALYTICS_ZOO_ROOT} | ||
export LLM_HOME=${ANALYTICS_ZOO_ROOT}/python/llm/src | ||
export LLM_INFERENCE_TEST_DIR=${ANALYTICS_ZOO_ROOT}/python/llm/test/llamaindex | ||
|
||
set -e | ||
|
||
echo "# Start testing inference" | ||
start=$(date "+%s") | ||
|
||
python -m pytest -s ${LLM_INFERENCE_TEST_DIR} | ||
|
||
now=$(date "+%s") | ||
time=$((now-start)) | ||
|
||
echo "Bigdl-llm llamaindex tests finished" | ||
echo "Time used:$time seconds" |