ipex-llm/python/llm/test/inference/test_call_models.py
Ruonan Wang 4be784a49d LLM: add UT for starcoder (convert, inference) update examples and readme (#8379)
* first commit to add path

* update example and readme

* update path

* fix

* update based on comment
2023-06-27 12:12:11 +08:00

74 lines
2.9 KiB
Python

#
# 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.
#
from bigdl.llm.models import Llama, Bloom, Gptneox, Starcoder
from bigdl.llm.utils import get_avx_flags
import pytest
from unittest import TestCase
import os
class Test_Models_Basics(TestCase):
def setUp(self):
self.llama_model_path = os.environ.get('LLAMA_INT4_CKPT_PATH')
self.bloom_model_path = os.environ.get('BLOOM_INT4_CKPT_PATH')
self.gptneox_model_path = os.environ.get('GPTNEOX_INT4_CKPT_PATH')
self.starcoder_model_path = os.environ.get('STARCODER_INT4_CKPT_PATH')
def test_llama_completion_success(self):
llm = Llama(self.llama_model_path)
output = llm("What is the capital of France?", max_tokens=32, stream=False)
# assert "Paris" in output['choices'][0]['text']
def test_llama_completion_with_stream_success(self):
llm = Llama(self.llama_model_path)
output = llm("What is the capital of France?", max_tokens=32, stream=True)
def test_bloom_completion_success(self):
llm = Bloom(self.bloom_model_path)
output = llm("What is the capital of France?", max_tokens=32, stream=False)
# avx = get_avx_flags()
# if avx == "_avx512":
# # For platforms without avx512, the current text completion may output gibberish
# assert "Paris" in output['choices'][0]['text']
def test_bloom_completion_with_stream_success(self):
llm = Bloom(self.bloom_model_path)
output = llm("What is the capital of France?", max_tokens=32, stream=True)
def test_gptneox_completion_success(self):
llm = Gptneox(self.gptneox_model_path)
output = llm("Q: What is the capital of France? A:", max_tokens=32, stream=False)
# assert "Paris" in output['choices'][0]['text']
def test_gptneox_completion_with_stream_success(self):
llm = Gptneox(self.gptneox_model_path)
output = llm("Q: What is the capital of France? A:", max_tokens=32, stream=True)
def test_starcoder_completion_success(self):
llm = Starcoder(self.starcoder_model_path)
output = llm("def print_hello_world(", max_tokens=32, stream=False)
# assert "Paris" in output['choices'][0]['text']
def test_starcoder_completion_with_stream_success(self):
llm = Starcoder(self.starcoder_model_path)
output = llm("def print_hello_world(", max_tokens=32, stream=True)
if __name__ == '__main__':
pytest.main([__file__])