Skip to content

Commit 200d876

Browse files
authored
feat(build): Integrate and build turbomind backend directly in setup.py (#3726)
* fix: add cmake_build_extension for turbomind extension building. * fix: use regex to extract version instead of exec(). * fix: make cmake_build_extention a build requirement for setuptools. * fix: enable turbomind only with cuda, and fix cuda package dependencies. * fix: fix yaml-cpp cmake policy issue by hotfix patch. * fix: tweak for ci build. * fix: auto detect cudaver for turbomaind. * doc: update installation docs
1 parent cde5a5e commit 200d876

File tree

18 files changed

+140
-271
lines changed

18 files changed

+140
-271
lines changed

.github/workflows/cuda11.8-whl-release.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ jobs:
5959
pyver: ['3.9', '3.10', '3.11', '3.12', '3.13']
6060
runs-on: windows-latest
6161
steps:
62+
- name: Set git for windows
63+
run: |
64+
git config --global core.longpaths true
6265
- name: Checkout repository
6366
uses: actions/checkout@v3
6467
- name: Set up python
@@ -67,7 +70,7 @@ jobs:
6770
python-version: ${{ matrix.pyver }}
6871
- name: Install python packages
6972
run: |
70-
pip install pybind11 wheel
73+
pip install build change-wheel-version
7174
- name: Setup CUDA Toolkit
7275
id: cuda-toolkit
7376
shell: pwsh
@@ -76,19 +79,8 @@ jobs:
7679
INPUT_CUDA_VERSION: '11.8.0'
7780
- name: Build wheel
7881
run: |
79-
mkdir build
80-
cd build
81-
pip install -U setuptools
82-
..\builder\windows\generate.ps1
83-
cmake --build . --config Release -- /m /v:q
84-
if (-Not $?) {
85-
echo "build failed"
86-
exit 1
87-
}
88-
cmake --install . --config Release
89-
cd ..
90-
rm build -Force -Recurse
91-
python setup.py bdist_wheel -d build/wheel
82+
python -m build --wheel -o build/wheel
83+
change_wheel_version build/*.whl --local-version cu118 --delete-old-wheel
9284
- name: Upload Artifacts
9385
uses: actions/upload-artifact@v4
9486
with:

.github/workflows/linux-x64-gpu.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,5 @@ jobs:
5555
cd /work
5656
source /opt/conda/bin/activate
5757
conda activate py310
58-
mkdir build && cd build
59-
bash ../generate.sh make
60-
make -j$(nproc) && make install
58+
pip install build
59+
python -m build --wheel

.github/workflows/pr_ete_test.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,11 @@ jobs:
6565
make -j$(nproc) && make install && cd .. && rm -rf openmpi-4.1.5*
6666
export PATH=$PATH:/usr/local/openmpi/bin
6767
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openmpi/lib
68-
python3 -m pip install cmake packaging wheel transformers_stream_generator transformers==4.51.3 datasets openai einops timm decord
69-
python3 -m pip install -r requirements_cuda.txt -r requirements/test.txt -r requirements/build.txt
70-
mkdir -p build && cd build &&\
71-
sh ../generate.sh &&\
72-
ninja -j$(nproc) && ninja install &&\
73-
cd .. &&\
74-
python3 -m pip install -e . &&\
75-
rm -rf build
68+
# We need to pin transformers version (<4.52.0) to avoid test failures due to breaking changes.
69+
python3 -m pip install transformers==4.51.3 timm
70+
python3 -m pip install -r requirements/lite.txt
71+
python3 -m pip install -r requirements/test.txt
72+
python3 -m pip install -e .
7673
# the install packeage from. https://github.com/Dao-AILab/flash-attention/releases
7774
python3 -m pip install /nvme/qa_test_models/offline_pkg/flash_attn-2.8.0.post2-cp310-cp310-linux_x86_64.whl
7875
- name: Check env

.github/workflows/pypi.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
pyver: ['3.9', '3.10', '3.11', '3.12', '3.13']
5959
runs-on: windows-latest
6060
steps:
61+
- name: Set git for windows
62+
run: |
63+
git config --global core.longpaths true
6164
- name: Checkout repository
6265
uses: actions/checkout@v3
6366
- name: Set up python
@@ -66,8 +69,7 @@ jobs:
6669
python-version: ${{ matrix.pyver }}
6770
- name: Install python packages
6871
run: |
69-
pip install -r requirements/build.txt
70-
pip install wheel
72+
pip install build change-wheel-version
7173
- name: Setup CUDA Toolkit
7274
id: cuda-toolkit
7375
shell: pwsh
@@ -76,20 +78,8 @@ jobs:
7678
INPUT_CUDA_VERSION: '12.1.0'
7779
- name: Build wheel
7880
run: |
79-
mkdir build
80-
cd build
81-
# https://github.com/pypa/setuptools/issues/1631
82-
pip install -U setuptools
83-
..\builder\windows\generate.ps1
84-
cmake --build . --config Release -- /m /v:q
85-
if (-Not $?) {
86-
echo "build failed"
87-
exit 1
88-
}
89-
cmake --install . --config Release
90-
cd ..
91-
rm build -Force -Recurse
92-
python setup.py bdist_wheel -d build/wheel
81+
python -m build --wheel -o build/wheel
82+
change_wheel_version build/*.whl --local-version cu121 --delete-old-wheel
9383
- name: Upload Artifacts
9484
uses: actions/upload-artifact@v4
9585
with:

.github/workflows/unit-test.yml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,13 @@ jobs:
5757
python3 -V
5858
python3 -m pip cache dir
5959
python3 -m pip install torch==2.4.0 torchvision==0.19.0 --index-url https://download.pytorch.org/whl/cu118
60-
- name: Build lmdeploy
61-
run: |
62-
python3 -m pip install cmake matplotlib
63-
python3 -m pip install -r requirements/build.txt
64-
mkdir build
65-
cd build
66-
cp -r /root/packages/_deps _deps
67-
cmake .. \
68-
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
69-
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
70-
-DCMAKE_INSTALL_PREFIX=./install \
71-
-DBUILD_PY_FFI=ON \
72-
-DBUILD_MULTI_GPU=OFF \
73-
-DCMAKE_CUDA_FLAGS="-lineinfo" \
74-
-DUSE_NVTX=ON \
75-
-DSM=80 \
76-
-DCMAKE_CUDA_ARCHITECTURES=80 \
77-
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
78-
-DBUILD_TEST=OFF
79-
make -j$(nproc) && make install
8060
- name: Install lmdeploy
8161
run: |
82-
python3 -m pip install pynvml packaging protobuf transformers_stream_generator
62+
python3 -m pip install pynvml packaging protobuf transformers_stream_generator matplotlib
8363
# manually install flash attn
8464
python3 -m pip install /root/packages/cu118/flash_attn-*.whl
8565
python3 -m pip install -r requirements_cuda.txt -r requirements/test.txt
86-
python3 -m pip install .
66+
python3 -m pip install -e .
8767
- name: Check env
8868
run: |
8969
python3 -m pip list

.github/workflows/windows-x64-gpu.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
name: cuda-${{ matrix.cudaver }}
3333
runs-on: windows-latest
3434
steps:
35+
- name: Set git for windows
36+
run: |
37+
git config --global core.longpaths true
3538
- name: Checkout repository
3639
uses: actions/checkout@v3
3740
- name: Set up python
@@ -40,8 +43,7 @@ jobs:
4043
python-version: '3.10'
4144
- name: Install python packages
4245
run: |
43-
pip install -r requirements/build.txt
44-
pip install wheel
46+
pip install build
4547
- name: Setup CUDA Toolkit
4648
id: cuda-toolkit
4749
shell: pwsh
@@ -50,16 +52,4 @@ jobs:
5052
INPUT_CUDA_VERSION: ${{ matrix.cudaver }}
5153
- name: Build wheel
5254
run: |
53-
$env:BUILD_TEST="OFF"
54-
mkdir build
55-
cd build
56-
..\builder\windows\generate.ps1
57-
cmake --build . --config Release -- /m /v:n
58-
if (-Not $?) {
59-
echo "build failed"
60-
exit 1
61-
}
62-
cmake --install . --config Release
63-
cd ..
64-
rm build -Force -Recurse
65-
python setup.py bdist_wheel -d build/wheel
55+
python -m build --wheel

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ repos:
2727
args: ["--remove"]
2828
- id: mixed-line-ending
2929
args: ["--fix=lf"]
30+
3031
- repo: https://github.com/executablebooks/mdformat
3132
rev: 0.7.9
3233
hooks:
@@ -55,3 +56,8 @@ repos:
5556
hooks:
5657
- id: check-copyright
5758
args: ["lmdeploy"]
59+
60+
exclude: |
61+
(?x)(
62+
^cmake/.*\.patch$
63+
)

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ project(TurboMind LANGUAGES CXX CUDA)
1818
if (MSVC)
1919
# use standard conformant preprocessor
2020
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:preprocessor>)
21-
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/Zc:preprocessor")
21+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/Zc:preprocessor -Xcompiler=/Zc:__cplusplus")
2222
endif ()
2323

2424
find_package(CUDAToolkit REQUIRED)
@@ -52,6 +52,7 @@ FetchContent_Declare(
5252
GIT_REPOSITORY https://github.com/NVIDIA/cutlass.git
5353
GIT_TAG v3.9.2
5454
GIT_SHALLOW ON
55+
EXCLUDE_FROM_ALL
5556
)
5657

5758
set(CUTLASS_ENABLE_SM90_EXTENDED_MMA_SHAPES ON CACHE BOOL "Enable extended GMMA shapes")
@@ -63,6 +64,8 @@ FetchContent_Declare(
6364
yaml-cpp
6465
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
6566
GIT_TAG 0.8.0
67+
PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/yaml-cpp_cmake_policy.patch
68+
UPDATE_DISCONNECTED 1
6669
)
6770
set(YAML_BUILD_SHARED_LIBS OFF CACHE BOOL "Build static library of yaml-cpp")
6871
FetchContent_MakeAvailable(yaml-cpp)
@@ -233,5 +236,9 @@ add_subdirectory(src)
233236

234237
# install python api
235238
if (BUILD_PY_FFI)
236-
install(TARGETS _turbomind DESTINATION ${CMAKE_SOURCE_DIR}/lmdeploy/lib)
239+
if (CALL_FROM_SETUP_PY)
240+
install(TARGETS _turbomind DESTINATION ${CMAKE_INSTALL_PREFIX})
241+
else()
242+
install(TARGETS _turbomind DESTINATION ${CMAKE_SOURCE_DIR}/lmdeploy/lib)
243+
endif()
237244
endif ()

builder/manywheel/entrypoint_build.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,19 @@ export PYTHON_VERSION=$PYTHON_VERSION
55
export PLAT_NAME=$PLAT_NAME
66
export USERID=${USERID}
77
export GROUPID=${GROUPID}
8-
export CUDAVER=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\).*$/\1/p')
98
export NCCL_INCLUDE_DIR=/usr/local/cuda/include
109
export NCCL_LIB_DIR=/usr/local/cuda/lib64
1110

1211
source /opt/conda/bin/activate
1312
conda activate $PYTHON_VERSION
1413

1514
cd lmdeploy
16-
rm -rf lmdeploy/lib
17-
mkdir -p build && cd build && rm -rf *
18-
bash ../generate.sh make
19-
make -j$(nproc) && make install
20-
if [ $? != 0 ]; then
21-
echo "build failed"
22-
exit 1
23-
fi
24-
cd ..
25-
rm -rf build
26-
python setup.py bdist_wheel --cuda=${CUDAVER} --plat-name $PLAT_NAME -d /tmpbuild/
15+
pip install build change-wheel-version
16+
python -m build --wheel -o /tmpbuild/
17+
for file in $(find /tmpbuild/ -name "*.whl")
18+
do
19+
platform_tag="$(basename $file | cut -d- -f3-4)-${PLAT_NAME}"
20+
change_wheel_version /tmpbuild/*.whl --delete-old-wheel --platform-tag ${platform_tag}
21+
done
2722
chown ${USERID}:${GROUPID} /tmpbuild/*
2823
mv /tmpbuild/* /lmdeploy_build/

builder/windows/README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
## Build lmdeploy wheel
1010

1111
```powershell
12-
mkdir build
13-
cd build
14-
..\builder\windows\generate.ps1
15-
cmake --build . --config Release -- /m
16-
cmake --install . --config Release
17-
cd ..
18-
rm build -Force -Recurse
19-
python setup.py bdist_wheel -d build\wheel
12+
pip install build
13+
python -m build --wheel
2014
```

0 commit comments

Comments
 (0)