|
| 1 | +# enable python only development |
| 2 | +# copy compiled files to the current directory directly |
| 3 | + |
| 4 | +import os |
| 5 | +import shutil |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | + |
| 9 | +# cannot directly `import vllm` , because it will try to |
| 10 | +# import from the current directory |
| 11 | +output = subprocess.run([sys.executable, "-m", "pip", "show", "vllm"], |
| 12 | + capture_output=True) |
| 13 | + |
| 14 | +assert output.returncode == 0, "vllm is not installed" |
| 15 | + |
| 16 | +text = output.stdout.decode("utf-8") |
| 17 | + |
| 18 | +package_path = None |
| 19 | +for line in text.split("\n"): |
| 20 | + if line.startswith("Location: "): |
| 21 | + package_path = line.split(": ")[1] |
| 22 | + break |
| 23 | + |
| 24 | +assert package_path is not None, "could not find package path" |
| 25 | + |
| 26 | +cwd = os.getcwd() |
| 27 | + |
| 28 | +assert cwd != package_path, "should not import from the current directory" |
| 29 | + |
| 30 | +files_to_copy = [ |
| 31 | + "vllm/_C.abi3.so", |
| 32 | + "vllm/_core_C.abi3.so", |
| 33 | + "vllm/_moe_C.abi3.so", |
| 34 | + "vllm/vllm_flash_attn/vllm_flash_attn_c.abi3.so", |
| 35 | + "vllm/vllm_flash_attn/flash_attn_interface.py", |
| 36 | + "vllm/vllm_flash_attn/__init__.py", |
| 37 | + # "vllm/_version.py", # not available in nightly wheels yet |
| 38 | +] |
| 39 | + |
| 40 | +for file in files_to_copy: |
| 41 | + src = os.path.join(package_path, file) |
| 42 | + dst = file |
| 43 | + print(f"Copying {src} to {dst}") |
| 44 | + shutil.copyfile(src, dst) |
| 45 | + |
| 46 | +pre_built_vllm_path = os.path.join(package_path, "vllm") |
| 47 | +tmp_path = os.path.join(package_path, "vllm_pre_built") |
| 48 | +current_vllm_path = os.path.join(cwd, "vllm") |
| 49 | + |
| 50 | +print(f"Renaming {pre_built_vllm_path} to {tmp_path}") |
| 51 | +os.rename(pre_built_vllm_path, tmp_path) |
| 52 | + |
| 53 | +print(f"linking {current_vllm_path} to {pre_built_vllm_path}") |
| 54 | +os.symlink(current_vllm_path, pre_built_vllm_path) |
0 commit comments