Skip to content

Commit

Permalink
Merge pull request #201 from wangzhaode/feature/python_ci
Browse files Browse the repository at this point in the history
[feat] add python ci.
  • Loading branch information
wangzhaode authored Jun 17, 2024
2 parents a5f0963 + a9aa1de commit 63e768d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ 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:
lib_suffix = 'dylib'

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'))

Expand Down
12 changes: 12 additions & 0 deletions python/test.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions script/py_build.sh
Original file line number Diff line number Diff line change
@@ -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 ..

0 comments on commit 63e768d

Please sign in to comment.