diff --git a/.gitmodules b/.gitmodules index d5f8b94d0442ba1f95861b38419aaea8e2e85f36..885ebe56b41110fddfeaa237b5e11fbd66f92e3d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,7 @@ path = tests/mindformers url = https://gitee.com/mindspore/mindformers.git branch = master +[submodule "ms_custom_ops"] + path = ms_custom_ops + url = https://gitee.com/mindspore/akg.git + branch = ms_custom_ops diff --git a/ms_custom_ops b/ms_custom_ops new file mode 160000 index 0000000000000000000000000000000000000000..4d04083faf501d1c87dc3604223699c3bcbea28f --- /dev/null +++ b/ms_custom_ops @@ -0,0 +1 @@ +Subproject commit 4d04083faf501d1c87dc3604223699c3bcbea28f diff --git a/setup.py b/setup.py index f7d37dcd1f72896ae00a59f6c85328812e932edd..c36ce7bb3e2bc5663e235a68e9cf1f05bafa85ad 100644 --- a/setup.py +++ b/setup.py @@ -125,9 +125,35 @@ class CustomBuildExt(build_ext): def build_extension(self, ext): if ext.name == "vllm_mindspore._C_ops": self.build_c_ops(ext) + elif ext.name == "vllm_mindspore.ms_custom_ops": + self.build_ms_custom_ops(ext) else: raise ValueError(f"Unknown extension name: {ext.name}") + def build_ms_custom_ops(self, ext): + # "vllm_mindspore.ms_custom_ops" --> "ms_custom_ops" + ext_dir = os.path.dirname( + os.path.realpath(self.get_ext_fullpath(ext.name))) + build_cmd = build_cmd = ( + "git submodule update --init ms_custom_ops && " + "cd ms_custom_ops && " + "python setup.py build && " + f"cp -r build/*/ms_custom_ops {ext_dir}/..") + try: + logger.info("Running build ms_custom_ops commands:\n%s", build_cmd) + result = subprocess.run(build_cmd, + cwd=self.ROOT_DIR, + text=True, + shell=True, + capture_output=False) + if result.returncode != 0: + raise RuntimeError( + "Build ms_custom_ops failed with exit code {}".format( + result.returncode)) + except subprocess.CalledProcessError as e: + raise RuntimeError("Failed to build {}: {}".format( + "ms_custom_ops", e)) from e + def build_c_ops(self, ext): # "vllm_mindspore._C_ops" --> "_C_ops" ext_name = ext.name.split('.')[-1] @@ -190,6 +216,7 @@ def _get_ext_modules(): if os.path.exists(_get_ascend_home_path()): # sources are specified in CMakeLists.txt ext_modules.append(Extension("vllm_mindspore._C_ops", sources=[])) + ext_modules.append(Extension("vllm_mindspore.ms_custom_ops", sources=[])) return ext_modules