Skip to content

Commit

Permalink
[refactor] refactor build script and ci.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhaode committed Jun 7, 2024
1 parent 0e39c2c commit 17d0a86
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 463 deletions.
79 changes: 0 additions & 79 deletions .github/model-test.yml

This file was deleted.

74 changes: 0 additions & 74 deletions .github/workflows/all.yml

This file was deleted.

40 changes: 12 additions & 28 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,21 @@ jobs:
build:
name: linux-build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# build
- name: build-pack
run: |
./script/build.sh
./script/package.sh package
zip -r package.zip package
# upload
- name: upload-zip
uses: actions/upload-artifact@v3
with:
path: ./*.zip
submodules: 'recursive'

test:
needs: build
name: ${{ matrix.model }}-linux-test
runs-on: ubuntu-latest
strategy:
matrix:
model: [qwen-1.8b, chatglm-6b, chatglm2-6b, chatglm3-6b, codegeex2-6b, qwen-7b-chat, baichuan2-7b-chat, llama2-7b-chat]
- name: build
run: ./script/build.sh

steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: workspace
- name: model-test
- 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 workspace
unzip package.zip
cd package
./script/model_test.sh ${{ matrix.model }}
cd build
./cli_demo ../Qwen1.5-0.5B-Chat-MNN/config.json ../resource/prompt.txt
40 changes: 12 additions & 28 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,21 @@ jobs:
build:
name: macos-build
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
# build
- name: build-pack
run: |
./script/build.sh
./script/package.sh package
zip -r package.zip package
# upload
- name: upload-zip
uses: actions/upload-artifact@v3
with:
path: ./*.zip
submodules: 'recursive'

test:
needs: build
name: ${{ matrix.model }}-macos-test
runs-on: macos-latest
strategy:
matrix:
model: [qwen-1.8b, chatglm-6b, chatglm2-6b, chatglm3-6b, codegeex2-6b, qwen-7b-chat, baichuan2-7b-chat, llama2-7b-chat]
- name: build
run: ./script/build.sh

steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: workspace
- name: model-test
- 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 workspace
unzip package.zip
cd package
./script/model_test.sh ${{ matrix.model }} prompt.txt
cd build
./cli_demo ../Qwen1.5-0.5B-Chat-MNN/config.json ../resource/prompt.txt
41 changes: 11 additions & 30 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,22 @@ jobs:
build:
name: windows-build
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
# build
- name: build-pack
run: |
.\script\build.ps1
.\script\package.ps1 package
7z a -r package.zip package
# upload
- name: upload-zip
uses: actions/upload-artifact@v3
with:
path: ./*.zip
submodules: 'recursive'

test:
needs: build
name: ${{ matrix.model }}-windows-test
runs-on: windows-latest
strategy:
matrix:
model: [qwen-1.8b, chatglm-6b, chatglm2-6b, chatglm3-6b, codegeex2-6b, qwen-7b-chat, baichuan2-7b-chat, llama2-7b-chat]
- name: build
run: .\script\build.ps1

steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: workspace
- name: windows-test
- name: download_mode
run: |
Invoke-WebRequest -Uri https://github.com/wangzhaode/mnn-llm/releases/download/qwen1.5-0.5b-chat-mnn/Qwen1.5-0.5B-Chat-MNN.zip -OutFile Qwen1.5-0.5B-Chat-MNN.zip
unzip Qwen1.5-0.5B-Chat-MNN.zip
- name: test_model
run: |
cd workspace
7z x package.zip
cd package
echo ${{ matrix.model }}
./script/download_model.ps1 ${{ matrix.model }}
cd build
.\Release\cli_demo ..\${{ matrix.model }} prompt.txt
.\Release\cli_demo ..\Qwen1.5-0.5B-Chat-MNN\config.json ..\resource\prompt.txt
Exit 0
34 changes: 26 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,33 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()

# include dir
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/)
# compile MNN first
set(MNN_LOW_MEMORY ON CACHE BOOL "Open MNN_LOW_MEMORY" FORCE)
set(MNN_SUPPORT_TRANSFORMER_FUSE ON CACHE BOOL "Open MNN_SUPPORT_TRANSFORMER_FUSE" FORCE)
if (BUILD_FOR_ANDROID)
set(MNN_ARM82 ON CACHE BOOL "Open MNN_ARM82" FORCE)
endif()
if (USING_VISUAL_MODEL)
set(MNN_BUILD_OPENCV ON CACHE BOOL "Open MNN_BUILD_OPENCV" FORCE)
set(MNN_IMGCODECS ON CACHE BOOL "Open MNN_IMGCODECS" FORCE)
endif()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/MNN)

# libs dir
link_directories(${CMAKE_CURRENT_LIST_DIR}/libs)
# include dir
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/
${CMAKE_CURRENT_LIST_DIR}/MNN/include/
${CMAKE_CURRENT_LIST_DIR}/MNN/tools/cv/include/cv/
)

# source files
FILE(GLOB SRCS ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
# compile static lib, surrpot Winwows
add_library(llm STATIC ${SRCS})
link_directories(${CMAKE_BINARY_DIR}/MNN/Release)
target_link_libraries(llm MNN.lib)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
Expand All @@ -53,8 +67,8 @@ add_executable(knowledge_demo ${CMAKE_CURRENT_LIST_DIR}/demo/knowledge_demo.cpp)
add_executable(pipeline_demo ${CMAKE_CURRENT_LIST_DIR}/demo/pipeline_demo.cpp)

if (BUILD_FOR_ANDROID)
add_library(MNN SHARED IMPORTED)
add_library(MNN_Express SHARED IMPORTED)
# add_library(MNN SHARED IMPORTED)
# add_library(MNN_Express SHARED IMPORTED)
set_target_properties(
MNN
PROPERTIES IMPORTED_LOCATION
Expand Down Expand Up @@ -86,8 +100,12 @@ else()
add_executable(web_demo ${CMAKE_CURRENT_LIST_DIR}/demo/web_demo.cpp)
if (MSVC)
target_link_libraries(web_demo llm pthreadVC2)
# copy all lib to target dir
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/libs/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug/)
add_custom_command(
TARGET cli_demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/build/MNN/Release/MNN.dll
$<TARGET_FILE_DIR:cli_demo>
)
else()
target_link_libraries(web_demo llm pthread)
endif()
Expand Down
Empty file removed libs/.gitkeep
Empty file.
Loading

0 comments on commit 17d0a86

Please sign in to comment.