@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / ef51831ee8
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, 05:45 UTC

[Doc] Add github links for source code references (#10672)

Signed-off-by: Russell Bryant <rbryant@redhat.com> Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk> Co-authored-by: DarkLight1337 <tlleungac@connect.ust.hk>

Russell Bryant committed Dec 3, 2024 at 01:46 UTC ef51831ee8dbd64833b25e042d4e984d169202f9
2 files changed +68 -1
docs/requirements-docs.txt
+2 -1
@@ -16,4 +16,5 @@ mistral_common >= 1.5.0
16 aiohttp
17 starlette
18 openai # Required by docs/source/serving/openai_compatible_server.md's vllm.entrypoints.openai.cli_args
19 -partial-json-parser # Required by docs/source/serving/openai_compatible_server.md's vllm.entrypoints.openai.cli_args
\ No newline at end of file
19 +partial-json-parser # Required by docs/source/serving/openai_compatible_server.md's vllm.entrypoints.openai.cli_args
20 +requests
docs/source/conf.py
+66
@@ -10,11 +10,13 @@
10 # add these directories to sys.path here. If the directory is relative to the
11 # documentation root, use os.path.abspath to make it absolute, like shown here.
12
13 +import inspect
14 import logging
15 import os
16 import sys
17 from typing import List
18
19 +import requests
20 from sphinx.ext import autodoc
21
22 logger = logging.getLogger(__name__)
@@ -34,6 +36,7 @@ author = 'the vLLM Team'
36 extensions = [
37 "sphinx.ext.napoleon",
38 "sphinx.ext.viewcode",
39 + "sphinx.ext.linkcode",
40 "sphinx.ext.intersphinx",
41 "sphinx_copybutton",
42 "sphinx.ext.autodoc",
@@ -94,6 +97,69 @@ def setup(app):
97 generate_examples()
98
99
100 +_cached_base: str = ""
101 +_cached_branch: str = ""
102 +
103 +
104 +def get_repo_base_and_branch(pr_number):
105 + global _cached_base, _cached_branch
106 + if _cached_base and _cached_branch:
107 + return _cached_base, _cached_branch
108 +
109 + url = f"https://api.github.com/repos/vllm-project/vllm/pulls/{pr_number}"
110 + response = requests.get(url)
111 + if response.status_code == 200:
112 + data = response.json()
113 + _cached_base = data['head']['repo']['full_name']
114 + _cached_branch = data['head']['ref']
115 + return _cached_base, _cached_branch
116 + else:
117 + logger.error("Failed to fetch PR details: %s", response)
118 + return None, None
119 +
120 +
121 +def linkcode_resolve(domain, info):
122 + if domain != 'py':
123 + return None
124 + if not info['module']:
125 + return None
126 + filename = info['module'].replace('.', '/')
127 + module = info['module']
128 +
129 + # try to determine the correct file and line number to link to
130 + obj = sys.modules[module]
131 +
132 + # get as specific as we can
133 + lineno: int = 0
134 + filename: str = ""
135 + try:
136 + for part in info['fullname'].split('.'):
137 + obj = getattr(obj, part)
138 +
139 + if not (inspect.isclass(obj) or inspect.isfunction(obj)
140 + or inspect.ismethod(obj)):
141 + obj = obj.__class__ # Get the class of the instance
142 +
143 + lineno = inspect.getsourcelines(obj)[1]
144 + filename = (inspect.getsourcefile(obj)
145 + or f"{filename}.py").split("vllm/", 1)[1]
146 + except Exception:
147 + # For some things, like a class member, won't work, so
148 + # we'll use the line number of the parent (the class)
149 + pass
150 +
151 + if filename.startswith("checkouts/"):
152 + # a PR build on readthedocs
153 + pr_number = filename.split("/")[1]
154 + filename = filename.split("/", 2)[2]
155 + base, branch = get_repo_base_and_branch(pr_number)
156 + if base and branch:
157 + return f"https://github.com/{base}/blob/{branch}/{filename}#L{lineno}"
158 +
159 + # Otherwise, link to the source file on the main branch
160 + return f"https://github.com/vllm-project/vllm/blob/main/{filename}#L{lineno}"
161 +
162 +
163 # Mock out external dependencies here, otherwise the autodoc pages may be blank.
164 autodoc_mock_imports = [
165 "compressed_tensors",