Adapt for iluvatar gpu (#2684)

This commit is contained in:
liddk1121
2025-07-07 16:53:14 +08:00
committed by GitHub
parent 2579e8fea8
commit 1b54a2831e
50 changed files with 4485 additions and 80 deletions

View File

@@ -22,6 +22,7 @@ import subprocess
from pathlib import Path
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext
from wheel.bdist_wheel import bdist_wheel
long_description = "FastDeploy: Large Language Model Serving.\n\n"
long_description += "GitHub: https://github.com/PaddlePaddle/FastDeploy\n"
@@ -35,7 +36,6 @@ PLAT_TO_CMAKE = {
"win-arm64": "ARM64",
}
from wheel.bdist_wheel import bdist_wheel
class CustomBdistWheel(bdist_wheel):
"""Custom wheel builder for pure Python packages."""
@@ -49,10 +49,14 @@ class CustomBdistWheel(bdist_wheel):
self.plat_name_supplied = True
self.plat_name = 'any'
class CMakeExtension(Extension):
"""A setuptools Extension for CMake-based builds."""
def __init__(self, name: str, sourcedir: str = "", version: str = None) -> None:
def __init__(self,
name: str,
sourcedir: str = "",
version: str = None) -> None:
"""
Initialize CMake extension.
@@ -83,16 +87,12 @@ class CMakeBuild(build_ext):
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
extdir = ext_fullpath.parent.resolve()
cfg = "Debug" if int(os.environ.get("DEBUG", 0)) else "Release"
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}",
f"-DVERSION_INFO=",
f"-DPYBIND11_PYTHON_VERSION=",
f"-DPYTHON_VERSION=",
f"-DCMAKE_BUILD_TYPE={cfg}", "-DVERSION_INFO=",
"-DPYBIND11_PYTHON_VERSION=", "-DPYTHON_VERSION=",
f"-DPYTHON_INCLUDE_DIR={sys.prefix}/include/python{sys.version_info.major}.{sys.version_info.minor}",
f"-DPYTHON_LIBRARY={sys.prefix}/lib/libpython{sys.version_info.major}.{sys.version_info.minor}.so"
]
@@ -134,22 +134,27 @@ class CMakeBuild(build_ext):
build_temp.mkdir(parents=True, exist_ok=True)
subprocess.run(["cmake", ext.sourcedir, *cmake_args],
cwd=build_temp,
check=True)
cwd=build_temp,
check=True)
subprocess.run(["cmake", "--build", ".", *build_args],
cwd=build_temp,
check=True)
cwd=build_temp,
check=True)
def load_requirements():
"""Load dependencies from requirements.txt"""
requirements_file_name = 'requirements.txt'
if paddle.is_compiled_with_custom_device('iluvatar_gpu'):
requirements_file_name = 'requirements_iluvatar.txt'
requirements_path = os.path.join(os.path.dirname(__file__),
'requirements.txt')
requirements_file_name)
with open(requirements_path, 'r') as f:
return [
line.strip() for line in f
if line.strip() and not line.startswith('#')
]
def get_device_type():
"""Get the device type (rocm/gpu/xpu/npu/cpu) that paddle is compiled with."""
if paddle.is_compiled_with_rocm():
@@ -160,13 +165,17 @@ def get_device_type():
return "xpu"
elif paddle.is_compiled_with_custom_device('npu'):
return "npu"
elif paddle.is_compiled_with_custom_device('iluvatar_gpu'):
return "iluvatar-gpu"
else:
return "cpu"
def get_name():
"""get package name"""
return "fastdeploy-" + get_device_type()
cmdclass_dict = {'bdist_wheel': CustomBdistWheel}
cmdclass_dict['build_ext'] = CMakeBuild
FASTDEPLOY_VERSION = os.environ.get("FASTDEPLOY_VERSION", "2.0.0")
@@ -187,8 +196,8 @@ setup(
"model_executor/ops/gpu/*",
"model_executor/ops/gpu/deep_gemm/include/**/*",
"model_executor/ops/cpu/*", "model_executor/ops/xpu/*",
"model_executor/ops/xpu/libs/*",
"model_executor/ops/npu/*", "model_executor/ops/base/*",
"model_executor/ops/xpu/libs/*", "model_executor/ops/npu/*",
"model_executor/ops/base/*", "model_executor/ops/iluvatar/*",
"model_executor/models/*", "model_executor/layers/*",
"input/mm_processor/utils/*",
"version.txt"
@@ -198,9 +207,10 @@ setup(
ext_modules=[
CMakeExtension(
"rdma_comm",
sourcedir="fastdeploy/cache_manager/transfer_factory/kvcache_transfer",
sourcedir=
"fastdeploy/cache_manager/transfer_factory/kvcache_transfer",
version=None)
],
] if os.getenv("ENABLE_FD_RDMA", "0") == "1" else [],
cmdclass=cmdclass_dict if os.getenv("ENABLE_FD_RDMA", "0") == "1" else {},
zip_safe=False,
classifiers=[