From a9aa1deb278026d303b727ebc7b3698c09cd00d4 Mon Sep 17 00:00:00 2001 From: yanxing Date: Mon, 17 Jun 2024 16:31:53 +0800 Subject: [PATCH] [feat] add python ci. --- .github/workflows/python.yml | 43 ++++++++++++++++++++++++++++++++++++ python/setup.py | 10 ++++----- python/test.py | 12 ++++++++++ script/py_build.sh | 10 +++++++++ 4 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/python.yml create mode 100644 python/test.py create mode 100755 script/py_build.sh diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 00000000..76a1baeb --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,43 @@ +name: python +on: + push: + branches: + - master + - 'feature/**' + paths: + - 'src/**' + - 'python/**' + - '.github/workflows/python.yml' + pull_request: + branches: [master] + paths: + - 'src/**' + - 'python/**' + - '.github/workflows/python.yml' + +jobs: + build: + name: linux-build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - uses: s-weigand/setup-conda@v1 + + - name: build + run: ./script/py_build.sh + + - name: download_mode + run: | + wget -c -nv https://github.com/wangzhaode/mnn-llm/releases/download/qwen1.5-0.5b-chat-mnn/Qwen1.5-0.5B-Chat-MNN.zip + unzip Qwen1.5-0.5B-Chat-MNN.zip + + - name: test_model + run: | + conda install -c conda-forge gcc=12.1.0 + cd python + pip install dist/*.whl + python test.py ../Qwen1.5-0.5B-Chat-MNN/config.json diff --git a/python/setup.py b/python/setup.py index d691ca3d..6e1cc349 100644 --- a/python/setup.py +++ b/python/setup.py @@ -11,7 +11,7 @@ def make_relative_rpath(path): elif IS_WINDOWS: return [] else: - return ['-Wl,-rpath,$ORIGIN/' + path] + return [f'-Wl,-rpath,@loader_path/../../../{path},-rpath,$ORIGIN/{path}' ] lib_suffix = 'so' if IS_DARWIN: @@ -19,14 +19,14 @@ def make_relative_rpath(path): packages = find_packages() lib_files = [('lib', - [f'../libs/libMNN.{lib_suffix}', - f'../libs/libMNN_Express.{lib_suffix}', + [f'../build/MNN/libMNN.{lib_suffix}', + f'../build/MNN/express/libMNN_Express.{lib_suffix}', f'../build/libllm.{lib_suffix}'])] module = Extension('cmnnllm', sources=['./mnnllm.cpp'], - include_dirs=['../include'], - library_dirs=['../build', '../libs'], + include_dirs=['../include', '../MNN/include'], + library_dirs=['../build'], extra_compile_args=['-std=c++17'], extra_link_args=['-lllm'] + make_relative_rpath('lib')) diff --git a/python/test.py b/python/test.py new file mode 100644 index 00000000..3b61efc5 --- /dev/null +++ b/python/test.py @@ -0,0 +1,12 @@ +import mnnllm +import sys + +config_path = sys.argv[1] +# create model +qwen = mnnllm.create(config_path) +# load model +qwen.load() + +# response stream +out = qwen.response('你好', True) +print(out) diff --git a/script/py_build.sh b/script/py_build.sh new file mode 100755 index 00000000..d186451b --- /dev/null +++ b/script/py_build.sh @@ -0,0 +1,10 @@ +# 1. build lib +mkdir build +cd build +cmake .. +make -j4 +cd .. +# 2. install python wheel +cd python +python setup.py bdist_wheel +cd .. \ No newline at end of file