Skip to content

Commit 9d0ea69

Browse files
Superjomnnv-guomingz
authored andcommitted
chore: add tags to API reference
Signed-off-by: Superjomn <[email protected]>
1 parent 10dbf4f commit 9d0ea69

File tree

10 files changed

+453
-65
lines changed

10 files changed

+453
-65
lines changed

docs/source/_static/custom.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.tag {
2+
padding: 2px 5px;
3+
border-radius: 4px;
4+
font-size: 0.8em;
5+
margin-right: 5px;
6+
color: #000;
7+
}
8+
9+
code.beta {
10+
display: inline-block;
11+
background-color: #6c757d;
12+
color: #999;
13+
}
14+
15+
code.prototype {
16+
display: inline-block;
17+
background-color: #fd7e14;
18+
color: #fff;
19+
}
20+
21+
code.deprecated {
22+
display: inline-block;
23+
background-color: red;
24+
color: #fff;
25+
}

docs/source/conf.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313

1414
import pygit2
15+
from docutils import nodes
1516

1617
sys.path.insert(0, os.path.abspath('.'))
1718

@@ -60,10 +61,16 @@
6061
'sphinx_togglebutton',
6162
]
6263

64+
autodoc_member_order = 'bysource'
6365
autodoc_pydantic_model_show_json = True
6466
autodoc_pydantic_model_show_config_summary = True
6567
autodoc_pydantic_field_doc_policy = "description"
6668
autodoc_pydantic_model_show_field_list = True # Display field list with descriptions
69+
autodoc_pydantic_model_member_order = "groupwise"
70+
autodoc_pydantic_model_hide_pydantic_methods = True
71+
autodoc_pydantic_field_list_validators = False
72+
autodoc_pydantic_settings_signature_prefix = "" # remove any prefix
73+
autodoc_pydantic_settings_hide_reused_validator = True # hide all the validator should be better
6774

6875
myst_url_schemes = {
6976
"http":
@@ -143,10 +150,26 @@
143150
print('CPP_INCLUDE_DIR', CPP_INCLUDE_DIR)
144151
print('CPP_GEN_DIR', CPP_GEN_DIR)
145152

153+
html_css_files = [
154+
'custom.css',
155+
]
156+
157+
158+
def tag_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
159+
"""A custom role for displaying tags."""
160+
tag_name = text.lower()
161+
node = nodes.literal(text, text, classes=['tag', tag_name])
162+
return [node], []
163+
146164

147165
def setup(app):
148166
from helper import generate_examples, generate_llmapi
149167

168+
from tensorrt_llm.llmapi.utils import tag_llm_params
169+
tag_llm_params()
170+
171+
app.add_role('tag', tag_role)
172+
150173
generate_examples()
151174
generate_llmapi()
152175

docs/source/helper.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,18 @@ def extract_all_and_eval(file_path):
286286
return local_vars
287287

288288

289+
def get_pydantic_methods() -> list[str]:
290+
from pydantic import BaseModel
291+
292+
class Dummy(BaseModel):
293+
pass
294+
295+
methods = set(
296+
[method for method in dir(Dummy) if not method.startswith('_')])
297+
methods.discard("__init__")
298+
return list(methods)
299+
300+
289301
def generate_llmapi():
290302
root_dir = Path(__file__).parent.parent.parent.resolve()
291303

@@ -301,14 +313,18 @@ def generate_llmapi():
301313
for cls_name in public_classes_names:
302314
cls_name = cls_name.strip()
303315
options = [
304-
" :members:", " :undoc-members:", " :show-inheritance:"
316+
" :members:",
317+
" :undoc-members:",
318+
" :show-inheritance:",
319+
" :special-members: __init__",
320+
" :member-order: groupwise",
305321
]
306322

307-
if cls_name != 'LLM': # Conditionally add :special-members: __init__
308-
options.append(" :special-members: __init__")
309-
310-
if cls_name in ['TrtLLM', 'TorchLLM', 'LLM']:
311-
options.append(" :inherited-members:")
323+
options.append(" :inherited-members:")
324+
if cls_name in ["TorchLlmArgs", "TrtLlmArgs"]:
325+
# exclude tons of methods from Pydantic
326+
options.append(
327+
f" :exclude-members: {','.join(get_pydantic_methods())}")
312328

313329
content += f".. autoclass:: tensorrt_llm.llmapi.{cls_name}\n"
314330
content += "\n".join(options) + "\n\n"

tensorrt_llm/llmapi/llm.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
_xgrammar_tokenizer_info)
4141
# TODO[chunweiy]: move the following symbols back to utils scope, and remove the following import
4242
from .utils import (append_docstring, exception_handler, get_device_count,
43-
print_colored_debug)
43+
print_colored_debug, set_api_status)
4444

4545

4646
class RequestOutput(DetokenizedGenerationResultBase, GenerationResult):
@@ -212,6 +212,7 @@ def __init__(self,
212212
atexit.register(LLM._shutdown_wrapper, weakref.ref(self))
213213

214214
@property
215+
@set_api_status("beta")
215216
def llm_id(self) -> str:
216217
if self._llm_id is None:
217218
hostname = socket.gethostname()
@@ -421,6 +422,7 @@ def generate_async(
421422
return RequestOutput._from_generation_result(result, prompt,
422423
self.tokenizer)
423424

425+
@set_api_status("beta")
424426
def get_stats(self, timeout: Optional[float] = 2) -> List[dict]:
425427
'''Get iteration statistics from the runtime.
426428
To collect statistics, call this function after prompts have been submitted with LLM().generate().
@@ -434,6 +436,7 @@ def get_stats(self, timeout: Optional[float] = 2) -> List[dict]:
434436
'''
435437
return self._executor.get_stats(timeout=timeout)
436438

439+
@set_api_status("beta")
437440
def get_stats_async(self, timeout: Optional[float] = 2) -> IterationResult:
438441
'''Get iteration statistics from the runtime.
439442
To collect statistics, you can call this function in an async coroutine or the /metrics endpoint (if you're using trtllm-serve)
@@ -447,6 +450,7 @@ def get_stats_async(self, timeout: Optional[float] = 2) -> IterationResult:
447450
'''
448451
return self._executor.aget_stats(timeout=timeout)
449452

453+
@set_api_status("beta")
450454
def get_kv_cache_events(self, timeout: Optional[float] = 2) -> List[dict]:
451455
'''Get iteration KV events from the runtime.
452456
@@ -468,6 +472,7 @@ def get_kv_cache_events(self, timeout: Optional[float] = 2) -> List[dict]:
468472
'''
469473
return self._executor.get_kv_events(timeout=timeout)
470474

475+
@set_api_status("beta")
471476
def get_kv_cache_events_async(self,
472477
timeout: Optional[float] = 2
473478
) -> IterationResult:
@@ -664,6 +669,7 @@ def tokenizer(self) -> Optional[TokenizerBase]:
664669
def tokenizer(self, tokenizer: TokenizerBase):
665670
self._tokenizer = tokenizer
666671

672+
@set_api_status("beta")
667673
def shutdown(self) -> None:
668674
if hasattr(self, "_executor") and self._executor is not None:
669675
self._executor.shutdown()
@@ -1037,13 +1043,11 @@ def __init__(self,
10371043
revision, tokenizer_revision, **kwargs)
10381044

10391045

1040-
_LLM_REPR = "TorchLLM"
1041-
10421046
# sphinx will ignore the LLM's docstring if it is not explicitly set
10431047
LLM.__doc__ = \
10441048
f"""LLM class is the main class for running a LLM model.
10451049
1046-
This class is an alias of {_LLM_REPR}.
1050+
For more details about the arguments, please refer to :class:`TorchLlmArgs`.
10471051
10481052
Parameters:
10491053
""" + TORCH_LLM_DOCSTRING

0 commit comments

Comments
 (0)