17
17
# limitations under the License.
18
18
#
19
19
20
- import os
21
- from typing import List , Dict
20
+ import glob
22
21
import importlib .util
22
+ import logging
23
+ import os
24
+ import subprocess
25
+ import sys
26
+ from pathlib import Path
23
27
from sysconfig import get_paths
28
+ from typing import Dict , List
24
29
25
30
from setuptools import Extension , find_packages , setup
26
31
from setuptools .command .build_ext import build_ext
27
32
from setuptools .command .install import install
28
33
from setuptools_scm import get_version
29
- import logging
30
- import sys
31
- import subprocess
32
- from pathlib import Path
33
- import glob
34
34
35
35
36
36
def load_module_from_path (module_name , path ):
@@ -45,15 +45,13 @@ def load_module_from_path(module_name, path):
45
45
logger = logging .getLogger (__name__ )
46
46
47
47
48
- def check_or_set_default_env (cmake_args ,
49
- env_name ,
50
- env_variable ,
51
- default_path = "" ):
48
+ def check_or_set_default_env (cmake_args , env_name , env_variable , default_path = "" ):
52
49
if env_variable is None :
53
50
logging .warning (
54
51
f"No { env_name } found in your environment, pleause try to set { env_name } "
55
52
"if you customize the installation path of this library, otherwise default "
56
- "path will be adapted during build this project" )
53
+ "path will be adapted during build this project"
54
+ )
57
55
logging .warning (f"Set default { env_name } : { default_path } " )
58
56
env_variable = default_path
59
57
else :
@@ -65,13 +63,12 @@ def check_or_set_default_env(cmake_args,
65
63
return cmake_args
66
64
67
65
68
- envs = load_module_from_path ('envs' ,
69
- os .path .join (ROOT_DIR , 'vllm_ascend' , 'envs.py' ))
66
+ envs = load_module_from_path ("envs" , os .path .join (ROOT_DIR , "vllm_ascend" , "envs.py" ))
70
67
71
68
72
69
class CMakeExtension (Extension ):
73
70
74
- def __init__ (self , name : str , cmake_lists_dir : str = '.' , ** kwa ) -> None :
71
+ def __init__ (self , name : str , cmake_lists_dir : str = "." , ** kwa ) -> None :
75
72
super ().__init__ (name , sources = [], py_limited_api = True , ** kwa )
76
73
self .cmake_lists_dir = os .path .abspath (cmake_lists_dir )
77
74
@@ -113,9 +110,9 @@ def configure(self, ext: CMakeExtension) -> None:
113
110
# Default use release mode to compile the csrc code
114
111
# Turbo now support compiled with Release, Debug and RelWithDebugInfo
115
112
if envs .CMAKE_BUILD_TYPE is None or envs .CMAKE_BUILD_TYPE not in [
116
- "Debug" ,
117
- "Release" ,
118
- "RelWithDebugInfo" ,
113
+ "Debug" ,
114
+ "Release" ,
115
+ "RelWithDebugInfo" ,
119
116
]:
120
117
envs .CMAKE_BUILD_TYPE = "Release"
121
118
cmake_args += [f"-DCMAKE_BUILD_TYPE={ envs .CMAKE_BUILD_TYPE } " ]
@@ -133,32 +130,36 @@ def configure(self, ext: CMakeExtension) -> None:
133
130
)
134
131
135
132
# find PYTHON_EXECUTABLE
136
- check_or_set_default_env (cmake_args , "PYTHON_EXECUTABLE" ,
137
- sys .executable )
133
+ check_or_set_default_env (cmake_args , "PYTHON_EXECUTABLE" , sys .executable )
138
134
139
135
# find PYTHON_INCLUDE_PATH
140
- check_or_set_default_env (cmake_args , "PYHTON_INCLUDE_PATH" ,
141
- get_paths ()["include" ])
136
+ check_or_set_default_env (
137
+ cmake_args , "PYHTON_INCLUDE_PATH" , get_paths ()["include" ]
138
+ )
142
139
143
140
# ccache and ninja can not be applied at ascendc kernels now
144
141
145
142
try :
146
143
# if pybind11 is installed via pip
147
- pybind11_cmake_path = (subprocess .check_output (
148
- [python_executable , "-m" , "pybind11" ,
149
- "--cmake" ]).decode ().strip ())
144
+ pybind11_cmake_path = (
145
+ subprocess .check_output (
146
+ [python_executable , "-m" , "pybind11" , "--cmake" ]
147
+ )
148
+ .decode ()
149
+ .strip ()
150
+ )
150
151
except subprocess .CalledProcessError as e :
151
152
# else specify pybind11 path installed from source code on CI container
152
153
raise RuntimeError (f"CMake configuration failed: { e } " )
153
154
154
155
# try retrive soc version from npu-smi
155
156
soc_command = [
156
- "bash" , "-c" ,
157
- "npu-smi info | grep OK | awk '{print $3}' | head -n 1"
157
+ "bash" ,
158
+ "-c" ,
159
+ "npu-smi info | grep OK | awk '{print $3}' | head -n 1" ,
158
160
]
159
161
try :
160
- soc_version = subprocess .check_output (soc_command ,
161
- text = True ).strip ()
162
+ soc_version = subprocess .check_output (soc_command , text = True ).strip ()
162
163
soc_version = "Ascend" + soc_version
163
164
except subprocess .CalledProcessError as e :
164
165
raise RuntimeError (f"Retrive Soc version failed: { e } " )
@@ -176,7 +177,7 @@ def configure(self, ext: CMakeExtension) -> None:
176
177
# To override this, set the FETCHCONTENT_BASE_DIR environment variable.
177
178
fc_base_dir = os .path .join (ROOT_DIR , ".deps" )
178
179
fc_base_dir = os .environ .get ("FETCHCONTENT_BASE_DIR" , fc_base_dir )
179
- cmake_args += [' -DFETCHCONTENT_BASE_DIR={}' .format (fc_base_dir )]
180
+ cmake_args += [" -DFETCHCONTENT_BASE_DIR={}" .format (fc_base_dir )]
180
181
181
182
build_tool = []
182
183
# TODO(ganyi): ninja and ccache support for ascend c auto codegen. now we can only use make build
@@ -192,15 +193,16 @@ def configure(self, ext: CMakeExtension) -> None:
192
193
raise RuntimeError (f"CMake configuration failed: { e } " )
193
194
194
195
subprocess .check_call (
195
- ['cmake' , ext .cmake_lists_dir , * build_tool , * cmake_args ],
196
- cwd = self .build_temp )
196
+ ["cmake" , ext .cmake_lists_dir , * build_tool , * cmake_args ],
197
+ cwd = self .build_temp ,
198
+ )
197
199
198
200
def build_extensions (self ) -> None :
199
201
# Ensure that CMake is present and working
200
202
try :
201
- subprocess .check_output ([' cmake' , ' --version' ])
203
+ subprocess .check_output ([" cmake" , " --version" ])
202
204
except OSError as e :
203
- raise RuntimeError (f' Cannot find CMake executable: { e } ' )
205
+ raise RuntimeError (f" Cannot find CMake executable: { e } " )
204
206
205
207
# Create build directory if it does not exist.
206
208
if not os .path .exists (self .build_temp ):
@@ -231,7 +233,7 @@ def target_name(s: str) -> str:
231
233
try :
232
234
subprocess .check_call (["cmake" , * build_args ], cwd = self .build_temp )
233
235
except OSError as e :
234
- raise RuntimeError (f' Build library failed: { e } ' )
236
+ raise RuntimeError (f" Build library failed: { e } " )
235
237
# Install the libraries
236
238
for ext in self .extensions :
237
239
# Install the extension into the proper location
@@ -247,13 +249,18 @@ def target_name(s: str) -> str:
247
249
# CMake, this is currently true for current extensions but may not
248
250
# always be the case.
249
251
prefix = outdir
250
- if '.' in ext .name :
252
+ if "." in ext .name :
251
253
prefix = prefix .parent
252
254
253
255
# prefix here should actually be the same for all components
254
256
install_args = [
255
- "cmake" , "--install" , "." , "--prefix" , prefix , "--component" ,
256
- target_name (ext .name )
257
+ "cmake" ,
258
+ "--install" ,
259
+ "." ,
260
+ "--prefix" ,
261
+ prefix ,
262
+ "--component" ,
263
+ target_name (ext .name ),
257
264
]
258
265
subprocess .check_call (install_args , cwd = self .build_temp )
259
266
@@ -331,7 +338,7 @@ def _read_requirements(filename: str) -> List[str]:
331
338
cmdclass = {"build_ext" : cmake_build_ext , "install" : custom_install }
332
339
333
340
setup (
334
- name = ' vllm_ascend' ,
341
+ name = " vllm_ascend" ,
335
342
# Follow:
336
343
# https://packaging.python.org/en/latest/specifications/version-specifiers
337
344
version = VERSION ,
@@ -363,7 +370,7 @@ def _read_requirements(filename: str) -> List[str]:
363
370
cmdclass = cmdclass ,
364
371
extras_require = {},
365
372
entry_points = {
366
- ' vllm.platform_plugins' : ["ascend = vllm_ascend:register" ],
367
- ' vllm.general_plugins' :
368
- [ "ascend_enhanced_model = vllm_ascend:register_model" ]
369
- } )
373
+ " vllm.platform_plugins" : ["ascend = vllm_ascend:register" ],
374
+ " vllm.general_plugins" : [ "ascend_enhanced_model = vllm_ascend:register_model" ],
375
+ },
376
+ )
0 commit comments