> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-hi/gpu-devops/tensorrt-llm.md).

# TensorRT-LLM

> **NVIDIA TensorRT अनुकूलन के साथ अधिकतम LLM इन्फ़रेंस थ्रूपुट — Triton Inference Server के माध्यम से तैनात**

TensorRT-LLM NVIDIA का ओपन-सोर्स लाइब्रेरी है जो NVIDIA GPUs पर बड़े भाषा मॉडल इन्फ़रेंस को अनुकूलित करती है। यह kernel fusion, quantization (INT4, INT8, FP8), in-flight batching, और paged KV-caching के माध्यम से अत्याधुनिक प्रदर्शन देती है। Triton Inference Server के साथ मिलकर, आपको production-grade serving infrastructure मिलती है।

**GitHub:** [NVIDIA/TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM) — 10K+ ⭐

***

## TensorRT-LLM क्यों?

| विशेषता                    | vLLM     | TensorRT-LLM |
| -------------------------- | -------- | ------------ |
| थ्रूपुट                    | उत्कृष्ट | सर्वश्रेष्ठ  |
| लेटेंसी                    | अच्छा    | उत्कृष्ट     |
| INT4/INT8 क्वांटाइज़ेशन    | आंशिक    | मूल          |
| FP8 समर्थन                 | सीमित    | पूर्ण        |
| मल्टी-GPU टेंसर समानांतरता | हाँ      | हाँ          |
| सेटअप जटिलता               | कम       | मध्यम-उच्च   |

{% hint style="success" %}
**TensorRT-LLM सामान्यतः 2–4x अधिक थ्रूपुट देता है** मानक HuggingFace transformers inference की तुलना में, और batch serving परिदृश्यों में vLLM से 30–50% बेहतर थ्रूपुट देता है।
{% endhint %}

***

## पूर्वापेक्षाएँ

* GPU किराये के साथ Clore.ai खाता
* **Ampere आर्किटेक्चर या उससे नए वाला NVIDIA GPU** (RTX 3090, A100, RTX 4090, H100)
* Linux और Docker का बुनियादी ज्ञान
* आपके चुने हुए मॉडल के लिए पर्याप्त VRAM

***

## मॉडल के अनुसार VRAM आवश्यकताएँ

| मॉडल          | FP16  | INT8 | INT4 |
| ------------- | ----- | ---- | ---- |
| Llama-3.1 8B  | 16GB  | 8GB  | 4GB  |
| Llama-3.1 70B | 140GB | 70GB | 35GB |
| Mistral 7B    | 14GB  | 7GB  | 4GB  |
| Mixtral 8x7B  | 90GB  | 45GB | 24GB |
| Qwen2.5 72B   | 144GB | 72GB | 36GB |

***

## चरण 1 — Clore.ai पर अपना GPU चुनें

1. में लॉग इन करें [clore.ai](https://clore.ai) → **मार्केटप्लेस**
2. **एकल GPU serving (7B–13B models) के लिए:** RTX 4090 24GB या RTX 3090 24GB
3. **बड़े मॉडलों (70B+) के लिए:** कई A100 80GB या H100

{% hint style="info" %}
**मल्टी-GPU रणनीति:**

* 2x A100 80GB → FP16 में Llama 3.1 70B या Qwen2.5 72B
* 4x A100 80GB → INT8 में Llama 3.1 405B
* Clore.ai marketplace में सूचीबद्ध multiple GPUs वाले servers चुनें
  {% endhint %}

***

## चरण 2 — TRT-LLM backend के साथ Triton Inference Server तैनात करें

**Docker इमेज:**

```
nvcr.io/nvidia/tritonserver:24.01-trtllm-python-py3
```

{% hint style="warning" %}
का उपयोग करें `-trtllm-python-py3` variant — इसमें TensorRT-LLM backend पहले से इंस्टॉल शामिल है। यह tag NVIDIA container release (24.01 = जनवरी 2024) के अनुरूप है। देखें [NGC](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver/tags) नवीनतम tag के लिए.
{% endhint %}

**एक्सपोज़्ड पोर्ट्स:**

```
22
8000
```

**Environment Variables:**

```
NVIDIA_VISIBLE_DEVICES=all
NVIDIA_DRIVER_CAPABILITIES=compute,utility
TRANSFORMERS_CACHE=/workspace/hf_cache
HF_HOME=/workspace/hf_cache
```

**वॉल्यूम/डिस्क:** कम से कम 100GB अनुशंसित

***

## चरण 3 — कनेक्ट करें और स्थापना सत्यापित करें

```bash
ssh root@<server-ip> -p <ssh-port>

# GPU जांचें
nvidia-smi

# TensorRT संस्करण जांचें
python3 -c "import tensorrt_llm; print(tensorrt_llm.__version__)"

# Triton उपलब्ध है या नहीं जांचें
tritonserver --version
```

***

## चरण 4 — मॉडल डाउनलोड और तैयार करें

हम उदाहरण के लिए Llama 3.1 8B का उपयोग करेंगे। अपने चुने हुए मॉडल के अनुसार path समायोजित करें।

### HuggingFace CLI इंस्टॉल करें

```bash
pip install huggingface_hub
huggingface-cli login
# संकेत मिलने पर अपना HuggingFace token दर्ज करें
```

### मॉडल weights डाउनलोड करें

```bash
mkdir -p /workspace/models/llama-3.1-8b
huggingface-cli download \
    meta-llama/Llama-3.1-8B-Instruct \
    --local-dir /workspace/models/llama-3.1-8b \
    --local-dir-use-symlinks False

# या snapshot_download का उपयोग करें
python3 << 'EOF'
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id="meta-llama/Llama-3.1-8B-Instruct",
    local_dir="/workspace/models/llama-3.1-8b",
    local_dir_use_symlinks=False
)
EOF
```

***

## चरण 5 — TensorRT engine बनाएं

यह मुख्य चरण है — मॉडल को एक अनुकूलित TensorRT engine में compile करना।

### FP16 Engine (सर्वोत्तम गुणवत्ता)

```bash
cd /workspace

# HuggingFace weights को TRT-LLM format में बदलें
python3 /usr/local/lib/python3.10/dist-packages/tensorrt_llm/examples/llama/convert_checkpoint.py \
    --model_dir /workspace/models/llama-3.1-8b \
    --output_dir /workspace/trt_checkpoints/llama-3.1-8b-fp16 \
    --dtype float16 \\
    --tp_size 1

# TensorRT engine बनाएं
trtllm-build \
    --checkpoint_dir /workspace/trt_checkpoints/llama-3.1-8b-fp16 \
    --output_dir /workspace/trt_engines/llama-3.1-8b-fp16 \
    --gemm_plugin float16 \
    --max_batch_size 32 \
    --max_input_len 4096 \
    --max_seq_len 8192 \
    --max_num_tokens 16384 \
    --use_paged_context_fmha enable
```

### INT8 SmoothQuant Engine (अधिक थ्रूपुट)

```bash
# SmoothQuant quantization के साथ convert करें
python3 /usr/local/lib/python3.10/dist-packages/tensorrt_llm/examples/llama/convert_checkpoint.py \
    --model_dir /workspace/models/llama-3.1-8b \
    --output_dir /workspace/trt_checkpoints/llama-3.1-8b-int8 \
    --dtype float16 \\
    --smoothquant 0.5 \
    --per_channel \
    --per_token

trtllm-build \
    --checkpoint_dir /workspace/trt_checkpoints/llama-3.1-8b-int8 \
    --output_dir /workspace/trt_engines/llama-3.1-8b-int8 \
    --gemm_plugin float16 \
    --smoothquant_plugin float16 \
    --max_batch_size 64 \
    --max_input_len 4096 \
    --max_seq_len 8192
```

### INT4 AWQ Engine (अधिकतम थ्रूपुट / न्यूनतम मेमोरी)

```bash
# quantization के लिए auto-gptq इंस्टॉल करें
pip install autoawq

# INT4 AWQ में quantize करें
python3 << 'EOF'
from awq import AutoAWQForCausalLM
from transformers import AutoTokenizer

model_path = "/workspace/models/llama-3.1-8b"
quant_path = "/workspace/models/llama-3.1-8b-awq-int4"

model = AutoAWQForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)

quant_config = {
    "zero_point": True,
    "q_group_size": 128,
    "w_bit": 4,
    "version": "GEMM"
}
model.quantize(tokenizer, quant_config=quant_config)
model.save_quantized(quant_path)
tokenizer.save_pretrained(quant_path)
EOF

# AWQ को TRT-LLM में convert करें
python3 /usr/local/lib/python3.10/dist-packages/tensorrt_llm/examples/llama/convert_checkpoint.py \
    --model_dir /workspace/models/llama-3.1-8b-awq-int4 \
    --output_dir /workspace/trt_checkpoints/llama-3.1-8b-int4 \
    --dtype float16 \\
    --quant_ckpt_path /workspace/models/llama-3.1-8b-awq-int4 \
    --use_weight_only \
    --weight_only_precision int4_awq \
    --per_group

trtllm-build \
    --checkpoint_dir /workspace/trt_checkpoints/llama-3.1-8b-int4 \
    --output_dir /workspace/trt_engines/llama-3.1-8b-int4 \
    --gemm_plugin float16 \
    --max_batch_size 128 \
    --max_input_len 4096 \
    --max_seq_len 8192
```

{% hint style="info" %}
**Engine build समय:** GPU और model size के आधार पर 10–30 मिनट। यह एक बार की प्रक्रिया है — एक बार बन जाने पर engine सेकंडों में लोड होता है।
{% endhint %}

***

## चरण 6 — TRT-LLM Python API के साथ त्वरित परीक्षण

Triton सेटअप करने से पहले, verify करें कि engine काम करता है:

```bash
python3 << 'EOF'
import tensorrt_llm
from tensorrt_llm.runtime import ModelRunner
from transformers import AutoTokenizer

engine_dir = "/workspace/trt_engines/llama-3.1-8b-fp16"
tokenizer_dir = "/workspace/models/llama-3.1-8b"

tokenizer = AutoTokenizer.from_pretrained(tokenizer_dir)
runner = ModelRunner.from_dir(
    engine_dir=engine_dir,
    rank=0
)

prompt = "फ्रांस की राजधानी क्या है?"
input_ids = tokenizer.encode(prompt, return_tensors="pt")

output = runner.generate(
    batch_input_ids=[input_ids[0].tolist()],
    max_new_tokens=200,
    temperature=0.7,
    top_p=0.9
)

output_ids = output[0][0][len(input_ids[0]):]
response = tokenizer.decode(output_ids, skip_special_tokens=True)
print(f"उत्तर: {response}")
EOF
```

***

## चरण 7 — Triton Inference Server सेट करें

### Model repository संरचना बनाएं

```bash
mkdir -p /workspace/triton_model_repo/llama/1

# model configuration बनाएं
cat > /workspace/triton_model_repo/llama/config.pbtxt << 'EOF'
backend: "tensorrtllm"
name: "llama"
max_batch_size: 64
model_transaction_policy {
  decoupled: true
}

dynamic_batching {
  preferred_batch_size: [1, 2, 4, 8, 16, 32, 64]
  max_queue_delay_microseconds: 1000
}

input [
  {
    name: "input_ids"
    data_type: TYPE_INT32
    dims: [-1]
  },
  {
    name: "input_lengths"
    data_type: TYPE_INT32
    dims: [1]
    reshape: { shape: [] }
  },
  {
    name: "request_output_len"
    data_type: TYPE_INT32
    dims: [1]
    reshape: { shape: [] }
  },
  {
    name: "temperature"
    data_type: TYPE_FP32
    dims: [1]
    reshape: { shape: [] }
    optional: true
  }
]

output [
  {
    name: "output_ids"
    data_type: TYPE_INT32
    dims: [-1, -1]
  },
  {
    name: "sequence_length"
    data_type: TYPE_INT32
    dims: [1]
  }
]

instance_group [
  {
    count: 1
    kind: KIND_GPU
    gpus: [0]
  }
]

parameters: {
  key: "gpt_model_type"
  value: { string_value: "inflight_fused_batching" }
}

parameters: {
  key: "gpt_model_path"
  value: { string_value: "/workspace/trt_engines/llama-3.1-8b-fp16" }
}

parameters: {
  key: "max_tokens_in_paged_kv_cache"
  value: { string_value: "8192" }
}

parameters: {
  key: "batch_scheduler_policy"
  value: { string_value: "guaranteed_no_evict" }
}
EOF
```

### Engine symlink बनाएं

```bash
ln -s /workspace/trt_engines/llama-3.1-8b-fp16 \
    /workspace/triton_model_repo/llama/1/
```

### Triton Server शुरू करें

```bash
tritonserver \
    --model-repository=/workspace/triton_model_repo \
    --http-port=8000 \
    --grpc-port=8001 \
    --metrics-port=8002 \
    --log-verbose=0 &

# server शुरू होने की प्रतीक्षा करें
sleep 30

# server स्वास्थ्य जांचें
curl -s http://localhost:8000/v2/health/ready
```

***

## चरण 8 — API क्वेरी करें

### OpenAI-संगत client

```python
import requests
import json

def generate(prompt: str, max_tokens: int = 200) -> str:
    url = "http://localhost:8000/v2/models/llama/generate"
    
    payload = {
        "text_input": prompt,
        "parameters": {
            "max_tokens": max_tokens,
            "temperature": 0.7,
            "top_p": 0.9
        }
    }
    
    response = requests.post(url, json=payload)
    result = response.json()
    return result.get("text_output", "")

# परीक्षण
print(generate("क्वांटम कंप्यूटिंग को सरल शब्दों में समझाएँ:"))
```

### थ्रूपुट बेंचमार्क करें

```bash
# tritonclient इंस्टॉल करें
pip install tritonclient[all]

# performance benchmark चलाएँ
perf_analyzer \
    -m llama \
    -u localhost:8001 \
    --protocol grpc \
    --input-data /workspace/sample_inputs.json \
    --concurrency-range 1:32:2 \
    --measurement-interval 10000 \
    --shape input_ids:512 \
    --shape input_lengths:1 \
    --shape request_output_len:1
```

***

## चरण 9 — OpenAI-संगत API wrapper जोड़ें

आसान एकीकरण के लिए, एक FastAPI wrapper जोड़ें:

```bash
pip install fastapi uvicorn tritonclient[all]

cat > /workspace/openai_server.py << 'EOF'
from fastapi import FastAPI
from pydantic import BaseModel
import tritonclient.http as httpclient
import numpy as np
from transformers import AutoTokenizer

app = FastAPI()
tokenizer = AutoTokenizer.from_pretrained("/workspace/models/llama-3.1-8b")
client = httpclient.InferenceServerClient("localhost:8000")

class ChatRequest(BaseModel):
    model: str = "llama"
    messages: list
    max_tokens: int = 512
    temperature: float = 0.7

@app.post("/v1/chat/completions")
async def chat(req: ChatRequest):
    prompt = tokenizer.apply_chat_template(
        req.messages,
        tokenize=False,
        add_generation_prompt=True
    )
    
    input_ids = tokenizer.encode(prompt)
    
    inputs = [
        httpclient.InferInput("input_ids", [len(input_ids)], "INT32"),
        httpclient.InferInput("input_lengths", [1], "INT32"),
        httpclient.InferInput("request_output_len", [1], "INT32"),
    ]
    inputs[0].set_data_from_numpy(np.array(input_ids, dtype=np.int32))
    inputs[1].set_data_from_numpy(np.array([len(input_ids)], dtype=np.int32))
    inputs[2].set_data_from_numpy(np.array([req.max_tokens], dtype=np.int32))
    
    result = client.infer("llama", inputs)
    output_ids = result.as_numpy("output_ids")[0][len(input_ids):]
    text = tokenizer.decode(output_ids, skip_special_tokens=True)
    
    return {
        "choices": [{"message": {"role": "assistant", "content": text}}]
    }

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)
EOF

python3 /workspace/openai_server.py &
```

***

## समस्या निवारण

### Engine Build OOM

```bash
# max_batch_size और max_num_tokens कम करें
trtllm-build \
    --checkpoint_dir /workspace/trt_checkpoints/llama-3.1-8b-fp16 \
    --output_dir /workspace/trt_engines/llama-3.1-8b-fp16 \
    --gemm_plugin float16 \
    --max_batch_size 8 \        # 32 से कम करें
    --max_input_len 2048 \      # 4096 से कम करें
    --max_seq_len 4096          # 8192 से कम करें
```

### Triton Server शुरू नहीं हो रहा

```bash
# लॉग्स जांचें
cat /workspace/triton.log

# इंजन फाइलें मौजूद हैं, सत्यापित करें
ls -la /workspace/trt_engines/llama-3.1-8b-fp16/

# GPU मेमोरी जांचें
nvidia-smi
```

### कम थ्रूपुट

```bash
# in-flight batching सक्षम करें और concurrency बढ़ाएँ
# उपलब्ध VRAM के आधार पर max_tokens_in_paged_kv_cache को tune करें
```

***

## Clore.ai GPUs पर प्रदर्शन बेंचमार्क

| मॉडल          | GPU         | क्वांटाइज़ेशन | थ्रूपुट (टोकन/सेकंड) |
| ------------- | ----------- | ------------- | -------------------- |
| Llama 3.1 8B  | RTX 4090    | FP16          | \~3,500              |
| Llama 3.1 8B  | RTX 4090    | INT4 AWQ      | \~6,200              |
| Llama 3.1 70B | 2x A100 80G | FP16          | \~1,800              |
| Mixtral 8x7B  | 2x RTX 4090 | INT8          | \~2,400              |

***

## अतिरिक्त संसाधन

* [TensorRT-LLM GitHub](https://github.com/NVIDIA/TensorRT-LLM)
* [Triton Inference Server](https://github.com/triton-inference-server/server)
* [NGC Container Registry](https://catalog.ngc.nvidia.com/)
* [TRT-LLM दस्तावेज़ीकरण](https://nvidia.github.io/TensorRT-LLM/)
* [AWQ क्वांटाइजेशन](https://github.com/mit-han-lab/llm-awq)

***

*Clore.ai पर TensorRT-LLM उत्पादन LLM serving के लिए सर्वोत्तम विकल्प है, जहाँ थ्रूपुट और latency महत्वपूर्ण हैं। सरल सेटअप के लिए, vLLM guide देखें।*

***

## Clore.ai GPU अनुशंसाएँ

{% hint style="warning" %}
**Clore.ai marketplace पर multi-GPU 80GB-class rigs सूचीबद्ध नहीं हैं।** आज सूचीबद्ध सबसे बड़े boxes 4× RTX PRO 6000 Blackwell (प्रत्येक 96GB, कुल 380GB) और 8–11× RTX 5090 (प्रत्येक 32GB) हैं। A100 / H200 / B200 क्षमता [bare metal](https://clore.ai/bare-metal) के रूप में अनुरोध पर बेची जाती है। देखें [GPU मूल्य और उपलब्धता](/guides/guides_v2-hi/getting-started/pricing.md) किसी deployment का आकार तय करने से पहले।
{% endhint %}

| उपयोग-प्रकरण       | अनुशंसित GPU    | Clore.ai पर अनुमानित लागत                 |
| ------------------ | --------------- | ----------------------------------------- |
| विकास/परीक्षण      | RTX 3090 (24GB) | $0.07–0.21/gpu/hr                         |
| प्रोडक्शन इन्फरेंस | RTX 4090 (24GB) | $0.14–0.42/gpu/hr                         |
| बड़े मॉडल (70B+)   | A100 80GB       | [bare metal](https://clore.ai/bare-metal) |

> 💡 इस गाइड के सभी उदाहरण [Clore.ai](https://clore.ai/marketplace) GPU servers पर तैनात किए जा सकते हैं। उपलब्ध GPUs ब्राउज़ करें और घंटे के हिसाब से किराए पर लें — कोई प्रतिबद्धता नहीं, पूर्ण root access.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-hi/gpu-devops/tensorrt-llm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
