Skip to content

Commit fbb5f50

Browse files
Superjomndominicshanshan
authored andcommitted
[None][doc] add legacy section for tensorrt engine (NVIDIA#6724)
Signed-off-by: Superjomn <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
1 parent ac373f2 commit fbb5f50

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

docs/source/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ Welcome to TensorRT-LLM's Documentation!
160160
blogs/XQA-kernel.md
161161
blogs/tech_blog/*
162162

163+
.. toctree::
164+
:maxdepth: 2
165+
:caption: Use TensorRT Engine
166+
:hidden:
167+
168+
legacy/tensorrt_quickstart.md
163169

164170
Indices and tables
165171
==================
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# LLM API with TensorRT Engine
2+
A simple inference example with TinyLlama using the LLM API:
3+
4+
```{literalinclude} ../../examples/llm-api/_tensorrt_engine/quickstart_example.py
5+
:language: python
6+
:linenos:
7+
```
8+
9+
For more advanced usage including distributed inference, multimodal, and speculative decoding, please refer to this [README](../../../examples/llm-api/README.md).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from tensorrt_llm import LLM, SamplingParams
2+
3+
4+
def main():
5+
6+
# Model could accept HF model name, a path to local HF model,
7+
# or TensorRT Model Optimizer's quantized checkpoints like nvidia/Llama-3.1-8B-Instruct-FP8 on HF.
8+
llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
9+
10+
# Sample prompts.
11+
prompts = [
12+
"Hello, my name is",
13+
"The capital of France is",
14+
"The future of AI is",
15+
]
16+
17+
# Create a sampling params.
18+
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
19+
20+
for output in llm.generate(prompts, sampling_params):
21+
print(
22+
f"Prompt: {output.prompt!r}, Generated text: {output.outputs[0].text!r}"
23+
)
24+
25+
# Got output like
26+
# Prompt: 'Hello, my name is', Generated text: '\n\nJane Smith. I am a student pursuing my degree in Computer Science at [university]. I enjoy learning new things, especially technology and programming'
27+
# Prompt: 'The president of the United States is', Generated text: 'likely to nominate a new Supreme Court justice to fill the seat vacated by the death of Antonin Scalia. The Senate should vote to confirm the'
28+
# Prompt: 'The capital of France is', Generated text: 'Paris.'
29+
# Prompt: 'The future of AI is', Generated text: 'an exciting time for us. We are constantly researching, developing, and improving our platform to create the most advanced and efficient model available. We are'
30+
31+
32+
if __name__ == '__main__':
33+
main()

examples/llm-api/llm_runtime.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def example_cuda_graph_config():
2929
cuda_graph_config=cuda_graph_config, # Enable CUDA graphs
3030
max_batch_size=4,
3131
max_seq_len=512,
32-
kv_cache_config=KvCacheConfig(free_gpu_memory_fraction=0.8,
33-
enable_block_reuse=True))
32+
kv_cache_config=KvCacheConfig(free_gpu_memory_fraction=0.5))
3433

3534
prompts = [
3635
"Hello, my name is",
@@ -56,7 +55,7 @@ def example_kv_cache_config():
5655
max_batch_size=8,
5756
max_seq_len=1024,
5857
kv_cache_config=KvCacheConfig(
59-
free_gpu_memory_fraction=0.85,
58+
free_gpu_memory_fraction=0.5,
6059
enable_block_reuse=True))
6160

6261
prompts = [

examples/llm-api/quickstart_example.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
from tensorrt_llm import LLM, SamplingParams
1+
from tensorrt_llm import BuildConfig, SamplingParams
2+
from tensorrt_llm._tensorrt_engine import LLM # NOTE the change
23

34

45
def main():
56

7+
build_config = BuildConfig()
8+
build_config.max_batch_size = 256
9+
build_config.max_num_tokens = 1024
10+
611
# Model could accept HF model name, a path to local HF model,
712
# or TensorRT Model Optimizer's quantized checkpoints like nvidia/Llama-3.1-8B-Instruct-FP8 on HF.
8-
llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
13+
llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
14+
build_config=build_config)
915

1016
# Sample prompts.
1117
prompts = [

tests/integration/defs/llmapi/test_llm_examples.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,18 @@ def test_llmapi_speculative_decoding_ngram(llm_root, engine_dir, llm_venv):
155155
"llm_speculative_decoding.py", "NGRAM")
156156

157157

158-
@pytest.mark.skip(reason="https://nvbugs/5365825")
158+
@pytest.mark.skip(reason="https://nvbugs/5365825"
159+
) # maybe unrelated, but this test will always timeout
159160
def test_llmapi_sampling(llm_root, engine_dir, llm_venv):
160161
_run_llmapi_example(llm_root, engine_dir, llm_venv, "llm_sampling.py")
161162

162163

163-
@pytest.mark.skip(reason="https://nvbugs/5365825")
164+
@pytest.mark.skip(reason="https://nvbugs/5365825"
165+
) # maybe unrelated, but this test will always timeout
164166
def test_llmapi_runtime(llm_root, engine_dir, llm_venv):
165167
_run_llmapi_example(llm_root, engine_dir, llm_venv, "llm_runtime.py")
168+
169+
170+
def test_llmapi_tensorrt_engine(llm_root, engine_dir, llm_venv):
171+
_run_llmapi_example(llm_root, engine_dir, llm_venv,
172+
"_tensorrt_engine/quickstart_example.py")

tests/integration/test_lists/test-db/l0_sanity_check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ l0_sanity_check:
3030
- llmapi/test_llm_examples.py::test_llmapi_speculative_decoding_ngram
3131
- llmapi/test_llm_examples.py::test_llmapi_sampling
3232
- llmapi/test_llm_examples.py::test_llmapi_runtime
33+
- llmapi/test_llm_examples.py::test_llmapi_tensorrt_engine
3334
- examples/test_llm_api_with_mpi.py::test_llm_api_single_gpu_with_mpirun[TinyLlama-1.1B-Chat-v1.0]

0 commit comments

Comments
 (0)