Skip to content

Commit

Permalink
[feat] add python ci.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhaode committed Jun 17, 2024
1 parent a5f0963 commit 73ed6b9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -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
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 73ed6b9

Please sign in to comment.