TensorRT-LLM 快速入门指南#
LLM API#
LLM API 是 Python API,旨在直接在 Python 中简化 TensorRT-LLM 的设置和推理。它通过简单地指定 HuggingFace 仓库名称或模型检查点来启用模型优化。LLM API 通过管理检查点转换、引擎构建、引擎加载和模型推理,简化了整个流程,所有这些功能都通过单一的 Python 对象实现。
from tensorrt_llm import LLM, SamplingParams
def main():
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
# The entry point of the program need to be protected for spawning processes.
if __name__ == '__main__':
main()