# TensorRT-LLM

[TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM)はNVIDIA GPU上のLLM推論を最適化します。モデルをTensorRTエンジンにコンパイルし、in-flight batching、paged KVキャッシュ、テンソル並列処理を実現します。[AutoDeploy](https://nvidia.github.io/TensorRT-LLM/torch/auto_deploy/auto-deploy.html)は、変更を加えることなくTransformersモデルを受け入れます。モデルを最適化されたランタイムへ自動的に変換します。

Hub のモデル ID を [build_and_run_ad.py](https://github.com/NVIDIA/TensorRT-LLM/blob/main/examples/auto_deploy/build_and_run_ad.py) に渡すことで、Transformers モデルを実行できます。

```bash
cd examples/auto_deploy
python build_and_run_ad.py --model meta-llama/Llama-3.2-1B
```

Under the hood, AutoDeploy creates an [LLM](https://nvidia.github.io/TensorRT-LLM/llm-api/reference.html#tensorrt_llm.llmapi.LLM) class. It loads the model configuration with [AutoConfig.from_pretrained()](/docs/transformers/main/ja/model_doc/auto#transformers.AutoConfig.from_pretrained) and extracts any parallelism metadata stored in `tp_plan`. [AutoModelForCausalLM.from_pretrained()](/docs/transformers/main/ja/model_doc/auto#transformers.AutoModel.from_pretrained) loads the model with the config and enables Transformers' built-in tensor parallelism.

```py
from tensorrt_llm._torch.auto_deploy import LLM

llm = LLM(model="meta-llama/Llama-3.2-1B")
```

TensorRT-LLM は `torch.export` でモデルグラフを抽出し、最適化を適用します。Transformers のアテンションを TensorRT-LLM の [アテンションカーネル](https://github.com/NVIDIA/TensorRT-LLM/tree/main/tensorrt_llm/_torch/attention_backend) に置き換え、モデルを最適化された実行バックエンドにコンパイルします。

## リソース

- より詳細な使用ガイドについては、[TensorRT-LLM ドキュメント](https://nvidia.github.io/TensorRT-LLM/)を参照してください。
- [AutoDeploy ガイド](https://nvidia.github.io/TensorRT-LLM/torch/auto_deploy/auto-deploy.html)では、高度な例を用いてその仕組みを説明しています。

