@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 2b184ddd4f
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 16, 10:45 UTC

[Misc][Installation] Improve source installation script and doc (#9309)

Co-authored-by: youkaichao <youkaichao@126.com>

Yunmeng committed Oct 13, 2024 at 00:36 UTC 2b184ddd4f9e4ff5305af87327410b9845a06baf
2 files changed +69 -12
docs/source/getting_started/installation.rst
+19
@@ -84,6 +84,8 @@ Latest code can contain bugs and may not be stable. Please use it with caution.
84 Build from source
85 ==================
86
87 +.. _python-only-build:
88 +
89 Python-only build (without compilation)
90 ----------------------------------------
91
@@ -114,6 +116,23 @@ The script will:
116
117 Now, you can edit the Python code in the current directory, and the changes will be reflected when you run vLLM.
118
119 +Once you have finished editing or want to install another vLLM wheel, you should exit the development environment using `the same script <https://github.com/vllm-project/vllm/blob/main/python_only_dev.py>`_ with the ``--quit-dev``(or ``-q`` for short) flag:
120 +
121 +.. code-block:: console
122 +
123 + $ python python_only_dev.py --quit-dev
124 +
125 +The script with ``--quit-dev`` flag will:
126 +
127 +* Remove the symbolic link from the current directory to the vLLM package.
128 +* Restore the original vLLM package from the backup.
129 +
130 +If you update the vLLM wheel and want to rebuild from the source and make further edits, you will need to start `all above <#python-only-build>`_ over again.
131 +
132 +.. note::
133 +
134 + There is a possibility that your source code may have a different commit ID compared to the latest vLLM wheel, which could potentially lead to unknown errors.
135 + It is recommended to use the same commit ID for the source code as the vLLM wheel you have installed. Please refer to `the above section <#install-the-latest-code>`_ for instructions on how to install a specified wheel.
136
137 Full build (with compilation)
138 ---------------------------------
python_only_dev.py
+50 -12
@@ -1,10 +1,20 @@
1 # enable python only development
2 # copy compiled files to the current directory directly
3
4 +import argparse
5 import os
6 import shutil
7 import subprocess
8 import sys
9 +import warnings
10 +
11 +parser = argparse.ArgumentParser(
12 + description="Development mode for python-only code")
13 +parser.add_argument('-q',
14 + '--quit-dev',
15 + action='store_true',
16 + help='Set the flag to quit development mode')
17 +args = parser.parse_args()
18
19 # cannot directly `import vllm` , because it will try to
20 # import from the current directory
@@ -37,18 +47,46 @@ files_to_copy = [
47 # "vllm/_version.py", # not available in nightly wheels yet
48 ]
49
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)
50 +# Try to create _version.py to avoid version related warning
51 +# Refer to https://github.com/vllm-project/vllm/pull/8771
52 +try:
53 + from setuptools_scm import get_version
54 + get_version(write_to="vllm/_version.py")
55 +except ImportError:
56 + warnings.warn(
57 + "To avoid warnings related to vllm._version, "
58 + "you should install setuptools-scm by `pip install setuptools-scm`",
59 + stacklevel=2)
60 +
61 +if not args.quit_dev:
62 + for file in files_to_copy:
63 + src = os.path.join(package_path, file)
64 + dst = file
65 + print(f"Copying {src} to {dst}")
66 + shutil.copyfile(src, dst)
67 +
68 + pre_built_vllm_path = os.path.join(package_path, "vllm")
69 + tmp_path = os.path.join(package_path, "vllm_pre_built")
70 + current_vllm_path = os.path.join(cwd, "vllm")
71 +
72 + print(f"Renaming {pre_built_vllm_path} to {tmp_path} for backup")
73 + os.rename(pre_built_vllm_path, tmp_path)
74
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")
75 + print(f"Linking {current_vllm_path} to {pre_built_vllm_path}")
76 + os.symlink(current_vllm_path, pre_built_vllm_path)
77 +else:
78 + vllm_symlink_path = os.path.join(package_path, "vllm")
79 + vllm_backup_path = os.path.join(package_path, "vllm_pre_built")
80 + current_vllm_path = os.path.join(cwd, "vllm")
81
50 -print(f"Renaming {pre_built_vllm_path} to {tmp_path}")
51 -os.rename(pre_built_vllm_path, tmp_path)
82 + print(f"Unlinking {current_vllm_path} to {vllm_symlink_path}")
83 + assert os.path.islink(
84 + vllm_symlink_path
85 + ), f"not in dev mode: {vllm_symlink_path} is not a symbolic link"
86 + assert current_vllm_path == os.readlink(
87 + vllm_symlink_path
88 + ), "current directory is not the source code of package"
89 + os.unlink(vllm_symlink_path)
90
53 -print(f"linking {current_vllm_path} to {pre_built_vllm_path}")
54 -os.symlink(current_vllm_path, pre_built_vllm_path)
91 + print(f"Recovering backup from {vllm_backup_path} to {vllm_symlink_path}")
92 + os.rename(vllm_backup_path, vllm_symlink_path)