diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 00000000..07ea17d4 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,40 @@ +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' + + - 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: | + 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